• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nasa / trick / 21044401961

15 Jan 2026 07:54PM UTC coverage: 55.668% (-0.2%) from 55.875%
21044401961

Pull #1965

github

web-flow
Merge 971139f89 into 3fa559ade
Pull Request #1965: 1964 methods return size one pointers

90 of 127 new or added lines in 3 files covered. (70.87%)

1023 existing lines in 21 files now uncovered.

12571 of 22582 relevant lines covered (55.67%)

306300.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.18
/trick_source/sim_services/MemoryManager/MemoryManager_get_attributes_for_address.cpp
1
#include "trick/MemoryManager.hh"
2
#include "trick/ClassicCheckPointAgent.hh"
3
#include "trick/AttributesUtils.hh"
4

5
static int getCompositeSubReference(
9✔
6
    size_t addrValue,
7
    ATTRIBUTES &attrOut,  
8
    size_t structAddrValue,  
9
    ATTRIBUTES *structAttr)
10
{
11
    // Make sure the address of interset is greater than starting address of this structure
12
    if(addrValue < structAddrValue) {
9✔
NEW
13
        return 1;
×
14
    }
15

16
    size_t addrOffsetFromStruct = addrValue - structAddrValue;
9✔
17

18
    // Find the structure member that corresponds to the reference address.
19
    ATTRIBUTES * retAttr = Trick::AttributesUtils::find_member_by_offset(structAttr, addrOffsetFromStruct);
9✔
20

21
    // If the name field of the returned attribute is empty, this means that the ATTRIBUTES don't contain a description 
22
    // for the specific address, i.e. it was **'d out. Returne a void pointer attribute with the offset from this 
23
    // structure
24
    if (retAttr->name[0] == '\0')
9✔
25
    {
NEW
26
        attrOut = ATTRIBUTES();
×
NEW
27
        attrOut.type = TRICK_VOID_PTR;
×
NEW
28
        attrOut.size = sizeof(void *);
×
NEW
29
        attrOut.offset = addrOffsetFromStruct;
×
NEW
30
        attrOut.num_index = 1;
×
NEW
31
        attrOut.index[0].size = 0;
×
32

NEW
33
        return 0;
×
34
    }
35

36
    // If the found attribute is a primitive type
37
    if (retAttr->type != TRICK_STRUCTURED)
9✔
38
    {
39
        // If the reference address is non-array or a pointer, return the primitive type but unconstrained pointer
40
        if (retAttr->index[0].size == 0)
5✔
41
        {
42
            if (retAttr->num_index == 0)
3✔
43
            {
44
                // Scalar
45
                attrOut = *retAttr;
3✔
46
                attrOut.num_index = 1;
3✔
47
                attrOut.index[0].size = 1;
3✔
48
            } else {
49
                // Pointer
NEW
50
                attrOut = *retAttr;
×
NEW
51
                attrOut.num_index = 1;
×
NEW
52
                attrOut.index[0].size = 0;
×
53
            }
54
            return 0;
3✔
55
        }
56

57
        // This is an array type. Calculate the offset from the address to the end of the attribute
58
        // Then, calculate the remaining elements in the array as a single value.
59
        // Calculate the maximum offset of this attribute.
60
        size_t max_offset = retAttr->size;
2✔
61
        for (int ii = 0; ii < retAttr->num_index; ii++)
5✔
62
        {
63
            if (retAttr->index[ii].size > 0)
3✔
64
            {
65
                max_offset *= retAttr->index[ii].size;
3✔
66
            }
67
        }
68

69
        size_t addrOffsetFromAttr = addrValue - (structAddrValue + retAttr->offset);
2✔
70

71
        attrOut = *retAttr;
2✔
72
        attrOut.num_index = 1;
2✔
73
        attrOut.index[0].size = (max_offset - addrOffsetFromAttr) / retAttr->size;
2✔
74

75
        return 0;
2✔
76
    }
77
    
78
    // If it is a reference, do nothing and return */
79
    if ((retAttr->mods & 1) == 1)
4✔
80
    { 
NEW
81
        attrOut = *retAttr;
×
82
        
NEW
83
        return 0;
×
84
    }
85

86
    // If attribute is an unarrayed struct, continue to call getCompositeSubReference
87
    if (retAttr->num_index == 0)
4✔
88
    {
89
        int ret = getCompositeSubReference(addrValue, attrOut, structAddrValue + retAttr->offset, (ATTRIBUTES *)retAttr->attr);
4✔
90

91
        if (ret != 0)
4✔
92
        {
NEW
93
            return 1; // ERROR.
×
94
        }
95
        return 0;
4✔
96
    }
97

98
    // If the member is a pointer, do nothing and return
NEW
99
    if (retAttr->index[0].size == 0)
×
100
    {
NEW
101
        return 0;
×
102
    }
103

NEW
104
    size_t addrOffsetFromAttr = addrValue - (structAddrValue + retAttr->offset);
×
105

NEW
106
    int ret = getCompositeSubReference(addrValue, attrOut, addrOffsetFromAttr, (ATTRIBUTES *)retAttr->attr);
×
107

NEW
108
    if (ret != 0)
×
109
    {
NEW
110
        return 1; // ERROR
×
111
    }
112

NEW
113
    return 0;
×
114
}
115

116
/**
117
 @par Detailed Description:
118
 */
119
void Trick::MemoryManager::get_attributes_for_address(void *address, ATTRIBUTES &attrOut)
165✔
120
{
121
    /** Find the allocation that contains the pointer-address. */
122
    ALLOC_INFO *alloc_info = get_alloc_info_of(address);
165✔
123

124
    if (alloc_info != NULL)
165✔
125
    {
126
        // Found the allocation. Look for the attribute that pertains to it.
127
        size_t addrValue = reinterpret_cast<size_t>(address);
151✔
128
        size_t allocAddrStart = reinterpret_cast<size_t>(alloc_info->start);
151✔
129
        size_t alloc_elem_size = alloc_info->size;
151✔
130
        size_t alloc_elem_index = (addrValue - allocAddrStart) / alloc_elem_size;
151✔
131
        size_t misalignment = (addrValue - allocAddrStart) % alloc_elem_size;
151✔
132

133
        if (alloc_info->type == TRICK_STRUCTURED)
151✔
134
        {
135
            // The allocation is not a primitive type, traverse the structure unil the attribute is found or an 
136
            // anonymous pointer is returned
137
            getCompositeSubReference(addrValue,
10✔
138
                                     attrOut,
139
                                     allocAddrStart + (alloc_elem_index * alloc_elem_size),
5✔
140
                                     alloc_info->attr);
141
        }
142
        else
143
        {
144
            // Primitive allocation is found, compute the remaining number of elements from the current address
145
            size_t allocAddrEnd = reinterpret_cast<size_t>(alloc_info->end)+1;
146✔
146
            size_t max_alloc_index = (allocAddrEnd - allocAddrStart) / alloc_elem_size;
146✔
147
            if(alloc_info->attr) {
146✔
148
               // If there's an attribute for this allocation for some reason, populate the return structure.
149
               attrOut = *(alloc_info->attr);
8✔
150
            }
151
            attrOut.num_index = 1;
146✔
152
            attrOut.index[0].size = max_alloc_index - alloc_elem_index;
146✔
153
        }
154
    }
155
    else
156
    {
157
        // No allocation found, num_index = 0 should indicate that it's not found. On the swig, side, the calling
158
        // function will set num_index to 1 anyway and it becomes a generic pointer according to swig/python.
159
        attrOut = ATTRIBUTES();
14✔
160
    }
161
}
165✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc