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

nasa / trick / 25459968639

06 May 2026 08:42PM UTC coverage: 55.916% (-0.8%) from 56.7%
25459968639

Pull #2011

github

web-flow
Merge f11412d5f into 7054e405e
Pull Request #2011: Single-file CI and code style adoption

14607 of 26123 relevant lines covered (55.92%)

466416.66 hits per line

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

69.37
/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) {
641✔
53

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

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

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

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

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

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

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

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

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

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

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

93
            case ARRAY_INDEX: {
49,815✔
94
                std::stringstream index_string;
49,815✔
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);
62,331✔
107
}
×
108

109
// MEMBER FUNCTION
110
void Trick::ClassicCheckPointAgent::write_decl(std::ostream& chkpnt_os, ALLOC_INFO *info) {
2,843✔
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,843✔
116
        return;
120✔
117
    }
118

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

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

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

127
        chkpnt_os << type_spec << " " << info->name << ";\n";
101✔
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(
799✔
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;
799✔
185
    char* sAddr = (char*)structure_address;
799✔
186

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

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

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

199
    if (ret != 0)
799✔
200
    {
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)
799✔
209
    {
210
        if (referenceOffset == 0)
634✔
211
        {
212
            reference_name[0] = '\0';
624✔
213
        }
214
        else
215
        {
216
            snprintf(reference_name, REFNAME_MAXSIZE, " + %zu", referenceOffset);
10✔
217
        }
218
        return 0;
634✔
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
232
        for (int j = 0; j < traversalResult.num_computed_indices; j++)
×
233
        {
234
            size_t len = strlen(reference_name);
×
235
            size_t rem = REFNAME_MAXSIZE - len;
×
236
            snprintf(&reference_name[len], rem, "[%d]", traversalResult.array_indices[j]);
×
237
        }
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
        {
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
        {
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,
651✔
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;
651✔
318

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

322
    if (ret == 0) {
651✔
323
        var_name += reference_name;
651✔
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,302✔
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,998✔
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,998✔
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,998✔
380

381
        switch (attr->type) {
67,599✔
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,420✔
388
               test_addr = (char*)address + offset * sizeof(bool);
14,420✔
389
               if (*(bool*)test_addr == false) return(1);
14,420✔
390
               break;
2,863✔
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 :
408✔
406
               if ((size_t)attr->size == sizeof(int)) {
408✔
407
                   test_addr = (char*)address + offset * sizeof(int);
404✔
408
                   if (*(int*)test_addr == 0) return(1);
404✔
409
               } else if ((size_t)attr->size == sizeof(short)) {
4✔
410
                   test_addr = (char*)address + offset * sizeof(short);
2✔
411
                   if (*(short*)test_addr == 0) return(1);
2✔
412
               } else if ((size_t)attr->size == sizeof(char)) {
2✔
413
                   test_addr = (char*)address + offset * sizeof(char);
2✔
414
                   if (*(char*)test_addr == 0) return(1);
2✔
415
               } else {
416
                   return(-1);
×
417
               }
418
               break;
90✔
419
           case TRICK_LONG :
103✔
420
           case TRICK_UNSIGNED_LONG :
421
               test_addr = (char*)address + offset * sizeof(long);
103✔
422
               if (*(long*)test_addr == 0) return(1);
103✔
423
               break;
51✔
424
           case TRICK_FLOAT :
2✔
425
               test_addr = (char*)address + offset * sizeof(float);
2✔
426
               if (fpclassify( *(float*)test_addr) == FP_ZERO) return(1);
2✔
427
               break;
2✔
428
           case TRICK_DOUBLE :
7,969✔
429
               test_addr = (char*)address + offset * sizeof(double);
7,969✔
430
               if (fpclassify( *(double*)test_addr) == FP_ZERO) return(1);
7,969✔
431
               break;
5,089✔
432
           case TRICK_LONG_LONG :
9,967✔
433
           case TRICK_UNSIGNED_LONG_LONG :
434
               test_addr = (char*)address + offset * sizeof(long long);
9,967✔
435
               if (*(long long*)test_addr == 0) return(1);
9,967✔
436
               break;
914✔
437
           case TRICK_BITFIELD :
×
438
           case TRICK_UNSIGNED_BITFIELD :
439
               test_addr = (char*)address + offset * (size_t)attr->size;
×
440
               if (attr->size == sizeof(int)) {
×
441
                   if (*(int*)test_addr == 0) return(1);
×
442
               } else if (attr->size == sizeof(short)) {
×
443
                   if (*(short*)test_addr == 0) return(1);
×
444
               } else if (attr->size == sizeof(char)) {
×
445
                   if (*(char*)test_addr == 0) return(1);
×
446
               } else {
447
                   message_publish(MSG_ERROR, "Checkpoint Agent INTERNAL ERROR:\n"
×
448
                                              "Unhandled bitfield struct size (%d) in bitfield assignment.\n", attr->size) ;
449
                   return(-1);
×
450
               }
451
               break;
×
452
           case TRICK_FILE_PTR :
×
453
               // FIXME
454
               return(0);
×
455
               break;
456
           case TRICK_STRING :
8,597✔
457
               test_addr = (char*)address + offset * sizeof(void*);
8,597✔
458
               if (*(std::string*)test_addr == "") return(1);
8,597✔
459
               break;
8,065✔
460
           case TRICK_STL :
2,541✔
461
               // Can't test properly, always return 0 to indicate the STL is not empty.
462
               return(0);
2,541✔
463
               break;
464
           default :
×
465
               message_publish(MSG_ERROR, "Checkpoint Agent file %s: Unhandled Type (%d).\n", __FILE__, attr->type) ;
×
466
               return(-1);
×
467
               break;
468
        }
469
        return(0);
26,492✔
470

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

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

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

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

504
    } else {
505
        return(-1);
×
506
    }
507
    return(0);
905✔
508
}
509

510
// STATIC FUNCTION
511
static void write_quoted_str( std::ostream& os, const char* s) {
8,547✔
512
    int ii;
513
    int len = strlen(s);
8,547✔
514
    os << "\"" ;
8,547✔
515
    for (ii=0 ; ii<len ; ii++) {
148,947✔
516
        switch ((s)[ii]) {
140,400✔
517
        case '\n': os << "\\n"; break;
54✔
518
        case '\t': os << "\\t"; break;
×
519
        case '\b': os << "\\b"; break;
×
520
        case '\"': os << "\\\""; break;
44✔
521
        default  : os << s[ii] ; break;
140,302✔
522
        }
523
    }
524
    os << "\"" ;
8,547✔
525
}
8,547✔
526

527
void Trick::ClassicCheckPointAgent::write_singleton( std::ostream& chkpnt_os, void* address, ATTRIBUTES* attr, int offset ) {
28,143✔
528

529
    void* src_addr;
530

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

578
                if ((size_t)attr->size == sizeof(int)) {
94✔
579
                    src_addr = (char*)address + offset * sizeof(int);
90✔
580
                    value =  *(int*)src_addr;
90✔
581
                } else if ((size_t)attr->size == sizeof(short)) {
4✔
582
                    src_addr = (char*)address + offset * sizeof(short);
2✔
583
                    value =  *(short*)src_addr;
2✔
584
                } else if ((size_t)attr->size == sizeof(char)) {
2✔
585
                    src_addr = (char*)address + offset * sizeof(char);
2✔
586
                    ENUM_ATTR* eattr = (ENUM_ATTR*)attr->attr;
2✔
587
                    if (eattr != nullptr && (eattr[0].mods & 0x40000000)) {
2✔
588
                        value = (int)(unsigned char)*(char*)src_addr;
1✔
589
                    } else {
590
                        value = (int)*(char*)src_addr;
1✔
591
                    }
592
                } else {
593
                    std::cerr << __FUNCTION__ << ": enumeration size error." << std::endl;
×
594
                    std::cerr.flush();
×
595
                    value = -1;
×
596
                }
597

598
                enum_attr = (ENUM_ATTR*)attr->attr;
94✔
599

600
                while ( !found && (enum_attr[ii].label[0] != '\0')) {
345✔
601
                   if (value == enum_attr[ii].value) {
251✔
602
                       chkpnt_os << enum_attr[ii].label;
94✔
603
                       found = 1;
94✔
604
                   }
605
                   ii++;
251✔
606
                }
607
                if (!found) {
94✔
608
                    chkpnt_os << std::dec << value;
×
609
                }
610

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

719
// MEMBER FUNCTION
720
// Get the variable-name associated with the given variable-address and data-type.
721
// If no data-type is specified, (i.e., if attr == NULL), then the name will refer
722
// to the (inner-most) primitive data-type associated with the address.
723

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

727
std::string Trick::ClassicCheckPointAgent::
1,048✔
728
    ref_string_from_ptr( void* pointer, ATTRIBUTES* attr, int curr_dim) {
729

730
    std::string reference_string;
1,048✔
731

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

736
    if (pointer == NULL) {
1,048✔
737
        reference_string = "NULL";
×
738
    } else {
739
        ALLOC_INFO *alloc_info;
740

741
        /** Find the allocation that contains the pointer-address. */
742
        alloc_info = mem_mgr->get_alloc_info_of( pointer);
1,048✔
743

744
        if (alloc_info != NULL) {
1,048✔
745
            // Special handling for character strings: prefer string literal format over allocation reference
746
            // The following info for "char *" is for reference purpose:
747
            // curr_dim = 0
748
            // attr.type = TRICK_CHARACTER (base type)
749
            // attr.num_index = 1 (1D array)
750
            // attr.index[0].size = 0 (not static array)
751
            // attr.size = sizeof(char)
752
            // This prevents anonymous allocations from appearing in subsequent checkpoints
753
            if ((attr != NULL) && (attr->type == TRICK_CHARACTER || attr->type == TRICK_UNSIGNED_CHARACTER) && ((curr_dim + 1) == attr->num_index)) {
1,011✔
754
                std::stringstream ss;
101✔
755
                write_quoted_str( ss, (const char*)pointer);
101✔
756
                reference_string = ss.str();
101✔
757
            } else {
101✔
758
                int alloc_elem_size;
759
                int alloc_elem_index;
760
                int misalignment;
761

762
                alloc_elem_size = alloc_info->size;
910✔
763
                alloc_elem_index = (int) (((long) pointer - (long) alloc_info->start) / alloc_elem_size);
910✔
764
                misalignment = (int) (((long) pointer - (long) alloc_info->start) % alloc_elem_size);
910✔
765

766
                // If type-checking AND the type specifiers match AND  the type we're looking for
767
                // is either not structured or if it is, the attr-list that describes the contents
768
                // of the structure is the same.
769

770
                if ( (attr != NULL) && (attr->type == alloc_info->type) &&
910✔
771
                     ( (attr->type != TRICK_STRUCTURED) || (attr->attr == alloc_info->attr))) {
852✔
772

773
                int ii;
774
                int n_l_ptrs, n_r_ptrs;
775

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

779
                // Calculate the number of pointers (asterisks) on the right side of the assignment.
780
                n_r_ptrs = 0;
258✔
781
                for (ii=0 ; ii <alloc_info->num_index ; ii++) {
490✔
782
                    if (alloc_info->index[ii] == 0) n_r_ptrs++;
232✔
783
                }
784

785
                if (n_l_ptrs != (n_r_ptrs + 1)) {
258✔
786
                    reference_string = "NULL /*ERROR: # asterisks disagree.*/";
×
787
                } else {
788
                    if (misalignment == 0) {
258✔
789
                        std::stringstream workss;
258✔
790
                        if (alloc_info->name != NULL) {
258✔
791
                            workss << "&" << alloc_info->name;
258✔
792
                            if (alloc_info->num_index != 0) {
258✔
793
                                workss << "[" << alloc_elem_index << "]";
166✔
794
                            }
795
                            reference_string = workss.str();
258✔
796
                        } else {
797
                            std::stringstream ss;
×
798
                            ss << "Checkpoint Agent ERROR: The name of the allocation at " << alloc_info->start << " is NULL."
×
799
                               << "Therefore, Trick::ClassicCheckPointAgent::ref_string_from_ptr() can't generate a textual reference to it."
×
800
                               << std::endl;
×
801
                            message_publish(MSG_ERROR, ss.str().c_str() );
×
802
                            reference_string = "ERROR - Allocation name is NULL";
×
803
                        }
×
804

805
                    } else {
258✔
806
                        message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Badly aligned pointer.\n"
×
807
                                                   "   It is not aligned with the data object\n"
808
                                                   "   (of the same type) into which it is pointing.\n") ;
809
                        reference_string = "ERROR - Badly aligned pointer";
×
810
                    }
811
                }
812
            } else if (alloc_info->type == TRICK_STRUCTURED) {
910✔
813
                // The type specifications don't match, but the right-side is structured,
814
                // so we apparently the matching type is buried in the right hand side structure.
815

816
                if (alloc_info->name != NULL) {
651✔
817
                    std::string rightside;
651✔
818
                    std::stringstream element_name;
651✔
819
                    element_name << "&" << alloc_info->name;
651✔
820
                    if (alloc_info->num_index != 0) {
651✔
821
                        element_name << '[' << alloc_elem_index << ']';
100✔
822
                    }
823
                    rightside = get_var_name( pointer,
651✔
824
                                              alloc_info->attr,
825
                                              (char *) alloc_info->start + (alloc_elem_index * alloc_info->size),
651✔
826
                                              element_name.str(),
1,302✔
827
                                              &attr
828
                                            );
651✔
829
                    reference_string = rightside;
651✔
830
                } else {
651✔
831
                    std::stringstream ss;
×
832
                    ss << "Checkpoint Agent ERROR: The name of the allocation at " << alloc_info->start << " is NULL."
×
833
                       << "Therefore, Trick::ClassicCheckPointAgent::ref_string_from_ptr() can't generate a textual reference to it."
×
834
                       << std::endl;
×
835
                    message_publish(MSG_ERROR, ss.str().c_str() );
×
836
                    reference_string = "ERROR - Allocation name is NULL";
×
837
                }
×
838
            } else { // The type specifications don't match, and the right hand side is not structured
839

840
                if (attr != NULL) {
1✔
841
                    const char* left_type_spec  = trickTypeCharString(attr->type, "");
×
842
                    const char* right_type_spec = trickTypeCharString(alloc_info->type, alloc_info->user_type_name);
×
843
                    message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Type mismatch. Type specifications disagree.\n"
×
844
                                               "   The left side type specifier is \"%s\" but the right side is \"%s\".\n",
845
                                    left_type_spec, right_type_spec) ;
846
                    reference_string = "ERROR - Type specifications disagree";
×
847
                } else {
848

849
                    if (misalignment == 0) {
1✔
850
                        std::stringstream workss;
1✔
851

852
                        if (alloc_info->name != NULL) {
1✔
853
                            workss << "&" << alloc_info->name;
1✔
854
                            if (alloc_info->num_index != 0) {
1✔
855
                                workss << "[" << alloc_elem_index << "]";
×
856
                            }
857
                            reference_string = workss.str();
1✔
858
                        } else {
859
                            std::stringstream ss;
×
860
                            ss << "Checkpoint Agent ERROR: The name of the allocation at " << alloc_info->start << " is NULL."
×
861
                               << "Therefore, Trick::ClassicCheckPointAgent::ref_string_from_ptr() can't generate a textual reference to it."
×
862
                               << std::endl;
×
863
                            message_publish(MSG_ERROR, ss.str().c_str() );
×
864
                            reference_string = "ERROR - Allocation name is NULL";
×
865
                        }
×
866

867
                    } else {
1✔
868
                        message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Badly aligned pointer.\n"
×
869
                                                   "   It is not aligned with the data object\n"
870
                                                   "   (of the same type) into which it is pointing.\n") ;
871
                        reference_string = "ERROR - Badly Aligned Pointer";
×
872
                    }
873
                }
874

875
                }
876
            }
877
        } else if ((attr != NULL) && ((curr_dim + 1) == attr->num_index)) {
37✔
878

879
            if (attr->type == TRICK_CHARACTER) {
37✔
880
                std::stringstream ss;
37✔
881
                write_quoted_str( ss, (const char*)pointer);
37✔
882
                reference_string = ss.str();
37✔
883
            } else if (attr->type == TRICK_WCHAR) {
37✔
884
                message_publish(MSG_ERROR, "Checkpoint Agent ERROR: TRICK_WCHAR not fully supported yet.\n") ;
×
885
                reference_string = "ERROR: TRICK_WCHAR not fully supported yet.";
×
886
            } else {
887
                std::string lname = left_side_name();
×
888
                message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Pointer <%p> in \"%s\" is not in Trick managed memory\n"
×
889
                                           "nor is it a character pointer.\n", pointer, lname.c_str()) ;
890
                reference_string = "ERROR - Pointer not in Trick managed memory";
×
891
            }
×
892

893
        } else {
37✔
894
            std::string lname = left_side_name();
×
895
            message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Pointer <%p> in \"%s\" is not in Trick managed memory\n"
×
896
                                       "nor is it a character pointer.\n", pointer, lname.c_str()) ;
897
            reference_string = "ERROR - Pointer not in Trick managed memory";
×
898
        }
×
899
    }
900
    return( reference_string);
1,048✔
901
}
×
902

903
// MEMBER FUNCTION
904
void Trick::ClassicCheckPointAgent::write_rvalue( std::ostream& chkpnt_os, void* address, ATTRIBUTES* attr, int curr_dim, int offset) {
31,861✔
905

906
    // If the variable that we are pointing to is Un-arrayed
907
    if (curr_dim == attr->num_index) {
31,861✔
908

909
        write_singleton( chkpnt_os, address, attr, offset);
28,143✔
910

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

914
        // If the variable is a pointer
915
        if (attr->index[curr_dim].size == 0) {
3,718✔
916
            std::string ref_string;
993✔
917

918
            void* pointer = *(void**)((char*)address + offset * sizeof(void*));
993✔
919

920
            ref_string = ref_string_from_ptr( pointer, attr, curr_dim);
993✔
921

922
            chkpnt_os << ref_string.c_str() ;
993✔
923

924
        } else { // Fixed dimension
993✔
925

926
            char* src_addr;
927

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

932
                int use_quoted_string;
933

934
                // If ALL but the last of the elements of a character array
935
                // "isprintable" AND the last is '\0' then print out the array
936
                // as a quoted string. Otherwise print out each of the characters.
937

938
                use_quoted_string = 1;
2,721✔
939
                if (attr->type == TRICK_CHARACTER) {
2,721✔
940

941
                    int array_len = attr->index[curr_dim].size;
304✔
942
                    int ii = array_len - 1;
304✔
943
                    src_addr = (char*)address + offset * array_len * sizeof(char);
304✔
944
                    if (src_addr[ii] != '\0') {
304✔
945
                        use_quoted_string = 0;
23✔
946
                    }
947
                    ii--;
304✔
948
                    while ( use_quoted_string && (ii >= 0) ) {
1,097✔
949
                        use_quoted_string = isprint( src_addr[ii]);
793✔
950
                        ii--;
793✔
951
                    }
952
                }
953

954

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

963

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

966
                    write_quoted_str(chkpnt_os, src_addr);
256✔
967

968
                } else {
969

970
                    int ii, jj;
971
                    int array_len;
972

973
                    // Determine the number of array elements we need to print out
974
                    // to get all of the non-zero values.
975

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

978
                    chkpnt_os << "\n";
2,465✔
979

980
                    for (ii=0 ; ii < curr_dim+1 ; ii++) {
4,935✔
981
                        chkpnt_os << "    ";
2,470✔
982
                    }
983
                    chkpnt_os << "{";
2,465✔
984

985
                    for (ii = 0; ii < array_len ; ii++ ) {
6,668✔
986

987
                        if (ii > 0) {
4,203✔
988
                            chkpnt_os << ", ";
1,738✔
989

990
                            // Conditionally line-break and indent.
991
                            if (( (ii+1) % array_elements_per_line[attr->type]) == 0 ) {
1,738✔
992
                                // Line-break.
993
                                chkpnt_os << "\n";
198✔
994
                                // Indent.
995
                                for (jj=0 ; jj < curr_dim+1 ; jj++) {
396✔
996
                                    chkpnt_os << "    ";
198✔
997
                                }
998
                                chkpnt_os << " ";
198✔
999
                            }
1000
                        }
1001
                        write_rvalue( chkpnt_os, address, attr, curr_dim + 1, offset * attr->index[curr_dim].size + ii);
4,203✔
1002
                    }
1003
                    chkpnt_os << "}";
2,465✔
1004

1005
                }
1006

1007
            } else { // Not the final fixed dimension.
2,721✔
1008

1009
                int ii;
1010

1011
                chkpnt_os << "\n";
4✔
1012
                for (ii=0 ; ii < curr_dim+1 ; ii++) {
8✔
1013
                    chkpnt_os << "    ";
4✔
1014
                }
1015
                chkpnt_os << "{";
4✔
1016

1017
                for (ii=0 ; ii< attr->index[curr_dim].size ; ii++) {
265✔
1018
                    if (ii > 0) {
261✔
1019
                        chkpnt_os << ",";
257✔
1020
                    }
1021
                    write_rvalue( chkpnt_os, address, attr, curr_dim + 1, offset * attr->index[curr_dim].size + ii);
261✔
1022
                }
1023

1024
                chkpnt_os << "\n";
4✔
1025

1026
                for (ii=0 ; ii < curr_dim+1 ; ii++) {
8✔
1027
                    chkpnt_os << "    " ;
4✔
1028
                }
1029
                chkpnt_os << "}";
4✔
1030
            }
1031
        }
1032

1033
    } else {
1034
        chkpnt_os << "/*ERROR*/";
×
1035

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

1039
        return;
×
1040
    }
1041
}
1042

1043
// MEMBER FUNCTION
1044
// Create an assignment statement.
1045
void Trick::ClassicCheckPointAgent::assign_rvalue(std::ostream& chkpnt_os, void* address, ATTRIBUTES* attr, int curr_dim, int offset) {
62,331✔
1046

1047
    std::string lname = left_side_name();
62,331✔
1048

1049
    if (!output_perm_check(attr)) {
62,331✔
1050
        if (debug_level) {
×
1051
            message_publish(MSG_DEBUG, "Checkpoint Agent INFO: No assignment generated for \"%s\" "
×
1052
                                       "because its io specification does not allow it.\n", lname.c_str()) ;
1053
        }
1054
        return;
×
1055
    }
1056

1057
    if ((reduced_checkpoint && is_nil_valued( (void*)address, attr, curr_dim, offset ) ) ) {
62,331✔
1058
        if (debug_level) {
32,393✔
1059
            message_publish(MSG_DEBUG, "Checkpoint Agent INFO: No assignment generated for \"%s\" "
×
1060
                                       "because its value is nil and the reduced_checkpoint flag is set.\n", lname.c_str()) ;
1061
        }
1062
        return;
32,393✔
1063
    }
1064

1065
    if (debug_level) {
29,938✔
1066
        message_publish(MSG_DEBUG, "Checkpoint Agent INFO: Generating assignment for [%p] %s.\n",(void*)address, lname.c_str()) ;
×
1067
    }
1068

1069
    if (!input_perm_check(attr)) {
29,938✔
1070
        chkpnt_os << "/* OUTPUT-ONLY: ";
23✔
1071
    }
1072
    if ( attr->type == TRICK_STL ) {
29,938✔
1073
        chkpnt_os << "// STL: " << lname ;
2,541✔
1074
    } else {
1075
        chkpnt_os << lname << " = ";
27,397✔
1076

1077
        write_rvalue( chkpnt_os, (void*)address, attr, curr_dim, offset);
27,397✔
1078
        chkpnt_os << ";";
27,397✔
1079

1080
        // Check if we need to add decimal comments for hexfloat values
1081
        bool should_add_decimal_comment = hexfloat_decimal_comment_checkpoint && hexfloat_checkpoint && (attr->type == TRICK_FLOAT || attr->type == TRICK_DOUBLE);
27,397✔
1082

1083
        // Add decimal comment for hexfloat values
1084
        if (should_add_decimal_comment) {
27,397✔
1085
            // Temporarily disable hexfloat to get decimal representation
1086
            bool saved_hexfloat = hexfloat_checkpoint;
×
1087
            hexfloat_checkpoint = false;
×
1088

1089
            // Capture decimal output to string stream
1090
            std::stringstream decimal_ss;
×
1091
            write_rvalue( decimal_ss, (void*)address, attr, curr_dim, offset);
×
1092

1093
            // Restore hexfloat setting
1094
            hexfloat_checkpoint = saved_hexfloat;
×
1095

1096
            // Add // to each line of the decimal output
1097
            std::string decimal_str = decimal_ss.str();
×
1098
            std::istringstream iss(decimal_str);
×
1099
            std::string line;
×
1100
            bool first_line = true;
×
1101
            
1102
            while (std::getline(iss, line)) {
×
1103
                if (first_line) {
×
1104
                    chkpnt_os << std::endl << "// " << lname << " = " << line;
×
1105
                    first_line = false;
×
1106
                } else {
1107
                    chkpnt_os << std::endl << "//" << line;
×
1108
                }
1109
            }
1110
        }
×
1111
    }
1112
    if (!input_perm_check(attr)) {
29,938✔
1113
        chkpnt_os << "*/";
23✔
1114
    }
1115
    chkpnt_os << std::endl;
29,938✔
1116
    chkpnt_os.flush();
29,938✔
1117

1118
}
62,331✔
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