@@ -249,11 +249,6 @@ ParseSupportFilesFromPrologue(const lldb::ModuleSP &module,
249
249
return support_files;
250
250
}
251
251
252
- static inline bool IsSwiftLanguage (LanguageType language) {
253
- return language == eLanguageTypePLI || language == eLanguageTypeSwift ||
254
- ((uint32_t )language == (uint32_t )llvm::dwarf::DW_LANG_Swift);
255
- }
256
-
257
252
void SymbolFileDWARF::Initialize () {
258
253
LogChannelDWARF::Initialize ();
259
254
PluginManager::RegisterPlugin (GetPluginNameStatic (),
@@ -974,7 +969,7 @@ bool SymbolFileDWARF::ParseImportedModules(
974
969
return false ;
975
970
auto lang = sc.comp_unit ->GetLanguage ();
976
971
if (!ClangModulesDeclVendor::LanguageSupportsClangModules (lang) &&
977
- ! IsSwiftLanguage ( lang) )
972
+ lang != eLanguageTypeSwift )
978
973
return false ;
979
974
UpdateExternalModuleListIfNeeded ();
980
975
@@ -3185,18 +3180,15 @@ VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc,
3185
3180
const char *name = nullptr ;
3186
3181
const char *mangled = nullptr ;
3187
3182
Declaration decl;
3188
- uint32_t i;
3189
3183
DWARFFormValue type_die_form;
3190
3184
DWARFExpression location;
3191
3185
bool is_external = false ;
3192
3186
bool is_artificial = false ;
3193
- bool location_is_const_value_data = false ;
3194
- bool has_explicit_location = false ;
3195
- DWARFFormValue const_value;
3187
+ DWARFFormValue const_value_form, location_form;
3196
3188
Variable::RangeList scope_ranges;
3197
3189
// AccessType accessibility = eAccessNone;
3198
3190
3199
- for (i = 0 ; i < num_attributes; ++i) {
3191
+ for (size_t i = 0 ; i < num_attributes; ++i) {
3200
3192
dw_attr_t attr = attributes.AttributeAtIndex (i);
3201
3193
DWARFFormValue form_value;
3202
3194
@@ -3226,65 +3218,11 @@ VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc,
3226
3218
is_external = form_value.Boolean ();
3227
3219
break ;
3228
3220
case DW_AT_const_value:
3229
- // If we have already found a DW_AT_location attribute, ignore this
3230
- // attribute.
3231
- if (!has_explicit_location) {
3232
- location_is_const_value_data = true ;
3233
- // The constant value will be either a block, a data value or a
3234
- // string.
3235
- auto debug_info_data = die.GetData ();
3236
- if (DWARFFormValue::IsBlockForm (form_value.Form ())) {
3237
- // Retrieve the value as a block expression.
3238
- uint32_t block_offset =
3239
- form_value.BlockData () - debug_info_data.GetDataStart ();
3240
- uint32_t block_length = form_value.Unsigned ();
3241
- location = DWARFExpression (
3242
- module,
3243
- DataExtractor (debug_info_data, block_offset, block_length),
3244
- die.GetCU ());
3245
- } else if (DWARFFormValue::IsDataForm (form_value.Form ())) {
3246
- // Constant value size does not have to match the size of the
3247
- // variable. We will fetch the size of the type after we create
3248
- // it.
3249
- const_value = form_value;
3250
- } else if (const char *str = form_value.AsCString ()) {
3251
- uint32_t string_length = strlen (str) + 1 ;
3252
- location = DWARFExpression (
3253
- module,
3254
- DataExtractor (str, string_length,
3255
- die.GetCU ()->GetByteOrder (),
3256
- die.GetCU ()->GetAddressByteSize ()),
3257
- die.GetCU ());
3258
- }
3259
- }
3221
+ const_value_form = form_value;
3222
+ break ;
3223
+ case DW_AT_location:
3224
+ location_form = form_value;
3260
3225
break ;
3261
- case DW_AT_location: {
3262
- location_is_const_value_data = false ;
3263
- has_explicit_location = true ;
3264
- if (DWARFFormValue::IsBlockForm (form_value.Form ())) {
3265
- auto data = die.GetData ();
3266
-
3267
- uint32_t block_offset =
3268
- form_value.BlockData () - data.GetDataStart ();
3269
- uint32_t block_length = form_value.Unsigned ();
3270
- location = DWARFExpression (
3271
- module, DataExtractor (data, block_offset, block_length),
3272
- die.GetCU ());
3273
- } else {
3274
- DataExtractor data = die.GetCU ()->GetLocationData ();
3275
- dw_offset_t offset = form_value.Unsigned ();
3276
- if (form_value.Form () == DW_FORM_loclistx)
3277
- offset = die.GetCU ()->GetLoclistOffset (offset).getValueOr (-1 );
3278
- if (data.ValidOffset (offset)) {
3279
- data = DataExtractor (data, offset, data.GetByteSize () - offset);
3280
- location = DWARFExpression (module, data, die.GetCU ());
3281
- assert (func_low_pc != LLDB_INVALID_ADDRESS);
3282
- location.SetLocationListAddresses (
3283
- attributes.CompileUnitAtIndex (i)->GetBaseAddress (),
3284
- func_low_pc);
3285
- }
3286
- }
3287
- } break ;
3288
3226
case DW_AT_specification:
3289
3227
spec_die = form_value.Reference ();
3290
3228
break ;
@@ -3311,9 +3249,69 @@ VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc,
3311
3249
}
3312
3250
3313
3251
if (tag == DW_TAG_variable && mangled &&
3314
- IsSwiftLanguage ( sc.comp_unit ->GetLanguage ()) )
3252
+ sc.comp_unit ->GetLanguage () == eLanguageTypeSwift )
3315
3253
mangled = NULL ;
3316
3254
3255
+ // Prefer DW_AT_location over DW_AT_const_value. Both can be emitted e.g.
3256
+ // for static constexpr member variables -- DW_AT_const_value will be
3257
+ // present in the class declaration and DW_AT_location in the DIE defining
3258
+ // the member.
3259
+ bool location_is_const_value_data = false ;
3260
+ bool has_explicit_location = false ;
3261
+ bool use_type_size_for_value = false ;
3262
+ if (location_form.IsValid ()) {
3263
+ has_explicit_location = true ;
3264
+ if (DWARFFormValue::IsBlockForm (location_form.Form ())) {
3265
+ const DWARFDataExtractor &data = die.GetData ();
3266
+
3267
+ uint32_t block_offset =
3268
+ location_form.BlockData () - data.GetDataStart ();
3269
+ uint32_t block_length = location_form.Unsigned ();
3270
+ location = DWARFExpression (
3271
+ module, DataExtractor (data, block_offset, block_length),
3272
+ die.GetCU ());
3273
+ } else {
3274
+ DataExtractor data = die.GetCU ()->GetLocationData ();
3275
+ dw_offset_t offset = location_form.Unsigned ();
3276
+ if (location_form.Form () == DW_FORM_loclistx)
3277
+ offset = die.GetCU ()->GetLoclistOffset (offset).getValueOr (-1 );
3278
+ if (data.ValidOffset (offset)) {
3279
+ data = DataExtractor (data, offset, data.GetByteSize () - offset);
3280
+ location = DWARFExpression (module, data, die.GetCU ());
3281
+ assert (func_low_pc != LLDB_INVALID_ADDRESS);
3282
+ location.SetLocationListAddresses (
3283
+ location_form.GetUnit ()->GetBaseAddress (), func_low_pc);
3284
+ }
3285
+ }
3286
+ } else if (const_value_form.IsValid ()) {
3287
+ location_is_const_value_data = true ;
3288
+ // The constant value will be either a block, a data value or a
3289
+ // string.
3290
+ const DWARFDataExtractor &debug_info_data = die.GetData ();
3291
+ if (DWARFFormValue::IsBlockForm (const_value_form.Form ())) {
3292
+ // Retrieve the value as a block expression.
3293
+ uint32_t block_offset =
3294
+ const_value_form.BlockData () - debug_info_data.GetDataStart ();
3295
+ uint32_t block_length = const_value_form.Unsigned ();
3296
+ location = DWARFExpression (
3297
+ module,
3298
+ DataExtractor (debug_info_data, block_offset, block_length),
3299
+ die.GetCU ());
3300
+ } else if (DWARFFormValue::IsDataForm (const_value_form.Form ())) {
3301
+ // Constant value size does not have to match the size of the
3302
+ // variable. We will fetch the size of the type after we create
3303
+ // it.
3304
+ use_type_size_for_value = true ;
3305
+ } else if (const char *str = const_value_form.AsCString ()) {
3306
+ uint32_t string_length = strlen (str) + 1 ;
3307
+ location = DWARFExpression (
3308
+ module,
3309
+ DataExtractor (str, string_length, die.GetCU ()->GetByteOrder (),
3310
+ die.GetCU ()->GetAddressByteSize ()),
3311
+ die.GetCU ());
3312
+ }
3313
+ }
3314
+
3317
3315
const DWARFDIE parent_context_die = GetDeclContextDIEContainingDIE (die);
3318
3316
const dw_tag_t parent_tag = die.GetParent ().Tag ();
3319
3317
bool is_static_member =
@@ -3493,18 +3491,18 @@ VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc,
3493
3491
}
3494
3492
3495
3493
if (symbol_context_scope) {
3496
- SymbolFileTypeSP type_sp (
3497
- new SymbolFileType ( *this , GetUID (type_die_form.Reference () )));
3494
+ auto type_sp = std::make_shared<SymbolFileType> (
3495
+ *this , GetUID (type_die_form.Reference ()));
3498
3496
3499
- if (const_value. Form () && type_sp && type_sp->GetType ())
3497
+ if (use_type_size_for_value && type_sp->GetType ())
3500
3498
location.UpdateValue (
3501
- const_value .Unsigned (),
3499
+ const_value_form .Unsigned (),
3502
3500
type_sp->GetType ()->GetByteSize (nullptr ).getValueOr (0 ),
3503
3501
die.GetCU ()->GetAddressByteSize ());
3504
3502
3505
3503
// Swift let-bindings are marked by a DW_TAG_const_type.
3506
3504
bool is_constant = false ;
3507
- if (IsSwiftLanguage ( sc.comp_unit ->GetLanguage ()) ) {
3505
+ if (sc.comp_unit ->GetLanguage () == eLanguageTypeSwift ) {
3508
3506
DWARFDIE type_die = die.GetReferencedDIE (llvm::dwarf::DW_AT_type);
3509
3507
if (type_die && type_die.Tag () == llvm::dwarf::DW_TAG_const_type)
3510
3508
is_constant = true ;
0 commit comments