Skip to content

Commit 6aad81c

Browse files
committed
Cleanup fixed form sizes.
The fix form sizes use to have two arrays: one for 4 byte addresses and in for 8 byte addresses. The table had an issue where DW_FORM_flag_present wasn't being represented as a fixed size form because its actual size _is_ zero and zero was used to indicate the form isn't fixed in size. Any code that needed to quickly access the DWARF had to get a FixedFormSizes instance using the address byte size. This fix cleans things up by adding a DWARFFormValue::GetFixedSize() both as a static method and as a member function on DWARFFormValue. It correctly can indicate if a form size is zero. This cleanup is a precursor to a follow up patch where I hope to speed up DWARF parsing. I verified performance doesn't regress by loading hundreds of DWARF files and setting a breakpoint by file and line and by name in files that do not have DWARF indexes. Performance remained consistent between the two approaches. Differential Revision: https://reviews.llvm.org/D62416 llvm-svn: 361675
1 parent b4c756d commit 6aad81c

File tree

11 files changed

+87
-162
lines changed

11 files changed

+87
-162
lines changed

lldb/lldb.xcodeproj/xcshareddata/xcschemes/desktop.xcscheme

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
buildConfiguration = "DebugClang"
4646
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4747
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
48-
launchStyle = "1"
48+
launchStyle = "0"
4949
useCustomWorkingDirectory = "NO"
5050
ignoresPersistentStateOnLaunch = "NO"
5151
debugDocumentVersioning = "YES"
@@ -61,6 +61,12 @@
6161
ReferencedContainer = "container:lldb.xcodeproj">
6262
</BuildableReference>
6363
</BuildableProductRunnable>
64+
<CommandLineArguments>
65+
<CommandLineArgument
66+
argument = "~/Documents/src/args/a.out "
67+
isEnabled = "YES">
68+
</CommandLineArgument>
69+
</CommandLineArguments>
6470
<AdditionalOptions>
6571
</AdditionalOptions>
6672
</LaunchAction>

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,8 @@ bool DWARFBaseDIE::Supports_DW_AT_APPLE_objc_complete_type() const {
136136

137137
size_t DWARFBaseDIE::GetAttributes(DWARFAttributes &attributes,
138138
uint32_t depth) const {
139-
if (IsValid()) {
140-
return m_die->GetAttributes(m_cu, m_cu->GetFixedFormSizes(), attributes,
141-
depth);
142-
}
139+
if (IsValid())
140+
return m_die->GetAttributes(m_cu, attributes, depth);
143141
if (depth == 0)
144142
attributes.Clear();
145143
return 0;

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ extern int g_verbose;
3333

3434
bool DWARFDebugInfoEntry::FastExtract(
3535
const DWARFDataExtractor &debug_info_data, const DWARFUnit *cu,
36-
const DWARFFormValue::FixedFormSizes &fixed_form_sizes,
3736
lldb::offset_t *offset_ptr) {
3837
m_offset = *offset_ptr;
3938
m_parent_idx = 0;
@@ -69,9 +68,9 @@ bool DWARFDebugInfoEntry::FastExtract(
6968
for (i = 0; i < numAttributes; ++i) {
7069
form = abbrevDecl->GetFormByIndexUnchecked(i);
7170

72-
const uint8_t fixed_skip_size = fixed_form_sizes.GetSize(form);
71+
llvm::Optional<uint8_t> fixed_skip_size = DWARFFormValue::GetFixedSize(form, cu);
7372
if (fixed_skip_size)
74-
offset += fixed_skip_size;
73+
offset += *fixed_skip_size;
7574
else {
7675
bool form_is_indirect = false;
7776
do {
@@ -723,8 +722,8 @@ void DWARFDebugInfoEntry::DumpAttribute(
723722
// results. Any duplicate attributes will have the first instance take
724723
// precedence (this can happen for declaration attributes).
725724
size_t DWARFDebugInfoEntry::GetAttributes(
726-
const DWARFUnit *cu, DWARFFormValue::FixedFormSizes fixed_form_sizes,
727-
DWARFAttributes &attributes, uint32_t curr_depth) const {
725+
const DWARFUnit *cu, DWARFAttributes &attributes,
726+
uint32_t curr_depth) const {
728727
const DWARFAbbreviationDeclaration *abbrevDecl = nullptr;
729728
lldb::offset_t offset = 0;
730729
if (cu)
@@ -733,10 +732,6 @@ size_t DWARFDebugInfoEntry::GetAttributes(
733732
if (abbrevDecl) {
734733
const DWARFDataExtractor &debug_info_data = cu->GetData();
735734

736-
if (fixed_form_sizes.Empty())
737-
fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize(
738-
cu->GetAddressByteSize());
739-
740735
const uint32_t num_attributes = abbrevDecl->NumAttributes();
741736
for (uint32_t i = 0; i < num_attributes; ++i) {
742737
DWARFFormValue form_value(cu);
@@ -769,9 +764,9 @@ size_t DWARFDebugInfoEntry::GetAttributes(
769764
spec_die.GetAttributes(attributes, curr_depth + 1);
770765
}
771766
} else {
772-
const uint8_t fixed_skip_size = fixed_form_sizes.GetSize(form);
767+
llvm::Optional<uint8_t> fixed_skip_size = DWARFFormValue::GetFixedSize(form, cu);
773768
if (fixed_skip_size)
774-
offset += fixed_skip_size;
769+
offset += *fixed_skip_size;
775770
else
776771
DWARFFormValue::SkipValue(form, debug_info_data, &offset, cu);
777772
}
@@ -1120,7 +1115,7 @@ bool DWARFDebugInfoEntry::MatchesDWARFDeclContext(
11201115
DWARFDIE
11211116
DWARFDebugInfoEntry::GetParentDeclContextDIE(DWARFUnit *cu) const {
11221117
DWARFAttributes attributes;
1123-
GetAttributes(cu, DWARFFormValue::FixedFormSizes(), attributes);
1118+
GetAttributes(cu, attributes);
11241119
return GetParentDeclContextDIE(cu, attributes);
11251120
}
11261121

@@ -1170,7 +1165,7 @@ DWARFDebugInfoEntry::GetParentDeclContextDIE(
11701165
const char *DWARFDebugInfoEntry::GetQualifiedName(DWARFUnit *cu,
11711166
std::string &storage) const {
11721167
DWARFAttributes attributes;
1173-
GetAttributes(cu, DWARFFormValue::FixedFormSizes(), attributes);
1168+
GetAttributes(cu, attributes);
11741169
return GetQualifiedName(cu, attributes, storage);
11751170
}
11761171

lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class DWARFDebugInfoEntry {
6969

7070
bool FastExtract(const lldb_private::DWARFDataExtractor &debug_info_data,
7171
const DWARFUnit *cu,
72-
const DWARFFormValue::FixedFormSizes &fixed_form_sizes,
7372
lldb::offset_t *offset_ptr);
7473

7574
bool Extract(const DWARFUnit *cu, lldb::offset_t *offset_ptr);
@@ -79,7 +78,6 @@ class DWARFDebugInfoEntry {
7978
DWARFDebugInfoEntry **block_die);
8079

8180
size_t GetAttributes(const DWARFUnit *cu,
82-
DWARFFormValue::FixedFormSizes fixed_form_sizes,
8381
DWARFAttributes &attrs,
8482
uint32_t curr_depth = 0)
8583
const; // "curr_depth" for internal use only, don't set this yourself!!!

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

Lines changed: 53 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -21,92 +21,6 @@ class DWARFUnit;
2121

2222
using namespace lldb_private;
2323

24-
static uint8_t g_form_sizes_addr4[] = {
25-
0, // 0x00 unused
26-
4, // 0x01 DW_FORM_addr
27-
0, // 0x02 unused
28-
0, // 0x03 DW_FORM_block2
29-
0, // 0x04 DW_FORM_block4
30-
2, // 0x05 DW_FORM_data2
31-
4, // 0x06 DW_FORM_data4
32-
8, // 0x07 DW_FORM_data8
33-
0, // 0x08 DW_FORM_string
34-
0, // 0x09 DW_FORM_block
35-
0, // 0x0a DW_FORM_block1
36-
1, // 0x0b DW_FORM_data1
37-
1, // 0x0c DW_FORM_flag
38-
0, // 0x0d DW_FORM_sdata
39-
4, // 0x0e DW_FORM_strp
40-
0, // 0x0f DW_FORM_udata
41-
0, // 0x10 DW_FORM_ref_addr (addr size for DWARF2 and earlier, 4 bytes for
42-
// DWARF32, 8 bytes for DWARF32 in DWARF 3 and later
43-
1, // 0x11 DW_FORM_ref1
44-
2, // 0x12 DW_FORM_ref2
45-
4, // 0x13 DW_FORM_ref4
46-
8, // 0x14 DW_FORM_ref8
47-
0, // 0x15 DW_FORM_ref_udata
48-
0, // 0x16 DW_FORM_indirect
49-
4, // 0x17 DW_FORM_sec_offset
50-
0, // 0x18 DW_FORM_exprloc
51-
0, // 0x19 DW_FORM_flag_present
52-
0, // 0x1a
53-
0, // 0x1b
54-
0, // 0x1c
55-
0, // 0x1d
56-
0, // 0x1e
57-
0, // 0x1f
58-
8, // 0x20 DW_FORM_ref_sig8
59-
60-
};
61-
62-
static uint8_t g_form_sizes_addr8[] = {
63-
0, // 0x00 unused
64-
8, // 0x01 DW_FORM_addr
65-
0, // 0x02 unused
66-
0, // 0x03 DW_FORM_block2
67-
0, // 0x04 DW_FORM_block4
68-
2, // 0x05 DW_FORM_data2
69-
4, // 0x06 DW_FORM_data4
70-
8, // 0x07 DW_FORM_data8
71-
0, // 0x08 DW_FORM_string
72-
0, // 0x09 DW_FORM_block
73-
0, // 0x0a DW_FORM_block1
74-
1, // 0x0b DW_FORM_data1
75-
1, // 0x0c DW_FORM_flag
76-
0, // 0x0d DW_FORM_sdata
77-
4, // 0x0e DW_FORM_strp
78-
0, // 0x0f DW_FORM_udata
79-
0, // 0x10 DW_FORM_ref_addr (addr size for DWARF2 and earlier, 4 bytes for
80-
// DWARF32, 8 bytes for DWARF32 in DWARF 3 and later
81-
1, // 0x11 DW_FORM_ref1
82-
2, // 0x12 DW_FORM_ref2
83-
4, // 0x13 DW_FORM_ref4
84-
8, // 0x14 DW_FORM_ref8
85-
0, // 0x15 DW_FORM_ref_udata
86-
0, // 0x16 DW_FORM_indirect
87-
4, // 0x17 DW_FORM_sec_offset
88-
0, // 0x18 DW_FORM_exprloc
89-
0, // 0x19 DW_FORM_flag_present
90-
0, // 0x1a
91-
0, // 0x1b
92-
0, // 0x1c
93-
0, // 0x1d
94-
0, // 0x1e
95-
0, // 0x1f
96-
8, // 0x20 DW_FORM_ref_sig8
97-
};
98-
99-
DWARFFormValue::FixedFormSizes
100-
DWARFFormValue::GetFixedFormSizesForAddressSize(uint8_t addr_size) {
101-
switch (addr_size) {
102-
case 4:
103-
return FixedFormSizes(g_form_sizes_addr4, sizeof(g_form_sizes_addr4));
104-
case 8:
105-
return FixedFormSizes(g_form_sizes_addr8, sizeof(g_form_sizes_addr8));
106-
}
107-
return FixedFormSizes();
108-
}
109-
11024
void DWARFFormValue::Clear() {
11125
m_unit = nullptr;
11226
m_form = 0;
@@ -231,6 +145,59 @@ bool DWARFFormValue::ExtractValue(const DWARFDataExtractor &data,
231145
return true;
232146
}
233147

148+
struct FormSize {
149+
uint8_t valid:1, size:7;
150+
};
151+
static FormSize g_form_sizes[] = {
152+
{0,0}, // 0x00 unused
153+
{0,0}, // 0x01 DW_FORM_addr
154+
{0,0}, // 0x02 unused
155+
{0,0}, // 0x03 DW_FORM_block2
156+
{0,0}, // 0x04 DW_FORM_block4
157+
{1,2}, // 0x05 DW_FORM_data2
158+
{1,4}, // 0x06 DW_FORM_data4
159+
{1,8}, // 0x07 DW_FORM_data8
160+
{0,0}, // 0x08 DW_FORM_string
161+
{0,0}, // 0x09 DW_FORM_block
162+
{0,0}, // 0x0a DW_FORM_block1
163+
{1,1}, // 0x0b DW_FORM_data1
164+
{1,1}, // 0x0c DW_FORM_flag
165+
{0,0}, // 0x0d DW_FORM_sdata
166+
{1,4}, // 0x0e DW_FORM_strp
167+
{0,0}, // 0x0f DW_FORM_udata
168+
{0,0}, // 0x10 DW_FORM_ref_addr (addr size for DWARF2 and earlier, 4 bytes for
169+
// DWARF32, 8 bytes for DWARF32 in DWARF 3 and later
170+
{1,1}, // 0x11 DW_FORM_ref1
171+
{1,2}, // 0x12 DW_FORM_ref2
172+
{1,4}, // 0x13 DW_FORM_ref4
173+
{1,8}, // 0x14 DW_FORM_ref8
174+
{0,0}, // 0x15 DW_FORM_ref_udata
175+
{0,0}, // 0x16 DW_FORM_indirect
176+
{1,4}, // 0x17 DW_FORM_sec_offset
177+
{0,0}, // 0x18 DW_FORM_exprloc
178+
{1,0}, // 0x19 DW_FORM_flag_present
179+
{0,0}, // 0x1a
180+
{0,0}, // 0x1b
181+
{0,0}, // 0x1c
182+
{0,0}, // 0x1d
183+
{0,0}, // 0x1e
184+
{0,0}, // 0x1f
185+
{1,8}, // 0x20 DW_FORM_ref_sig8
186+
};
187+
188+
llvm::Optional<uint8_t>
189+
DWARFFormValue::GetFixedSize(dw_form_t form, const DWARFUnit *u) {
190+
if (form <= DW_FORM_ref_sig8 && g_form_sizes[form].valid)
191+
return g_form_sizes[form].size;
192+
if (form == DW_FORM_addr && u)
193+
return u->GetAddressByteSize();
194+
return llvm::None;
195+
}
196+
197+
llvm::Optional<uint8_t> DWARFFormValue::GetFixedSize() const {
198+
return GetFixedSize(m_form, m_unit);
199+
}
200+
234201
bool DWARFFormValue::SkipValue(const DWARFDataExtractor &debug_info_data,
235202
lldb::offset_t *offset_ptr) const {
236203
return DWARFFormValue::SkipValue(m_form, debug_info_data, offset_ptr, m_unit);

lldb/source/Plugins/SymbolFile/DWARF/DWARFFormValue.h

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "DWARFDataExtractor.h"
1313
#include <stddef.h>
14+
#include "llvm/ADT/Optional.h"
1415

1516
class DWARFUnit;
1617
class SymbolFileDWARF;
@@ -29,24 +30,6 @@ class DWARFFormValue {
2930
const uint8_t *data;
3031
} ValueType;
3132

32-
class FixedFormSizes {
33-
public:
34-
FixedFormSizes() : m_fix_sizes(nullptr), m_size(0) {}
35-
36-
FixedFormSizes(const uint8_t *fix_sizes, size_t size)
37-
: m_fix_sizes(fix_sizes), m_size(size) {}
38-
39-
uint8_t GetSize(uint32_t index) const {
40-
return index < m_size ? m_fix_sizes[index] : 0;
41-
}
42-
43-
bool Empty() const { return m_size == 0; }
44-
45-
private:
46-
const uint8_t *m_fix_sizes;
47-
size_t m_size;
48-
};
49-
5033
enum {
5134
eValueTypeInvalid = 0,
5235
eValueTypeUnsigned,
@@ -71,6 +54,9 @@ class DWARFFormValue {
7154
bool ExtractValue(const lldb_private::DWARFDataExtractor &data,
7255
lldb::offset_t *offset_ptr);
7356
const uint8_t *BlockData() const;
57+
static llvm::Optional<uint8_t> GetFixedSize(dw_form_t form,
58+
const DWARFUnit *u);
59+
llvm::Optional<uint8_t> GetFixedSize() const;
7460
DWARFDIE Reference() const;
7561
uint64_t Reference(dw_offset_t offset) const;
7662
bool Boolean() const { return m_value.value.uval != 0; }
@@ -88,7 +74,6 @@ class DWARFFormValue {
8874
lldb::offset_t *offset_ptr, const DWARFUnit *unit);
8975
static bool IsBlockForm(const dw_form_t form);
9076
static bool IsDataForm(const dw_form_t form);
91-
static FixedFormSizes GetFixedFormSizesForAddressSize(uint8_t addr_size);
9277
static int Compare(const DWARFFormValue &a, const DWARFFormValue &b);
9378
void Clear();
9479
static bool FormIsSupported(dw_form_t form);

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ void DWARFUnit::ExtractUnitDIEIfNeeded() {
6060
// We are in our compile unit, parse starting at the offset we were told to
6161
// parse
6262
const DWARFDataExtractor &data = GetData();
63-
DWARFFormValue::FixedFormSizes fixed_form_sizes =
64-
DWARFFormValue::GetFixedFormSizesForAddressSize(GetAddressByteSize());
6563
if (offset < GetNextUnitOffset() &&
66-
m_first_die.FastExtract(data, this, fixed_form_sizes, &offset)) {
64+
m_first_die.FastExtract(data, this, &offset)) {
6765
AddUnitDIE(m_first_die);
6866
return;
6967
}
@@ -167,10 +165,7 @@ void DWARFUnit::ExtractDIEsRWLocked() {
167165
die_index_stack.reserve(32);
168166
die_index_stack.push_back(0);
169167
bool prev_die_had_children = false;
170-
DWARFFormValue::FixedFormSizes fixed_form_sizes =
171-
DWARFFormValue::GetFixedFormSizesForAddressSize(GetAddressByteSize());
172-
while (offset < next_cu_offset &&
173-
die.FastExtract(data, this, fixed_form_sizes, &offset)) {
168+
while (offset < next_cu_offset && die.FastExtract(data, this, &offset)) {
174169
const bool null_die = die.IsNULL();
175170
if (depth == 0) {
176171
assert(m_die_array.empty() && "Compile unit DIE already added");
@@ -415,10 +410,6 @@ TypeSystem *DWARFUnit::GetTypeSystem() {
415410
return nullptr;
416411
}
417412

418-
DWARFFormValue::FixedFormSizes DWARFUnit::GetFixedFormSizes() {
419-
return DWARFFormValue::GetFixedFormSizesForAddressSize(GetAddressByteSize());
420-
}
421-
422413
void DWARFUnit::SetBaseAddress(dw_addr_t base_addr) { m_base_addr = base_addr; }
423414

424415
// Compare function DWARFDebugAranges::Range structures

lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,6 @@ class DWARFUnit : public lldb_private::UserID {
157157

158158
const DWARFDebugAranges &GetFunctionAranges();
159159

160-
DWARFFormValue::FixedFormSizes GetFixedFormSizes();
161-
162160
void SetBaseAddress(dw_addr_t base_addr);
163161

164162
DWARFBaseDIE GetUnitDIEOnly() { return DWARFDIE(this, GetUnitDIEPtrOnly()); }

0 commit comments

Comments
 (0)