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

nasa / trick / 24529915492

16 Apr 2026 07:32PM UTC coverage: 55.99% (+0.2%) from 55.802%
24529915492

push

github

web-flow
1964 methods return size one pointers (#1965)

* Fixed issues pertaining to swig access and printing of pointers returned by methods in classes.

- Fixed issue determining single vs double precision printing of a floating-point variable

- Added a function to TMM to get attributes of an address and also the remaining offset of from the start of those attributes

- Refactored several attribute related functions to AttributeUtils (Hong Chen)

- Added tests to SIM_test_ip to test printing of pointers of various dimensions pointing to various parts of various variables

- Updated swig_int_typemap to use the new attributes getter for units specification and insight into the memory the returned variables and pointers pointer to.

- Removed -std=c++11 for Trick to go full minimum required standard of c++14 (Hong Chen)

* Partially addressed MR comments

* Format using PR 2011 clang-format with BreakBeforeBraces: Allman

* Remove ununsed skipIndex and commented code

* Remove space added by clang-format

* Change swig_double to use default member initialization. Removed unnecessary assignment in swig_int_typemap. Set remainingOffset after checking if traverse call succeeded. Explicitly cast isFloat to int for array indexing.

173 of 205 new or added lines in 5 files covered. (84.39%)

2 existing lines in 2 files now uncovered.

12679 of 22645 relevant lines covered (55.99%)

309062.91 hits per line

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

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

5
#include <string.h>
6

7
static int getCompositeSubReference(
2,199✔
8
    size_t addrValue,
9
    ATTRIBUTES& attrOut,
10
    size_t structAddrValue,
11
    ATTRIBUTES* structAttr,
12
    size_t& remainingOffset)
13
{
14
    if (addrValue < structAddrValue)
2,199✔
15
    {
NEW
16
        return 1;
×
17
    }
18

19
    size_t addrOffsetFromStruct = addrValue - structAddrValue;
2,199✔
20

21
    Trick::AttributesUtils::TraversalResult traversalResult;
2,199✔
22

23
    int ret = Trick::AttributesUtils::traverse_for_offset(addrOffsetFromStruct, structAttr, traversalResult);
2,199✔
24

25
    if (ret != 0)
2,199✔
26
    {
NEW
27
        return 1;
×
28
    }
29

30
    remainingOffset = traversalResult.offset_from_found_attr;
2,199✔
31

32
    // Handle anonymous/**'d out members
33
    if (traversalResult.is_in_anonymous_member)
2,199✔
34
    {
NEW
35
        attrOut = ATTRIBUTES();
×
NEW
36
        attrOut.type = TRICK_VOID_PTR;
×
NEW
37
        attrOut.size = sizeof(void*);
×
NEW
38
        attrOut.offset = addrOffsetFromStruct;
×
NEW
39
        attrOut.num_index = 1;
×
NEW
40
        attrOut.index[0].size = 0;
×
41

NEW
42
        return 0;
×
43
    }
44

45
    ATTRIBUTES* retAttr = traversalResult.found_attr;
2,199✔
46

47
    // If the found attribute is a primitive type
48
    if (retAttr->type != TRICK_STRUCTURED)
2,199✔
49
    {
50
        // Scalar or pointer - return as unconstrained pointer
51
        if (retAttr->index[0].size == 0)
1,245✔
52
        {
53
            attrOut = *retAttr;
11✔
54
            attrOut.num_index = 1;
11✔
55
            attrOut.index[0].size = (retAttr->num_index == 0) ? 1 : 0;
11✔
56
            return 0;
11✔
57
        }
58

59
        attrOut = *retAttr;
1,234✔
60
        return 0;
1,234✔
61
    }
62

63
    // If it is a reference type, do nothing and return
64
    if ((retAttr->mods & 1) == 1)
954✔
65
    {
NEW
66
        attrOut = *retAttr;
×
NEW
67
        return 0;
×
68
    }
69

70
    // If attribute is an unarrayed struct, continue to call getCompositeSubReference
71
    if (retAttr->num_index == 0)
954✔
72
    {
73
        return getCompositeSubReference(addrValue, attrOut, structAddrValue + retAttr->offset, (ATTRIBUTES*)retAttr->attr, remainingOffset);
954✔
74
    }
75

76
    // If the member is a pointer, do nothing and return
NEW
77
    if (retAttr->index[0].size == 0)
×
78
    {
NEW
79
        attrOut = *retAttr;
×
NEW
80
        return 0;
×
81
    }
82

83
    // Arrayed struct - recurse into the element
NEW
84
    return getCompositeSubReference(addrValue, attrOut,
×
NEW
85
        structAddrValue + retAttr->offset + traversalResult.offset_from_found_attr,
×
NEW
86
        (ATTRIBUTES*)retAttr->attr, remainingOffset);
×
87
}
88

89
/**
90
 * Given an address, populate the attributes instance describing the properties of the address and any
91
 * remaining offset to the address so that the attributes pertain to the starting address of that attribute
92
 * and the offset is some array element or subcomponent within that attribute.
93
 * @param address pointer to the address of interest
94
 * @param attrOut reference to the ATTRIBUTES instance to be populated
95
 * @param remainingOffset reference to the size_t to be populate with the number of bytes to the start of
96
 *                        the attributes returned. (i.e. attrStartAddr = address - remainingOffset )
97
 */
98
void Trick::MemoryManager::get_attributes_for_address(void* address, ATTRIBUTES& attrOut, size_t& remainingOffset)
1,700✔
99
{
100
    if (address == nullptr)
1,700✔
101
    {
102
        attrOut = ATTRIBUTES();
42✔
103
        return;
42✔
104
    }
105

106
    /** Find the allocation that contains the pointer-address. */
107
    ALLOC_INFO* alloc_info = get_alloc_info_of(address);
1,658✔
108

109
    if (alloc_info != NULL)
1,658✔
110
    {
111
        // Found the allocation. Look for the attribute that pertains to it.
112
        size_t addrValue = reinterpret_cast<size_t>(address);
1,658✔
113
        size_t allocAddrStart = reinterpret_cast<size_t>(alloc_info->start);
1,658✔
114
        remainingOffset = addrValue - allocAddrStart;
1,658✔
115
        size_t alloc_elem_size = alloc_info->size;
1,658✔
116
        size_t alloc_elem_index = (addrValue - allocAddrStart) / alloc_elem_size;
1,658✔
117
        // size_t misalignment = (addrValue - allocAddrStart) % alloc_elem_size;
118

119
        if (alloc_info->type == TRICK_STRUCTURED)
1,658✔
120
        {
121
            // The allocation is not a primitive type, traverse the structure unil the attribute is found or an
122
            // anonymous pointer is returned
123
            getCompositeSubReference(addrValue, attrOut, allocAddrStart + (alloc_elem_index * alloc_elem_size),
1,245✔
124
                alloc_info->attr, remainingOffset);
125
        }
126
        else
127
        {
128
            // Primitive allocation is found, compute the remaining number of elements from the current address
129
            size_t allocAddrEnd = reinterpret_cast<size_t>(alloc_info->end) + 1;
413✔
130
            size_t offsetFromStart = addrValue - allocAddrStart;
413✔
131
            // size_t max_alloc_index = (allocAddrEnd - allocAddrStart) / alloc_elem_size;
132
            if (alloc_info->attr && alloc_info->type != TRICK_ENUMERATED)
413✔
133
            {
134
                // If there's an attribute for this allocation for some reason, populate the return structure.
NEW
135
                attrOut = *(alloc_info->attr);
×
136
            }
137
            else
138
            {
139
                attrOut.type = alloc_info->type;
413✔
140
                if (alloc_info->name)
413✔
141
                {
142
                    attrOut.name = strdup(alloc_info->name);
6✔
143
                }
144
                attrOut.stl_type = TRICK_STL_UNKNOWN;
413✔
145
                attrOut.num_index = alloc_info->num_index;
413✔
146
                for (int ii = 0; ii < alloc_info->num_index; ++ii)
1,173✔
147
                {
148
                    attrOut.index[ii].size = alloc_info->index[ii];
760✔
149
                }
150
            }
151
        }
152
    }
153
    else
154
    {
155
        // No allocation found, num_index = 0 should indicate that it's not found. On the swig, side, the calling
156
        // function will set num_index to 1 anyway and it becomes a generic pointer according to swig/python.
NEW
157
        attrOut = ATTRIBUTES();
×
158
    }
159
}
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