@@ -351,6 +351,10 @@ rust_printstr (struct ui_file *stream, struct type *type,
351
351
352
352
353
353
354
+ static void rust_value_print_inner (struct value * val , struct ui_file * stream ,
355
+ int recurse ,
356
+ const struct value_print_options * options );
357
+
354
358
/* Helper function to print a string slice. */
355
359
356
360
static void
@@ -369,13 +373,12 @@ rust_val_print_str (struct ui_file *stream, struct value *val,
369
373
/* rust_val_print helper for structs and untagged unions. */
370
374
371
375
static void
372
- val_print_struct (struct type * type , int embedded_offset ,
373
- CORE_ADDR address , struct ui_file * stream ,
374
- int recurse , struct value * val ,
376
+ val_print_struct (struct value * val , struct ui_file * stream , int recurse ,
375
377
const struct value_print_options * options )
376
378
{
377
379
int i ;
378
380
int first_field ;
381
+ struct type * type = check_typedef (value_type (val ));
379
382
380
383
if (rust_slice_type_p (type ) && strcmp (TYPE_NAME (type ), "&str" ) == 0 )
381
384
{
@@ -386,7 +389,7 @@ val_print_struct (struct type *type, int embedded_offset,
386
389
However, RUST_VAL_PRINT_STR looks up the fields of the string
387
390
inside VAL, assuming that VAL is the string.
388
391
So, recreate VAL as a value representing just the string. */
389
- val = value_at_lazy (type , value_address (val ) + embedded_offset );
392
+ val = value_at_lazy (type , value_address (val ));
390
393
rust_val_print_str (stream , val , options );
391
394
return ;
392
395
}
@@ -441,11 +444,8 @@ val_print_struct (struct type *type, int embedded_offset,
441
444
fputs_filtered (": " , stream );
442
445
}
443
446
444
- val_print (TYPE_FIELD_TYPE (type , i ),
445
- embedded_offset + TYPE_FIELD_BITPOS (type , i ) / 8 ,
446
- address ,
447
- stream , recurse + 1 , val , & opts ,
448
- current_language );
447
+ rust_value_print_inner (value_field (val , i ), stream , recurse + 1 ,
448
+ & opts );
449
449
}
450
450
451
451
if (options -> prettyformat )
@@ -463,12 +463,11 @@ val_print_struct (struct type *type, int embedded_offset,
463
463
/* rust_val_print helper for discriminated unions (Rust enums). */
464
464
465
465
static void
466
- rust_print_enum (struct type * type , int embedded_offset ,
467
- CORE_ADDR address , struct ui_file * stream ,
468
- int recurse , struct value * val ,
466
+ rust_print_enum (struct value * val , struct ui_file * stream , int recurse ,
469
467
const struct value_print_options * options )
470
468
{
471
469
struct value_print_options opts = * options ;
470
+ struct type * type = check_typedef (value_type (val ));
472
471
473
472
opts .deref_ref = 0 ;
474
473
@@ -482,9 +481,7 @@ rust_print_enum (struct type *type, int embedded_offset,
482
481
}
483
482
484
483
const gdb_byte * valaddr = value_contents_for_printing (val );
485
- struct field * variant_field = rust_enum_variant (type ,
486
- valaddr + embedded_offset );
487
- embedded_offset += FIELD_BITPOS (* variant_field ) / 8 ;
484
+ struct field * variant_field = rust_enum_variant (type , valaddr );
488
485
struct type * variant_type = FIELD_TYPE (* variant_field );
489
486
490
487
int nfields = TYPE_NFIELDS (variant_type );
@@ -508,6 +505,10 @@ rust_print_enum (struct type *type, int embedded_offset,
508
505
fprintf_filtered (stream , "{" );
509
506
}
510
507
508
+ struct value * union_value = value_field (val , 0 );
509
+ int fieldno = (variant_field - & TYPE_FIELD (value_type (union_value ), 0 ));
510
+ val = value_field (union_value , fieldno );
511
+
511
512
bool first_field = true;
512
513
for (int j = 0 ; j < TYPE_NFIELDS (variant_type ); j ++ )
513
514
{
@@ -520,12 +521,8 @@ rust_print_enum (struct type *type, int embedded_offset,
520
521
styled_string (variable_name_style .style (),
521
522
TYPE_FIELD_NAME (variant_type , j )));
522
523
523
- val_print (TYPE_FIELD_TYPE (variant_type , j ),
524
- (embedded_offset
525
- + TYPE_FIELD_BITPOS (variant_type , j ) / 8 ),
526
- address ,
527
- stream , recurse + 1 , val , & opts ,
528
- current_language );
524
+ rust_value_print_inner (value_field (val , j ), stream , recurse + 1 ,
525
+ & opts );
529
526
}
530
527
531
528
if (is_tuple )
@@ -556,9 +553,24 @@ rust_val_print (struct type *type, int embedded_offset,
556
553
struct value * val ,
557
554
const struct value_print_options * options )
558
555
{
559
- const gdb_byte * valaddr = value_contents_for_printing (val );
556
+ generic_val_print (type , embedded_offset , address , stream ,
557
+ recurse , val , options , & rust_decorations );
558
+ }
560
559
561
- type = check_typedef (type );
560
+ /* la_value_print_inner implementation for Rust. */
561
+ static void
562
+ rust_value_print_inner (struct value * val , struct ui_file * stream ,
563
+ int recurse ,
564
+ const struct value_print_options * options )
565
+ {
566
+ struct value_print_options opts = * options ;
567
+ opts .deref_ref = 1 ;
568
+
569
+ if (opts .prettyformat == Val_prettyformat_default )
570
+ opts .prettyformat = (opts .prettyformat_structs
571
+ ? Val_prettyformat : Val_no_prettyformat );
572
+
573
+ struct type * type = check_typedef (value_type (val ));
562
574
switch (TYPE_CODE (type ))
563
575
{
564
576
case TYPE_CODE_PTR :
@@ -568,34 +580,32 @@ rust_val_print (struct type *type, int embedded_offset,
568
580
if (TYPE_CODE (TYPE_TARGET_TYPE (type )) == TYPE_CODE_ARRAY
569
581
&& rust_u8_type_p (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type )))
570
582
&& get_array_bounds (TYPE_TARGET_TYPE (type ), & low_bound ,
571
- & high_bound )) {
572
- /* We have a pointer to a byte string, so just print
573
- that. */
574
- struct type * elttype = check_typedef ( TYPE_TARGET_TYPE ( type ));
575
- CORE_ADDR addr ;
576
- struct gdbarch * arch = get_type_arch ( type );
577
- int unit_size = gdbarch_addressable_memory_unit_size ( arch );
583
+ & high_bound ))
584
+ {
585
+ /* We have a pointer to a byte string, so just print
586
+ that. */
587
+ struct type * elttype = check_typedef ( TYPE_TARGET_TYPE ( type )) ;
588
+ CORE_ADDR addr = value_as_address ( val );
589
+ struct gdbarch * arch = get_type_arch ( type );
578
590
579
- addr = unpack_pointer (type , valaddr + embedded_offset * unit_size );
580
- if (options -> addressprint )
581
- {
582
- fputs_filtered (paddress (arch , addr ), stream );
583
- fputs_filtered (" " , stream );
584
- }
591
+ if (opts .addressprint )
592
+ {
593
+ fputs_filtered (paddress (arch , addr ), stream );
594
+ fputs_filtered (" " , stream );
595
+ }
585
596
586
- fputs_filtered ("b" , stream );
587
- val_print_string (TYPE_TARGET_TYPE (elttype ), "ASCII" , addr ,
588
- high_bound - low_bound + 1 , stream ,
589
- options );
590
- break ;
591
- }
597
+ fputs_filtered ("b" , stream );
598
+ val_print_string (TYPE_TARGET_TYPE (elttype ), "ASCII" , addr ,
599
+ high_bound - low_bound + 1 , stream ,
600
+ & opts );
601
+ break ;
602
+ }
592
603
}
593
- /* Fall through. */
604
+ goto generic_print ;
594
605
595
606
case TYPE_CODE_METHODPTR :
596
607
case TYPE_CODE_MEMBERPTR :
597
- c_val_print (type , embedded_offset , address , stream ,
598
- recurse , val , options );
608
+ c_value_print_inner (val , stream , recurse , & opts );
599
609
break ;
600
610
601
611
case TYPE_CODE_INT :
@@ -610,8 +620,6 @@ rust_val_print (struct type *type, int embedded_offset,
610
620
611
621
case TYPE_CODE_STRING :
612
622
{
613
- struct gdbarch * arch = get_type_arch (type );
614
- int unit_size = gdbarch_addressable_memory_unit_size (arch );
615
623
LONGEST low_bound , high_bound ;
616
624
617
625
if (!get_array_bounds (type , & low_bound , & high_bound ))
@@ -622,8 +630,8 @@ rust_val_print (struct type *type, int embedded_offset,
622
630
encoding. */
623
631
fputs_filtered ("b" , stream );
624
632
rust_printstr (stream , TYPE_TARGET_TYPE (type ),
625
- valaddr + embedded_offset * unit_size ,
626
- high_bound - low_bound + 1 , "ASCII" , 0 , options );
633
+ value_contents_for_printing ( val ) ,
634
+ high_bound - low_bound + 1 , "ASCII" , 0 , & opts );
627
635
}
628
636
break ;
629
637
@@ -645,24 +653,20 @@ rust_val_print (struct type *type, int embedded_offset,
645
653
for printing a union is same as that for a struct, the only
646
654
difference is that the input type will have overlapping
647
655
fields. */
648
- val_print_struct (type , embedded_offset , address , stream ,
649
- recurse , val , options );
656
+ val_print_struct (val , stream , recurse , & opts );
650
657
break ;
651
658
652
659
case TYPE_CODE_STRUCT :
653
660
if (rust_enum_p (type ))
654
- rust_print_enum (type , embedded_offset , address , stream ,
655
- recurse , val , options );
661
+ rust_print_enum (val , stream , recurse , & opts );
656
662
else
657
- val_print_struct (type , embedded_offset , address , stream ,
658
- recurse , val , options );
663
+ val_print_struct (val , stream , recurse , & opts );
659
664
break ;
660
665
661
666
default :
662
667
generic_print :
663
668
/* Nothing special yet. */
664
- generic_val_print (type , embedded_offset , address , stream ,
665
- recurse , val , options , & rust_decorations );
669
+ generic_value_print (val , stream , recurse , & opts , & rust_decorations );
666
670
}
667
671
}
668
672
@@ -2154,7 +2158,7 @@ extern const struct language_defn rust_language_defn =
2154
2158
rust_print_type , /* Print a type using appropriate syntax */
2155
2159
rust_print_typedef , /* Print a typedef using appropriate syntax */
2156
2160
rust_val_print , /* Print a value using appropriate syntax */
2157
- nullptr , /* la_value_print_inner */
2161
+ rust_value_print_inner , /* la_value_print_inner */
2158
2162
c_value_print , /* Print a top-level value */
2159
2163
default_read_var_value , /* la_read_var_value */
2160
2164
NULL , /* Language specific skip_trampoline */
0 commit comments