Skip to content

Commit c909b49

Browse files
committed
[lldb][NFCI] Change return type of DWARFDebugInfoEntry::GetAttributes
The purpose of this method is to get the list of attributes of a DebugInfoEntry. Prior to this change we were passing in a mutable reference to a DWARFAttributes object and having the method fill it in for us while returning the size of the filled out list. But instead of doing that, we can just return a `DWARFAttributes` object ourselves since every caller creates a new list before calling GetAttributes. Differential Revision: https://reviews.llvm.org/D150402
1 parent 297e06c commit c909b49

File tree

9 files changed

+342
-355
lines changed

9 files changed

+342
-355
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParser.cpp

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -31,71 +31,70 @@ DWARFASTParser::ParseChildArrayInfo(const DWARFDIE &parent_die,
3131
if (tag != DW_TAG_subrange_type)
3232
continue;
3333

34-
DWARFAttributes attributes;
35-
const size_t num_child_attributes = die.GetAttributes(attributes);
36-
if (num_child_attributes > 0) {
37-
uint64_t num_elements = 0;
38-
uint64_t lower_bound = 0;
39-
uint64_t upper_bound = 0;
40-
bool upper_bound_valid = false;
41-
uint32_t i;
42-
for (i = 0; i < num_child_attributes; ++i) {
43-
const dw_attr_t attr = attributes.AttributeAtIndex(i);
44-
DWARFFormValue form_value;
45-
if (attributes.ExtractFormValueAtIndex(i, form_value)) {
46-
switch (attr) {
47-
case DW_AT_name:
48-
break;
49-
50-
case DW_AT_count:
51-
if (DWARFDIE var_die = die.GetReferencedDIE(DW_AT_count)) {
52-
if (var_die.Tag() == DW_TAG_variable)
53-
if (exe_ctx) {
54-
if (auto frame = exe_ctx->GetFrameSP()) {
55-
Status error;
56-
lldb::VariableSP var_sp;
57-
auto valobj_sp = frame->GetValueForVariableExpressionPath(
58-
var_die.GetName(), eNoDynamicValues, 0, var_sp, error);
59-
if (valobj_sp) {
60-
num_elements = valobj_sp->GetValueAsUnsigned(0);
61-
break;
62-
}
34+
DWARFAttributes attributes = die.GetAttributes();
35+
if (attributes.Size() == 0)
36+
continue;
37+
38+
uint64_t num_elements = 0;
39+
uint64_t lower_bound = 0;
40+
uint64_t upper_bound = 0;
41+
bool upper_bound_valid = false;
42+
for (size_t i = 0; i < attributes.Size(); ++i) {
43+
const dw_attr_t attr = attributes.AttributeAtIndex(i);
44+
DWARFFormValue form_value;
45+
if (attributes.ExtractFormValueAtIndex(i, form_value)) {
46+
switch (attr) {
47+
case DW_AT_name:
48+
break;
49+
50+
case DW_AT_count:
51+
if (DWARFDIE var_die = die.GetReferencedDIE(DW_AT_count)) {
52+
if (var_die.Tag() == DW_TAG_variable)
53+
if (exe_ctx) {
54+
if (auto frame = exe_ctx->GetFrameSP()) {
55+
Status error;
56+
lldb::VariableSP var_sp;
57+
auto valobj_sp = frame->GetValueForVariableExpressionPath(
58+
var_die.GetName(), eNoDynamicValues, 0, var_sp, error);
59+
if (valobj_sp) {
60+
num_elements = valobj_sp->GetValueAsUnsigned(0);
61+
break;
6362
}
6463
}
65-
} else
66-
num_elements = form_value.Unsigned();
67-
break;
68-
69-
case DW_AT_bit_stride:
70-
array_info.bit_stride = form_value.Unsigned();
71-
break;
72-
73-
case DW_AT_byte_stride:
74-
array_info.byte_stride = form_value.Unsigned();
75-
break;
76-
77-
case DW_AT_lower_bound:
78-
lower_bound = form_value.Unsigned();
79-
break;
80-
81-
case DW_AT_upper_bound:
82-
upper_bound_valid = true;
83-
upper_bound = form_value.Unsigned();
84-
break;
85-
86-
default:
87-
break;
88-
}
89-
}
90-
}
64+
}
65+
} else
66+
num_elements = form_value.Unsigned();
67+
break;
68+
69+
case DW_AT_bit_stride:
70+
array_info.bit_stride = form_value.Unsigned();
71+
break;
9172

92-
if (num_elements == 0) {
93-
if (upper_bound_valid && upper_bound >= lower_bound)
94-
num_elements = upper_bound - lower_bound + 1;
73+
case DW_AT_byte_stride:
74+
array_info.byte_stride = form_value.Unsigned();
75+
break;
76+
77+
case DW_AT_lower_bound:
78+
lower_bound = form_value.Unsigned();
79+
break;
80+
81+
case DW_AT_upper_bound:
82+
upper_bound_valid = true;
83+
upper_bound = form_value.Unsigned();
84+
break;
85+
86+
default:
87+
break;
88+
}
9589
}
90+
}
9691

97-
array_info.element_orders.push_back(num_elements);
92+
if (num_elements == 0) {
93+
if (upper_bound_valid && upper_bound >= lower_bound)
94+
num_elements = upper_bound - lower_bound + 1;
9895
}
96+
97+
array_info.element_orders.push_back(num_elements);
9998
}
10099
return array_info;
101100
}

0 commit comments

Comments
 (0)