@@ -519,6 +519,33 @@ TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc,
519519 return UpdateSymbolContextScopeForType (sc, die, type_sp);
520520}
521521
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+
522549lldb::TypeSP
523550DWARFASTParserClang::ParseTypeModifier (const SymbolContext &sc,
524551 const DWARFDIE &die,
@@ -1406,26 +1433,9 @@ void DWARFASTParserClang::ParseInheritance(
14061433 encoding_form = form_value;
14071434 break ;
14081435 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;
14291439 break ;
14301440
14311441 case DW_AT_accessibility:
@@ -2557,29 +2567,9 @@ VariantMember::VariantMember(DWARFDIE &die, lldb::ModuleSP module_sp) {
25572567 break ;
25582568
25592569 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;
25832573 break ;
25842574
25852575 default :
@@ -2608,28 +2598,9 @@ DiscriminantValue::DiscriminantValue(const DWARFDIE &die, ModuleSP module_sp) {
26082598 type_ref = form_value;
26092599 break ;
26102600 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;
26332604 break ;
26342605 default :
26352606 break ;
@@ -2686,28 +2657,9 @@ MemberAttributes::MemberAttributes(const DWARFDIE &die,
26862657 data_bit_offset = form_value.Unsigned ();
26872658 break ;
26882659 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;
27112663 break ;
27122664
27132665 case DW_AT_accessibility:
0 commit comments