@@ -2534,28 +2534,6 @@ DWARFASTParserClang::ParseFunctionFromDWARF(CompileUnit &comp_unit,
2534
2534
}
2535
2535
2536
2536
namespace {
2537
- // / Parsed form of all attributes that are relevant for parsing type members.
2538
- struct MemberAttributes {
2539
- explicit MemberAttributes (const DWARFDIE &die, const DWARFDIE &parent_die,
2540
- ModuleSP module_sp);
2541
- const char *name = nullptr ;
2542
- // / Indicates how many bits into the word (according to the host endianness)
2543
- // / the low-order bit of the field starts. Can be negative.
2544
- int64_t bit_offset = 0 ;
2545
- // / Indicates the size of the field in bits.
2546
- size_t bit_size = 0 ;
2547
- uint64_t data_bit_offset = UINT64_MAX;
2548
- AccessType accessibility = eAccessNone;
2549
- std::optional<uint64_t > byte_size;
2550
- std::optional<DWARFFormValue> const_value_form;
2551
- DWARFFormValue encoding_form;
2552
- // / Indicates the byte offset of the word from the base address of the
2553
- // / structure.
2554
- uint32_t member_byte_offset = UINT32_MAX;
2555
- bool is_artificial = false ;
2556
- bool is_declaration = false ;
2557
- };
2558
-
2559
2537
// / Parsed form of all attributes that are relevant for parsing Objective-C
2560
2538
// / properties.
2561
2539
struct PropertyAttributes {
@@ -2684,9 +2662,8 @@ std::vector<VariantMember> &VariantPart::members() { return this->_members; }
2684
2662
2685
2663
DiscriminantValue &VariantPart::discriminant () { return this ->_discriminant ; }
2686
2664
2687
- MemberAttributes::MemberAttributes (const DWARFDIE &die,
2688
- const DWARFDIE &parent_die,
2689
- ModuleSP module_sp) {
2665
+ DWARFASTParserClang::MemberAttributes::MemberAttributes (
2666
+ const DWARFDIE &die, const DWARFDIE &parent_die, ModuleSP module_sp) {
2690
2667
DWARFAttributes attributes = die.GetAttributes ();
2691
2668
for (size_t i = 0 ; i < attributes.Size (); ++i) {
2692
2669
const dw_attr_t attr = attributes.AttributeAtIndex (i);
@@ -2908,13 +2885,63 @@ llvm::Expected<llvm::APInt> DWARFASTParserClang::ExtractIntFromFormValue(
2908
2885
return result;
2909
2886
}
2910
2887
2888
+ void DWARFASTParserClang::CreateStaticMemberVariable (
2889
+ const DWARFDIE &die, const MemberAttributes &attrs,
2890
+ const lldb_private::CompilerType &class_clang_type) {
2891
+ Log *log = GetLog (DWARFLog::TypeCompletion | DWARFLog::Lookups);
2892
+ assert (die.Tag () == DW_TAG_member);
2893
+
2894
+ Type *var_type = die.ResolveTypeUID (attrs.encoding_form .Reference ());
2895
+
2896
+ if (!var_type)
2897
+ return ;
2898
+
2899
+ auto accessibility =
2900
+ attrs.accessibility == eAccessNone ? eAccessPublic : attrs.accessibility ;
2901
+
2902
+ CompilerType ct = var_type->GetForwardCompilerType ();
2903
+ clang::VarDecl *v = TypeSystemClang::AddVariableToRecordType (
2904
+ class_clang_type, attrs.name , ct, accessibility);
2905
+ if (!v) {
2906
+ LLDB_LOG (log, " Failed to add variable to the record type" );
2907
+ return ;
2908
+ }
2909
+
2910
+ bool unused;
2911
+ // TODO: Support float/double static members as well.
2912
+ if (!ct.IsIntegerOrEnumerationType (unused))
2913
+ return ;
2914
+
2915
+ auto maybe_const_form_value = attrs.const_value_form ;
2916
+
2917
+ // Newer versions of Clang don't emit the DW_AT_const_value
2918
+ // on the declaration of an inline static data member. Instead
2919
+ // it's attached to the definition DIE. If that's the case,
2920
+ // try and fetch it.
2921
+ if (!maybe_const_form_value) {
2922
+ maybe_const_form_value = FindConstantOnVariableDefinition (die);
2923
+ if (!maybe_const_form_value)
2924
+ return ;
2925
+ }
2926
+
2927
+ llvm::Expected<llvm::APInt> const_value_or_err =
2928
+ ExtractIntFromFormValue (ct, *maybe_const_form_value);
2929
+ if (!const_value_or_err) {
2930
+ LLDB_LOG_ERROR (log, const_value_or_err.takeError (),
2931
+ " Failed to add const value to variable {1}: {0}" ,
2932
+ v->getQualifiedNameAsString ());
2933
+ return ;
2934
+ }
2935
+
2936
+ TypeSystemClang::SetIntegerInitializerForVariable (v, *const_value_or_err);
2937
+ }
2938
+
2911
2939
void DWARFASTParserClang::ParseSingleMember (
2912
2940
const DWARFDIE &die, const DWARFDIE &parent_die,
2913
2941
const lldb_private::CompilerType &class_clang_type,
2914
2942
lldb::AccessType default_accessibility,
2915
2943
lldb_private::ClangASTImporter::LayoutInfo &layout_info,
2916
2944
FieldInfo &last_field_info) {
2917
- Log *log = GetLog (DWARFLog::TypeCompletion | DWARFLog::Lookups);
2918
2945
// This function can only parse DW_TAG_member.
2919
2946
assert (die.Tag () == DW_TAG_member);
2920
2947
@@ -2940,47 +2967,7 @@ void DWARFASTParserClang::ParseSingleMember(
2940
2967
// can consistently detect them on both GCC and Clang without below heuristic.
2941
2968
if (attrs.member_byte_offset == UINT32_MAX &&
2942
2969
attrs.data_bit_offset == UINT64_MAX && attrs.is_declaration ) {
2943
- Type *var_type = die.ResolveTypeUID (attrs.encoding_form .Reference ());
2944
- if (var_type) {
2945
- const auto accessibility = attrs.accessibility == eAccessNone
2946
- ? eAccessPublic
2947
- : attrs.accessibility ;
2948
- CompilerType ct = var_type->GetForwardCompilerType ();
2949
- clang::VarDecl *v = TypeSystemClang::AddVariableToRecordType (
2950
- class_clang_type, attrs.name , ct, accessibility);
2951
- if (!v) {
2952
- LLDB_LOG (log, " Failed to add variable to the record type" );
2953
- return ;
2954
- }
2955
-
2956
- bool unused;
2957
- // TODO: Support float/double static members as well.
2958
- if (!ct.IsIntegerOrEnumerationType (unused))
2959
- return ;
2960
-
2961
- auto maybe_const_form_value = attrs.const_value_form ;
2962
-
2963
- // Newer versions of Clang don't emit the DW_AT_const_value
2964
- // on the declaration of an inline static data member. Instead
2965
- // it's attached to the definition DIE. If that's the case,
2966
- // try and fetch it.
2967
- if (!maybe_const_form_value) {
2968
- maybe_const_form_value = FindConstantOnVariableDefinition (die);
2969
- if (!maybe_const_form_value)
2970
- return ;
2971
- }
2972
-
2973
- llvm::Expected<llvm::APInt> const_value_or_err =
2974
- ExtractIntFromFormValue (ct, *maybe_const_form_value);
2975
- if (!const_value_or_err) {
2976
- LLDB_LOG_ERROR (log, const_value_or_err.takeError (),
2977
- " Failed to add const value to variable {1}: {0}" ,
2978
- v->getQualifiedNameAsString ());
2979
- return ;
2980
- }
2981
-
2982
- TypeSystemClang::SetIntegerInitializerForVariable (v, *const_value_or_err);
2983
- }
2970
+ CreateStaticMemberVariable (die, attrs, class_clang_type);
2984
2971
return ;
2985
2972
}
2986
2973
0 commit comments