[Lldb-commits] [lldb] r319359 - refactor: Unify+simplify DWARFCompileUnit ctor+Clear() into in-class initializers + Extract()
Jan Kratochvil via lldb-commits
lldb-commits at lists.llvm.org
Wed Nov 29 13:13:11 PST 2017
Author: jankratochvil
Date: Wed Nov 29 13:13:11 2017
New Revision: 319359
URL: http://llvm.org/viewvc/llvm-project?rev=319359&view=rev
Log:
refactor: Unify+simplify DWARFCompileUnit ctor+Clear() into in-class initializers + Extract()
It has no functionality effect.
I was concerned about the worse performance of DWARFDebugInfo::Parse this way
of allocating+destroying a CU for each iteration but I see it is now used only
by DWARFDebugInfo::Dump so that is no longer a problem.
Differential revision: https://reviews.llvm.org/D40212
Modified:
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp?rev=319359&r1=319358&r2=319359&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.cpp Wed Nov 29 13:13:11 2017
@@ -39,68 +39,48 @@ using namespace std;
extern int g_verbose;
DWARFCompileUnit::DWARFCompileUnit(SymbolFileDWARF *dwarf2Data)
- : m_dwarf2Data(dwarf2Data), m_abbrevs(NULL), m_user_data(NULL),
- m_die_array(), m_func_aranges_ap(), m_base_addr(0),
- m_offset(DW_INVALID_OFFSET), m_length(0), m_version(0),
- m_addr_size(DWARFCompileUnit::GetDefaultAddressSize()),
- m_producer(eProducerInvalid), m_producer_version_major(0),
- m_producer_version_minor(0), m_producer_version_update(0),
- m_language_type(eLanguageTypeUnknown), m_is_dwarf64(false),
- m_is_optimized(eLazyBoolCalculate), m_addr_base(0),
- m_ranges_base(0), m_base_obj_offset(DW_INVALID_OFFSET) {}
+ : m_dwarf2Data(dwarf2Data) {}
DWARFCompileUnit::~DWARFCompileUnit() {}
-void DWARFCompileUnit::Clear() {
- m_offset = DW_INVALID_OFFSET;
- m_length = 0;
- m_version = 0;
- m_abbrevs = NULL;
- m_addr_size = DWARFCompileUnit::GetDefaultAddressSize();
- m_base_addr = 0;
- m_die_array.clear();
- m_func_aranges_ap.reset();
- m_user_data = NULL;
- m_producer = eProducerInvalid;
- m_language_type = eLanguageTypeUnknown;
- m_is_dwarf64 = false;
- m_is_optimized = eLazyBoolCalculate;
- m_addr_base = 0;
- m_base_obj_offset = DW_INVALID_OFFSET;
-}
+DWARFCompileUnitSP DWARFCompileUnit::Extract(SymbolFileDWARF *dwarf2Data,
+ lldb::offset_t *offset_ptr) {
+ DWARFCompileUnitSP cu_sp(new DWARFCompileUnit(dwarf2Data));
+ // Out of memory?
+ if (cu_sp.get() == NULL)
+ return nullptr;
-bool DWARFCompileUnit::Extract(const DWARFDataExtractor &debug_info,
- lldb::offset_t *offset_ptr) {
- Clear();
+ const DWARFDataExtractor &debug_info = dwarf2Data->get_debug_info_data();
- m_offset = *offset_ptr;
+ cu_sp->m_offset = *offset_ptr;
if (debug_info.ValidOffset(*offset_ptr)) {
dw_offset_t abbr_offset;
- const DWARFDebugAbbrev *abbr = m_dwarf2Data->DebugAbbrev();
- m_length = debug_info.GetDWARFInitialLength(offset_ptr);
- m_is_dwarf64 = debug_info.IsDWARF64();
- m_version = debug_info.GetU16(offset_ptr);
+ const DWARFDebugAbbrev *abbr = dwarf2Data->DebugAbbrev();
+ cu_sp->m_length = debug_info.GetDWARFInitialLength(offset_ptr);
+ cu_sp->m_is_dwarf64 = debug_info.IsDWARF64();
+ cu_sp->m_version = debug_info.GetU16(offset_ptr);
abbr_offset = debug_info.GetDWARFOffset(offset_ptr);
- m_addr_size = debug_info.GetU8(offset_ptr);
+ cu_sp->m_addr_size = debug_info.GetU8(offset_ptr);
- bool length_OK = debug_info.ValidOffset(GetNextCompileUnitOffset() - 1);
- bool version_OK = SymbolFileDWARF::SupportedVersion(m_version);
+ bool length_OK =
+ debug_info.ValidOffset(cu_sp->GetNextCompileUnitOffset() - 1);
+ bool version_OK = SymbolFileDWARF::SupportedVersion(cu_sp->m_version);
bool abbr_offset_OK =
- m_dwarf2Data->get_debug_abbrev_data().ValidOffset(abbr_offset);
- bool addr_size_OK = ((m_addr_size == 4) || (m_addr_size == 8));
+ dwarf2Data->get_debug_abbrev_data().ValidOffset(abbr_offset);
+ bool addr_size_OK = (cu_sp->m_addr_size == 4) || (cu_sp->m_addr_size == 8);
if (length_OK && version_OK && addr_size_OK && abbr_offset_OK &&
abbr != NULL) {
- m_abbrevs = abbr->GetAbbreviationDeclarationSet(abbr_offset);
- return true;
+ cu_sp->m_abbrevs = abbr->GetAbbreviationDeclarationSet(abbr_offset);
+ return cu_sp;
}
// reset the offset to where we tried to parse from if anything went wrong
- *offset_ptr = m_offset;
+ *offset_ptr = cu_sp->m_offset;
}
- return false;
+ return nullptr;
}
void DWARFCompileUnit::ClearDIEs(bool keep_compile_unit_die) {
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h?rev=319359&r1=319358&r2=319359&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h Wed Nov 29 13:13:11 2017
@@ -18,6 +18,8 @@ class NameToDIE;
class SymbolFileDWARF;
class SymbolFileDWARFDwo;
+typedef std::shared_ptr<DWARFCompileUnit> DWARFCompileUnitSP;
+
class DWARFCompileUnit {
public:
enum Producer {
@@ -28,17 +30,15 @@ public:
eProcucerOther
};
- DWARFCompileUnit(SymbolFileDWARF *dwarf2Data);
+ static DWARFCompileUnitSP Extract(SymbolFileDWARF *dwarf2Data,
+ lldb::offset_t *offset_ptr);
~DWARFCompileUnit();
- bool Extract(const lldb_private::DWARFDataExtractor &debug_info,
- lldb::offset_t *offset_ptr);
size_t ExtractDIEsIfNeeded(bool cu_die_only);
DWARFDIE LookupAddress(const dw_addr_t address);
size_t AppendDIEsWithTag(const dw_tag_t tag,
DWARFDIECollection &matching_dies,
uint32_t depth = UINT32_MAX) const;
- void Clear();
bool Verify(lldb_private::Stream *s) const;
void Dump(lldb_private::Stream *s) const;
// Offset of the initial length field.
@@ -163,7 +163,7 @@ protected:
SymbolFileDWARF *m_dwarf2Data;
std::unique_ptr<SymbolFileDWARFDwo> m_dwo_symbol_file;
const DWARFAbbreviationDeclarationSet *m_abbrevs;
- void *m_user_data;
+ void *m_user_data = nullptr;
DWARFDebugInfoEntry::collection
m_die_array; // The compile unit debug information entry item
std::unique_ptr<DWARFDebugAranges> m_func_aranges_ap; // A table similar to
@@ -172,24 +172,24 @@ protected:
// points to the exact
// DW_TAG_subprogram
// DIEs
- dw_addr_t m_base_addr;
+ dw_addr_t m_base_addr = 0;
// Offset of the initial length field.
dw_offset_t m_offset;
dw_offset_t m_length;
uint16_t m_version;
uint8_t m_addr_size;
- Producer m_producer;
- uint32_t m_producer_version_major;
- uint32_t m_producer_version_minor;
- uint32_t m_producer_version_update;
- lldb::LanguageType m_language_type;
+ Producer m_producer = eProducerInvalid;
+ uint32_t m_producer_version_major = 0;
+ uint32_t m_producer_version_minor = 0;
+ uint32_t m_producer_version_update = 0;
+ lldb::LanguageType m_language_type = lldb::eLanguageTypeUnknown;
bool m_is_dwarf64;
- lldb_private::LazyBool m_is_optimized;
- dw_addr_t m_addr_base; // Value of DW_AT_addr_base
- dw_addr_t m_ranges_base; // Value of DW_AT_ranges_base
- dw_offset_t m_base_obj_offset; // If this is a dwo compile unit this is the
- // offset of the base compile unit in the main
- // object file
+ lldb_private::LazyBool m_is_optimized = lldb_private::eLazyBoolCalculate;
+ dw_addr_t m_addr_base = 0; // Value of DW_AT_addr_base
+ dw_addr_t m_ranges_base = 0; // Value of DW_AT_ranges_base
+ // If this is a dwo compile unit this is the offset of the base compile unit
+ // in the main object file
+ dw_offset_t m_base_obj_offset = DW_INVALID_OFFSET;
void ParseProducerInfo();
@@ -202,6 +202,8 @@ protected:
NameToDIE &globals, NameToDIE &types, NameToDIE &namespaces);
private:
+ DWARFCompileUnit(SymbolFileDWARF *dwarf2Data);
+
const DWARFDebugInfoEntry *GetCompileUnitDIEPtrOnly() {
ExtractDIEsIfNeeded(true);
if (m_die_array.empty())
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp?rev=319359&r1=319358&r2=319359&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.cpp Wed Nov 29 13:13:11 2017
@@ -97,17 +97,12 @@ void DWARFDebugInfo::ParseCompileUnitHea
if (m_compile_units.empty()) {
if (m_dwarf2Data != NULL) {
lldb::offset_t offset = 0;
- const DWARFDataExtractor &debug_info_data =
- m_dwarf2Data->get_debug_info_data();
- while (debug_info_data.ValidOffset(offset)) {
- DWARFCompileUnitSP cu_sp(new DWARFCompileUnit(m_dwarf2Data));
- // Out of memory?
+ for (;;) {
+ DWARFCompileUnitSP cu_sp =
+ DWARFCompileUnit::Extract(m_dwarf2Data, &offset);
if (cu_sp.get() == NULL)
break;
- if (cu_sp->Extract(debug_info_data, &offset) == false)
- break;
-
m_compile_units.push_back(cu_sp);
offset = cu_sp->GetNextCompileUnitOffset();
@@ -248,12 +243,10 @@ void DWARFDebugInfo::Parse(SymbolFileDWA
if (dwarf2Data) {
lldb::offset_t offset = 0;
uint32_t depth = 0;
- DWARFCompileUnitSP cu(new DWARFCompileUnit(dwarf2Data));
- if (cu.get() == NULL)
- return;
DWARFDebugInfoEntry die;
- while (cu->Extract(dwarf2Data->get_debug_info_data(), &offset)) {
+ DWARFCompileUnitSP cu;
+ while ((cu = DWARFCompileUnit::Extract(dwarf2Data, &offset))) {
const dw_offset_t next_cu_offset = cu->GetNextCompileUnitOffset();
depth = 0;
@@ -288,12 +281,6 @@ void DWARFDebugInfo::Parse(SymbolFileDWA
if (!dwarf2Data->get_debug_info_data().ValidOffset(offset))
break;
- // See if during the callback anyone retained a copy of the compile
- // unit other than ourselves and if so, let whomever did own the object
- // and create a new one for our own use!
- if (!cu.unique())
- cu.reset(new DWARFCompileUnit(dwarf2Data));
-
// Make sure we start on a proper
offset = next_cu_offset;
}
Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h?rev=319359&r1=319358&r2=319359&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfo.h Wed Nov 29 13:13:11 2017
@@ -61,8 +61,6 @@ public:
DWARFDebugAranges &GetCompileUnitAranges();
protected:
- typedef std::shared_ptr<DWARFCompileUnit> DWARFCompileUnitSP;
-
static bool OffsetLessThanCompileUnitOffset(dw_offset_t offset,
const DWARFCompileUnitSP &cu_sp);
More information about the lldb-commits
mailing list