• 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

68.85
/trick_source/sim_services/CheckPointAgent/ClassicCheckPointAgent.cpp
1
#include "trick/ClassicCheckPointAgent.hh"
2

3
#include "trick/AttributesUtils.hh"
4
#include "trick/ChkPtParseContext.hh"
5
#include "trick/MemoryManager.hh"
6
#include "trick/bitfield_proto.h"
7
#include "trick/io_alloc.h"
8
#include "trick/message_proto.h"
9
#include "trick/message_type.h"
10
#include "trick/parameter_types.h"
11
#include "trick/wcs_ext.h"
12

13
#include <iomanip>
14
#include <iostream>
15
#include <math.h>
16
#include <sstream>
17
#include <stdlib.h>
18
#include <string.h>
19
#include <string>
20

21
const int Trick::ClassicCheckPointAgent::array_elements_per_line[TRICK_NUMBER_OF_TYPES] = {
22
     5, /** TRICK_VOID (for pointers) */
23
    20, /** TRICK_CHARACTER */
24
    20, /** TRICK_UNSIGNED_CHARACTER */
25
     1, /** TRICK_STRING */
26
    10, /** TRICK_SHORT */
27
    10, /** TRICK_UNSIGNED_SHORT */
28
     5, /** TRICK_INTEGER */
29
     5, /** TRICK_UNSIGNED_INTEGER */
30
     5, /** TRICK_LONG */
31
     5, /** TRICK_UNSIGNED_LONG */
32
     5, /** TRICK_FLOAT */
33
     5, /** TRICK_DOUBLE */
34
     5, /** TRICK_BITFIELD */
35
     5, /** TRICK_UNSIGNED_BITFIELD */
36
     5, /** TRICK_LONG_LONG */
37
     5, /** TRICK_UNSIGNED_LONG_LONG */
38
     5, /** TRICK_FILE_PTR */
39
    10, /** TRICK_BOOLEAN */
40
    10, /** TRICK_WCHAR */
41
     1, /** TRICK_WSTRING */
42
     5, /** TRICK_VOID_PTR */
43
    10, /** TRICK_ENUMERATED */
44
     5, /** TRICK_STRUCTURED (for pointers) */
45
     5, /** TRICK_OPAQUE_TYPE */
46
     1  /** TRICK_STL */
47
};
48

49
static constexpr size_t REFNAME_MAXSIZE = 256;
50

51
// MEMBER FUNCTION
52
Trick::ClassicCheckPointAgent::ClassicCheckPointAgent( Trick::MemoryManager *MM) {
634✔
53

54
   mem_mgr = MM;
634✔
55
   reduced_checkpoint = 1;
634✔
56
   hexfloat_checkpoint = 0;
634✔
57
   debug_level = 0;
634✔
58
}
634✔
59

60
// MEMBER FUNCTION
61
Trick::ClassicCheckPointAgent::~ClassicCheckPointAgent() { }
1,266✔
62

63
// MEMBER FUNCTION
64
bool Trick::ClassicCheckPointAgent::input_perm_check(ATTRIBUTES * attr) {
134,525✔
65
    return (attr->io & TRICK_CHKPNT_INPUT) ;
134,525✔
66
}
67

68
bool Trick::ClassicCheckPointAgent::output_perm_check(ATTRIBUTES * attr) {
181,837✔
69
    return (attr->io & TRICK_CHKPNT_OUTPUT) ;
181,837✔
70
}
71

72
// MEMBER FUNCTION
73
std::string Trick::ClassicCheckPointAgent::left_side_name() {
62,274✔
74

75
    std::string name ;
124,548✔
76
    int ii;
77
    int n_elements = leftside_stack.size();
62,274✔
78

79
    for (ii = 0; ii < n_elements ; ii++) {
241,370✔
80

81
        VarNameElement & element = leftside_stack[ii];
179,096✔
82

83
        switch( element.type) {
179,096✔
84

85
            case BASE_NAME: {
62,274✔
86
                name = element.name;
62,274✔
87
            } break;
62,274✔
88

89
            case ELEM_NAME: {
67,007✔
90
                name += '.' + element.name;
67,007✔
91
            } break;
67,007✔
92

93
            case ARRAY_INDEX: {
49,815✔
94
                std::stringstream index_string;
99,630✔
95
                index_string << element.index;
49,815✔
96
                name += '[';
49,815✔
97
                name += index_string.str();
49,815✔
98
                name += ']';
49,815✔
99
            } break;
49,815✔
100

101
            default: {
×
102
                message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Left side name-stack appears to be corrupted.\n") ;
×
103
            }
104
        }
105
    }
106
    return( name);
124,548✔
107
}
108

109
// MEMBER FUNCTION
110
void Trick::ClassicCheckPointAgent::write_decl(std::ostream& chkpnt_os, ALLOC_INFO *info) {
2,837✔
111

112
    const char *type_spec;
113

114
    // Safety check for NULL info pointer or NULL name
115
    if (info == NULL || info->name == NULL) {
2,837✔
116
        return;
120✔
117
    }
118

119
    type_spec = trickTypeCharString(info->type, info->user_type_name);
2,717✔
120

121
    if (info->stcl == TRICK_EXTERN) {
2,717✔
122
        chkpnt_os << "// extern ";
×
123
    }
124

125
    if ( info->num_index == 0 ) {
2,717✔
126

127
        chkpnt_os << type_spec << " " << info->name << ";\n";
95✔
128

129
    } else if ((info->num_index > 0) && (info->num_index <= TRICK_MAX_INDEX)) {
2,622✔
130
        int ii;
131

132
        chkpnt_os << type_spec;
2,622✔
133

134
        ii = info->num_index-1;
2,622✔
135
        while ((ii >= 0) && (info->index[ii] == 0)) {
2,735✔
136
            chkpnt_os << "*";
113✔
137
            ii --;
113✔
138
        }
139

140
        chkpnt_os << " " << info->name ;
2,622✔
141

142
        ii = 0;
2,622✔
143
        while ((ii < info->num_index) && (info->index[ii] != 0)) {
5,243✔
144
            chkpnt_os << "[" << info->index[ii] << "]" ;
2,621✔
145
            ii ++;
2,621✔
146
        }
147
          chkpnt_os << ";" << std::endl;
2,622✔
148

149
    } else {
150
        // ERROR - num_index cant be negative.
151
    }
152
}
153

154
// STATIC FUNCTION
155
/*
156
   Given an address, that is within the bounds of a composite
157
   object (i.e., a struct or class instance), store the corresponding sub-name
158
   in reference_name buffer and return.
159

160
   A return value of 1 indicates an error occured. A return value of 0 indicates
161
   success.
162

163
   The following BNF production describes a valid sub-reference:
164

165
   <sub_reference> --> ""
166
                     | "+" + <offset>
167
                     | "[" + <index>+ "]" + <sub_reference>
168
                     | "." + <member_name> + <sub_reference>
169

170
   <offset> is an integer. It is the the reference offset minus the offset of
171
   the last data member.
172
   <index> is an integer. It is an array index.
173
   <member_name> is a name of a member of the given composite type.
174
*/
175

176
static int getCompositeSubReference(
753✔
177
    void* reference_address, /* Address we are looking for */
178
    ATTRIBUTES** left_type, /* Attributes of type we are looking for */
179
    void* structure_address, /* Address of struct we are in */
180
    ATTRIBUTES* A, /* Attributes of current struct we are in */
181
    char* reference_name /* destination buffer of composite subreference */
182
)
183
{
184
    char* rAddr = (char*)reference_address;
753✔
185
    char* sAddr = (char*)structure_address;
753✔
186

187
    // Validate addresses before computing offset (to avoid unsigned underflow)
188
    if (rAddr < sAddr)
753✔
189
    {
NEW
190
        message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Address to find is less than struct address.\\n");
×
NEW
191
        return 1;
×
192
    }
193

194
    size_t referenceOffset = (size_t)rAddr - (size_t)sAddr;
753✔
195

196
    Trick::AttributesUtils::TraversalResult traversalResult;
753✔
197
    int ret = Trick::AttributesUtils::traverse_for_offset(referenceOffset, A, traversalResult);
753✔
198

199
    if (ret != 0)
753✔
200
    {
NEW
201
        return 1; // Error
×
202
    }
203

204
    // Find the structure member that corresponds to the reference address.
205
    // If name is empty, we have failed.
206

207
    /******If failed to find member, set reference_name to offset only and return ****/
208
    if (traversalResult.is_in_anonymous_member)
753✔
209
    {
210
        if (referenceOffset == 0)
588✔
211
        {
212
            reference_name[0] = '\0';
578✔
213
        }
214
        else
215
        {
216
            snprintf(reference_name, REFNAME_MAXSIZE, " + %zu", referenceOffset);
10✔
217
        }
218
        return 0;
588✔
219
    }
220

221
    /******************************************************************************/
222

223
    ATTRIBUTES* Ai = traversalResult.found_attr;
165✔
224

225
    /* We found a member corresponding to the reference address, so print it's name. */
226
    snprintf(reference_name, REFNAME_MAXSIZE, ".%s", Ai->name);
165✔
227

228
    // If it's a primitive type with computed array indices
229
    if (Ai->type != TRICK_STRUCTURED && traversalResult.num_computed_indices > 0)
165✔
230
    {
231
        // Append array indices
NEW
232
        for (int j = 0; j < traversalResult.num_computed_indices; j++)
×
233
        {
234
            size_t len = strlen(reference_name);
×
NEW
235
            size_t rem = REFNAME_MAXSIZE - len;
×
NEW
236
            snprintf(&reference_name[len], rem, "[%d]", traversalResult.array_indices[j]);
×
237
        }
NEW
238
        return 0;
×
239
    }
240

241
    /******** TRICK_STRUCTURED ****************************************************/
242
    /* if it is a reference, do nothing and return */
243
    if (Ai->type == TRICK_STRUCTURED && (Ai->mods & 1) == 1)
165✔
244
    {
245
        return 0;
1✔
246
    }
247

248
    /* if member is an unarrayed struct, continue to call getCompositeSubReference.*/
249
    if (Ai->type == TRICK_STRUCTURED && Ai->num_index == 0)
164✔
250
    {
251
        /* if left_type specifies the current member, stop here */
252
        if ((left_type != NULL) && (*left_type != NULL) && (Ai->attr == (*left_type)->attr))
147✔
253
        {
UNCOV
254
            return 0;
×
255
        }
256

257
        char buf[REFNAME_MAXSIZE];
258
        ret = getCompositeSubReference(rAddr, left_type, sAddr + Ai->offset, (ATTRIBUTES*)Ai->attr, buf);
147✔
259

260
        if (ret == 0)
147✔
261
        {
262
            size_t len = strlen(reference_name);
147✔
263
            size_t rem = REFNAME_MAXSIZE - len;
147✔
264
            snprintf(&reference_name[len], rem, "%s", buf);
147✔
265
        }
266
        return ret;
147✔
267
    }
268

269
    /*** Member is an arrayed struct *********************************************/
270

271
    // If it's a structured type with array indices
272
    if (Ai->type == TRICK_STRUCTURED && traversalResult.num_computed_indices > 0)
17✔
273
    {
274
        // Append array indices
275
        for (int j = 0; j < traversalResult.num_computed_indices; j++)
3✔
276
        {
277
            size_t len = strlen(reference_name);
2✔
278
            size_t rem = REFNAME_MAXSIZE - len;
2✔
279
            snprintf(&reference_name[len], rem, "[%d]", traversalResult.array_indices[j]);
2✔
280
        }
281

282
        /* if left_type specifies the current member, stop here */
283
        if (left_type != NULL && *left_type != NULL && Ai->attr == (*left_type)->attr)
1✔
284
        {
NEW
285
            return 0;
×
286
        }
287

288
        /**** Go find the subreference for the arrayed struct member and append *********/
289

290
        // Recurse into the array element
291
        char buf[REFNAME_MAXSIZE];
292
        ret = getCompositeSubReference(rAddr, left_type, sAddr + Ai->offset + traversalResult.offset_from_found_attr,
2✔
293
            (ATTRIBUTES*)Ai->attr, buf);
1✔
294

295
        if (ret == 0)
1✔
296
        {
297
            size_t len = strlen(reference_name);
1✔
298
            size_t rem = REFNAME_MAXSIZE - len;
1✔
299
            snprintf(&reference_name[len], rem, "%s", buf);
1✔
300
        }
301
        return ret;
1✔
302
    }
303

304
    return 0;
16✔
305
}
306

307
// MEMBER FUNCTION
308
// Get the fully qualified varible name of the Allocation, given the address.
309

310
std::string Trick::ClassicCheckPointAgent::get_var_name( void* addr,
605✔
311
                                                         ATTRIBUTES* A,
312
                                                         void* struct_addr,
313
                                                         std::string name,
314
                                                         ATTRIBUTES** left_type) {
315
    char reference_name[REFNAME_MAXSIZE];
316
    int ret;
317
    std::string var_name;
1,210✔
318

319
    var_name = name;
605✔
320
    ret = getCompositeSubReference( addr, left_type, struct_addr, A, reference_name );
605✔
321

322
    if (ret == 0) {
605✔
323
        var_name += reference_name;
605✔
324
    } else {
325
          std::stringstream ss;
×
326
          ss << "Checkpoint Agent ERROR: Unable to create a subreference of variable \"" << name << "\"."
×
327
             << std::endl;
×
328
          message_publish(MSG_ERROR, ss.str().c_str() );
×
329
    }
330
    return (var_name);
1,210✔
331
}
332

333
// MEMBER FUNCTION
334
int Trick::ClassicCheckPointAgent::restore( std::istream* checkpoint_stream) {
24✔
335

336
    ChkPtParseContext* context = new ChkPtParseContext( mem_mgr, checkpoint_stream);
24✔
337
    int status = 0;
24✔
338

339
    if ( CCP_parse( context)) {
24✔
340
        status = 1;
×
341
    } else if ((context->bad_declaration_count > 0) ||
24✔
342
               (context->bad_assignment_count > 0)) {
24✔
343
        std::stringstream ss;
×
344
        ss << "Checkpoint Agent ERROR: " << context->bad_declaration_count << " invalid declaration(s) "
×
345
           << "and " << context->bad_assignment_count << " invalid assignment(s)."
×
346
           << std::endl;
×
347
        message_publish(MSG_ERROR, ss.str().c_str() );
×
348
        status = 1;
×
349
    }
350

351
    if (status) {
24✔
352
        std::stringstream ss;
×
353
        ss << "Checkpoint Agent ERROR: Checkpoint restore failed."
×
354
           << std::endl;
×
355
        message_publish(MSG_INFO, ss.str().c_str() );
×
356
    }
357
    delete context ;
24✔
358
    return (status);
24✔
359
}
360

361
// MEMBER FUNCTION
362
int Trick::ClassicCheckPointAgent::is_nil_valued( void* address,
71,941✔
363
                                                  ATTRIBUTES* attr,
364
                                                  int curr_dim,
365
                                                  int offset
366
                                                ) {
367

368
    char* test_addr;
369
    int remaining_dimensions = attr->num_index - curr_dim;
71,941✔
370

371
    /** @par Detailed Description: */
372

373
    /** @par
374
        If we're referencing a singleton then calculate the test-address
375
        from the (base) address, the offset and the data-type. Then
376
        test that calculated address (with the given type) for nil.
377
        If it's nil return 1, otherwise return 0.
378
     */
379
    if (remaining_dimensions ==0) {
71,941✔
380

381
        switch (attr->type) {
67,542✔
382
           case TRICK_CHARACTER :
7,280✔
383
           case TRICK_UNSIGNED_CHARACTER :
384
               test_addr = (char*)address + offset * sizeof(char);
7,280✔
385
               if (*(char*)test_addr == '\0') return(1);
7,280✔
386
               break;
53✔
387
           case TRICK_BOOLEAN:
14,386✔
388
               test_addr = (char*)address + offset * sizeof(bool);
14,386✔
389
               if (*(bool*)test_addr == false) return(1);
14,386✔
390
               break;
2,789✔
391
           case TRICK_WCHAR :
×
392
               test_addr = (char*)address + offset * sizeof(wchar_t);
×
393
               if (*(wchar_t*)test_addr == 0) return(1);
×
394
               break;
×
395
           case TRICK_SHORT :
2,379✔
396
           case TRICK_UNSIGNED_SHORT :
397
               test_addr = (char*)address + offset * sizeof(short);
2,379✔
398
               if (*(short*)test_addr == 0) return(1);
2,379✔
399
               break;
2,001✔
400
           case TRICK_INTEGER :
13,933✔
401
           case TRICK_UNSIGNED_INTEGER :
402
               test_addr = (char*)address + offset * sizeof(int);
13,933✔
403
               if (*(int*)test_addr == 0) return(1);
13,933✔
404
               break;
7,364✔
405
           case TRICK_ENUMERATED :
402✔
406
               if ((size_t)attr->size == sizeof(int)) {
402✔
407
                   test_addr = (char*)address + offset * sizeof(int);
402✔
408
                   if (*(int*)test_addr == 0) return(1);
402✔
409
               } else if ((size_t)attr->size == sizeof(short)) {
×
410
                   test_addr = (char*)address + offset * sizeof(short);
×
411
                   if (*(short*)test_addr == 0) return(1);
×
412
               } else {
413
                   return(-1);
×
414
               }
415
               break;
84✔
416
           case TRICK_LONG :
103✔
417
           case TRICK_UNSIGNED_LONG :
418
               test_addr = (char*)address + offset * sizeof(long);
103✔
419
               if (*(long*)test_addr == 0) return(1);
103✔
420
               break;
51✔
421
           case TRICK_FLOAT :
2✔
422
               test_addr = (char*)address + offset * sizeof(float);
2✔
423
               if (fpclassify( *(float*)test_addr) == FP_ZERO) return(1);
2✔
424
               break;
2✔
425
           case TRICK_DOUBLE :
7,969✔
426
               test_addr = (char*)address + offset * sizeof(double);
7,969✔
427
               if (fpclassify( *(double*)test_addr) == FP_ZERO) return(1);
7,969✔
428
               break;
5,089✔
429
           case TRICK_LONG_LONG :
9,967✔
430
           case TRICK_UNSIGNED_LONG_LONG :
431
               test_addr = (char*)address + offset * sizeof(long long);
9,967✔
432
               if (*(long long*)test_addr == 0) return(1);
9,967✔
433
               break;
914✔
434
           case TRICK_BITFIELD :
×
435
           case TRICK_UNSIGNED_BITFIELD :
436
               test_addr = (char*)address + offset * (size_t)attr->size;
×
437
               if (attr->size == sizeof(int)) {
×
438
                   if (*(int*)test_addr == 0) return(1);
×
439
               } else if (attr->size == sizeof(short)) {
×
440
                   if (*(short*)test_addr == 0) return(1);
×
441
               } else if (attr->size == sizeof(char)) {
×
442
                   if (*(char*)test_addr == 0) return(1);
×
443
               } else {
444
                   message_publish(MSG_ERROR, "Checkpoint Agent INTERNAL ERROR:\n"
×
445
                                              "Unhandled bitfield struct size (%d) in bitfield assignment.\n", attr->size) ;
446
                   return(-1);
×
447
               }
448
               break;
×
449
           case TRICK_FILE_PTR :
×
450
               // FIXME
451
               return(0);
×
452
               break;
453
           case TRICK_STRING :
8,597✔
454
               test_addr = (char*)address + offset * sizeof(void*);
8,597✔
455
               if (*(std::string*)test_addr == "") return(1);
8,597✔
456
               break;
8,065✔
457
           case TRICK_STL :
2,524✔
458
               // Can't test properly, always return 0 to indicate the STL is not empty.
459
               return(0);
2,524✔
460
               break;
461
           default :
×
462
               message_publish(MSG_ERROR, "Checkpoint Agent file %s: Unhandled Type (%d).\n", __FILE__, attr->type) ;
×
463
               return(-1);
×
464
               break;
465
        }
466
        return(0);
26,412✔
467

468
    /** @par
469
        If on the otherhand we are referencing an array, then we must consider two cases.
470
     */
471
    } else if (remaining_dimensions > 0) {
4,399✔
472
       int curr_dim_size;
473
       curr_dim_size = attr->index[curr_dim].size ;
4,399✔
474

475
       /**  @par
476
            If the array is unconstrained (i.e., it's a pointer) then we just need to check
477
            whether the pointer is NULL.
478
        */
479
       if ( curr_dim_size == 0) {
4,399✔
480
           test_addr = ((char*)address) + (offset*sizeof(void *));
1,846✔
481
           if (*(char**)test_addr == NULL) return(1);
1,846✔
482

483
       /** @par
484
           If the array (at this dimension) is constrained (i.e., it's a fixed array )
485
           then it is nil if and only if each of it's sub-elements (at the next dimension,
486
           which can themselves be arrays) are nil. So, for each of the elements in current
487
           dimension, we recursively call is_nil_valued() on each of the sub-elements to
488
           find out whether this array is nil valued and return the result.
489
           */
490
       } else {
491
           int ii;
492
           int zerotest;
493

494
           for (ii=0; ii < curr_dim_size; ii++) {
9,752✔
495
               zerotest = is_nil_valued( address, attr, curr_dim+1, offset*curr_dim_size+ii);
9,667✔
496
               if (!(zerotest == 1)) return(zerotest);
9,667✔
497
           }
498
           return(1);
85✔
499
       }
500

501
    } else {
502
        return(-1);
×
503
    }
504
    return(0);
905✔
505
}
506

507
// STATIC FUNCTION
508
static void write_quoted_str( std::ostream& os, const char* s) {
8,547✔
509
    int ii;
510
    int len = strlen(s);
8,547✔
511
    os << "\"" ;
8,547✔
512
    for (ii=0 ; ii<len ; ii++) {
147,570✔
513
        switch ((s)[ii]) {
139,023✔
514
        case '\n': os << "\\n"; break;
54✔
515
        case '\t': os << "\\t"; break;
×
516
        case '\b': os << "\\b"; break;
×
517
        case '\"': os << "\\\""; break;
44✔
518
        default  : os << s[ii] ; break;
138,925✔
519
        }
520
    }
521
    os << "\"" ;
8,547✔
522
}
8,547✔
523

524
void Trick::ClassicCheckPointAgent::write_singleton( std::ostream& chkpnt_os, void* address, ATTRIBUTES* attr, int offset ) {
28,063✔
525

526
    void* src_addr;
527

528
    switch(attr->type) {
28,063✔
529
        case TRICK_VOID:
×
530
            chkpnt_os << std::endl << "// ERROR - VOID data type cannot be checkpointed." << std::endl;
×
531
            message_publish(MSG_ERROR, "Checkpoint Agent ERROR: VOID data type cannot be checkpointed.\n") ;
×
532
        break;
×
533
        case TRICK_UNSIGNED_CHARACTER:
1✔
534
            src_addr = (char*)address + offset * sizeof(unsigned char);
1✔
535
            chkpnt_os << std::dec << (int)*(unsigned char*)src_addr ;
1✔
536
        break;
1✔
537
        case TRICK_BOOLEAN:
2,790✔
538
            src_addr = (char*)address + offset * sizeof(bool);
2,790✔
539
            if (*(bool*)src_addr) {
2,790✔
540
                chkpnt_os << "true" ;
2,789✔
541
            } else {
542
                chkpnt_os << "false" ;
1✔
543
            }
544
        break;
2,790✔
545
        case TRICK_CHARACTER:
1,121✔
546
            src_addr = (char*)address + offset * sizeof(char);
1,121✔
547
            if (isprint( *(char*)src_addr) ) {
1,121✔
548
                chkpnt_os << "'" << *(char*)src_addr << "'" ;
682✔
549
            } else {
550
                unsigned int ch = *(unsigned char*)src_addr;
439✔
551
                  chkpnt_os << "'\\x" << std::hex << ch << "'" ;
439✔
552
            }
553
        break;
1,121✔
554
        case TRICK_WCHAR: {
×
555
            src_addr = (char*)address + offset * sizeof(wchar_t);
×
556
            char buff[16] = {0};
×
557
            wctomb(buff,*(wchar_t*)src_addr);
×
558
            chkpnt_os << std::dec << buff;
×
559
            }
560
            break;
×
561
        case TRICK_SHORT:
8✔
562
            src_addr = (char*)address + offset * sizeof(short);
8✔
563
            chkpnt_os << std::dec << *(short*)src_addr;
8✔
564
            break;
8✔
565
        case TRICK_UNSIGNED_SHORT:
1,997✔
566
            src_addr = (char*)address + offset * sizeof(unsigned short);
1,997✔
567
            chkpnt_os << std::dec << *(unsigned short*)src_addr;
1,997✔
568
            break;
1,997✔
569
        case TRICK_ENUMERATED: {
88✔
570
                int ii = 0;
88✔
571
                int found = 0;
88✔
572
                int value;
573
                ENUM_ATTR* enum_attr;
574

575
                if ((size_t)attr->size == sizeof(int)) {
88✔
576
                    src_addr = (char*)address + offset * sizeof(int);
88✔
577
                    value =  *(int*)src_addr;
88✔
578
                } else if ((size_t)attr->size == sizeof(short)) {
×
579
                    src_addr = (char*)address + offset * sizeof(short);
×
580
                    value =  *(short*)src_addr;
×
581
                } else {
582
                    std::cerr << __FUNCTION__ << ": enumeration size error." << std::endl;
×
583
                    std::cerr.flush();
×
584
                    value = -1;
×
585
                }
586

587
                enum_attr = (ENUM_ATTR*)attr->attr;
88✔
588

589
                while ( !found && (enum_attr[ii].label[0] != '\0')) {
333✔
590
                   if (value == enum_attr[ii].value) {
245✔
591
                       chkpnt_os << enum_attr[ii].label;
88✔
592
                       found = 1;
88✔
593
                   }
594
                   ii++;
245✔
595
                }
596
                if (!found) {
88✔
597
                    chkpnt_os << std::dec << value;
×
598
                }
599

600
            } break;
88✔
601
        case TRICK_INTEGER:
7,380✔
602
            src_addr = (char*)address + offset * sizeof(int);
7,380✔
603
            chkpnt_os << std::dec << *(int*)src_addr;
7,380✔
604
            break;
7,380✔
605
        case TRICK_UNSIGNED_INTEGER:
321✔
606
            src_addr = (char*)address + offset * sizeof(unsigned int);
321✔
607
            chkpnt_os << std::dec << *(unsigned int*)src_addr;
321✔
608
            break;
321✔
609
        case TRICK_LONG:
41✔
610
            src_addr = (char*)address + offset * sizeof(long);
41✔
611
            chkpnt_os << std::dec << *(long*)src_addr;
41✔
612
            break;
41✔
613
        case TRICK_UNSIGNED_LONG:
15✔
614
            src_addr = (char*)address + offset * sizeof(unsigned long);
15✔
615
            chkpnt_os << std::dec << *(unsigned long*)src_addr;
15✔
616
            break;
15✔
617
        case TRICK_FLOAT:
4✔
618
            src_addr = (char*)address + offset * sizeof(float);
4✔
619
            if (fpclassify( *(float*)src_addr) != FP_NAN) {
4✔
620
                if (hexfloat_checkpoint) {
4✔
621
                    double temp_dbl = *(float*)src_addr;
×
622
                    unsigned char* byte_p = (unsigned char*)&temp_dbl;
×
623
                    chkpnt_os << "0g";
×
624
                    for (int ii=sizeof(double)-1 ; ii>= 0 ; ii--) {
×
625
                        chkpnt_os << std::hex << std::setw(2) << std::setfill('0') << (unsigned int)byte_p[ii];
×
626
                    }
627
                } else {
628
                    chkpnt_os << std::setprecision(8) << *(float*)src_addr;
4✔
629
                }
630
            } else {
631
                chkpnt_os << "NAN";
×
632
            }
633
            break;
4✔
634
        case TRICK_DOUBLE:
5,226✔
635
            src_addr = (char*)address + offset * sizeof(double);
5,226✔
636
            if (fpclassify( *(double*)src_addr) != FP_NAN) {
5,226✔
637
                if (hexfloat_checkpoint) {
5,226✔
638
                    double temp_dbl = *(double*)src_addr;
4✔
639
                    unsigned char* byte_p = (unsigned char*)&temp_dbl;
4✔
640
                    chkpnt_os << "0g";
4✔
641
                    for (int ii=sizeof(double)-1 ; ii>= 0 ; ii--) {
36✔
642
                        chkpnt_os << std::hex << std::setw(2) << std::setfill('0') << (unsigned int)byte_p[ii];
32✔
643
                    }
644
                } else {
645
                    chkpnt_os << std::setprecision(16) << *(double*)src_addr;
5,222✔
646
                }
647
            } else {
648
                chkpnt_os << "NAN";
×
649
            }
650
            break;
5,226✔
651
        case TRICK_BITFIELD: {
×
652
                int sbf = 0;
×
653
                src_addr = (char*)address + offset * (size_t)attr->size;
×
654
                if (attr->size == sizeof(int)) {
×
655
                     sbf = extract_bitfield_any( *(int*)src_addr, attr->size, attr->index[0].start, attr->index[0].size);
×
656
                } else if (attr->size == sizeof(short)) {
×
657
                     sbf = extract_bitfield_any( *(short*)src_addr, attr->size, attr->index[0].start, attr->index[0].size);
×
658
                } else if (attr->size == sizeof(char)) {
×
659
                     sbf = extract_bitfield_any( *(char*)src_addr, attr->size, attr->index[0].start, attr->index[0].size);
×
660
                } else {
661
                     message_publish(MSG_ERROR, "Checkpoint Agent INTERNAL ERROR:\n"
×
662
                                                "Unsupported bitfield size (%d) bytes.\n", attr->size) ;
663
                }
664
                chkpnt_os << std::dec << sbf;
×
665
            } break;
×
666
        case TRICK_UNSIGNED_BITFIELD: {
×
667
                int bf = 0;
×
668
                src_addr = (char*)address + offset * (size_t)attr->size;
×
669
                if (attr->size == sizeof(int)) {
×
670
                     bf = extract_unsigned_bitfield_any( *(unsigned int*)src_addr, attr->size, attr->index[0].start, attr->index[0].size);
×
671
                } else if (attr->size == sizeof(short)) {
×
672
                     bf = extract_unsigned_bitfield_any( *(unsigned short*)src_addr, attr->size, attr->index[0].start, attr->index[0].size);
×
673
                } else if (attr->size == sizeof(char)) {
×
674
                     bf = extract_unsigned_bitfield_any( *(unsigned char*)src_addr, attr->size, attr->index[0].start, attr->index[0].size);
×
675
                } else {
676
                     message_publish(MSG_ERROR, "Checkpoint Agent INTERNAL ERROR:\n"
×
677
                                                "Unsupported bitfield size (%d) bytes.\n", attr->size) ;
678
                }
679
                chkpnt_os << std::dec << bf;
×
680
            } break;
×
681
        case TRICK_LONG_LONG:
900✔
682
            src_addr = (char*)address + offset * sizeof(long long);
900✔
683
            chkpnt_os << std::dec << *(long long*)src_addr;
900✔
684
            break;
900✔
685
        case TRICK_UNSIGNED_LONG_LONG:
18✔
686
            src_addr = (char*)address + offset * sizeof(unsigned long long);
18✔
687
            chkpnt_os << std::dec << *(unsigned long long*)src_addr;
18✔
688
            break;
18✔
689
        case  TRICK_FILE_PTR:
×
690
            src_addr = (char*)address + offset * sizeof(void*);
×
691
            chkpnt_os << *(void**)src_addr;
×
692
            break;
×
693
        case TRICK_STRING:
8,153✔
694
            src_addr = (char*)address + offset * sizeof(std::string);
8,153✔
695
            write_quoted_str(chkpnt_os, (*(std::string*)src_addr).c_str());
8,153✔
696
            break;
8,153✔
697
        case TRICK_OPAQUE_TYPE:
×
698
            chkpnt_os << std::endl << "// ERROR - OPAQUE data type (" << attr->type_name << ") cannot be checkpointed." << std::endl;
×
699
            message_publish(MSG_ERROR, "Checkpoint Agent ERROR: OPAQUE data type (%s) cannot be checkpointed.\n", attr->type_name) ;
×
700
        break;
×
701
        default:
×
702
            chkpnt_os << "0";
×
703
            message_publish(MSG_ERROR, "Checkpoint Agent file %s: Unhandled Type (%d).\n", __FILE__, attr->type) ;
×
704
            break;
×
705
    }
706
}
28,063✔
707

708
// MEMBER FUNCTION
709
// Get the variable-name associated with the given variable-address and data-type.
710
// If no data-type is specified, (i.e., if attr == NULL), then the name will refer
711
// to the (inner-most) primitive data-type associated with the address.
712

713
// attr and curr_dim together specify the expected data-type.
714
// If (attr == NULL) then type checking can't and won't be performed.
715

716
std::string Trick::ClassicCheckPointAgent::
1,002✔
717
    ref_string_from_ptr( void* pointer, ATTRIBUTES* attr, int curr_dim) {
718

719
    std::string reference_string;
2,004✔
720

721
    if ((attr != NULL) && ((curr_dim >= attr->num_index) || (attr->index[curr_dim].size != 0))) {
1,002✔
722
        message_publish(MSG_ERROR, "Checkpoint Agent ERROR: ref_string_from_ptr called with a non-pointer type.\n") ;
×
723
    }
724

725
    if (pointer == NULL) {
1,002✔
726
        reference_string = "NULL";
×
727
    } else {
728
        ALLOC_INFO *alloc_info;
729

730
        /** Find the allocation that contains the pointer-address. */
731
        alloc_info = mem_mgr->get_alloc_info_of( pointer);
1,002✔
732

733
        if (alloc_info != NULL) {
1,002✔
734
            // Special handling for character strings: prefer string literal format over allocation reference
735
            // The following info for "char *" is for reference purpose:
736
            // curr_dim = 0
737
            // attr.type = TRICK_CHARACTER (base type)
738
            // attr.num_index = 1 (1D array)
739
            // attr.index[0].size = 0 (not static array)
740
            // attr.size = sizeof(char)
741
            // This prevents anonymous allocations from appearing in subsequent checkpoints
742
            if ((attr != NULL) && (attr->type == TRICK_CHARACTER || attr->type == TRICK_UNSIGNED_CHARACTER) && ((curr_dim + 1) == attr->num_index)) {
965✔
743
                std::stringstream ss;
101✔
744
                write_quoted_str( ss, (const char*)pointer);
101✔
745
                reference_string = ss.str();
101✔
746
            } else {
747
                int alloc_elem_size;
748
                int alloc_elem_index;
749
                int misalignment;
750

751
                alloc_elem_size = alloc_info->size;
864✔
752
                alloc_elem_index = (int) (((long) pointer - (long) alloc_info->start) / alloc_elem_size);
864✔
753
                misalignment = (int) (((long) pointer - (long) alloc_info->start) % alloc_elem_size);
864✔
754

755
                // If type-checking AND the type specifiers match AND  the type we're looking for
756
                // is either not structured or if it is, the attr-list that describes the contents
757
                // of the structure is the same.
758

759
                if ( (attr != NULL) && (attr->type == alloc_info->type) &&
864✔
760
                     ( (attr->type != TRICK_STRUCTURED) || (attr->attr == alloc_info->attr))) {
852✔
761

762
                int ii;
763
                int n_l_ptrs, n_r_ptrs;
764

765
                // Calculate the number of pointers (asterisks) on the left side of the assignment.
766
                n_l_ptrs = attr->num_index - curr_dim;
258✔
767

768
                // Calculate the number of pointers (asterisks) on the right side of the assignment.
769
                n_r_ptrs = 0;
258✔
770
                for (ii=0 ; ii <alloc_info->num_index ; ii++) {
490✔
771
                    if (alloc_info->index[ii] == 0) n_r_ptrs++;
232✔
772
                }
773

774
                if (n_l_ptrs != (n_r_ptrs + 1)) {
258✔
775
                    reference_string = "NULL /*ERROR: # asterisks disagree.*/";
×
776
                } else {
777
                    if (misalignment == 0) {
258✔
778
                        std::stringstream workss;
516✔
779
                        if (alloc_info->name != NULL) {
258✔
780
                            workss << "&" << alloc_info->name;
258✔
781
                            if (alloc_info->num_index != 0) {
258✔
782
                                workss << "[" << alloc_elem_index << "]";
166✔
783
                            }
784
                            reference_string = workss.str();
258✔
785
                        } else {
786
                            std::stringstream ss;
×
787
                            ss << "Checkpoint Agent ERROR: The name of the allocation at " << alloc_info->start << " is NULL."
×
788
                               << "Therefore, Trick::ClassicCheckPointAgent::ref_string_from_ptr() can't generate a textual reference to it."
×
789
                               << std::endl;
×
790
                            message_publish(MSG_ERROR, ss.str().c_str() );
×
791
                            reference_string = "ERROR - Allocation name is NULL";
×
792
                        }
793

794
                    } else {
795
                        message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Badly aligned pointer.\n"
×
796
                                                   "   It is not aligned with the data object\n"
797
                                                   "   (of the same type) into which it is pointing.\n") ;
798
                        reference_string = "ERROR - Badly aligned pointer";
×
799
                    }
800
                }
258✔
801
            } else if (alloc_info->type == TRICK_STRUCTURED) {
606✔
802
                // The type specifications don't match, but the right-side is structured,
803
                // so we apparently the matching type is buried in the right hand side structure.
804

805
                if (alloc_info->name != NULL) {
605✔
806
                    std::string rightside;
1,210✔
807
                    std::stringstream element_name;
1,210✔
808
                    element_name << "&" << alloc_info->name;
605✔
809
                    if (alloc_info->num_index != 0) {
605✔
810
                        element_name << '[' << alloc_elem_index << ']';
54✔
811
                    }
812
                    rightside = get_var_name( pointer,
605✔
813
                                              alloc_info->attr,
814
                                              (char *) alloc_info->start + (alloc_elem_index * alloc_info->size),
605✔
815
                                              element_name.str(),
1,210✔
816
                                              &attr
817
                                            );
605✔
818
                    reference_string = rightside;
605✔
819
                } else {
820
                    std::stringstream ss;
×
821
                    ss << "Checkpoint Agent ERROR: The name of the allocation at " << alloc_info->start << " is NULL."
×
822
                       << "Therefore, Trick::ClassicCheckPointAgent::ref_string_from_ptr() can't generate a textual reference to it."
×
823
                       << std::endl;
×
824
                    message_publish(MSG_ERROR, ss.str().c_str() );
×
825
                    reference_string = "ERROR - Allocation name is NULL";
×
826
                }
827
            } else { // The type specifications don't match, and the right hand side is not structured
828

829
                if (attr != NULL) {
1✔
830
                    const char* left_type_spec  = trickTypeCharString(attr->type, "");
×
831
                    const char* right_type_spec = trickTypeCharString(alloc_info->type, alloc_info->user_type_name);
×
832
                    message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Type mismatch. Type specifications disagree.\n"
×
833
                                               "   The left side type specifier is \"%s\" but the right side is \"%s\".\n",
834
                                    left_type_spec, right_type_spec) ;
835
                    reference_string = "ERROR - Type specifications disagree";
×
836
                } else {
837

838
                    if (misalignment == 0) {
1✔
839
                        std::stringstream workss;
2✔
840

841
                        if (alloc_info->name != NULL) {
1✔
842
                            workss << "&" << alloc_info->name;
1✔
843
                            if (alloc_info->num_index != 0) {
1✔
844
                                workss << "[" << alloc_elem_index << "]";
×
845
                            }
846
                            reference_string = workss.str();
1✔
847
                        } else {
848
                            std::stringstream ss;
×
849
                            ss << "Checkpoint Agent ERROR: The name of the allocation at " << alloc_info->start << " is NULL."
×
850
                               << "Therefore, Trick::ClassicCheckPointAgent::ref_string_from_ptr() can't generate a textual reference to it."
×
851
                               << std::endl;
×
852
                            message_publish(MSG_ERROR, ss.str().c_str() );
×
853
                            reference_string = "ERROR - Allocation name is NULL";
×
854
                        }
855

856
                    } else {
857
                        message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Badly aligned pointer.\n"
×
858
                                                   "   It is not aligned with the data object\n"
859
                                                   "   (of the same type) into which it is pointing.\n") ;
860
                        reference_string = "ERROR - Badly Aligned Pointer";
×
861
                    }
862
                }
863

864
                }
865
            }
866
        } else if ((attr != NULL) && ((curr_dim + 1) == attr->num_index)) {
37✔
867

868
            if (attr->type == TRICK_CHARACTER) {
37✔
869
                std::stringstream ss;
37✔
870
                write_quoted_str( ss, (const char*)pointer);
37✔
871
                reference_string = ss.str();
37✔
872
            } else if (attr->type == TRICK_WCHAR) {
×
873
                message_publish(MSG_ERROR, "Checkpoint Agent ERROR: TRICK_WCHAR not fully supported yet.\n") ;
×
874
                reference_string = "ERROR: TRICK_WCHAR not fully supported yet.";
×
875
            } else {
876
                std::string lname = left_side_name();
×
877
                message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Pointer <%p> in \"%s\" is not in Trick managed memory\n"
×
878
                                           "nor is it a character pointer.\n", pointer, lname.c_str()) ;
879
                reference_string = "ERROR - Pointer not in Trick managed memory";
×
880
            }
37✔
881

882
        } else {
883
            std::string lname = left_side_name();
×
884
            message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Pointer <%p> in \"%s\" is not in Trick managed memory\n"
×
885
                                       "nor is it a character pointer.\n", pointer, lname.c_str()) ;
886
            reference_string = "ERROR - Pointer not in Trick managed memory";
×
887
        }
888
    }
889
    return( reference_string);
2,004✔
890
}
891

892
// MEMBER FUNCTION
893
void Trick::ClassicCheckPointAgent::write_rvalue( std::ostream& chkpnt_os, void* address, ATTRIBUTES* attr, int curr_dim, int offset) {
31,781✔
894

895
    // If the variable that we are pointing to is Un-arrayed
896
    if (curr_dim == attr->num_index) {
31,781✔
897

898
        write_singleton( chkpnt_os, address, attr, offset);
28,063✔
899

900
    // If the variable that we are pointing to is Arrayed
901
    } else if (curr_dim < attr->num_index) {
3,718✔
902

903
        // If the variable is a pointer
904
        if (attr->index[curr_dim].size == 0) {
3,718✔
905
            std::string ref_string;
1,986✔
906

907
            void* pointer = *(void**)((char*)address + offset * sizeof(void*));
993✔
908

909
            ref_string = ref_string_from_ptr( pointer, attr, curr_dim);
993✔
910

911
            chkpnt_os << ref_string.c_str() ;
993✔
912

913
        } else { // Fixed dimension
914

915
            char* src_addr;
916

917
            // If this is the final, fixed dimension
918
            if (((curr_dim + 1) == attr->num_index) ||
2,725✔
919
                (attr->index[curr_dim + 1].size == 0)) {
49✔
920

921
                int use_quoted_string;
922

923
                // If ALL but the last of the elements of a character array
924
                // "isprintable" AND the last is '\0' then print out the array
925
                // as a quoted string. Otherwise print out each of the characters.
926

927
                use_quoted_string = 1;
2,721✔
928
                if (attr->type == TRICK_CHARACTER) {
2,721✔
929

930
                    int array_len = attr->index[curr_dim].size;
304✔
931
                    int ii = array_len - 1;
304✔
932
                    src_addr = (char*)address + offset * array_len * sizeof(char);
304✔
933
                    if (src_addr[ii] != '\0') {
304✔
934
                        use_quoted_string = 0;
22✔
935
                    }
936
                    ii--;
304✔
937
                    while ( use_quoted_string && (ii >= 0) ) {
1,097✔
938
                        use_quoted_string = isprint( src_addr[ii]);
793✔
939
                        ii--;
793✔
940
                    }
941
                }
942

943

944
                // This is necessary due to https://github.com/nasa/trick/issues/1399
945
                // If there is a string array where the memory is not initialized, the code above
946
                // can incorrectly decide to write it as a quoted string when it should be an
947
                // empty array, causing a segfault when the checkpoint is reloaded.
948
                if (attr->index[curr_dim + 1].size == 0 && ((curr_dim + 1) != attr->num_index)) {
2,721✔
949
                    use_quoted_string = 0;
45✔
950
                } 
951

952

953
                if ((attr->type == TRICK_CHARACTER) && use_quoted_string)  {
2,721✔
954

955
                    write_quoted_str(chkpnt_os, src_addr);
256✔
956

957
                } else {
958

959
                    int ii, jj;
960
                    int array_len;
961

962
                    // Determine the number of array elements we need to print out
963
                    // to get all of the non-zero values.
964

965
                    array_len = attr->index[curr_dim].size ;
2,465✔
966

967
                    chkpnt_os << "\n";
2,465✔
968

969
                    for (ii=0 ; ii < curr_dim+1 ; ii++) {
4,935✔
970
                        chkpnt_os << "    ";
2,470✔
971
                    }
972
                    chkpnt_os << "{";
2,465✔
973

974
                    for (ii = 0; ii < array_len ; ii++ ) {
6,668✔
975

976
                        if (ii > 0) {
4,203✔
977
                            chkpnt_os << ", ";
1,738✔
978

979
                            // Conditionally line-break and indent.
980
                            if (( (ii+1) % array_elements_per_line[attr->type]) == 0 ) {
1,738✔
981
                                // Line-break.
982
                                chkpnt_os << "\n";
198✔
983
                                // Indent.
984
                                for (jj=0 ; jj < curr_dim+1 ; jj++) {
396✔
985
                                    chkpnt_os << "    ";
198✔
986
                                }
987
                                chkpnt_os << " ";
198✔
988
                            }
989
                        }
990
                        write_rvalue( chkpnt_os, address, attr, curr_dim + 1, offset * attr->index[curr_dim].size + ii);
4,203✔
991
                    }
992
                    chkpnt_os << "}";
2,465✔
993

994
                }
2,721✔
995

996
            } else { // Not the final fixed dimension.
997

998
                int ii;
999

1000
                chkpnt_os << "\n";
4✔
1001
                for (ii=0 ; ii < curr_dim+1 ; ii++) {
8✔
1002
                    chkpnt_os << "    ";
4✔
1003
                }
1004
                chkpnt_os << "{";
4✔
1005

1006
                for (ii=0 ; ii< attr->index[curr_dim].size ; ii++) {
265✔
1007
                    if (ii > 0) {
261✔
1008
                        chkpnt_os << ",";
257✔
1009
                    }
1010
                    write_rvalue( chkpnt_os, address, attr, curr_dim + 1, offset * attr->index[curr_dim].size + ii);
261✔
1011
                }
1012

1013
                chkpnt_os << "\n";
4✔
1014

1015
                for (ii=0 ; ii < curr_dim+1 ; ii++) {
8✔
1016
                    chkpnt_os << "    " ;
4✔
1017
                }
1018
                chkpnt_os << "}";
4✔
1019
            }
1020
        }
1021

1022
    } else {
1023
        chkpnt_os << "/*ERROR*/";
×
1024

1025
        message_publish(MSG_ERROR, "Checkpoint Agent ERROR: The specified current dimension \"%d\" is greater\n"
×
1026
                                   "than the number of dimensions specified in the type ATTRIBUTES.\n", curr_dim) ;
1027

1028
        return;
×
1029
    }
1030
}
1031

1032
// MEMBER FUNCTION
1033
// Create an assignment statement.
1034
void Trick::ClassicCheckPointAgent::assign_rvalue(std::ostream& chkpnt_os, void* address, ATTRIBUTES* attr, int curr_dim, int offset) {
62,274✔
1035

1036
    std::string lname = left_side_name();
62,274✔
1037

1038
    if (!output_perm_check(attr)) {
62,274✔
1039
        if (debug_level) {
×
1040
            message_publish(MSG_DEBUG, "Checkpoint Agent INFO: No assignment generated for \"%s\" "
×
1041
                                       "because its io specification does not allow it.\n", lname.c_str()) ;
1042
        }
1043
        return;
×
1044
    }
1045

1046
    if ((reduced_checkpoint && is_nil_valued( (void*)address, attr, curr_dim, offset ) ) ) {
62,274✔
1047
        if (debug_level) {
32,433✔
1048
            message_publish(MSG_DEBUG, "Checkpoint Agent INFO: No assignment generated for \"%s\" "
×
1049
                                       "because its value is nil and the reduced_checkpoint flag is set.\n", lname.c_str()) ;
1050
        }
1051
        return;
32,433✔
1052
    }
1053

1054
    if (debug_level) {
29,841✔
1055
        message_publish(MSG_DEBUG, "Checkpoint Agent INFO: Generating assignment for [%p] %s.\n",(void*)address, lname.c_str()) ;
×
1056
    }
1057

1058
    if (!input_perm_check(attr)) {
29,841✔
1059
        chkpnt_os << "/* OUTPUT-ONLY: ";
23✔
1060
    }
1061
    if ( attr->type == TRICK_STL ) {
29,841✔
1062
        chkpnt_os << "// STL: " << lname ;
2,524✔
1063
    } else {
1064
        chkpnt_os << lname << " = ";
27,317✔
1065

1066
        write_rvalue( chkpnt_os, (void*)address, attr, curr_dim, offset);
27,317✔
1067
        chkpnt_os << ";";
27,317✔
1068

1069
        // Check if we need to add decimal comments for hexfloat values
1070
        bool should_add_decimal_comment = hexfloat_decimal_comment_checkpoint && hexfloat_checkpoint && (attr->type == TRICK_FLOAT || attr->type == TRICK_DOUBLE);
27,317✔
1071

1072
        // Add decimal comment for hexfloat values
1073
        if (should_add_decimal_comment) {
27,317✔
1074
            // Temporarily disable hexfloat to get decimal representation
1075
            bool saved_hexfloat = hexfloat_checkpoint;
×
1076
            hexfloat_checkpoint = false;
×
1077

1078
            // Capture decimal output to string stream
1079
            std::stringstream decimal_ss;
×
1080
            write_rvalue( decimal_ss, (void*)address, attr, curr_dim, offset);
×
1081

1082
            // Restore hexfloat setting
1083
            hexfloat_checkpoint = saved_hexfloat;
×
1084

1085
            // Add // to each line of the decimal output
1086
            std::string decimal_str = decimal_ss.str();
×
1087
            std::istringstream iss(decimal_str);
×
1088
            std::string line;
×
1089
            bool first_line = true;
×
1090
            
1091
            while (std::getline(iss, line)) {
×
1092
                if (first_line) {
×
1093
                    chkpnt_os << std::endl << "// " << lname << " = " << line;
×
1094
                    first_line = false;
×
1095
                } else {
1096
                    chkpnt_os << std::endl << "//" << line;
×
1097
                }
1098
            }
1099
        }
1100
    }
1101
    if (!input_perm_check(attr)) {
29,841✔
1102
        chkpnt_os << "*/";
23✔
1103
    }
1104
    chkpnt_os << std::endl;
29,841✔
1105
    chkpnt_os.flush();
29,841✔
1106

1107
}
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