[Lldb-commits] [lldb] r333224 - Use DWARFBaseDIE as a compile-time protection

Jan Kratochvil via lldb-commits lldb-commits at lists.llvm.org
Thu May 24 13:51:13 PDT 2018


Author: jankratochvil
Date: Thu May 24 13:51:13 2018
New Revision: 333224

URL: http://llvm.org/viewvc/llvm-project?rev=333224&view=rev
Log:
Use DWARFBaseDIE as a compile-time protection

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

Modified:
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
    lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp?rev=333224&r1=333223&r2=333224&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp Thu May 24 13:51:13 2018
@@ -638,7 +638,7 @@ void DWARFDebugInfoEntry::Dump(SymbolFil
 
 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();
@@ -912,7 +912,7 @@ dw_offset_t DWARFDebugInfoEntry::GetAttr
   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;
 

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp?rev=333224&r1=333223&r2=333224&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp Thu May 24 13:51:13 2018
@@ -207,7 +207,7 @@ void DWARFUnit::AddUnitDIE(DWARFDebugInf
   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.
 

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h?rev=333224&r1=333223&r2=333224&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFUnit.h Thu May 24 13:51:13 2018
@@ -113,7 +113,7 @@ public:
 
   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()); }
 

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=333224&r1=333223&r2=333224&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Thu May 24 13:51:13 2018
@@ -748,7 +748,7 @@ lldb::CompUnitSP SymbolFileDWARF::ParseC
       } 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) {
@@ -883,7 +883,7 @@ bool SymbolFileDWARF::ParseCompileUnitSu
   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(
@@ -922,7 +922,7 @@ bool SymbolFileDWARF::ParseImportedModul
       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;
@@ -997,7 +997,7 @@ bool SymbolFileDWARF::ParseCompileUnitLi
 
   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,
@@ -1082,7 +1082,7 @@ bool SymbolFileDWARF::ParseCompileUnitDe
   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;
 
@@ -1578,7 +1578,7 @@ void SymbolFileDWARF::UpdateExternalModu
   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);
 




More information about the lldb-commits mailing list