Skip to content

Commit 202c3ff

Browse files
committedMay 30, 2019
Improve DWARF parsing and accessing by 1% to 2%
When LLDB first started we didn't have our mmap of the DWARF data done correctly and if the backing file would change we would get live changes as the file changed and it would cause problems. We now mmap correctly and do not run into these issues. There was legacy code in DWARFDebugInfoEntry::GetAbbreviationDeclarationPtr(...) that would always extract the abbrev index each time the function was called to verify that DWARF data hadn't changed and a warning was emitted if it did. We no longer need this and the code was removed. The other thing this function did when it parsed the abbrev index was give us the offset of the first attribute bytes by adding the LEB128 size to the offset. This required an extra parameter to DWARFDebugInfoEntry::GetAbbreviationDeclarationPtr(...) which is now removed. I added "lldb::offset_t DWARFDebugInfoEntry::GetFirstAttributeOffset() const" which calculates this when we need it and modified all sites that need the offset to call it. Now that we aren't decoding and verifying the abbrev index, it speeds up DWARF access by 1% to 2%. Differential Revision: https://reviews.llvm.org/D62634 llvm-svn: 362103
1 parent f61b548 commit 202c3ff

File tree

2 files changed

+18
-38
lines changed

2 files changed

+18
-38
lines changed
 

Diff for: ‎lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp

+15-36
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
#include <algorithm>
1414

15+
#include "llvm/Support/LEB128.h"
16+
1517
#include "lldb/Core/Module.h"
1618
#include "lldb/Expression/DWARFExpression.h"
1719
#include "lldb/Symbol/ObjectFile.h"
@@ -239,15 +241,14 @@ bool DWARFDebugInfoEntry::GetDIENamesAndRanges(
239241
std::vector<DIERef> die_refs;
240242
bool set_frame_base_loclist_addr = false;
241243

242-
lldb::offset_t offset;
243-
const DWARFAbbreviationDeclaration *abbrevDecl =
244-
GetAbbreviationDeclarationPtr(cu, offset);
244+
auto abbrevDecl = GetAbbreviationDeclarationPtr(cu);
245245

246246
SymbolFileDWARF *dwarf2Data = cu->GetSymbolFileDWARF();
247247
lldb::ModuleSP module = dwarf2Data->GetObjectFile()->GetModule();
248248

249249
if (abbrevDecl) {
250250
const DWARFDataExtractor &debug_info_data = cu->GetData();
251+
lldb::offset_t offset = GetFirstAttributeOffset();
251252

252253
if (!debug_info_data.ValidOffset(offset))
253254
return false;
@@ -561,13 +562,10 @@ void DWARFDebugInfoEntry::DumpAttribute(
561562
size_t DWARFDebugInfoEntry::GetAttributes(
562563
const DWARFUnit *cu, DWARFAttributes &attributes,
563564
uint32_t curr_depth) const {
564-
const DWARFAbbreviationDeclaration *abbrevDecl = nullptr;
565-
lldb::offset_t offset = 0;
566-
if (cu)
567-
abbrevDecl = GetAbbreviationDeclarationPtr(cu, offset);
568-
565+
auto abbrevDecl = GetAbbreviationDeclarationPtr(cu);
569566
if (abbrevDecl) {
570567
const DWARFDataExtractor &debug_info_data = cu->GetData();
568+
lldb::offset_t offset = GetFirstAttributeOffset();
571569

572570
const uint32_t num_attributes = abbrevDecl->NumAttributes();
573571
for (uint32_t i = 0; i < num_attributes; ++i) {
@@ -631,15 +629,14 @@ dw_offset_t DWARFDebugInfoEntry::GetAttributeValue(
631629
form_value, end_attr_offset_ptr,
632630
check_specification_or_abstract_origin);
633631

634-
lldb::offset_t offset;
635-
const DWARFAbbreviationDeclaration *abbrevDecl =
636-
GetAbbreviationDeclarationPtr(cu, offset);
632+
auto abbrevDecl = GetAbbreviationDeclarationPtr(cu);
637633

638634
if (abbrevDecl) {
639635
uint32_t attr_idx = abbrevDecl->FindAttributeIndex(attr);
640636

641637
if (attr_idx != DW_INVALID_INDEX) {
642638
const DWARFDataExtractor &debug_info_data = cu->GetData();
639+
lldb::offset_t offset = GetFirstAttributeOffset();
643640

644641
uint32_t idx = 0;
645642
while (idx < attr_idx)
@@ -1244,35 +1241,17 @@ bool DWARFDebugInfoEntry::LookupAddress(const dw_addr_t address,
12441241
return found_address;
12451242
}
12461243

1244+
lldb::offset_t DWARFDebugInfoEntry::GetFirstAttributeOffset() const {
1245+
return GetOffset() + llvm::getULEB128Size(m_abbr_idx);
1246+
}
1247+
12471248
const DWARFAbbreviationDeclaration *
1248-
DWARFDebugInfoEntry::GetAbbreviationDeclarationPtr(
1249-
const DWARFUnit *cu, lldb::offset_t &offset) const {
1249+
DWARFDebugInfoEntry::GetAbbreviationDeclarationPtr(const DWARFUnit *cu) const {
12501250
if (cu) {
1251-
offset = GetOffset();
1252-
12531251
const DWARFAbbreviationDeclarationSet *abbrev_set = cu->GetAbbreviations();
1254-
if (abbrev_set) {
1255-
const DWARFAbbreviationDeclaration *abbrev_decl =
1256-
abbrev_set->GetAbbreviationDeclaration(m_abbr_idx);
1257-
if (abbrev_decl) {
1258-
// Make sure the abbreviation code still matches. If it doesn't and the
1259-
// DWARF data was mmap'ed, the backing file might have been modified
1260-
// which is bad news.
1261-
const uint64_t abbrev_code = cu->GetData().GetULEB128(&offset);
1262-
1263-
if (abbrev_decl->Code() == abbrev_code)
1264-
return abbrev_decl;
1265-
1266-
SymbolFileDWARF *dwarf2Data = cu->GetSymbolFileDWARF();
1267-
1268-
dwarf2Data->GetObjectFile()->GetModule()->ReportErrorIfModifyDetected(
1269-
"0x%8.8x: the DWARF debug information has been modified (abbrev "
1270-
"code was %u, and is now %u)",
1271-
GetOffset(), (uint32_t)abbrev_decl->Code(), (uint32_t)abbrev_code);
1272-
}
1273-
}
1252+
if (abbrev_set)
1253+
return abbrev_set->GetAbbreviationDeclaration(m_abbr_idx);
12741254
}
1275-
offset = DW_INVALID_OFFSET;
12761255
return nullptr;
12771256
}
12781257

Diff for: ‎lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ class DWARFDebugInfoEntry {
118118
lldb_private::DWARFExpression *frame_base = nullptr) const;
119119

120120
const DWARFAbbreviationDeclaration *
121-
GetAbbreviationDeclarationPtr(const DWARFUnit *cu,
122-
lldb::offset_t &offset) const;
121+
GetAbbreviationDeclarationPtr(const DWARFUnit *cu) const;
122+
123+
lldb::offset_t GetFirstAttributeOffset() const;
123124

124125
dw_tag_t Tag() const { return m_tag; }
125126

0 commit comments

Comments
 (0)