Skip to content

Commit

Permalink
Use DWARFBaseDIE as a compile-time protection
Browse files Browse the repository at this point in the history
As suggested by Pavel Labath in D46810 DWARFUnit::GetUnitDIEOnly() returning
a pointer to m_first_die should not permit using methods like GetFirstChild().

Differential revision: https://reviews.llvm.org/D47276

llvm-svn: 333224
  • Loading branch information
jankratochvil committed May 24, 2018
1 parent e522c97 commit 93afb05
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
Expand Up @@ -638,7 +638,7 @@ void DWARFDebugInfoEntry::Dump(SymbolFileDWARF *dwarf2Data,

void DWARFDebugInfoEntry::DumpLocation(SymbolFileDWARF *dwarf2Data,
DWARFUnit *cu, Stream &s) const {
const DWARFDIE cu_die = cu->GetUnitDIEOnly();
const DWARFBaseDIE cu_die = cu->GetUnitDIEOnly();
const char *cu_name = NULL;
if (cu_die)
cu_name = cu_die.GetName();
Expand Down Expand Up @@ -912,7 +912,7 @@ dw_offset_t DWARFDebugInfoEntry::GetAttributeValue(
if (!dwo_cu)
return 0;

DWARFDIE dwo_cu_die = dwo_cu->GetUnitDIEOnly();
DWARFBaseDIE dwo_cu_die = dwo_cu->GetUnitDIEOnly();
if (!dwo_cu_die.IsValid())
return 0;

Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
Expand Up @@ -207,7 +207,7 @@ void DWARFUnit::AddUnitDIE(DWARFDebugInfoEntry &die) {
if (!dwo_cu)
return; // Can't fetch the compile unit from the dwo file.

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

Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
Expand Up @@ -113,7 +113,7 @@ class DWARFUnit {

void SetBaseAddress(dw_addr_t base_addr);

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

DWARFDIE DIE() { return DWARFDIE(this, DIEPtr()); }

Expand Down
12 changes: 6 additions & 6 deletions lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
Expand Up @@ -748,7 +748,7 @@ lldb::CompUnitSP SymbolFileDWARF::ParseCompileUnit(DWARFUnit *dwarf_cu,
} else {
ModuleSP module_sp(m_obj_file->GetModule());
if (module_sp) {
const DWARFDIE cu_die = dwarf_cu->GetUnitDIEOnly();
const DWARFDIE cu_die = dwarf_cu->DIE();
if (cu_die) {
FileSpec cu_file_spec{cu_die.GetName(), false};
if (cu_file_spec) {
Expand Down Expand Up @@ -883,7 +883,7 @@ bool SymbolFileDWARF::ParseCompileUnitSupportFiles(
assert(sc.comp_unit);
DWARFUnit *dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
if (dwarf_cu) {
const DWARFDIE cu_die = dwarf_cu->GetUnitDIEOnly();
const DWARFBaseDIE cu_die = dwarf_cu->GetUnitDIEOnly();

if (cu_die) {
FileSpec cu_comp_dir = resolveCompDir(
Expand Down Expand Up @@ -922,7 +922,7 @@ bool SymbolFileDWARF::ParseImportedModules(
UpdateExternalModuleListIfNeeded();

if (sc.comp_unit) {
const DWARFDIE die = dwarf_cu->GetUnitDIEOnly();
const DWARFDIE die = dwarf_cu->DIE();

if (die) {
for (DWARFDIE child_die = die.GetFirstChild(); child_die;
Expand Down Expand Up @@ -997,7 +997,7 @@ bool SymbolFileDWARF::ParseCompileUnitLineTable(const SymbolContext &sc) {

DWARFUnit *dwarf_cu = GetDWARFCompileUnit(sc.comp_unit);
if (dwarf_cu) {
const DWARFDIE dwarf_cu_die = dwarf_cu->GetUnitDIEOnly();
const DWARFBaseDIE dwarf_cu_die = dwarf_cu->GetUnitDIEOnly();
if (dwarf_cu_die) {
const dw_offset_t cu_line_offset =
dwarf_cu_die.GetAttributeValueAsUnsigned(DW_AT_stmt_list,
Expand Down Expand Up @@ -1082,7 +1082,7 @@ bool SymbolFileDWARF::ParseCompileUnitDebugMacros(const SymbolContext &sc) {
if (dwarf_cu == nullptr)
return false;

const DWARFDIE dwarf_cu_die = dwarf_cu->GetUnitDIEOnly();
const DWARFBaseDIE dwarf_cu_die = dwarf_cu->GetUnitDIEOnly();
if (!dwarf_cu_die)
return false;

Expand Down Expand Up @@ -1578,7 +1578,7 @@ void SymbolFileDWARF::UpdateExternalModuleListIfNeeded() {
for (uint32_t cu_idx = 0; cu_idx < num_compile_units; ++cu_idx) {
DWARFUnit *dwarf_cu = debug_info->GetCompileUnitAtIndex(cu_idx);

const DWARFDIE die = dwarf_cu->GetUnitDIEOnly();
const DWARFBaseDIE die = dwarf_cu->GetUnitDIEOnly();
if (die && die.HasChildren() == false) {
const char *name = die.GetAttributeValueAsString(DW_AT_name, nullptr);

Expand Down

0 comments on commit 93afb05

Please sign in to comment.