@@ -519,6 +519,33 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
519
519
return UpdateSymbolContextScopeForType (sc, die, type_sp);
520
520
}
521
521
522
+ static std::optional<uint32_t >
523
+ ExtractDataMemberLocation (DWARFDIE const &die, DWARFFormValue const &form_value,
524
+ ModuleSP module_sp) {
525
+ // With DWARF 3 and later, if the value is an integer constant,
526
+ // this form value is the offset in bytes from the beginning of
527
+ // the containing entity.
528
+ if (!form_value.BlockData ())
529
+ return form_value.Unsigned ();
530
+
531
+ Value initialValue (0 );
532
+ Value memberOffset (0 );
533
+ const DWARFDataExtractor &debug_info_data = die.GetData ();
534
+ uint32_t block_length = form_value.Unsigned ();
535
+ uint32_t block_offset =
536
+ form_value.BlockData () - debug_info_data.GetDataStart ();
537
+ if (!DWARFExpression::Evaluate (
538
+ nullptr , // ExecutionContext *
539
+ nullptr , // RegisterContext *
540
+ module_sp, DataExtractor (debug_info_data, block_offset, block_length),
541
+ die.GetCU (), eRegisterKindDWARF, &initialValue, nullptr , memberOffset,
542
+ nullptr )) {
543
+ return {};
544
+ }
545
+
546
+ return memberOffset.ResolveValue (nullptr ).UInt ();
547
+ }
548
+
522
549
lldb::TypeSP
523
550
DWARFASTParserClang::ParseTypeModifier (const SymbolContext &sc,
524
551
const DWARFDIE &die,
@@ -1406,26 +1433,9 @@ void DWARFASTParserClang::ParseInheritance(
1406
1433
encoding_form = form_value;
1407
1434
break ;
1408
1435
case DW_AT_data_member_location:
1409
- if (form_value.BlockData ()) {
1410
- Value initialValue (0 );
1411
- Value memberOffset (0 );
1412
- const DWARFDataExtractor &debug_info_data = die.GetData ();
1413
- uint32_t block_length = form_value.Unsigned ();
1414
- uint32_t block_offset =
1415
- form_value.BlockData () - debug_info_data.GetDataStart ();
1416
- if (DWARFExpression::Evaluate (
1417
- nullptr , nullptr , module_sp,
1418
- DataExtractor (debug_info_data, block_offset, block_length),
1419
- die.GetCU (), eRegisterKindDWARF, &initialValue, nullptr ,
1420
- memberOffset, nullptr )) {
1421
- member_byte_offset = memberOffset.ResolveValue (nullptr ).UInt ();
1422
- }
1423
- } else {
1424
- // With DWARF 3 and later, if the value is an integer constant,
1425
- // this form value is the offset in bytes from the beginning of
1426
- // the containing entity.
1427
- member_byte_offset = form_value.Unsigned ();
1428
- }
1436
+ if (auto maybe_offset =
1437
+ ExtractDataMemberLocation (die, form_value, module_sp))
1438
+ member_byte_offset = *maybe_offset;
1429
1439
break ;
1430
1440
1431
1441
case DW_AT_accessibility:
@@ -2557,29 +2567,9 @@ VariantMember::VariantMember(DWARFDIE &die, lldb::ModuleSP module_sp) {
2557
2567
break ;
2558
2568
2559
2569
case DW_AT_data_member_location:
2560
- if (form_value.BlockData ()) {
2561
- Value initialValue (0 );
2562
- Value memberOffset (0 );
2563
- const DWARFDataExtractor &debug_info_data = die.GetData ();
2564
- uint32_t block_length = form_value.Unsigned ();
2565
- uint32_t block_offset =
2566
- form_value.BlockData () - debug_info_data.GetDataStart ();
2567
- if (DWARFExpression::Evaluate (
2568
- nullptr , // ExecutionContext *
2569
- nullptr , // RegisterContext *
2570
- module_sp,
2571
- DataExtractor (debug_info_data, block_offset,
2572
- block_length),
2573
- die.GetCU (), eRegisterKindDWARF, &initialValue, nullptr ,
2574
- memberOffset, nullptr )) {
2575
- byte_offset = memberOffset.ResolveValue (nullptr ).UInt ();
2576
- }
2577
- } else {
2578
- // With DWARF 3 and later, if the value is an integer constant,
2579
- // this form value is the offset in bytes from the beginning of
2580
- // the containing entity.
2581
- byte_offset = form_value.Unsigned ();
2582
- }
2570
+ if (auto maybe_offset =
2571
+ ExtractDataMemberLocation (die, form_value, module_sp))
2572
+ byte_offset = *maybe_offset;
2583
2573
break ;
2584
2574
2585
2575
default :
@@ -2608,28 +2598,9 @@ DiscriminantValue::DiscriminantValue(const DWARFDIE &die, ModuleSP module_sp) {
2608
2598
type_ref = form_value;
2609
2599
break ;
2610
2600
case DW_AT_data_member_location:
2611
- if (form_value.BlockData ()) {
2612
- Value initialValue (0 );
2613
- Value memberOffset (0 );
2614
- const DWARFDataExtractor &debug_info_data = die.GetData ();
2615
- uint32_t block_length = form_value.Unsigned ();
2616
- uint32_t block_offset =
2617
- form_value.BlockData () - debug_info_data.GetDataStart ();
2618
- if (DWARFExpression::Evaluate (
2619
- nullptr , // ExecutionContext *
2620
- nullptr , // RegisterContext *
2621
- module_sp,
2622
- DataExtractor (debug_info_data, block_offset, block_length),
2623
- die.GetCU (), eRegisterKindDWARF, &initialValue, nullptr ,
2624
- memberOffset, nullptr )) {
2625
- byte_offset = memberOffset.ResolveValue (nullptr ).UInt ();
2626
- }
2627
- } else {
2628
- // With DWARF 3 and later, if the value is an integer constant,
2629
- // this form value is the offset in bytes from the beginning of
2630
- // the containing entity.
2631
- byte_offset = form_value.Unsigned ();
2632
- }
2601
+ if (auto maybe_offset =
2602
+ ExtractDataMemberLocation (die, form_value, module_sp))
2603
+ byte_offset = *maybe_offset;
2633
2604
break ;
2634
2605
default :
2635
2606
break ;
@@ -2686,28 +2657,9 @@ MemberAttributes::MemberAttributes(const DWARFDIE &die,
2686
2657
data_bit_offset = form_value.Unsigned ();
2687
2658
break ;
2688
2659
case DW_AT_data_member_location:
2689
- if (form_value.BlockData ()) {
2690
- Value initialValue (0 );
2691
- Value memberOffset (0 );
2692
- const DWARFDataExtractor &debug_info_data = die.GetData ();
2693
- uint32_t block_length = form_value.Unsigned ();
2694
- uint32_t block_offset =
2695
- form_value.BlockData () - debug_info_data.GetDataStart ();
2696
- if (DWARFExpression::Evaluate (
2697
- nullptr , // ExecutionContext *
2698
- nullptr , // RegisterContext *
2699
- module_sp,
2700
- DataExtractor (debug_info_data, block_offset, block_length),
2701
- die.GetCU (), eRegisterKindDWARF, &initialValue, nullptr ,
2702
- memberOffset, nullptr )) {
2703
- member_byte_offset = memberOffset.ResolveValue (nullptr ).UInt ();
2704
- }
2705
- } else {
2706
- // With DWARF 3 and later, if the value is an integer constant,
2707
- // this form value is the offset in bytes from the beginning of
2708
- // the containing entity.
2709
- member_byte_offset = form_value.Unsigned ();
2710
- }
2660
+ if (auto maybe_offset =
2661
+ ExtractDataMemberLocation (die, form_value, module_sp))
2662
+ member_byte_offset = *maybe_offset;
2711
2663
break ;
2712
2664
2713
2665
case DW_AT_accessibility:
0 commit comments