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

nasa / trick / 22693001714

04 Mar 2026 10:45PM UTC coverage: 55.816%. First build
22693001714

Pull #1965

github

web-flow
Merge 5fc9bb718 into 43b8fa7c8
Pull Request #1965: 1964 methods return size one pointers

153 of 184 new or added lines in 3 files covered. (83.15%)

12630 of 22628 relevant lines covered (55.82%)

301477.02 hits per line

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

68.79
/trick_source/sim_services/CheckPointAgent/ClassicCheckPointerAgent.cpp
1
#include "trick/MemoryManager.hh"
2
#include "trick/parameter_types.h"
3
#include "trick/io_alloc.h"
4
#include "trick/wcs_ext.h"
5
#include "trick/bitfield_proto.h"
6
#include "trick/message_proto.h"
7
#include "trick/message_type.h"
8

9
#include "trick/ClassicCheckPointAgent.hh"
10
#include "trick/AttributesUtils.hh"
11
#include "trick/ChkPtParseContext.hh"
12

13
#include <string>
14
#include <iostream>
15
#include <iomanip>
16
#include <sstream>
17
#include <stdlib.h>
18
#include <math.h>
19
#include <string.h>
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) {
631✔
53

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

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

63
// MEMBER FUNCTION
64
bool Trick::ClassicCheckPointAgent::input_perm_check(ATTRIBUTES * attr) {
134,555✔
65
    return (attr->io & TRICK_CHKPNT_INPUT) ;
134,555✔
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;
197
    int ret = Trick::AttributesUtils::traverse_for_offset(referenceOffset, (size_t)sAddr, 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
            return 0;
×
254
        }
255

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

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

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

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

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

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

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

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

303
    return 0;
16✔
304
}
305

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

525
    void* src_addr;
526

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

761
                int ii;
762
                int n_l_ptrs, n_r_ptrs;
763

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

912
        } else { // Fixed dimension
913

914
            char* src_addr;
915

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

920
                int use_quoted_string;
921

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

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

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

942

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

951

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

954
                    write_quoted_str(chkpnt_os, src_addr);
256✔
955

956
                } else {
957

958
                    int ii, jj;
959
                    int array_len;
960

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

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

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

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

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

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

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

993
                }
2,721✔
994

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

997
                int ii;
998

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

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

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

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

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

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

1027
        return;
×
1028
    }
1029
}
1030

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

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

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

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

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

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

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

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

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

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

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

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

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