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

nasa / trick / 25870723371

14 May 2026 04:03PM UTC coverage: 56.928% (+0.2%) from 56.774%
25870723371

Pull #2117

github

web-flow
Merge 694a6c711 into af8c162b8
Pull Request #2117: Completed std::wstring support.

24 of 43 new or added lines in 6 files covered. (55.81%)

199 existing lines in 2 files now uncovered.

12974 of 22790 relevant lines covered (56.93%)

298441.05 hits per line

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

68.82
/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,606✔
65
    return (attr->io & TRICK_CHKPNT_INPUT) ;
134,606✔
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 ;
124,662✔
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;
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,662✔
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;
1,302✔
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,772✔
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✔
NEW
460
           case TRICK_WSTRING :
×
NEW
461
               test_addr = (char*)address + offset * sizeof(std::wstring);
×
NEW
462
               if (*(std::wstring*)test_addr == L"") return(1);
×
NEW
463
               break;
×
464
           case TRICK_STL :
2,541✔
465
               // Can't test properly, always return 0 to indicate the STL is not empty.
466
               return(0);
2,541✔
467
               break;
468
           default :
×
469
               message_publish(MSG_ERROR, "Checkpoint Agent file %s: Unhandled Type (%d).\n", __FILE__, attr->type) ;
×
470
               return(-1);
×
471
               break;
472
        }
473
        return(0);
26,401✔
474

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

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

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

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

508
    } else {
509
        return(-1);
×
510
    }
511
    return(0);
905✔
512
}
513

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

531
void Trick::ClassicCheckPointAgent::write_singleton( std::ostream& chkpnt_os, void* address, ATTRIBUTES* attr, int offset ) {
28,052✔
532

533
    void* src_addr;
534

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

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

602
                enum_attr = (ENUM_ATTR*)attr->attr;
94✔
603

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

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

733
// MEMBER FUNCTION
734
// Get the variable-name associated with the given variable-address and data-type.
735
// If no data-type is specified, (i.e., if attr == NULL), then the name will refer
736
// to the (inner-most) primitive data-type associated with the address.
737

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

741
std::string Trick::ClassicCheckPointAgent::
1,048✔
742
    ref_string_from_ptr( void* pointer, ATTRIBUTES* attr, int curr_dim) {
743

744
    std::string reference_string;
2,096✔
745

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

750
    if (pointer == NULL) {
1,048✔
751
        reference_string = "NULL";
×
752
    } else {
753
        ALLOC_INFO *alloc_info;
754

755
        /** Find the allocation that contains the pointer-address. */
756
        alloc_info = mem_mgr->get_alloc_info_of( pointer);
1,048✔
757

758
        if (alloc_info != NULL) {
1,048✔
759
            // Special handling for character strings: prefer string literal format over allocation reference
760
            // The following info for "char *" is for reference purpose:
761
            // curr_dim = 0
762
            // attr.type = TRICK_CHARACTER (base type)
763
            // attr.num_index = 1 (1D array)
764
            // attr.index[0].size = 0 (not static array)
765
            // attr.size = sizeof(char)
766
            // This prevents anonymous allocations from appearing in subsequent checkpoints
767
            if ((attr != NULL) && (attr->type == TRICK_CHARACTER || attr->type == TRICK_UNSIGNED_CHARACTER) && ((curr_dim + 1) == attr->num_index)) {
1,011✔
768
                std::stringstream ss;
101✔
769
                write_quoted_str( ss, (const char*)pointer);
101✔
770
                reference_string = ss.str();
101✔
771
            } else {
772
                int alloc_elem_size;
773
                int alloc_elem_index;
774
                int misalignment;
775

776
                alloc_elem_size = alloc_info->size;
910✔
777
                alloc_elem_index = (int) (((long) pointer - (long) alloc_info->start) / alloc_elem_size);
910✔
778
                misalignment = (int) (((long) pointer - (long) alloc_info->start) % alloc_elem_size);
910✔
779

780
                // If type-checking AND the type specifiers match AND  the type we're looking for
781
                // is either not structured or if it is, the attr-list that describes the contents
782
                // of the structure is the same.
783

784
                if ( (attr != NULL) && (attr->type == alloc_info->type) &&
910✔
785
                     ( (attr->type != TRICK_STRUCTURED) || (attr->attr == alloc_info->attr))) {
852✔
786

787
                int ii;
788
                int n_l_ptrs, n_r_ptrs;
789

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

793
                // Calculate the number of pointers (asterisks) on the right side of the assignment.
794
                n_r_ptrs = 0;
258✔
795
                for (ii=0 ; ii <alloc_info->num_index ; ii++) {
490✔
796
                    if (alloc_info->index[ii] == 0) n_r_ptrs++;
232✔
797
                }
798

799
                if (n_l_ptrs != (n_r_ptrs + 1)) {
258✔
800
                    reference_string = "NULL /*ERROR: # asterisks disagree.*/";
×
801
                } else {
802
                    if (misalignment == 0) {
258✔
803
                        std::stringstream workss;
516✔
804
                        if (alloc_info->name != NULL) {
258✔
805
                            workss << "&" << alloc_info->name;
258✔
806
                            if (alloc_info->num_index != 0) {
258✔
807
                                workss << "[" << alloc_elem_index << "]";
166✔
808
                            }
809
                            reference_string = workss.str();
258✔
810
                        } else {
811
                            std::stringstream ss;
×
812
                            ss << "Checkpoint Agent ERROR: The name of the allocation at " << alloc_info->start << " is NULL."
×
813
                               << "Therefore, Trick::ClassicCheckPointAgent::ref_string_from_ptr() can't generate a textual reference to it."
×
814
                               << std::endl;
×
815
                            message_publish(MSG_ERROR, ss.str().c_str() );
×
816
                            reference_string = "ERROR - Allocation name is NULL";
×
817
                        }
818

819
                    } else {
820
                        message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Badly aligned pointer.\n"
×
821
                                                   "   It is not aligned with the data object\n"
822
                                                   "   (of the same type) into which it is pointing.\n") ;
823
                        reference_string = "ERROR - Badly aligned pointer";
×
824
                    }
825
                }
258✔
826
            } else if (alloc_info->type == TRICK_STRUCTURED) {
652✔
827
                // The type specifications don't match, but the right-side is structured,
828
                // so we apparently the matching type is buried in the right hand side structure.
829

830
                if (alloc_info->name != NULL) {
651✔
831
                    std::string rightside;
1,302✔
832
                    std::stringstream element_name;
1,302✔
833
                    element_name << "&" << alloc_info->name;
651✔
834
                    if (alloc_info->num_index != 0) {
651✔
835
                        element_name << '[' << alloc_elem_index << ']';
100✔
836
                    }
837
                    rightside = get_var_name( pointer,
651✔
838
                                              alloc_info->attr,
839
                                              (char *) alloc_info->start + (alloc_elem_index * alloc_info->size),
651✔
840
                                              element_name.str(),
1,302✔
841
                                              &attr
842
                                            );
651✔
843
                    reference_string = rightside;
651✔
844
                } else {
845
                    std::stringstream ss;
×
846
                    ss << "Checkpoint Agent ERROR: The name of the allocation at " << alloc_info->start << " is NULL."
×
847
                       << "Therefore, Trick::ClassicCheckPointAgent::ref_string_from_ptr() can't generate a textual reference to it."
×
848
                       << std::endl;
×
849
                    message_publish(MSG_ERROR, ss.str().c_str() );
×
850
                    reference_string = "ERROR - Allocation name is NULL";
×
851
                }
852
            } else { // The type specifications don't match, and the right hand side is not structured
853

854
                if (attr != NULL) {
1✔
855
                    const char* left_type_spec  = trickTypeCharString(attr->type, "");
×
856
                    const char* right_type_spec = trickTypeCharString(alloc_info->type, alloc_info->user_type_name);
×
857
                    message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Type mismatch. Type specifications disagree.\n"
×
858
                                               "   The left side type specifier is \"%s\" but the right side is \"%s\".\n",
859
                                    left_type_spec, right_type_spec) ;
860
                    reference_string = "ERROR - Type specifications disagree";
×
861
                } else {
862

863
                    if (misalignment == 0) {
1✔
864
                        std::stringstream workss;
2✔
865

866
                        if (alloc_info->name != NULL) {
1✔
867
                            workss << "&" << alloc_info->name;
1✔
868
                            if (alloc_info->num_index != 0) {
1✔
869
                                workss << "[" << alloc_elem_index << "]";
×
870
                            }
871
                            reference_string = workss.str();
1✔
872
                        } else {
873
                            std::stringstream ss;
×
874
                            ss << "Checkpoint Agent ERROR: The name of the allocation at " << alloc_info->start << " is NULL."
×
875
                               << "Therefore, Trick::ClassicCheckPointAgent::ref_string_from_ptr() can't generate a textual reference to it."
×
876
                               << std::endl;
×
877
                            message_publish(MSG_ERROR, ss.str().c_str() );
×
878
                            reference_string = "ERROR - Allocation name is NULL";
×
879
                        }
880

881
                    } else {
882
                        message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Badly aligned pointer.\n"
×
883
                                                   "   It is not aligned with the data object\n"
884
                                                   "   (of the same type) into which it is pointing.\n") ;
885
                        reference_string = "ERROR - Badly Aligned Pointer";
×
886
                    }
887
                }
888

889
                }
890
            }
891
        } else if ((attr != NULL) && ((curr_dim + 1) == attr->num_index)) {
37✔
892

893
            if (attr->type == TRICK_CHARACTER) {
37✔
894
                std::stringstream ss;
37✔
895
                write_quoted_str( ss, (const char*)pointer);
37✔
896
                reference_string = ss.str();
37✔
897
            } else if (attr->type == TRICK_WCHAR) {
×
898
                message_publish(MSG_ERROR, "Checkpoint Agent ERROR: TRICK_WCHAR not fully supported yet.\n") ;
×
899
                reference_string = "ERROR: TRICK_WCHAR not fully supported yet.";
×
900
            } else {
901
                std::string lname = left_side_name();
×
902
                message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Pointer <%p> in \"%s\" is not in Trick managed memory\n"
×
903
                                           "nor is it a character pointer.\n", pointer, lname.c_str()) ;
904
                reference_string = "ERROR - Pointer not in Trick managed memory";
×
905
            }
37✔
906

907
        } else {
908
            std::string lname = left_side_name();
×
909
            message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Pointer <%p> in \"%s\" is not in Trick managed memory\n"
×
910
                                       "nor is it a character pointer.\n", pointer, lname.c_str()) ;
911
            reference_string = "ERROR - Pointer not in Trick managed memory";
×
912
        }
913
    }
914
    return( reference_string);
2,096✔
915
}
916

917
// MEMBER FUNCTION
918
void Trick::ClassicCheckPointAgent::write_rvalue( std::ostream& chkpnt_os, void* address, ATTRIBUTES* attr, int curr_dim, int offset) {
31,770✔
919

920
    // If the variable that we are pointing to is Un-arrayed
921
    if (curr_dim == attr->num_index) {
31,770✔
922

923
        write_singleton( chkpnt_os, address, attr, offset);
28,052✔
924

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

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

932
            void* pointer = *(void**)((char*)address + offset * sizeof(void*));
993✔
933

934
            ref_string = ref_string_from_ptr( pointer, attr, curr_dim);
993✔
935

936
            chkpnt_os << ref_string.c_str() ;
993✔
937

938
        } else { // Fixed dimension
939

940
            char* src_addr;
941

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

946
                int use_quoted_string;
947

948
                // If ALL but the last of the elements of a character array
949
                // "isprintable" AND the last is '\0' then print out the array
950
                // as a quoted string. Otherwise print out each of the characters.
951

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

955
                    int array_len = attr->index[curr_dim].size;
304✔
956
                    int ii = array_len - 1;
304✔
957
                    src_addr = (char*)address + offset * array_len * sizeof(char);
304✔
958
                    if (src_addr[ii] != '\0') {
304✔
959
                        use_quoted_string = 0;
23✔
960
                    }
961
                    ii--;
304✔
962
                    while ( use_quoted_string && (ii >= 0) ) {
1,097✔
963
                        use_quoted_string = isprint( src_addr[ii]);
793✔
964
                        ii--;
793✔
965
                    }
966
                }
967

968

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

977

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

980
                    write_quoted_str(chkpnt_os, src_addr);
256✔
981

982
                } else {
983

984
                    int ii, jj;
985
                    int array_len;
986

987
                    // Determine the number of array elements we need to print out
988
                    // to get all of the non-zero values.
989

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

992
                    chkpnt_os << "\n";
2,465✔
993

994
                    for (ii=0 ; ii < curr_dim+1 ; ii++) {
4,935✔
995
                        chkpnt_os << "    ";
2,470✔
996
                    }
997
                    chkpnt_os << "{";
2,465✔
998

999
                    for (ii = 0; ii < array_len ; ii++ ) {
6,668✔
1000

1001
                        if (ii > 0) {
4,203✔
1002
                            chkpnt_os << ", ";
1,738✔
1003

1004
                            // Conditionally line-break and indent.
1005
                            if (( (ii+1) % array_elements_per_line[attr->type]) == 0 ) {
1,738✔
1006
                                // Line-break.
1007
                                chkpnt_os << "\n";
198✔
1008
                                // Indent.
1009
                                for (jj=0 ; jj < curr_dim+1 ; jj++) {
396✔
1010
                                    chkpnt_os << "    ";
198✔
1011
                                }
1012
                                chkpnt_os << " ";
198✔
1013
                            }
1014
                        }
1015
                        write_rvalue( chkpnt_os, address, attr, curr_dim + 1, offset * attr->index[curr_dim].size + ii);
4,203✔
1016
                    }
1017
                    chkpnt_os << "}";
2,465✔
1018

1019
                }
2,721✔
1020

1021
            } else { // Not the final fixed dimension.
1022

1023
                int ii;
1024

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

1031
                for (ii=0 ; ii< attr->index[curr_dim].size ; ii++) {
265✔
1032
                    if (ii > 0) {
261✔
1033
                        chkpnt_os << ",";
257✔
1034
                    }
1035
                    write_rvalue( chkpnt_os, address, attr, curr_dim + 1, offset * attr->index[curr_dim].size + ii);
261✔
1036
                }
1037

1038
                chkpnt_os << "\n";
4✔
1039

1040
                for (ii=0 ; ii < curr_dim+1 ; ii++) {
8✔
1041
                    chkpnt_os << "    " ;
4✔
1042
                }
1043
                chkpnt_os << "}";
4✔
1044
            }
1045
        }
1046

1047
    } else {
1048
        chkpnt_os << "/*ERROR*/";
×
1049

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

1053
        return;
×
1054
    }
1055
}
1056

1057
// MEMBER FUNCTION
1058
// Create an assignment statement.
1059
void Trick::ClassicCheckPointAgent::assign_rvalue(std::ostream& chkpnt_os, void* address, ATTRIBUTES* attr, int curr_dim, int offset) {
62,331✔
1060

1061
    std::string lname = left_side_name();
62,331✔
1062

1063
    if (!output_perm_check(attr)) {
62,331✔
1064
        if (debug_level) {
×
1065
            message_publish(MSG_DEBUG, "Checkpoint Agent INFO: No assignment generated for \"%s\" "
×
1066
                                       "because its io specification does not allow it.\n", lname.c_str()) ;
1067
        }
1068
        return;
×
1069
    }
1070

1071
    if ((reduced_checkpoint && is_nil_valued( (void*)address, attr, curr_dim, offset ) ) ) {
62,331✔
1072
        if (debug_level) {
32,484✔
1073
            message_publish(MSG_DEBUG, "Checkpoint Agent INFO: No assignment generated for \"%s\" "
×
1074
                                       "because its value is nil and the reduced_checkpoint flag is set.\n", lname.c_str()) ;
1075
        }
1076
        return;
32,484✔
1077
    }
1078

1079
    if (debug_level) {
29,847✔
1080
        message_publish(MSG_DEBUG, "Checkpoint Agent INFO: Generating assignment for [%p] %s.\n",(void*)address, lname.c_str()) ;
×
1081
    }
1082

1083
    if (!input_perm_check(attr)) {
29,847✔
1084
        chkpnt_os << "/* OUTPUT-ONLY: ";
23✔
1085
    }
1086
    if ( attr->type == TRICK_STL ) {
29,847✔
1087
        chkpnt_os << "// STL: " << lname ;
2,541✔
1088
    } else {
1089
        chkpnt_os << lname << " = ";
27,306✔
1090

1091
        write_rvalue( chkpnt_os, (void*)address, attr, curr_dim, offset);
27,306✔
1092
        chkpnt_os << ";";
27,306✔
1093

1094
        // Check if we need to add decimal comments for hexfloat values
1095
        bool should_add_decimal_comment = hexfloat_decimal_comment_checkpoint && hexfloat_checkpoint && (attr->type == TRICK_FLOAT || attr->type == TRICK_DOUBLE);
27,306✔
1096

1097
        // Add decimal comment for hexfloat values
1098
        if (should_add_decimal_comment) {
27,306✔
1099
            // Temporarily disable hexfloat to get decimal representation
1100
            bool saved_hexfloat = hexfloat_checkpoint;
×
1101
            hexfloat_checkpoint = false;
×
1102

1103
            // Capture decimal output to string stream
1104
            std::stringstream decimal_ss;
×
1105
            write_rvalue( decimal_ss, (void*)address, attr, curr_dim, offset);
×
1106

1107
            // Restore hexfloat setting
1108
            hexfloat_checkpoint = saved_hexfloat;
×
1109

1110
            // Add // to each line of the decimal output
1111
            std::string decimal_str = decimal_ss.str();
×
1112
            std::istringstream iss(decimal_str);
×
1113
            std::string line;
×
1114
            bool first_line = true;
×
1115
            
1116
            while (std::getline(iss, line)) {
×
1117
                if (first_line) {
×
1118
                    chkpnt_os << std::endl << "// " << lname << " = " << line;
×
1119
                    first_line = false;
×
1120
                } else {
1121
                    chkpnt_os << std::endl << "//" << line;
×
1122
                }
1123
            }
1124
        }
1125
    }
1126
    if (!input_perm_check(attr)) {
29,847✔
1127
        chkpnt_os << "*/";
23✔
1128
    }
1129
    chkpnt_os << std::endl;
29,847✔
1130
    chkpnt_os.flush();
29,847✔
1131

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