Skip to content

Commit

Permalink
Revert "[lldb] [DWARF-5] Be lazier about loading .dwo files"
Browse files Browse the repository at this point in the history
This reverts commit 8dfd6ca.

This change broke the windows lldb bot:
https://lab.llvm.org/buildbot/#/builders/83/builds/8842
  • Loading branch information
sstamenova committed Jul 31, 2021
1 parent 66d92ef commit dfb6f7b
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 225 deletions.
1 change: 0 additions & 1 deletion lldb/include/lldb/Symbol/CompileUnit.h
Expand Up @@ -442,7 +442,6 @@ class CompileUnit : public std::enable_shared_from_this<CompileUnit>,

CompileUnit(const CompileUnit &) = delete;
const CompileUnit &operator=(const CompileUnit &) = delete;
const char *GetCachedLanguage() const;
};

} // namespace lldb_private
Expand Down
116 changes: 53 additions & 63 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
Expand Up @@ -35,12 +35,12 @@ DWARFUnit::DWARFUnit(SymbolFileDWARF &dwarf, lldb::user_id_t uid,
DIERef::Section section, bool is_dwo)
: UserID(uid), m_dwarf(dwarf), m_header(header), m_abbrevs(&abbrevs),
m_cancel_scopes(false), m_section(section), m_is_dwo(is_dwo),
m_has_parsed_non_skeleton_unit(false), m_dwo_id(header.GetDWOId()) {}
m_dwo_id(header.GetDWOId()) {}

DWARFUnit::~DWARFUnit() = default;

// Parses first DIE of a compile unit, excluding DWO.
void DWARFUnit::ExtractUnitDIENoDwoIfNeeded() {
// Parses first DIE of a compile unit.
void DWARFUnit::ExtractUnitDIEIfNeeded() {
{
llvm::sys::ScopedReader lock(m_first_die_mutex);
if (m_first_die)
Expand All @@ -50,8 +50,7 @@ void DWARFUnit::ExtractUnitDIENoDwoIfNeeded() {
if (m_first_die)
return; // Already parsed

LLDB_SCOPED_TIMERF("%8.8x: DWARFUnit::ExtractUnitDIENoDwoIfNeeded()",
GetOffset());
LLDB_SCOPED_TIMERF("%8.8x: DWARFUnit::ExtractUnitDIEIfNeeded()", GetOffset());

// Set the offset to that of the first DIE and calculate the start of the
// next compilation unit header.
Expand All @@ -67,58 +66,6 @@ void DWARFUnit::ExtractUnitDIENoDwoIfNeeded() {
}
}

// Parses first DIE of a compile unit including DWO.
void DWARFUnit::ExtractUnitDIEIfNeeded() {
ExtractUnitDIENoDwoIfNeeded();

if (m_has_parsed_non_skeleton_unit)
return;

m_has_parsed_non_skeleton_unit = true;

std::shared_ptr<SymbolFileDWARFDwo> dwo_symbol_file =
m_dwarf.GetDwoSymbolFileForCompileUnit(*this, m_first_die);
if (!dwo_symbol_file)
return;

DWARFUnit *dwo_cu = dwo_symbol_file->GetDWOCompileUnitForHash(m_dwo_id);

if (!dwo_cu)
return; // Can't fetch the compile unit from the dwo file.
dwo_cu->SetUserData(this);

DWARFBaseDIE dwo_cu_die = dwo_cu->GetUnitDIEOnly();
if (!dwo_cu_die.IsValid())
return; // Can't fetch the compile unit DIE from the dwo file.

// Here for DWO CU we want to use the address base set in the skeleton unit
// (DW_AT_addr_base) if it is available and use the DW_AT_GNU_addr_base
// otherwise. We do that because pre-DWARF v5 could use the DW_AT_GNU_*
// attributes which were applicable to the DWO units. The corresponding
// DW_AT_* attributes standardized in DWARF v5 are also applicable to the
// main unit in contrast.
if (m_addr_base)
dwo_cu->SetAddrBase(*m_addr_base);
else if (m_gnu_addr_base)
dwo_cu->SetAddrBase(*m_gnu_addr_base);

if (GetVersion() <= 4 && m_gnu_ranges_base)
dwo_cu->SetRangesBase(*m_gnu_ranges_base);
else if (dwo_symbol_file->GetDWARFContext()
.getOrLoadRngListsData()
.GetByteSize() > 0)
dwo_cu->SetRangesBase(llvm::DWARFListTableHeader::getHeaderSize(DWARF32));

if (GetVersion() >= 5 &&
dwo_symbol_file->GetDWARFContext().getOrLoadLocListsData().GetByteSize() >
0)
dwo_cu->SetLoclistsBase(llvm::DWARFListTableHeader::getHeaderSize(DWARF32));

dwo_cu->SetBaseAddress(GetBaseAddress());

m_dwo = std::shared_ptr<DWARFUnit>(std::move(dwo_symbol_file), dwo_cu);
}

// Parses a compile unit and indexes its DIEs if it hasn't already been done.
// It will leave this compile unit extracted forever.
void DWARFUnit::ExtractDIEsIfNeeded() {
Expand Down Expand Up @@ -344,12 +291,14 @@ void DWARFUnit::SetDwoStrOffsetsBase() {
}

uint64_t DWARFUnit::GetDWOId() {
ExtractUnitDIENoDwoIfNeeded();
ExtractUnitDIEIfNeeded();
return m_dwo_id;
}

// m_die_array_mutex must be already held as read/write.
void DWARFUnit::AddUnitDIE(const DWARFDebugInfoEntry &cu_die) {
llvm::Optional<uint64_t> addr_base, gnu_addr_base, gnu_ranges_base;

DWARFAttributes attributes;
size_t num_attributes = cu_die.GetAttributes(this, attributes);

Expand All @@ -359,7 +308,8 @@ void DWARFUnit::AddUnitDIE(const DWARFDebugInfoEntry &cu_die) {
continue;
DWARFFormValue form_value;
if (attributes.ExtractFormValueAtIndex(i, form_value)) {
SetAddrBase(form_value.Unsigned());
addr_base = form_value.Unsigned();
SetAddrBase(*addr_base);
break;
}
}
Expand Down Expand Up @@ -391,10 +341,10 @@ void DWARFUnit::AddUnitDIE(const DWARFDebugInfoEntry &cu_die) {
m_line_table_offset = form_value.Unsigned();
break;
case DW_AT_GNU_addr_base:
m_gnu_addr_base = form_value.Unsigned();
gnu_addr_base = form_value.Unsigned();
break;
case DW_AT_GNU_ranges_base:
m_gnu_ranges_base = form_value.Unsigned();
gnu_ranges_base = form_value.Unsigned();
break;
case DW_AT_GNU_dwo_id:
m_dwo_id = form_value.Unsigned();
Expand All @@ -403,10 +353,50 @@ void DWARFUnit::AddUnitDIE(const DWARFDebugInfoEntry &cu_die) {
}

if (m_is_dwo) {
m_has_parsed_non_skeleton_unit = true;
SetDwoStrOffsetsBase();
return;
}

std::shared_ptr<SymbolFileDWARFDwo> dwo_symbol_file =
m_dwarf.GetDwoSymbolFileForCompileUnit(*this, cu_die);
if (!dwo_symbol_file)
return;

DWARFUnit *dwo_cu = dwo_symbol_file->GetDWOCompileUnitForHash(m_dwo_id);

if (!dwo_cu)
return; // Can't fetch the compile unit from the dwo file.
dwo_cu->SetUserData(this);

DWARFBaseDIE dwo_cu_die = dwo_cu->GetUnitDIEOnly();
if (!dwo_cu_die.IsValid())
return; // Can't fetch the compile unit DIE from the dwo file.

// Here for DWO CU we want to use the address base set in the skeleton unit
// (DW_AT_addr_base) if it is available and use the DW_AT_GNU_addr_base
// otherwise. We do that because pre-DWARF v5 could use the DW_AT_GNU_*
// attributes which were applicable to the DWO units. The corresponding
// DW_AT_* attributes standardized in DWARF v5 are also applicable to the main
// unit in contrast.
if (addr_base)
dwo_cu->SetAddrBase(*addr_base);
else if (gnu_addr_base)
dwo_cu->SetAddrBase(*gnu_addr_base);

if (GetVersion() <= 4 && gnu_ranges_base)
dwo_cu->SetRangesBase(*gnu_ranges_base);
else if (dwo_symbol_file->GetDWARFContext()
.getOrLoadRngListsData()
.GetByteSize() > 0)
dwo_cu->SetRangesBase(llvm::DWARFListTableHeader::getHeaderSize(DWARF32));

if (GetVersion() >= 5 &&
dwo_symbol_file->GetDWARFContext().getOrLoadLocListsData().GetByteSize() >
0)
dwo_cu->SetLoclistsBase(llvm::DWARFListTableHeader::getHeaderSize(DWARF32));
dwo_cu->SetBaseAddress(GetBaseAddress());

m_dwo = std::shared_ptr<DWARFUnit>(std::move(dwo_symbol_file), dwo_cu);
}

size_t DWARFUnit::GetDebugInfoSize() const {
Expand All @@ -422,7 +412,7 @@ dw_offset_t DWARFUnit::GetAbbrevOffset() const {
}

dw_offset_t DWARFUnit::GetLineTableOffset() {
ExtractUnitDIENoDwoIfNeeded();
ExtractUnitDIEIfNeeded();
return m_line_table_offset;
}

Expand Down
14 changes: 5 additions & 9 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
Expand Up @@ -92,7 +92,6 @@ class DWARFUnit : public lldb_private::UserID {
uint64_t GetDWOId();

void ExtractUnitDIEIfNeeded();
void ExtractUnitDIENoDwoIfNeeded();
void ExtractDIEsIfNeeded();

class ScopedExtractDIEs {
Expand Down Expand Up @@ -152,7 +151,7 @@ class DWARFUnit : public lldb_private::UserID {
const DWARFAbbreviationDeclarationSet *GetAbbreviations() const;
dw_offset_t GetAbbrevOffset() const;
uint8_t GetAddressByteSize() const { return m_header.GetAddressByteSize(); }
dw_addr_t GetAddrBase() const { return m_addr_base ? *m_addr_base : 0; }
dw_addr_t GetAddrBase() const { return m_addr_base; }
dw_addr_t GetBaseAddress() const { return m_base_addr; }
dw_offset_t GetLineTableOffset();
dw_addr_t GetRangesBase() const { return m_ranges_base; }
Expand Down Expand Up @@ -269,7 +268,7 @@ class DWARFUnit : public lldb_private::UserID {
// Get the DWARF unit DWARF debug information entry. Parse the single DIE
// if needed.
const DWARFDebugInfoEntry *GetUnitDIEPtrOnly() {
ExtractUnitDIENoDwoIfNeeded();
ExtractUnitDIEIfNeeded();
// m_first_die_mutex is not required as m_first_die is never cleared.
if (!m_first_die)
return NULL;
Expand Down Expand Up @@ -316,11 +315,9 @@ class DWARFUnit : public lldb_private::UserID {
lldb_private::LazyBool m_is_optimized = lldb_private::eLazyBoolCalculate;
llvm::Optional<lldb_private::FileSpec> m_comp_dir;
llvm::Optional<lldb_private::FileSpec> m_file_spec;
llvm::Optional<dw_addr_t> m_addr_base; ///< Value of DW_AT_addr_base.
dw_addr_t m_loclists_base = 0; ///< Value of DW_AT_loclists_base.
dw_addr_t m_ranges_base = 0; ///< Value of DW_AT_rnglists_base.
llvm::Optional<uint64_t> m_gnu_addr_base;
llvm::Optional<uint64_t> m_gnu_ranges_base;
dw_addr_t m_addr_base = 0; ///< Value of DW_AT_addr_base.
dw_addr_t m_loclists_base = 0; ///< Value of DW_AT_loclists_base.
dw_addr_t m_ranges_base = 0; ///< Value of DW_AT_rnglists_base.

/// Value of DW_AT_stmt_list.
dw_offset_t m_line_table_offset = DW_INVALID_OFFSET;
Expand All @@ -333,7 +330,6 @@ class DWARFUnit : public lldb_private::UserID {

const DIERef::Section m_section;
bool m_is_dwo;
bool m_has_parsed_non_skeleton_unit;
/// Value of DW_AT_GNU_dwo_id (v4) or dwo_id from CU header (v5).
uint64_t m_dwo_id;

Expand Down

0 comments on commit dfb6f7b

Please sign in to comment.