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

nasa / trick / 14387041328

10 Apr 2025 05:52PM UTC coverage: 55.877% (-0.06%) from 55.933%
14387041328

Pull #1871

github

web-flow
Merge 3ba8d8b01 into 46b481741
Pull Request #1871: Fix several ICG class template bugs

12308 of 22027 relevant lines covered (55.88%)

84508.07 hits per line

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

93.24
/trick_source/sim_services/MemoryManager/MemoryManager.cpp
1
#include <dlfcn.h>
2
#include <stdlib.h>
3
#include "trick/MemoryManager.hh"
4
#include "trick/ClassicCheckPointAgent.hh"
5
// Global pointer to the (singleton) MemoryManager for the C language interface.
6
Trick::MemoryManager * trick_MM = NULL;
7

8
// CLASS VARIABLE INITIALIZATION
9
int Trick::MemoryManager::instance_count = 0;
10
bool Trick::MemoryManager::restore_stls_default = true;
11

12
// CONSTRUCTOR
13
Trick::MemoryManager::MemoryManager()
632✔
14
{
15

16

17
    // The MemoryManager is a singleton. That is only one instance of it is allowed.
18
    if (instance_count != 0) {
623✔
19
        throw std::logic_error("Only one instance of the Memory Manager is allowed.");
1✔
20
    }
21
    instance_count ++;
622✔
22

23
    debug_level = 0;
622✔
24
    hexfloat_checkpoint = 0;
622✔
25
    reduced_checkpoint  = 1;
622✔
26
    resetting_memory = false;
622✔
27
    expanded_arrays  = 0;
622✔
28
    // start counter at 100mil.  This (hopefully) ensures all alloc'ed ids are after external variables.
29
    alloc_info_map_counter = 100000000 ;
622✔
30
    // start counter at 0.  This forces extern vars to appear in front of actual allocations in checkpoint.
31
    extern_alloc_info_map_counter = 0 ;
622✔
32
    pthread_mutex_init(&mm_mutex, NULL);
622✔
33

34
    defaultCheckPointAgent = new ClassicCheckPointAgent( this);
622✔
35
    defaultCheckPointAgent->set_reduced_checkpoint( reduced_checkpoint);
622✔
36
    defaultCheckPointAgent->set_hexfloat_checkpoint( hexfloat_checkpoint);
622✔
37
    defaultCheckPointAgent->set_debug_level( debug_level);
622✔
38

39
    currentCheckPointAgent = defaultCheckPointAgent;
622✔
40

41
    dlhandles.push_back(dlopen( NULL, RTLD_LAZY)) ;
622✔
42

43
    local_anon_var_prefix = "trick_anon_local_";
622✔
44
    extern_anon_var_prefix = "trick_anon_extern_";
622✔
45

46
    primitive_types.insert(std::string("char")) ;
622✔
47
    primitive_types.insert(std::string("unsigned char")) ;
622✔
48
    primitive_types.insert(std::string("short")) ;
622✔
49
    primitive_types.insert(std::string("unsigned short")) ;
622✔
50
    primitive_types.insert(std::string("int")) ;
622✔
51
    primitive_types.insert(std::string("unsigned int")) ;
622✔
52
    primitive_types.insert(std::string("long")) ;
622✔
53
    primitive_types.insert(std::string("unsigned long")) ;
622✔
54
    primitive_types.insert(std::string("long long")) ;
622✔
55
    primitive_types.insert(std::string("unsigned long long")) ;
622✔
56
    primitive_types.insert(std::string("double")) ;
622✔
57
    primitive_types.insert(std::string("float")) ;
622✔
58
    primitive_types.insert(std::string("bool")) ;
622✔
59
    // add stdint.h types
60
    primitive_types.insert(std::string("int8_t")) ;
622✔
61
    primitive_types.insert(std::string("uint8_t")) ;
622✔
62
    primitive_types.insert(std::string("int16_t")) ;
622✔
63
    primitive_types.insert(std::string("uint16_t")) ;
622✔
64
    primitive_types.insert(std::string("int32_t")) ;
622✔
65
    primitive_types.insert(std::string("uint32_t")) ;
622✔
66
    primitive_types.insert(std::string("int64_t")) ;
622✔
67
    primitive_types.insert(std::string("uint64_t")) ;
622✔
68

69
    trick_MM = this;
622✔
70
    return ;
622✔
71
}
72

73
Trick::MemoryManager::~MemoryManager() {
621✔
74

75
    ALLOC_INFO_MAP::iterator ait ;
621✔
76

77
    if (instance_count > 0) {
621✔
78
        instance_count --;
621✔
79
    }
80

81
    delete defaultCheckPointAgent ;
621✔
82

83
    for ( ait = alloc_info_map.begin() ; ait != alloc_info_map.end() ; ++ait ) {
7,533✔
84
        ALLOC_INFO * ai_ptr = (*ait).second ;
6,912✔
85
        if (ai_ptr->stcl == TRICK_LOCAL) {
6,912✔
86
            if ( ai_ptr->alloc_type == TRICK_ALLOC_MALLOC ) {
2,230✔
87
                free((char *)ai_ptr->start - ai_ptr->sentinel_bytes) ;
1,587✔
88
            } else if ( ai_ptr->alloc_type == TRICK_ALLOC_NEW ) {
643✔
89
                io_src_delete_class( ai_ptr );
29✔
90
            }
91
        }
92
        if (ai_ptr->name) { free(ai_ptr->name); }
6,912✔
93
        if (ai_ptr->user_type_name) { free(ai_ptr->user_type_name); }
6,912✔
94
        free(ai_ptr) ;
6,912✔
95
    }
96
    alloc_info_map.clear() ;
621✔
97
}
621✔
98

99
#include <sstream>
100
void Trick::MemoryManager::emitMessage( std::string message) {
8✔
101
    std::cerr << "MemoryManager:" << message << std::endl;
8✔
102
    std::cerr.flush();
8✔
103
}
8✔
104

105
void Trick::MemoryManager::emitError( std::string message) {
8✔
106
    std::stringstream ss;
8✔
107
    ss << "ERROR:" << message << std::endl;
8✔
108
    emitMessage( ss.str() );
8✔
109
}
8✔
110

111
void Trick::MemoryManager::emitWarning( std::string message) {
×
112
    std::stringstream ss;
×
113
    ss << "WARNING:" << message << std::endl;
×
114
    emitMessage( ss.str() );
×
115
}
×
116

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