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

nasa / trick / 21044401961

15 Jan 2026 07:54PM UTC coverage: 55.668% (-0.2%) from 55.875%
21044401961

Pull #1965

github

web-flow
Merge 971139f89 into 3fa559ade
Pull Request #1965: 1964 methods return size one pointers

90 of 127 new or added lines in 3 files covered. (70.87%)

1023 existing lines in 21 files now uncovered.

12571 of 22582 relevant lines covered (55.67%)

306300.23 hits per line

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

67.88
/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
// MEMBER FUNCTION
50
Trick::ClassicCheckPointAgent::ClassicCheckPointAgent( Trick::MemoryManager *MM) {
629✔
51

52
   mem_mgr = MM;
629✔
53
   reduced_checkpoint = 1;
629✔
54
   hexfloat_checkpoint = 0;
629✔
55
   debug_level = 0;
629✔
56
}
629✔
57

58
// MEMBER FUNCTION
59
Trick::ClassicCheckPointAgent::~ClassicCheckPointAgent() { }
1,256✔
60

61
// MEMBER FUNCTION
62
bool Trick::ClassicCheckPointAgent::input_perm_check(ATTRIBUTES * attr) {
124,498✔
63
    return (attr->io & TRICK_CHKPNT_INPUT) ;
124,498✔
64
}
65

66
bool Trick::ClassicCheckPointAgent::output_perm_check(ATTRIBUTES * attr) {
171,632✔
67
    return (attr->io & TRICK_CHKPNT_OUTPUT) ;
171,632✔
68
}
69

70
// MEMBER FUNCTION
71
std::string Trick::ClassicCheckPointAgent::left_side_name() {
58,880✔
72

73
    std::string name ;
117,760✔
74
    int ii;
75
    int n_elements = leftside_stack.size();
58,880✔
76

77
    for (ii = 0; ii < n_elements ; ii++) {
227,951✔
78

79
        VarNameElement & element = leftside_stack[ii];
169,071✔
80

81
        switch( element.type) {
169,071✔
82

83
            case BASE_NAME: {
58,880✔
84
                name = element.name;
58,880✔
85
            } break;
58,880✔
86

87
            case ELEM_NAME: {
63,189✔
88
                name += '.' + element.name;
63,189✔
89
            } break;
63,189✔
90

91
            case ARRAY_INDEX: {
47,002✔
92
                std::stringstream index_string;
94,004✔
93
                index_string << element.index;
47,002✔
94
                name += '[';
47,002✔
95
                name += index_string.str();
47,002✔
96
                name += ']';
47,002✔
97
            } break;
47,002✔
98

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

107
// MEMBER FUNCTION
108
void Trick::ClassicCheckPointAgent::write_decl(std::ostream& chkpnt_os, ALLOC_INFO *info) {
2,696✔
109

110
    const char *type_spec;
111

112
    type_spec = trickTypeCharString(info->type, info->user_type_name);
2,696✔
113

114
    if (info->stcl == TRICK_EXTERN) {
2,696✔
115
        chkpnt_os << "// extern ";
×
116
    }
117

118
    if ( info->num_index == 0 ) {
2,696✔
119

120
        chkpnt_os << type_spec << " " << info->name << ";\n";
94✔
121

122
    } else if ((info->num_index > 0) && (info->num_index <= TRICK_MAX_INDEX)) {
2,602✔
123
        int ii;
124

125
        chkpnt_os << type_spec;
2,602✔
126

127
        ii = info->num_index-1;
2,602✔
128
        while ((ii >= 0) && (info->index[ii] == 0)) {
2,711✔
129
            chkpnt_os << "*";
109✔
130
            ii --;
109✔
131
        }
132

133
        chkpnt_os << " " << info->name ;
2,602✔
134

135
        ii = 0;
2,602✔
136
        while ((ii < info->num_index) && (info->index[ii] != 0)) {
5,203✔
137
            chkpnt_os << "[" << info->index[ii] << "]" ;
2,601✔
138
            ii ++;
2,601✔
139
        }
140
          chkpnt_os << ";" << std::endl;
2,602✔
141

142
    } else {
143
        // ERROR - num_index cant be negative.
144
    }
145
}
2,696✔
146

147
// STATIC FUNCTION
148
/*
149
   Given an address, that is within the bounds of a composite
150
   object (i.e., a struct or class instance), store the corresponding sub-name
151
   in reference_name buffer and return.
152

153
   A return value of 1 indicates an error occured. A return value of 0 indicates
154
   success.
155

156
   The following BNF production describes a valid sub-reference:
157

158
   <sub_reference> --> ""
159
                     | "+" + <offset>
160
                     | "[" + <index>+ "]" + <sub_reference>
161
                     | "." + <member_name> + <sub_reference>
162

163
   <offset> is an integer. It is the the reference offset minus the offset of
164
   the last data member.
165
   <index> is an integer. It is an array index.
166
   <member_name> is a name of a member of the given composite type.
167
*/
168

169
static int getCompositeSubReference(
714✔
170
    void*        reference_address, /* Address we are looking for */
171
    ATTRIBUTES** left_type,         /* Attributes of type we are looking for */
172
    void*        structure_address, /* Address of struct we are in */
173
    ATTRIBUTES*  A,                 /* Attributes of current struct we are in */
174
    char* reference_name            /* destination buffer of composite subreference */
175
    ) {
176

177
    int   j, m;
178
    long  offset;
179
    int   my_index[TRICK_MAX_INDEX];
180
    int   ret;
181

182
    char* rAddr = (char*)reference_address;
714✔
183
    char* sAddr = (char*)structure_address;
714✔
184

185
    long referenceOffset = (long)rAddr - (long)sAddr;
714✔
186

187
    // selected ATTRIBUTES stucture from A (singular)
188
    ATTRIBUTES* Ai;
189

190

191
    if ( referenceOffset < 0) {
714✔
192
        message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Address to find is less than struct address.\n") ;
×
193
        return 1;
×
194
    }
195

196
    // Find the structure member that corresponds to the reference address.
197
    // If name is empty, we have failed.
198
    Ai = Trick::AttributesUtils::find_member_by_offset(A, referenceOffset);
714✔
199

200
/******If failed to find member, set reference_name to offset only and return ****/
201
    if (Ai->name[0] == '\0') {
714✔
202
        /* If we fail to find a member corresponding to the reference address,
203
           it must mean that the ATTRIBUTES don't contain a description for
204
           that particular member, i.e., it was **'ed out. In this case, we can only
205
           represent the reference_address as a byte offset into the structure.
206
         */
207
        if (referenceOffset == 0) {
557✔
208
            reference_name[0] = '\0' ;
547✔
209
        } else if (referenceOffset > 0) {
10✔
210
            snprintf(reference_name, (size_t)256, " + %ld" , referenceOffset);
10✔
211
        } else {
212
            return 1; // ERROR
×
213
        }
214
        return 0;
557✔
215
    }
216

217
/******************************************************************************/
218
    
219
/* We found a member corresponding to the reference address, so print it's name. */
220
    snprintf(reference_name, (size_t)256, ".%s", Ai->name);
157✔
221

222
/* If the referenced member variable is an intrinsic type */
223
    if (Ai->type != TRICK_STRUCTURED) {
157✔
224

225
/* If the reference address is non-array or a pointer, return reference_name as is */
226
        if((Ai->num_index == 0) || (Ai->index[0].size == 0)) {
14✔
227
            return 0;
14✔
228
        }
229

230
/* else, rAddr is pointing to an array, determine its dimensions and determine 
231
   the element pointed to by rAddr. Then print the index and return */
232

NEW
233
        offset = (long)rAddr - ((long)sAddr + Ai->offset);
×
234
        {
NEW
235
            int num_fixed_dims = 0;
×
NEW
236
            bool ok = Trick::AttributesUtils::compute_fixed_indices_for_linear_offset(*Ai, offset, my_index, num_fixed_dims);
×
NEW
237
            if (!ok)
×
238
            {
239
                std::cerr << "Checkpoint Agent " << __FUNCTION__
NEW
240
                          << " ERROR: divide by zero during array indices calculation" << std::endl;
×
NEW
241
                return 1;
×
242
            }
NEW
243
            for (j = 0; j < num_fixed_dims; j++)
×
244
            {
NEW
245
                size_t len = strlen(reference_name);
×
NEW
246
                size_t rem = (size_t)256 - len;
×
NEW
247
                snprintf(&reference_name[len], rem, "[%d]", my_index[j]);
×
248
            }
249
        }
250
    return 0;
×
251
    }
252
/******** TRICK_STRUCTURED ****************************************************/
253
    /* if it is a reference, do nothing and return */
254
    if ((Ai->mods & 1) == 1) { // Ai->type == TRICK_STRUCTURED
143✔
255
        return 0;
1✔
256
    }
257
/*if member is an unarrayed struct, continue to call getCompositeSubReference.*/
258
    if (Ai->num_index == 0) {
142✔
259
        /* if left_type specifies the current member, stop here */
260
        if ( (left_type != NULL) && (*left_type != NULL) && (Ai->attr == (*left_type)->attr)) {
139✔
UNCOV
261
            return 0;
×
262
        }
263

264
        char buf[256];
265
        ret = getCompositeSubReference( rAddr, left_type, sAddr + Ai->offset, (ATTRIBUTES *) Ai->attr, buf);
139✔
266

267
        if (ret == 0) {
139✔
268
            size_t len = strlen(reference_name);
139✔
269
            size_t rem = (size_t)256 - len;
139✔
270
            snprintf(&reference_name[len], rem, "%s", buf);
139✔
271
        } else {
UNCOV
272
            return 1; // ERROR.
×
273
        }
274
    return 0;
139✔
275
    }
276

277
/***** If the member is not a pointer do nothing and return *******************/
278
    if (Ai->index[0].size == 0) {
3✔
279
        return 0;
2✔
280
    }
281

282
/*** Member is an arrayed struct *********************************************/
283

284
    offset = (long)rAddr - ((long)sAddr + Ai->offset);
1✔
285
    {
286
        int num_fixed_dims = 0;
1✔
287
        bool ok = Trick::AttributesUtils::compute_fixed_indices_for_linear_offset(*Ai, offset, my_index, num_fixed_dims);
1✔
288
        if (!ok)
1✔
289
        {
290
            std::cerr << "Checkpoint Agent " << __FUNCTION__
NEW
291
                      << " ERROR: divide by zero during array indices calculation" << std::endl;
×
NEW
292
            return 1;
×
293
        }
294

295
        for (j = 0; j < Ai->num_index; j++)
3✔
296
        {
297
            size_t len = strlen(reference_name);
2✔
298
            size_t rem = (size_t)256 - len;
2✔
299
            snprintf(&reference_name[len], rem, "[%d]", my_index[j]);
2✔
300
        }
301
    }
302

303
    /* if left_type specifies the current member, stop here */
304
    if ( (left_type != NULL) && (*left_type != NULL) && (Ai->attr == (*left_type)->attr)) {
1✔
UNCOV
305
        return 0;
×
306
    } 
307

308
/**** Go find the subreference for the arrayed struct member and append *********/
309

310
    /* get the offset into the array that rAddr points to */
311
    offset = 0;
1✔
312
    for (j = 0; j < Ai->num_index; j++) {
3✔
313
      m = my_index[j];
2✔
314
      for(int k = j + 1; m && (k < Ai->num_index); k++) {
3✔
315
        m *= Ai->index[k].size;
1✔
316
      }
317
      offset += m*Ai->size;
2✔
318
    }
319

320
    {
321
        char buf[256];
322
        ret = getCompositeSubReference( rAddr, left_type, sAddr + Ai->offset + offset, (ATTRIBUTES *) Ai->attr, buf);
1✔
323

324
        if (ret == 0) {
1✔
325
            size_t len = strlen(reference_name);
1✔
326
            size_t rem = (size_t)256 - len;
1✔
327
            snprintf(&reference_name[len], rem, "%s", buf);
1✔
328
        } else {
UNCOV
329
            return 1; // ERROR
×
330
        }
331
    }
332

333
    return 0;
1✔
334
}
335

336

337
// MEMBER FUNCTION
338
// Get the fully qualified varible name of the Allocation, given the address.
339

340
std::string Trick::ClassicCheckPointAgent::get_var_name( void* addr,
574✔
341
                                                         ATTRIBUTES* A,
342
                                                         void* struct_addr,
343
                                                         std::string name,
344
                                                         ATTRIBUTES** left_type) {
345
    char reference_name[256];
346
    int ret;
347
    std::string var_name;
1,148✔
348

349
    var_name = name;
574✔
350
    ret = getCompositeSubReference( addr, left_type, struct_addr, A, reference_name );
574✔
351

352
    if (ret == 0) {
574✔
353
        var_name += reference_name;
574✔
354
    } else {
UNCOV
355
          std::stringstream ss;
×
UNCOV
356
          ss << "Checkpoint Agent ERROR: Unable to create a subreference of variable \"" << name << "\"."
×
UNCOV
357
             << std::endl;
×
UNCOV
358
          message_publish(MSG_ERROR, ss.str().c_str() );
×
359
    }
360
    return (var_name);
1,148✔
361
}
362

363
// MEMBER FUNCTION
364
int Trick::ClassicCheckPointAgent::restore( std::istream* checkpoint_stream) {
23✔
365

366
    ChkPtParseContext* context = new ChkPtParseContext( mem_mgr, checkpoint_stream);
23✔
367
    int status = 0;
23✔
368

369
    if ( CCP_parse( context)) {
23✔
370
        status = 1;
×
371
    } else if ((context->bad_declaration_count > 0) ||
23✔
372
               (context->bad_assignment_count > 0)) {
23✔
373
        std::stringstream ss;
×
UNCOV
374
        ss << "Checkpoint Agent ERROR: " << context->bad_declaration_count << " invalid declaration(s) "
×
UNCOV
375
           << "and " << context->bad_assignment_count << " invalid assignment(s)."
×
UNCOV
376
           << std::endl;
×
377
        message_publish(MSG_ERROR, ss.str().c_str() );
×
378
        status = 1;
×
379
    }
380

381
    if (status) {
23✔
UNCOV
382
        std::stringstream ss;
×
UNCOV
383
        ss << "Checkpoint Agent ERROR: Checkpoint restore failed."
×
UNCOV
384
           << std::endl;
×
UNCOV
385
        message_publish(MSG_INFO, ss.str().c_str() );
×
386
    }
387
    delete context ;
23✔
388
    return (status);
23✔
389
}
390

391
// MEMBER FUNCTION
392
int Trick::ClassicCheckPointAgent::is_nil_valued( void* address,
68,118✔
393
                                                  ATTRIBUTES* attr,
394
                                                  int curr_dim,
395
                                                  int offset
396
                                                ) {
397

398
    char* test_addr;
399
    int remaining_dimensions = attr->num_index - curr_dim;
68,118✔
400

401
    /** @par Detailed Description: */
402

403
    /** @par
404
        If we're referencing a singleton then calculate the test-address
405
        from the (base) address, the offset and the data-type. Then
406
        test that calculated address (with the given type) for nil.
407
        If it's nil return 1, otherwise return 0.
408
     */
409
    if (remaining_dimensions ==0) {
68,118✔
410

411
        switch (attr->type) {
63,798✔
412
           case TRICK_CHARACTER :
6,976✔
413
           case TRICK_UNSIGNED_CHARACTER :
414
               test_addr = (char*)address + offset * sizeof(char);
6,976✔
415
               if (*(char*)test_addr == '\0') return(1);
6,976✔
416
               break;
120✔
417
           case TRICK_BOOLEAN:
13,557✔
418
               test_addr = (char*)address + offset * sizeof(bool);
13,557✔
419
               if (*(bool*)test_addr == false) return(1);
13,557✔
420
               break;
2,629✔
UNCOV
421
           case TRICK_WCHAR :
×
UNCOV
422
               test_addr = (char*)address + offset * sizeof(wchar_t);
×
UNCOV
423
               if (*(wchar_t*)test_addr == 0) return(1);
×
UNCOV
424
               break;
×
425
           case TRICK_SHORT :
2,241✔
426
           case TRICK_UNSIGNED_SHORT :
427
               test_addr = (char*)address + offset * sizeof(short);
2,241✔
428
               if (*(short*)test_addr == 0) return(1);
2,241✔
429
               break;
1,885✔
430
           case TRICK_INTEGER :
13,144✔
431
           case TRICK_UNSIGNED_INTEGER :
432
               test_addr = (char*)address + offset * sizeof(int);
13,144✔
433
               if (*(int*)test_addr == 0) return(1);
13,144✔
434
               break;
6,949✔
435
           case TRICK_ENUMERATED :
380✔
436
               if ((size_t)attr->size == sizeof(int)) {
380✔
437
                   test_addr = (char*)address + offset * sizeof(int);
380✔
438
                   if (*(int*)test_addr == 0) return(1);
380✔
UNCOV
439
               } else if ((size_t)attr->size == sizeof(short)) {
×
UNCOV
440
                   test_addr = (char*)address + offset * sizeof(short);
×
UNCOV
441
                   if (*(short*)test_addr == 0) return(1);
×
442
               } else {
UNCOV
443
                   return(-1);
×
444
               }
445
               break;
80✔
446
           case TRICK_LONG :
97✔
447
           case TRICK_UNSIGNED_LONG :
448
               test_addr = (char*)address + offset * sizeof(long);
97✔
449
               if (*(long*)test_addr == 0) return(1);
97✔
450
               break;
48✔
451
           case TRICK_FLOAT :
2✔
452
               test_addr = (char*)address + offset * sizeof(float);
2✔
453
               if (fpclassify( *(float*)test_addr) == FP_ZERO) return(1);
2✔
454
               break;
2✔
455
           case TRICK_DOUBLE :
7,526✔
456
               test_addr = (char*)address + offset * sizeof(double);
7,526✔
457
               if (fpclassify( *(double*)test_addr) == FP_ZERO) return(1);
7,526✔
458
               break;
4,805✔
459
           case TRICK_LONG_LONG :
9,392✔
460
           case TRICK_UNSIGNED_LONG_LONG :
461
               test_addr = (char*)address + offset * sizeof(long long);
9,392✔
462
               if (*(long long*)test_addr == 0) return(1);
9,392✔
463
               break;
863✔
464
           case TRICK_BITFIELD :
×
465
           case TRICK_UNSIGNED_BITFIELD :
466
               test_addr = (char*)address + offset * (size_t)attr->size;
×
467
               if (attr->size == sizeof(int)) {
×
UNCOV
468
                   if (*(int*)test_addr == 0) return(1);
×
469
               } else if (attr->size == sizeof(short)) {
×
UNCOV
470
                   if (*(short*)test_addr == 0) return(1);
×
471
               } else if (attr->size == sizeof(char)) {
×
UNCOV
472
                   if (*(char*)test_addr == 0) return(1);
×
473
               } else {
474
                   message_publish(MSG_ERROR, "Checkpoint Agent INTERNAL ERROR:\n"
×
475
                                              "Unhandled bitfield struct size (%d) in bitfield assignment.\n", attr->size) ;
476
                   return(-1);
×
477
               }
UNCOV
478
               break;
×
UNCOV
479
           case TRICK_FILE_PTR :
×
480
               // FIXME
UNCOV
481
               return(0);
×
482
               break;
483
           case TRICK_STRING :
8,101✔
484
               test_addr = (char*)address + offset * sizeof(void*);
8,101✔
485
               if (*(std::string*)test_addr == "") return(1);
8,101✔
486
               break;
7,598✔
487
           case TRICK_STL :
2,382✔
488
               // Can't test properly, always return 0 to indicate the STL is not empty.
489
               return(0);
2,382✔
490
               break;
UNCOV
491
           default :
×
UNCOV
492
               message_publish(MSG_ERROR, "Checkpoint Agent file %s: Unhandled Type (%d).\n", __FILE__, attr->type) ;
×
UNCOV
493
               return(-1);
×
494
               break;
495
        }
496
        return(0);
24,979✔
497

498
    /** @par
499
        If on the otherhand we are referencing an array, then we must consider two cases.
500
     */
501
    } else if (remaining_dimensions > 0) {
4,320✔
502
       int curr_dim_size;
503
       curr_dim_size = attr->index[curr_dim].size ;
4,320✔
504

505
       /**  @par
506
            If the array is unconstrained (i.e., it's a pointer) then we just need to check
507
            whether the pointer is NULL.
508
        */
509
       if ( curr_dim_size == 0) {
4,320✔
510
           test_addr = ((char*)address) + (offset*sizeof(void *));
1,783✔
511
           if (*(char**)test_addr == NULL) return(1);
1,783✔
512

513
       /** @par
514
           If the array (at this dimension) is constrained (i.e., it's a fixed array )
515
           then it is nil if and only if each of it's sub-elements (at the next dimension,
516
           which can themselves be arrays) are nil. So, for each of the elements in current
517
           dimension, we recursively call is_nil_valued() on each of the sub-elements to
518
           find out whether this array is nil valued and return the result.
519
           */
520
       } else {
521
           int ii;
522
           int zerotest;
523

524
           for (ii=0; ii < curr_dim_size; ii++) {
9,368✔
525
               zerotest = is_nil_valued( address, attr, curr_dim+1, offset*curr_dim_size+ii);
9,238✔
526
               if (!(zerotest == 1)) return(zerotest);
9,238✔
527
           }
528
           return(1);
130✔
529
       }
530

531
    } else {
UNCOV
532
        return(-1);
×
533
    }
534
    return(0);
865✔
535
}
536

537
// STATIC FUNCTION
538
static void write_quoted_str( std::ostream& os, const char* s) {
8,035✔
539
    int ii;
540
    int len = strlen(s);
8,035✔
541
    os << "\"" ;
8,035✔
542
    for (ii=0 ; ii<len ; ii++) {
139,672✔
543
        switch ((s)[ii]) {
131,637✔
544
        case '\n': os << "\\n"; break;
54✔
UNCOV
545
        case '\t': os << "\\t"; break;
×
UNCOV
546
        case '\b': os << "\\b"; break;
×
547
        case '\"': os << "\\\""; break;
62✔
548
        default  : os << s[ii] ; break;
131,521✔
549
        }
550
    }
551
    os << "\"" ;
8,035✔
552
}
8,035✔
553

554
void Trick::ClassicCheckPointAgent::write_singleton( std::ostream& chkpnt_os, void* address, ATTRIBUTES* attr, int offset ) {
28,749✔
555

556
    void* src_addr;
557

558
    switch(attr->type) {
28,749✔
UNCOV
559
        case TRICK_VOID:
×
UNCOV
560
            chkpnt_os << std::endl << "// ERROR - VOID data type cannot be checkpointed." << std::endl;
×
UNCOV
561
            message_publish(MSG_ERROR, "Checkpoint Agent ERROR: VOID data type cannot be checkpointed.\n") ;
×
UNCOV
562
        break;
×
563
        case TRICK_UNSIGNED_CHARACTER:
1✔
564
            src_addr = (char*)address + offset * sizeof(unsigned char);
1✔
565
            chkpnt_os << std::dec << (int)*(unsigned char*)src_addr ;
1✔
566
        break;
1✔
567
        case TRICK_BOOLEAN:
2,630✔
568
            src_addr = (char*)address + offset * sizeof(bool);
2,630✔
569
            if (*(bool*)src_addr) {
2,630✔
570
                chkpnt_os << "true" ;
2,629✔
571
            } else {
572
                chkpnt_os << "false" ;
1✔
573
            }
574
        break;
2,630✔
575
        case TRICK_CHARACTER:
3,307✔
576
            src_addr = (char*)address + offset * sizeof(char);
3,307✔
577
            if (isprint( *(char*)src_addr) ) {
3,307✔
578
                chkpnt_os << "'" << *(char*)src_addr << "'" ;
2,842✔
579
            } else {
580
                unsigned int ch = *(unsigned char*)src_addr;
465✔
581
                  chkpnt_os << "'\\x" << std::hex << ch << "'" ;
465✔
582
            }
583
        break;
3,307✔
UNCOV
584
        case TRICK_WCHAR: {
×
585
            src_addr = (char*)address + offset * sizeof(wchar_t);
×
UNCOV
586
            char buff[16] = {0};
×
UNCOV
587
            wctomb(buff,*(wchar_t*)src_addr);
×
UNCOV
588
            chkpnt_os << std::dec << buff;
×
589
            }
UNCOV
590
            break;
×
591
        case TRICK_SHORT:
8✔
592
            src_addr = (char*)address + offset * sizeof(short);
8✔
593
            chkpnt_os << std::dec << *(short*)src_addr;
8✔
594
            break;
8✔
595
        case TRICK_UNSIGNED_SHORT:
1,881✔
596
            src_addr = (char*)address + offset * sizeof(unsigned short);
1,881✔
597
            chkpnt_os << std::dec << *(unsigned short*)src_addr;
1,881✔
598
            break;
1,881✔
599
        case TRICK_ENUMERATED: {
84✔
600
                int ii = 0;
84✔
601
                int found = 0;
84✔
602
                int value;
603
                ENUM_ATTR* enum_attr;
604

605
                if ((size_t)attr->size == sizeof(int)) {
84✔
606
                    src_addr = (char*)address + offset * sizeof(int);
84✔
607
                    value =  *(int*)src_addr;
84✔
608
                } else if ((size_t)attr->size == sizeof(short)) {
×
609
                    src_addr = (char*)address + offset * sizeof(short);
×
UNCOV
610
                    value =  *(short*)src_addr;
×
611
                } else {
UNCOV
612
                    std::cerr << __FUNCTION__ << ": enumeration size error." << std::endl;
×
UNCOV
613
                    std::cerr.flush();
×
UNCOV
614
                    value = -1;
×
615
                }
616

617
                enum_attr = (ENUM_ATTR*)attr->attr;
84✔
618

619
                while ( !found && (enum_attr[ii].label[0] != '\0')) {
318✔
620
                   if (value == enum_attr[ii].value) {
234✔
621
                       chkpnt_os << enum_attr[ii].label;
84✔
622
                       found = 1;
84✔
623
                   }
624
                   ii++;
234✔
625
                }
626
                if (!found) {
84✔
UNCOV
627
                    chkpnt_os << std::dec << value;
×
628
                }
629

630
            } break;
84✔
631
        case TRICK_INTEGER:
6,980✔
632
            src_addr = (char*)address + offset * sizeof(int);
6,980✔
633
            chkpnt_os << std::dec << *(int*)src_addr;
6,980✔
634
            break;
6,980✔
635
        case TRICK_UNSIGNED_INTEGER:
306✔
636
            src_addr = (char*)address + offset * sizeof(unsigned int);
306✔
637
            chkpnt_os << std::dec << *(unsigned int*)src_addr;
306✔
638
            break;
306✔
639
        case TRICK_LONG:
39✔
640
            src_addr = (char*)address + offset * sizeof(long);
39✔
641
            chkpnt_os << std::dec << *(long*)src_addr;
39✔
642
            break;
39✔
643
        case TRICK_UNSIGNED_LONG:
14✔
644
            src_addr = (char*)address + offset * sizeof(unsigned long);
14✔
645
            chkpnt_os << std::dec << *(unsigned long*)src_addr;
14✔
646
            break;
14✔
647
        case TRICK_FLOAT:
4✔
648
            src_addr = (char*)address + offset * sizeof(float);
4✔
649
            if (fpclassify( *(float*)src_addr) != FP_NAN) {
4✔
650
                if (hexfloat_checkpoint) {
4✔
UNCOV
651
                    double temp_dbl = *(float*)src_addr;
×
UNCOV
652
                    unsigned char* byte_p = (unsigned char*)&temp_dbl;
×
UNCOV
653
                    chkpnt_os << "0g";
×
UNCOV
654
                    for (int ii=sizeof(double)-1 ; ii>= 0 ; ii--) {
×
UNCOV
655
                        chkpnt_os << std::hex << std::setw(2) << std::setfill('0') << (unsigned int)byte_p[ii];
×
656
                    }
657
                } else {
658
                    chkpnt_os << std::setprecision(8) << *(float*)src_addr;
4✔
659
                }
660
            } else {
UNCOV
661
                chkpnt_os << "NAN";
×
662
            }
663
            break;
4✔
664
        case TRICK_DOUBLE:
4,942✔
665
            src_addr = (char*)address + offset * sizeof(double);
4,942✔
666
            if (fpclassify( *(double*)src_addr) != FP_NAN) {
4,942✔
667
                if (hexfloat_checkpoint) {
4,942✔
668
                    double temp_dbl = *(double*)src_addr;
4✔
669
                    unsigned char* byte_p = (unsigned char*)&temp_dbl;
4✔
670
                    chkpnt_os << "0g";
4✔
671
                    for (int ii=sizeof(double)-1 ; ii>= 0 ; ii--) {
36✔
672
                        chkpnt_os << std::hex << std::setw(2) << std::setfill('0') << (unsigned int)byte_p[ii];
32✔
673
                    }
674
                } else {
675
                    chkpnt_os << std::setprecision(16) << *(double*)src_addr;
4,938✔
676
                }
677
            } else {
678
                chkpnt_os << "NAN";
×
679
            }
680
            break;
4,942✔
681
        case TRICK_BITFIELD: {
×
682
                int sbf = 0;
×
683
                src_addr = (char*)address + offset * (size_t)attr->size;
×
684
                if (attr->size == sizeof(int)) {
×
UNCOV
685
                     sbf = extract_bitfield_any( *(int*)src_addr, attr->size, attr->index[0].start, attr->index[0].size);
×
686
                } else if (attr->size == sizeof(short)) {
×
UNCOV
687
                     sbf = extract_bitfield_any( *(short*)src_addr, attr->size, attr->index[0].start, attr->index[0].size);
×
UNCOV
688
                } else if (attr->size == sizeof(char)) {
×
689
                     sbf = extract_bitfield_any( *(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 << sbf;
×
695
            } break;
×
696
        case TRICK_UNSIGNED_BITFIELD: {
×
697
                int bf = 0;
×
698
                src_addr = (char*)address + offset * (size_t)attr->size;
×
699
                if (attr->size == sizeof(int)) {
×
UNCOV
700
                     bf = extract_unsigned_bitfield_any( *(unsigned int*)src_addr, attr->size, attr->index[0].start, attr->index[0].size);
×
701
                } else if (attr->size == sizeof(short)) {
×
UNCOV
702
                     bf = extract_unsigned_bitfield_any( *(unsigned short*)src_addr, attr->size, attr->index[0].start, attr->index[0].size);
×
UNCOV
703
                } else if (attr->size == sizeof(char)) {
×
704
                     bf = extract_unsigned_bitfield_any( *(unsigned char*)src_addr, attr->size, attr->index[0].start, attr->index[0].size);
×
705
                } else {
UNCOV
706
                     message_publish(MSG_ERROR, "Checkpoint Agent INTERNAL ERROR:\n"
×
707
                                                "Unsupported bitfield size (%d) bytes.\n", attr->size) ;
708
                }
UNCOV
709
                chkpnt_os << std::dec << bf;
×
UNCOV
710
            } break;
×
711
        case TRICK_LONG_LONG:
850✔
712
            src_addr = (char*)address + offset * sizeof(long long);
850✔
713
            chkpnt_os << std::dec << *(long long*)src_addr;
850✔
714
            break;
850✔
715
        case TRICK_UNSIGNED_LONG_LONG:
17✔
716
            src_addr = (char*)address + offset * sizeof(unsigned long long);
17✔
717
            chkpnt_os << std::dec << *(unsigned long long*)src_addr;
17✔
718
            break;
17✔
UNCOV
719
        case  TRICK_FILE_PTR:
×
UNCOV
720
            src_addr = (char*)address + offset * sizeof(void*);
×
UNCOV
721
            chkpnt_os << *(void**)src_addr;
×
722
            break;
×
723
        case TRICK_STRING:
7,686✔
724
            src_addr = (char*)address + offset * sizeof(std::string);
7,686✔
725
            write_quoted_str(chkpnt_os, (*(std::string*)src_addr).c_str());
7,686✔
726
            break;
7,686✔
727
        case TRICK_OPAQUE_TYPE:
×
728
            chkpnt_os << std::endl << "// ERROR - OPAQUE data type (" << attr->type_name << ") cannot be checkpointed." << std::endl;
×
729
            message_publish(MSG_ERROR, "Checkpoint Agent ERROR: OPAQUE data type (%s) cannot be checkpointed.\n", attr->type_name) ;
×
UNCOV
730
        break;
×
UNCOV
731
        default:
×
UNCOV
732
            chkpnt_os << "0";
×
UNCOV
733
            message_publish(MSG_ERROR, "Checkpoint Agent file %s: Unhandled Type (%d).\n", __FILE__, attr->type) ;
×
UNCOV
734
            break;
×
735
    }
736
}
28,749✔
737

738
// MEMBER FUNCTION
739
// Get the variable-name associated with the given variable-address and data-type.
740
// If no data-type is specified, (i.e., if attr == NULL), then the name will refer
741
// to the (inner-most) primitive data-type associated with the address.
742

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

746
std::string Trick::ClassicCheckPointAgent::
960✔
747
    ref_string_from_ptr( void* pointer, ATTRIBUTES* attr, int curr_dim) {
748

749
    std::string reference_string;
1,920✔
750

751
    if ((attr != NULL) && ((curr_dim >= attr->num_index) || (attr->index[curr_dim].size != 0))) {
960✔
UNCOV
752
        message_publish(MSG_ERROR, "Checkpoint Agent ERROR: ref_string_from_ptr called with a non-pointer type.\n") ;
×
753
    }
754

755
    if (pointer == NULL) {
960✔
UNCOV
756
        reference_string = "NULL";
×
757
    } else {
758
        ALLOC_INFO *alloc_info;
759

760
        /** Find the allocation that contains the pointer-address. */
761
        alloc_info = mem_mgr->get_alloc_info_of( pointer);
960✔
762

763
        if (alloc_info != NULL) {
960✔
764
            int alloc_elem_size;
765
            int alloc_elem_index;
766
            int misalignment;
767

768
            alloc_elem_size = alloc_info->size;
925✔
769
            alloc_elem_index = (int) (((long) pointer - (long) alloc_info->start) / alloc_elem_size);
925✔
770
            misalignment = (int) (((long) pointer - (long) alloc_info->start) % alloc_elem_size);
925✔
771

772
            // If type-checking AND the type specifiers match AND  the type we're looking for
773
            // is either not structured or if it is, the attr-list that describes the contents
774
            // of the structure is the same.
775

776
            if ( (attr != NULL) && (attr->type == alloc_info->type) &&
925✔
777
                 ( (attr->type != TRICK_STRUCTURED) || (attr->attr == alloc_info->attr))) {
913✔
778

779
                int ii;
780
                int n_l_ptrs, n_r_ptrs;
781

782
                // Calculate the number of pointers (asterisks) on the left side of the assignment.
783
                n_l_ptrs = attr->num_index - curr_dim;
350✔
784

785
                // Calculate the number of pointers (asterisks) on the right side of the assignment.
786
                n_r_ptrs = 0;
350✔
787
                for (ii=0 ; ii <alloc_info->num_index ; ii++) {
674✔
788
                    if (alloc_info->index[ii] == 0) n_r_ptrs++;
324✔
789
                }
790

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

811
                    } else {
UNCOV
812
                        message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Badly aligned pointer.\n"
×
813
                                                   "   It is not aligned with the data object\n"
814
                                                   "   (of the same type) into which it is pointing.\n") ;
UNCOV
815
                        reference_string = "ERROR - Badly aligned pointer";
×
816
                    }
817
                }
350✔
818
            } else if (alloc_info->type == TRICK_STRUCTURED) {
575✔
819
                // The type specifications don't match, but the right-side is structured,
820
                // so we apparently the matching type is buried in the right hand side structure.
821

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

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

855
                    if (misalignment == 0) {
1✔
856
                        std::stringstream workss;
2✔
857

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

873
                    } else {
UNCOV
874
                        message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Badly aligned pointer.\n"
×
875
                                                   "   It is not aligned with the data object\n"
876
                                                   "   (of the same type) into which it is pointing.\n") ;
UNCOV
877
                        reference_string = "ERROR - Badly Aligned Pointer";
×
878
                    }
879
                }
880

881
            }
882
        } else if ((attr != NULL) && ((curr_dim + 1) == attr->num_index)) {
35✔
883

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

898
        } else {
UNCOV
899
            std::string lname = left_side_name();
×
UNCOV
900
            message_publish(MSG_ERROR, "Checkpoint Agent ERROR: Pointer <%p> in \"%s\" is not in Trick managed memory\n"
×
901
                                       "nor is it a character pointer.\n", pointer, lname.c_str()) ;
UNCOV
902
            reference_string = "ERROR - Pointer not in Trick managed memory";
×
903
        }
904
    }
905
    return( reference_string);
1,920✔
906
}
907

908
// MEMBER FUNCTION
909
void Trick::ClassicCheckPointAgent::write_rvalue( std::ostream& chkpnt_os, void* address, ATTRIBUTES* attr, int curr_dim, int offset) {
32,364✔
910

911
    // If the variable that we are pointing to is Un-arrayed
912
    if (curr_dim == attr->num_index) {
32,364✔
913

914
        write_singleton( chkpnt_os, address, attr, offset);
28,749✔
915

916
    // If the variable that we are pointing to is Arrayed
917
    } else if (curr_dim < attr->num_index) {
3,615✔
918

919
        // If the variable is a pointer
920
        if (attr->index[curr_dim].size == 0) {
3,615✔
921
            std::string ref_string;
1,902✔
922

923
            void* pointer = *(void**)((char*)address + offset * sizeof(void*));
951✔
924

925
            ref_string = ref_string_from_ptr( pointer, attr, curr_dim);
951✔
926

927
            chkpnt_os << ref_string.c_str() ;
951✔
928

929
        } else { // Fixed dimension
930

931
            char* src_addr;
932

933
            // If this is the final, fixed dimension
934
            if (((curr_dim + 1) == attr->num_index) ||
2,664✔
935
                (attr->index[curr_dim + 1].size == 0)) {
47✔
936

937
                int use_quoted_string;
938

939
                // If ALL but the last of the elements of a character array
940
                // "isprintable" AND the last is '\0' then print out the array
941
                // as a quoted string. Otherwise print out each of the characters.
942

943
                use_quoted_string = 1;
2,660✔
944
                if (attr->type == TRICK_CHARACTER) {
2,660✔
945

946
                    int array_len = attr->index[curr_dim].size;
369✔
947
                    int ii = array_len - 1;
369✔
948
                    src_addr = (char*)address + offset * array_len * sizeof(char);
369✔
949
                    if (src_addr[ii] != '\0') {
369✔
950
                        use_quoted_string = 0;
20✔
951
                    }
952
                    ii--;
369✔
953
                    while ( use_quoted_string && (ii >= 0) ) {
2,641✔
954
                        use_quoted_string = isprint( src_addr[ii]);
2,272✔
955
                        ii--;
2,272✔
956
                    }
957
                }
958

959

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

968

969
                if ((attr->type == TRICK_CHARACTER) && use_quoted_string)  {
2,660✔
970

971
                    write_quoted_str(chkpnt_os, src_addr);
314✔
972

973
                } else {
974

975
                    int ii, jj;
976
                    int array_len;
977

978
                    // Determine the number of array elements we need to print out
979
                    // to get all of the non-zero values.
980

981
                    array_len = attr->index[curr_dim].size ;
2,346✔
982

983
                    chkpnt_os << "\n";
2,346✔
984

985
                    for (ii=0 ; ii < curr_dim+1 ; ii++) {
4,697✔
986
                        chkpnt_os << "    ";
2,351✔
987
                    }
988
                    chkpnt_os << "{";
2,346✔
989

990
                    for (ii = 0; ii < array_len ; ii++ ) {
8,605✔
991

992
                        if (ii > 0) {
6,259✔
993
                            chkpnt_os << ", ";
3,913✔
994

995
                            // Conditionally line-break and indent.
996
                            if (( (ii+1) % array_elements_per_line[attr->type]) == 0 ) {
3,913✔
997
                                // Line-break.
998
                                chkpnt_os << "\n";
301✔
999
                                // Indent.
1000
                                for (jj=0 ; jj < curr_dim+1 ; jj++) {
602✔
1001
                                    chkpnt_os << "    ";
301✔
1002
                                }
1003
                                chkpnt_os << " ";
301✔
1004
                            }
1005
                        }
1006
                        write_rvalue( chkpnt_os, address, attr, curr_dim + 1, offset * attr->index[curr_dim].size + ii);
6,259✔
1007
                    }
1008
                    chkpnt_os << "}";
2,346✔
1009

1010
                }
2,660✔
1011

1012
            } else { // Not the final fixed dimension.
1013

1014
                int ii;
1015

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

1022
                for (ii=0 ; ii< attr->index[curr_dim].size ; ii++) {
265✔
1023
                    if (ii > 0) {
261✔
1024
                        chkpnt_os << ",";
257✔
1025
                    }
1026
                    write_rvalue( chkpnt_os, address, attr, curr_dim + 1, offset * attr->index[curr_dim].size + ii);
261✔
1027
                }
1028

1029
                chkpnt_os << "\n";
4✔
1030

1031
                for (ii=0 ; ii < curr_dim+1 ; ii++) {
8✔
1032
                    chkpnt_os << "    " ;
4✔
1033
                }
1034
                chkpnt_os << "}";
4✔
1035
            }
1036
        }
1037

1038
    } else {
1039
        chkpnt_os << "/*ERROR*/";
×
1040

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

UNCOV
1044
        return;
×
1045
    }
1046
}
1047

1048
// MEMBER FUNCTION
1049
// Create an assignment statement.
1050
void Trick::ClassicCheckPointAgent::assign_rvalue(std::ostream& chkpnt_os, void* address, ATTRIBUTES* attr, int curr_dim, int offset) {
58,880✔
1051

1052
    std::string lname = left_side_name();
58,880✔
1053

1054
    if (!output_perm_check(attr)) {
58,880✔
UNCOV
1055
        if (debug_level) {
×
UNCOV
1056
            message_publish(MSG_DEBUG, "Checkpoint Agent INFO: No assignment generated for \"%s\" "
×
1057
                                       "because its io specification does not allow it.\n", lname.c_str()) ;
1058
        }
1059
        return;
×
1060
    }
1061

1062
    if ((reduced_checkpoint && is_nil_valued( (void*)address, attr, curr_dim, offset ) ) ) {
58,880✔
1063
        if (debug_level) {
30,654✔
UNCOV
1064
            message_publish(MSG_DEBUG, "Checkpoint Agent INFO: No assignment generated for \"%s\" "
×
1065
                                       "because its value is nil and the reduced_checkpoint flag is set.\n", lname.c_str()) ;
1066
        }
1067
        return;
30,654✔
1068
    }
1069

1070
    if (debug_level) {
28,226✔
UNCOV
1071
        message_publish(MSG_DEBUG, "Checkpoint Agent INFO: Generating assignment for [%p] %s.\n",(void*)address, lname.c_str()) ;
×
1072
    }
1073

1074
    if (!input_perm_check(attr)) {
28,226✔
1075
        chkpnt_os << "/* OUTPUT-ONLY: ";
22✔
1076
    }
1077
    if ( attr->type == TRICK_STL ) {
28,226✔
1078
        chkpnt_os << "// STL: " << lname ;
2,382✔
1079
    } else {
1080
        chkpnt_os << lname << " = ";
25,844✔
1081

1082
        write_rvalue( chkpnt_os, (void*)address, attr, curr_dim, offset);
25,844✔
1083
        chkpnt_os << ";";
25,844✔
1084

1085
        // Check if we need to add decimal comments for hexfloat values
1086
        bool should_add_decimal_comment = hexfloat_decimal_comment_checkpoint && hexfloat_checkpoint && (attr->type == TRICK_FLOAT || attr->type == TRICK_DOUBLE);
25,844✔
1087

1088
        // Add decimal comment for hexfloat values
1089
        if (should_add_decimal_comment) {
25,844✔
1090
            // Temporarily disable hexfloat to get decimal representation
UNCOV
1091
            bool saved_hexfloat = hexfloat_checkpoint;
×
UNCOV
1092
            hexfloat_checkpoint = false;
×
1093

1094
            // Capture decimal output to string stream
UNCOV
1095
            std::stringstream decimal_ss;
×
UNCOV
1096
            write_rvalue( decimal_ss, (void*)address, attr, curr_dim, offset);
×
1097

1098
            // Restore hexfloat setting
UNCOV
1099
            hexfloat_checkpoint = saved_hexfloat;
×
1100

1101
            // Add // to each line of the decimal output
UNCOV
1102
            std::string decimal_str = decimal_ss.str();
×
UNCOV
1103
            std::istringstream iss(decimal_str);
×
UNCOV
1104
            std::string line;
×
UNCOV
1105
            bool first_line = true;
×
1106
            
UNCOV
1107
            while (std::getline(iss, line)) {
×
UNCOV
1108
                if (first_line) {
×
UNCOV
1109
                    chkpnt_os << std::endl << "// " << lname << " = " << line;
×
UNCOV
1110
                    first_line = false;
×
1111
                } else {
UNCOV
1112
                    chkpnt_os << std::endl << "//" << line;
×
1113
                }
1114
            }
1115
        }
1116
    }
1117
    if (!input_perm_check(attr)) {
28,226✔
1118
        chkpnt_os << "*/";
22✔
1119
    }
1120
    chkpnt_os << std::endl;
28,226✔
1121
    chkpnt_os.flush();
28,226✔
1122

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