labath created this revision.
labath added reviewers: JDevlieghere, clayborg.
The llvm function is practically a drop-in replacement. There may be
slight differences in performance as the llvm version uses a switch
whereas our version used a lookup table, but I can't say which way that
will go. (In practice, the compiler will also turn the switch into a jump
table.)
The thing we definitely gain by this is support for new forms that
haven't been added to our tables (e.g. DW_FORM_data16) and the ability
to represent forms of size 0 like DW_FORM_implicit_const (which we
couldn't represent because we used 0 to mean "size unknown"). The thing
we definitely lose is 150 lines of code.
https://reviews.llvm.org/D44739
Files:
source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
source/Plugins/SymbolFile/DWARF/DWARFUnit.h
source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -3804,36 +3804,32 @@
block_length);
} else if (DWARFFormValue::IsDataForm(form_value.Form())) {
// Retrieve the value as a data expression.
- DWARFFormValue::FixedFormSizes fixed_form_sizes =
- DWARFFormValue::GetFixedFormSizesForAddressSize(
- attributes.CompileUnitAtIndex(i)->GetAddressByteSize(),
- attributes.CompileUnitAtIndex(i)->IsDWARF64());
+ llvm::dwarf::FormParams form_params =
+ attributes.CompileUnitAtIndex(i)->GetFormParams();
uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
- uint32_t data_length =
- fixed_form_sizes.GetSize(form_value.Form());
- if (data_length == 0) {
+ if (llvm::Optional<uint8_t> data_length =
+ llvm::dwarf::getFixedFormByteSize(
+ llvm::dwarf::Form(form_value.Form()), form_params))
+ location.CopyOpcodeData(module, debug_info_data, data_offset,
+ *data_length);
+ else {
const uint8_t *data_pointer = form_value.BlockData();
if (data_pointer) {
form_value.Unsigned();
} else if (DWARFFormValue::IsDataForm(form_value.Form())) {
// we need to get the byte size of the type later after we
// create the variable
const_value = form_value;
}
- } else
- location.CopyOpcodeData(module, debug_info_data, data_offset,
- data_length);
+ }
} else {
// Retrieve the value as a string expression.
if (form_value.Form() == DW_FORM_strp) {
- DWARFFormValue::FixedFormSizes fixed_form_sizes =
- DWARFFormValue::GetFixedFormSizesForAddressSize(
- attributes.CompileUnitAtIndex(i)
- ->GetAddressByteSize(),
- attributes.CompileUnitAtIndex(i)->IsDWARF64());
+ llvm::dwarf::FormParams form_params =
+ attributes.CompileUnitAtIndex(i)->GetFormParams();
uint32_t data_offset = attributes.DIEOffsetAtIndex(i);
- uint32_t data_length =
- fixed_form_sizes.GetSize(form_value.Form());
+ uint32_t data_length = *llvm::dwarf::getFixedFormByteSize(
+ DW_FORM_strp, form_params);
location.CopyOpcodeData(module, debug_info_data, data_offset,
data_length);
} else {
Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFUnit.h
+++ source/Plugins/SymbolFile/DWARF/DWARFUnit.h
@@ -74,7 +74,7 @@
lldb_private::TypeSystem *GetTypeSystem();
- DWARFFormValue::FixedFormSizes GetFixedFormSizes();
+ llvm::dwarf::FormParams GetFormParams() const;
void SetBaseAddress(dw_addr_t base_addr);
@@ -139,13 +139,14 @@
DWARFUnit();
- static void
- IndexPrivate(DWARFUnit *dwarf_cu, const lldb::LanguageType cu_language,
- const DWARFFormValue::FixedFormSizes &fixed_form_sizes,
- const dw_offset_t cu_offset, NameToDIE &func_basenames,
- NameToDIE &func_fullnames, NameToDIE &func_methods,
- NameToDIE &func_selectors, NameToDIE &objc_class_selectors,
- NameToDIE &globals, NameToDIE &types, NameToDIE &namespaces);
+ static void IndexPrivate(DWARFUnit *dwarf_cu,
+ const lldb::LanguageType cu_language,
+ llvm::dwarf::FormParams form_params,
+ const dw_offset_t cu_offset,
+ NameToDIE &func_basenames, NameToDIE &func_fullnames,
+ NameToDIE &func_methods, NameToDIE &func_selectors,
+ NameToDIE &objc_class_selectors, NameToDIE &globals,
+ NameToDIE &types, NameToDIE &namespaces);
// Offset of the initial length field.
dw_offset_t m_offset;
Index: source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -106,9 +106,10 @@
return Data().GetTypeSystem();
}
-DWARFFormValue::FixedFormSizes DWARFUnit::GetFixedFormSizes() {
- return DWARFFormValue::GetFixedFormSizesForAddressSize(GetAddressByteSize(),
- IsDWARF64());
+llvm::dwarf::FormParams DWARFUnit::GetFormParams() const {
+ return llvm::dwarf::FormParams{GetVersion(), GetAddressByteSize(),
+ IsDWARF64() ? llvm::dwarf::DWARF64
+ : llvm::dwarf::DWARF32};
}
void DWARFUnit::SetBaseAddress(dw_addr_t base_addr) {
@@ -298,30 +299,26 @@
}
const LanguageType cu_language = GetLanguageType();
- DWARFFormValue::FixedFormSizes fixed_form_sizes =
- DWARFFormValue::GetFixedFormSizesForAddressSize(GetAddressByteSize(),
- IsDWARF64());
-
- IndexPrivate(this, cu_language, fixed_form_sizes, GetOffset(), func_basenames,
+ IndexPrivate(this, cu_language, GetFormParams(), GetOffset(), func_basenames,
func_fullnames, func_methods, func_selectors,
objc_class_selectors, globals, types, namespaces);
SymbolFileDWARFDwo *dwo_symbol_file = GetDwoSymbolFile();
if (dwo_symbol_file) {
IndexPrivate(
- dwo_symbol_file->GetCompileUnit(), cu_language, fixed_form_sizes,
+ dwo_symbol_file->GetCompileUnit(), cu_language, GetFormParams(),
GetOffset(), func_basenames, func_fullnames, func_methods,
func_selectors, objc_class_selectors, globals, types, namespaces);
}
}
void DWARFUnit::IndexPrivate(
DWARFUnit *dwarf_cu, const LanguageType cu_language,
- const DWARFFormValue::FixedFormSizes &fixed_form_sizes,
- const dw_offset_t cu_offset, NameToDIE &func_basenames,
- NameToDIE &func_fullnames, NameToDIE &func_methods,
- NameToDIE &func_selectors, NameToDIE &objc_class_selectors,
- NameToDIE &globals, NameToDIE &types, NameToDIE &namespaces) {
+ llvm::dwarf::FormParams form_params, const dw_offset_t cu_offset,
+ NameToDIE &func_basenames, NameToDIE &func_fullnames,
+ NameToDIE &func_methods, NameToDIE &func_selectors,
+ NameToDIE &objc_class_selectors, NameToDIE &globals, NameToDIE &types,
+ NameToDIE &namespaces) {
DWARFDebugInfoEntry::const_iterator pos;
DWARFDebugInfoEntry::const_iterator begin =
dwarf_cu->Data().m_die_array.begin();
@@ -364,7 +361,7 @@
DWARFFormValue specification_die_form;
const size_t num_attributes =
- die.GetAttributes(dwarf_cu, fixed_form_sizes, attributes);
+ die.GetAttributes(dwarf_cu, form_params, attributes);
if (num_attributes > 0) {
for (uint32_t i = 0; i < num_attributes; ++i) {
dw_attr_t attr = attributes.AttributeAtIndex(i);
Index: source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
+++ source/Plugins/SymbolFile/DWARF/DWARFFormValue.h
@@ -28,24 +28,6 @@
const uint8_t *data;
} ValueType;
- class FixedFormSizes {
- public:
- FixedFormSizes() : m_fix_sizes(nullptr), m_size(0) {}
-
- FixedFormSizes(const uint8_t *fix_sizes, size_t size)
- : m_fix_sizes(fix_sizes), m_size(size) {}
-
- uint8_t GetSize(uint32_t index) const {
- return index < m_size ? m_fix_sizes[index] : 0;
- }
-
- bool Empty() const { return m_size == 0; }
-
- private:
- const uint8_t *m_fix_sizes;
- size_t m_size;
- };
-
enum {
eValueTypeInvalid = 0,
eValueTypeUnsigned,
@@ -82,8 +64,6 @@
lldb::offset_t *offset_ptr, const DWARFUnit *cu);
static bool IsBlockForm(const dw_form_t form);
static bool IsDataForm(const dw_form_t form);
- static FixedFormSizes GetFixedFormSizesForAddressSize(uint8_t addr_size,
- bool is_dwarf64);
static int Compare(const DWARFFormValue &a, const DWARFFormValue &b);
void Clear();
static bool FormIsSupported(dw_form_t form);
Index: source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFFormValue.cpp
@@ -15,143 +15,8 @@
#include "DWARFUnit.h"
#include "DWARFFormValue.h"
-class DWARFUnit;
-
using namespace lldb_private;
-static uint8_t g_form_sizes_addr4[] = {
- 0, // 0x00 unused
- 4, // 0x01 DW_FORM_addr
- 0, // 0x02 unused
- 0, // 0x03 DW_FORM_block2
- 0, // 0x04 DW_FORM_block4
- 2, // 0x05 DW_FORM_data2
- 4, // 0x06 DW_FORM_data4
- 8, // 0x07 DW_FORM_data8
- 0, // 0x08 DW_FORM_string
- 0, // 0x09 DW_FORM_block
- 0, // 0x0a DW_FORM_block1
- 1, // 0x0b DW_FORM_data1
- 1, // 0x0c DW_FORM_flag
- 0, // 0x0d DW_FORM_sdata
- 4, // 0x0e DW_FORM_strp
- 0, // 0x0f DW_FORM_udata
- 0, // 0x10 DW_FORM_ref_addr (addr size for DWARF2 and earlier, 4 bytes for
- // DWARF32, 8 bytes for DWARF32 in DWARF 3 and later
- 1, // 0x11 DW_FORM_ref1
- 2, // 0x12 DW_FORM_ref2
- 4, // 0x13 DW_FORM_ref4
- 8, // 0x14 DW_FORM_ref8
- 0, // 0x15 DW_FORM_ref_udata
- 0, // 0x16 DW_FORM_indirect
- 4, // 0x17 DW_FORM_sec_offset
- 0, // 0x18 DW_FORM_exprloc
- 0, // 0x19 DW_FORM_flag_present
- 0, // 0x1a
- 0, // 0x1b
- 0, // 0x1c
- 0, // 0x1d
- 0, // 0x1e
- 0, // 0x1f
- 8, // 0x20 DW_FORM_ref_sig8
-
-};
-
-static uint8_t g_form_sizes_addr8[] = {
- 0, // 0x00 unused
- 8, // 0x01 DW_FORM_addr
- 0, // 0x02 unused
- 0, // 0x03 DW_FORM_block2
- 0, // 0x04 DW_FORM_block4
- 2, // 0x05 DW_FORM_data2
- 4, // 0x06 DW_FORM_data4
- 8, // 0x07 DW_FORM_data8
- 0, // 0x08 DW_FORM_string
- 0, // 0x09 DW_FORM_block
- 0, // 0x0a DW_FORM_block1
- 1, // 0x0b DW_FORM_data1
- 1, // 0x0c DW_FORM_flag
- 0, // 0x0d DW_FORM_sdata
- 4, // 0x0e DW_FORM_strp
- 0, // 0x0f DW_FORM_udata
- 0, // 0x10 DW_FORM_ref_addr (addr size for DWARF2 and earlier, 4 bytes for
- // DWARF32, 8 bytes for DWARF32 in DWARF 3 and later
- 1, // 0x11 DW_FORM_ref1
- 2, // 0x12 DW_FORM_ref2
- 4, // 0x13 DW_FORM_ref4
- 8, // 0x14 DW_FORM_ref8
- 0, // 0x15 DW_FORM_ref_udata
- 0, // 0x16 DW_FORM_indirect
- 4, // 0x17 DW_FORM_sec_offset
- 0, // 0x18 DW_FORM_exprloc
- 0, // 0x19 DW_FORM_flag_present
- 0, // 0x1a
- 0, // 0x1b
- 0, // 0x1c
- 0, // 0x1d
- 0, // 0x1e
- 0, // 0x1f
- 8, // 0x20 DW_FORM_ref_sig8
-};
-
-// Difference with g_form_sizes_addr8:
-// DW_FORM_strp and DW_FORM_sec_offset are 8 instead of 4
-static uint8_t g_form_sizes_addr8_dwarf64[] = {
- 0, // 0x00 unused
- 8, // 0x01 DW_FORM_addr
- 0, // 0x02 unused
- 0, // 0x03 DW_FORM_block2
- 0, // 0x04 DW_FORM_block4
- 2, // 0x05 DW_FORM_data2
- 4, // 0x06 DW_FORM_data4
- 8, // 0x07 DW_FORM_data8
- 0, // 0x08 DW_FORM_string
- 0, // 0x09 DW_FORM_block
- 0, // 0x0a DW_FORM_block1
- 1, // 0x0b DW_FORM_data1
- 1, // 0x0c DW_FORM_flag
- 0, // 0x0d DW_FORM_sdata
- 8, // 0x0e DW_FORM_strp
- 0, // 0x0f DW_FORM_udata
- 0, // 0x10 DW_FORM_ref_addr (addr size for DWARF2 and earlier, 4 bytes for
- // DWARF32, 8 bytes for DWARF32 in DWARF 3 and later
- 1, // 0x11 DW_FORM_ref1
- 2, // 0x12 DW_FORM_ref2
- 4, // 0x13 DW_FORM_ref4
- 8, // 0x14 DW_FORM_ref8
- 0, // 0x15 DW_FORM_ref_udata
- 0, // 0x16 DW_FORM_indirect
- 8, // 0x17 DW_FORM_sec_offset
- 0, // 0x18 DW_FORM_exprloc
- 0, // 0x19 DW_FORM_flag_present
- 0, // 0x1a
- 0, // 0x1b
- 0, // 0x1c
- 0, // 0x1d
- 0, // 0x1e
- 0, // 0x1f
- 8, // 0x20 DW_FORM_ref_sig8
-};
-
-DWARFFormValue::FixedFormSizes
-DWARFFormValue::GetFixedFormSizesForAddressSize(uint8_t addr_size,
- bool is_dwarf64) {
- if (!is_dwarf64) {
- switch (addr_size) {
- case 4:
- return FixedFormSizes(g_form_sizes_addr4, sizeof(g_form_sizes_addr4));
- case 8:
- return FixedFormSizes(g_form_sizes_addr8, sizeof(g_form_sizes_addr8));
- }
- } else {
- if (addr_size == 8)
- return FixedFormSizes(g_form_sizes_addr8_dwarf64,
- sizeof(g_form_sizes_addr8_dwarf64));
- // is_dwarf64 && addr_size == 4 : no provider does this.
- }
- return FixedFormSizes();
-}
-
DWARFFormValue::DWARFFormValue() : m_cu(NULL), m_form(0), m_value() {}
DWARFFormValue::DWARFFormValue(const DWARFUnit *cu, dw_form_t form)
Index: source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
+++ source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
@@ -70,7 +70,7 @@
bool FastExtract(const lldb_private::DWARFDataExtractor &debug_info_data,
const DWARFUnit *cu,
- const DWARFFormValue::FixedFormSizes &fixed_form_sizes,
+ llvm::dwarf::FormParams form_params,
lldb::offset_t *offset_ptr);
bool Extract(SymbolFileDWARF *dwarf2Data, const DWARFUnit *cu,
@@ -82,7 +82,7 @@
DWARFDebugInfoEntry **block_die);
size_t GetAttributes(const DWARFUnit *cu,
- DWARFFormValue::FixedFormSizes fixed_form_sizes,
+ llvm::dwarf::FormParams form_params,
DWARFAttributes &attrs,
uint32_t curr_depth = 0)
const; // "curr_depth" for internal use only, don't set this yourself!!!
Index: source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
@@ -35,7 +35,7 @@
bool DWARFDebugInfoEntry::FastExtract(
const DWARFDataExtractor &debug_info_data, const DWARFUnit *cu,
- const DWARFFormValue::FixedFormSizes &fixed_form_sizes,
+ llvm::dwarf::FormParams form_params,
lldb::offset_t *offset_ptr) {
m_offset = *offset_ptr;
m_parent_idx = 0;
@@ -45,9 +45,6 @@
assert(abbr_idx < (1 << DIE_ABBR_IDX_BITSIZE));
m_abbr_idx = abbr_idx;
- // assert (fixed_form_sizes); // For best performance this should be
- // specified!
-
if (m_abbr_idx) {
lldb::offset_t offset = *offset_ptr;
@@ -72,9 +69,10 @@
for (i = 0; i < numAttributes; ++i) {
form = abbrevDecl->GetFormByIndexUnchecked(i);
- const uint8_t fixed_skip_size = fixed_form_sizes.GetSize(form);
- if (fixed_skip_size)
- offset += fixed_skip_size;
+ if (llvm::Optional<uint8_t> fixed_skip_size =
+ llvm::dwarf::getFixedFormByteSize(llvm::dwarf::Form(form),
+ form_params))
+ offset += *fixed_skip_size;
else {
bool form_is_indirect = false;
do {
@@ -764,17 +762,18 @@
// take precedence (this can happen for declaration attributes).
//----------------------------------------------------------------------
size_t DWARFDebugInfoEntry::GetAttributes(
- const DWARFUnit *cu, DWARFFormValue::FixedFormSizes fixed_form_sizes,
+ const DWARFUnit *cu,
+ llvm::dwarf::FormParams form_params,
DWARFAttributes &attributes, uint32_t curr_depth) const {
SymbolFileDWARF *dwarf2Data = nullptr;
const DWARFAbbreviationDeclaration *abbrevDecl = nullptr;
lldb::offset_t offset = 0;
if (cu) {
if (m_tag != DW_TAG_compile_unit) {
SymbolFileDWARFDwo *dwo_symbol_file = cu->GetDwoSymbolFile();
if (dwo_symbol_file)
- return GetAttributes(dwo_symbol_file->GetCompileUnit(),
- fixed_form_sizes, attributes, curr_depth);
+ return GetAttributes(dwo_symbol_file->GetCompileUnit(), form_params,
+ attributes, curr_depth);
}
dwarf2Data = cu->GetSymbolFileDWARF();
@@ -785,9 +784,8 @@
const DWARFDataExtractor &debug_info_data =
dwarf2Data->get_debug_info_data();
- if (fixed_form_sizes.Empty())
- fixed_form_sizes = DWARFFormValue::GetFixedFormSizesForAddressSize(
- cu->GetAddressByteSize(), cu->IsDWARF64());
+ if (!form_params)
+ form_params = cu->GetFormParams();
const uint32_t num_attributes = abbrevDecl->NumAttributes();
uint32_t i;
@@ -824,9 +822,10 @@
spec_die.GetAttributes(attributes, curr_depth + 1);
}
} else {
- const uint8_t fixed_skip_size = fixed_form_sizes.GetSize(form);
- if (fixed_skip_size)
- offset += fixed_skip_size;
+ if (llvm::Optional<uint8_t> fixed_skip_size =
+ llvm::dwarf::getFixedFormByteSize(llvm::dwarf::Form(form),
+ form_params))
+ offset += *fixed_skip_size;
else
DWARFFormValue::SkipValue(form, debug_info_data, &offset, cu);
}
@@ -1407,7 +1406,8 @@
DWARFDebugInfoEntry::GetParentDeclContextDIE(SymbolFileDWARF *dwarf2Data,
DWARFUnit *cu) const {
DWARFAttributes attributes;
- GetAttributes(cu, DWARFFormValue::FixedFormSizes(), attributes);
+ GetAttributes(cu, llvm::dwarf::FormParams{0, 0, llvm::dwarf::DWARF32},
+ attributes);
return GetParentDeclContextDIE(dwarf2Data, cu, attributes);
}
@@ -1468,7 +1468,8 @@
DWARFUnit *cu,
std::string &storage) const {
DWARFAttributes attributes;
- GetAttributes(cu, DWARFFormValue::FixedFormSizes(), attributes);
+ GetAttributes(cu, llvm::dwarf::FormParams{0, 0, llvm::dwarf::DWARF32},
+ attributes);
return GetQualifiedName(dwarf2Data, cu, attributes, storage);
}
Index: source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
@@ -401,10 +401,8 @@
size_t DWARFDIE::GetAttributes(DWARFAttributes &attributes,
uint32_t depth) const {
- if (IsValid()) {
- return m_die->GetAttributes(m_cu, m_cu->GetFixedFormSizes(), attributes,
- depth);
- }
+ if (IsValid())
+ return m_die->GetAttributes(m_cu, m_cu->GetFormParams(), attributes, depth);
if (depth == 0)
attributes.Clear();
return 0;
Index: source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
@@ -146,11 +146,9 @@
die_index_stack.reserve(32);
die_index_stack.push_back(0);
bool prev_die_had_children = false;
- DWARFFormValue::FixedFormSizes fixed_form_sizes =
- DWARFFormValue::GetFixedFormSizesForAddressSize(GetAddressByteSize(),
- m_is_dwarf64);
+ llvm::dwarf::FormParams form_params = GetFormParams();
while (offset < next_cu_offset &&
- die.FastExtract(debug_info_data, this, fixed_form_sizes, &offset)) {
+ die.FastExtract(debug_info_data, this, form_params, &offset)) {
// if (log)
// log->Printf("0x%8.8x: %*.*s%s%s",
// die.GetOffset(),
_______________________________________________
lldb-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits