[Lldb-commits] [lldb] r354033 - Move UnwindTable from ObjectFile to Module

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Thu Feb 14 06:40:11 PST 2019


Author: labath
Date: Thu Feb 14 06:40:10 2019
New Revision: 354033

URL: http://llvm.org/viewvc/llvm-project?rev=354033&view=rev
Log:
Move UnwindTable from ObjectFile to Module

Summary:
This is a preparatory step to enable adding extra unwind strategies by
symbol file plugins. This has been discussed on the lldb-dev mailing
list: <http://lists.llvm.org/pipermail/lldb-dev/2019-February/014703.html>.

Reviewers: jasonmolenda, clayborg, espindola

Subscribers: lemo, emaste, lldb-commits, arichardson

Differential Revision: https://reviews.llvm.org/D58129

Modified:
    lldb/trunk/include/lldb/Core/Module.h
    lldb/trunk/include/lldb/Symbol/ObjectFile.h
    lldb/trunk/include/lldb/Symbol/UnwindTable.h
    lldb/trunk/source/Commands/CommandObjectTarget.cpp
    lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
    lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
    lldb/trunk/source/Symbol/ObjectFile.cpp
    lldb/trunk/source/Symbol/UnwindTable.cpp

Modified: lldb/trunk/include/lldb/Core/Module.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Module.h?rev=354033&r1=354032&r2=354033&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Module.h (original)
+++ lldb/trunk/include/lldb/Core/Module.h Thu Feb 14 06:40:10 2019
@@ -693,6 +693,21 @@ public:
   //------------------------------------------------------------------
   virtual void SectionFileAddressesChanged();
 
+  //------------------------------------------------------------------
+  /// Returns a reference to the UnwindTable for this Module
+  ///
+  /// The UnwindTable contains FuncUnwinders objects for any function in this
+  /// Module.  If a FuncUnwinders object hasn't been created yet (i.e. the
+  /// function has yet to be unwound in a stack walk), it will be created when
+  /// requested.  Specifically, we do not create FuncUnwinders objects for
+  /// functions until they are needed.
+  ///
+  /// @return
+  ///     Returns the unwind table for this module. If this object has no
+  ///     associated object file, an empty UnwindTable is returned.
+  //------------------------------------------------------------------
+  UnwindTable &GetUnwindTable() { return m_unwind_table; }
+
   llvm::VersionTuple GetVersion();
 
   //------------------------------------------------------------------
@@ -1090,6 +1105,8 @@ protected:
   lldb::ObjectFileSP m_objfile_sp; ///< A shared pointer to the object file
                                    ///parser for this module as it may or may
                                    ///not be shared with the SymbolFile
+  UnwindTable m_unwind_table{*this}; ///< Table of FuncUnwinders objects created
+                                     /// for this Module's functions
   lldb::SymbolVendorUP
       m_symfile_up; ///< A pointer to the symbol vendor for this module.
   std::vector<lldb::SymbolVendorUP>

Modified: lldb/trunk/include/lldb/Symbol/ObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ObjectFile.h?rev=354033&r1=354032&r2=354033&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ObjectFile.h (original)
+++ lldb/trunk/include/lldb/Symbol/ObjectFile.h Thu Feb 14 06:40:10 2019
@@ -478,20 +478,6 @@ public:
   virtual bool ParseHeader() = 0;
 
   //------------------------------------------------------------------
-  /// Returns a reference to the UnwindTable for this ObjectFile
-  ///
-  /// The UnwindTable contains FuncUnwinders objects for any function in this
-  /// ObjectFile.  If a FuncUnwinders object hasn't been created yet (i.e. the
-  /// function has yet to be unwound in a stack walk), it will be created when
-  /// requested.  Specifically, we do not create FuncUnwinders objects for
-  /// functions until they are needed.
-  ///
-  /// @return
-  ///     Returns the unwind table for this object file.
-  //------------------------------------------------------------------
-  virtual lldb_private::UnwindTable &GetUnwindTable() { return m_unwind_table; }
-
-  //------------------------------------------------------------------
   /// Returns if the function bounds for symbols in this symbol file are
   /// likely accurate.
   ///
@@ -774,9 +760,6 @@ protected:
                          ///determined).
   DataExtractor
       m_data; ///< The data for this object file so things can be parsed lazily.
-  lldb_private::UnwindTable m_unwind_table; /// < Table of FuncUnwinders objects
-                                            /// created for this ObjectFile's
-                                            /// functions
   lldb::ProcessWP m_process_wp;
   const lldb::addr_t m_memory_addr;
   std::unique_ptr<lldb_private::SectionList> m_sections_up;

Modified: lldb/trunk/include/lldb/Symbol/UnwindTable.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/UnwindTable.h?rev=354033&r1=354032&r2=354033&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/UnwindTable.h (original)
+++ lldb/trunk/include/lldb/Symbol/UnwindTable.h Thu Feb 14 06:40:10 2019
@@ -22,7 +22,9 @@ namespace lldb_private {
 
 class UnwindTable {
 public:
-  UnwindTable(ObjectFile &objfile);
+  /// Create an Unwind table using the data in the given module.
+  explicit UnwindTable(Module &module);
+
   ~UnwindTable();
 
   lldb_private::DWARFCallFrameInfo *GetEHFrameInfo();
@@ -62,7 +64,7 @@ private:
   typedef collection::iterator iterator;
   typedef collection::const_iterator const_iterator;
 
-  ObjectFile &m_object_file;
+  Module &m_module;
   collection m_unwinds;
 
   bool m_initialized; // delay some initialization until ObjectFile is set up

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=354033&r1=354032&r2=354033&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Thu Feb 14 06:40:10 2019
@@ -3533,8 +3533,7 @@ protected:
         start_addr = abi->FixCodeAddress(start_addr);
 
       FuncUnwindersSP func_unwinders_sp(
-          sc.module_sp->GetObjectFile()
-              ->GetUnwindTable()
+          sc.module_sp->GetUnwindTable()
               .GetUncachedFuncUnwindersContainingAddress(start_addr, sc));
       if (!func_unwinders_sp)
         continue;

Modified: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp?rev=354033&r1=354032&r2=354033&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp Thu Feb 14 06:40:10 2019
@@ -2862,8 +2862,8 @@ Symtab *ObjectFileELF::GetSymtab() {
       }
     }
 
-    DWARFCallFrameInfo *eh_frame = GetUnwindTable().GetEHFrameInfo();
-    if (eh_frame) {
+    if (DWARFCallFrameInfo *eh_frame =
+            GetModule()->GetUnwindTable().GetEHFrameInfo()) {
       if (m_symtab_up == nullptr)
         m_symtab_up.reset(new Symtab(this));
       ParseUnwindSymbols(m_symtab_up.get(), eh_frame);

Modified: lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp?rev=354033&r1=354032&r2=354033&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Utility/RegisterContextLLDB.cpp Thu Feb 14 06:40:10 2019
@@ -239,9 +239,8 @@ void RegisterContextLLDB::InitializeZero
 
     if (m_sym_ctx_valid) {
       func_unwinders_sp =
-          pc_module_sp->GetObjectFile()
-              ->GetUnwindTable()
-              .GetFuncUnwindersContainingAddress(m_current_pc, m_sym_ctx);
+          pc_module_sp->GetUnwindTable().GetFuncUnwindersContainingAddress(
+              m_current_pc, m_sym_ctx);
     }
 
     if (func_unwinders_sp.get() != nullptr)
@@ -672,9 +671,8 @@ UnwindPlanSP RegisterContextLLDB::GetFas
     return unwind_plan_sp;
 
   FuncUnwindersSP func_unwinders_sp(
-      pc_module_sp->GetObjectFile()
-          ->GetUnwindTable()
-          .GetFuncUnwindersContainingAddress(m_current_pc, m_sym_ctx));
+      pc_module_sp->GetUnwindTable().GetFuncUnwindersContainingAddress(
+          m_current_pc, m_sym_ctx));
   if (!func_unwinders_sp)
     return unwind_plan_sp;
 
@@ -775,9 +773,8 @@ UnwindPlanSP RegisterContextLLDB::GetFul
   FuncUnwindersSP func_unwinders_sp;
   if (m_sym_ctx_valid) {
     func_unwinders_sp =
-        pc_module_sp->GetObjectFile()
-            ->GetUnwindTable()
-            .GetFuncUnwindersContainingAddress(m_current_pc, m_sym_ctx);
+        pc_module_sp->GetUnwindTable().GetFuncUnwindersContainingAddress(
+            m_current_pc, m_sym_ctx);
   }
 
   // No FuncUnwinders available for this pc (stripped function symbols, lldb
@@ -795,7 +792,7 @@ UnwindPlanSP RegisterContextLLDB::GetFul
     // Even with -fomit-frame-pointer, we can try eh_frame to get back on
     // track.
     DWARFCallFrameInfo *eh_frame =
-        pc_module_sp->GetObjectFile()->GetUnwindTable().GetEHFrameInfo();
+        pc_module_sp->GetUnwindTable().GetEHFrameInfo();
     if (eh_frame) {
       unwind_plan_sp = std::make_shared<UnwindPlan>(lldb::eRegisterKindGeneric);
       if (eh_frame->GetUnwindPlan(m_current_pc, *unwind_plan_sp))
@@ -805,7 +802,7 @@ UnwindPlanSP RegisterContextLLDB::GetFul
     }
 
     ArmUnwindInfo *arm_exidx =
-        pc_module_sp->GetObjectFile()->GetUnwindTable().GetArmUnwindInfo();
+        pc_module_sp->GetUnwindTable().GetArmUnwindInfo();
     if (arm_exidx) {
       unwind_plan_sp = std::make_shared<UnwindPlan>(lldb::eRegisterKindGeneric);
       if (arm_exidx->GetUnwindPlan(exe_ctx.GetTargetRef(), m_current_pc,

Modified: lldb/trunk/source/Symbol/ObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ObjectFile.cpp?rev=354033&r1=354032&r2=354033&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ObjectFile.cpp (original)
+++ lldb/trunk/source/Symbol/ObjectFile.cpp Thu Feb 14 06:40:10 2019
@@ -263,8 +263,7 @@ ObjectFile::ObjectFile(const lldb::Modul
     : ModuleChild(module_sp),
       m_file(), // This file could be different from the original module's file
       m_type(eTypeInvalid), m_strata(eStrataInvalid),
-      m_file_offset(file_offset), m_length(length), m_data(),
-      m_unwind_table(*this), m_process_wp(),
+      m_file_offset(file_offset), m_length(length), m_data(), m_process_wp(),
       m_memory_addr(LLDB_INVALID_ADDRESS), m_sections_up(), m_symtab_up(),
       m_synthetic_symbol_idx(0) {
   if (file_spec_ptr)
@@ -286,9 +285,8 @@ ObjectFile::ObjectFile(const lldb::Modul
                        DataBufferSP &header_data_sp)
     : ModuleChild(module_sp), m_file(), m_type(eTypeInvalid),
       m_strata(eStrataInvalid), m_file_offset(0), m_length(0), m_data(),
-      m_unwind_table(*this), m_process_wp(process_sp),
-      m_memory_addr(header_addr), m_sections_up(), m_symtab_up(),
-      m_synthetic_symbol_idx(0) {
+      m_process_wp(process_sp), m_memory_addr(header_addr), m_sections_up(),
+      m_symtab_up(), m_synthetic_symbol_idx(0) {
   if (header_data_sp)
     m_data.SetData(header_data_sp, 0, header_data_sp->GetByteSize());
   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));

Modified: lldb/trunk/source/Symbol/UnwindTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/UnwindTable.cpp?rev=354033&r1=354032&r2=354033&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/UnwindTable.cpp (original)
+++ lldb/trunk/source/Symbol/UnwindTable.cpp Thu Feb 14 06:40:10 2019
@@ -26,8 +26,8 @@
 using namespace lldb;
 using namespace lldb_private;
 
-UnwindTable::UnwindTable(ObjectFile &objfile)
-    : m_object_file(objfile), m_unwinds(), m_initialized(false), m_mutex(),
+UnwindTable::UnwindTable(Module &module)
+    : m_module(module), m_unwinds(), m_initialized(false), m_mutex(),
       m_eh_frame_up(), m_compact_unwind_up(), m_arm_unwind_up() {}
 
 // We can't do some of this initialization when the ObjectFile is running its
@@ -42,33 +42,36 @@ void UnwindTable::Initialize() {
   if (m_initialized) // check again once we've acquired the lock
     return;
   m_initialized = true;
+  ObjectFile *object_file = m_module.GetObjectFile();
+  if (!object_file)
+    return;
 
-  SectionList *sl = m_object_file.GetSectionList();
+  SectionList *sl = object_file->GetSectionList();
   if (!sl)
     return;
 
   SectionSP sect = sl->FindSectionByType(eSectionTypeEHFrame, true);
   if (sect.get()) {
     m_eh_frame_up.reset(
-        new DWARFCallFrameInfo(m_object_file, sect, DWARFCallFrameInfo::EH));
+        new DWARFCallFrameInfo(*object_file, sect, DWARFCallFrameInfo::EH));
   }
 
   sect = sl->FindSectionByType(eSectionTypeDWARFDebugFrame, true);
   if (sect) {
     m_debug_frame_up.reset(
-        new DWARFCallFrameInfo(m_object_file, sect, DWARFCallFrameInfo::DWARF));
+        new DWARFCallFrameInfo(*object_file, sect, DWARFCallFrameInfo::DWARF));
   }
 
   sect = sl->FindSectionByType(eSectionTypeCompactUnwind, true);
   if (sect) {
-    m_compact_unwind_up.reset(new CompactUnwindInfo(m_object_file, sect));
+    m_compact_unwind_up.reset(new CompactUnwindInfo(*object_file, sect));
   }
 
   sect = sl->FindSectionByType(eSectionTypeARMexidx, true);
   if (sect) {
     SectionSP sect_extab = sl->FindSectionByType(eSectionTypeARMextab, true);
     if (sect_extab.get()) {
-      m_arm_unwind_up.reset(new ArmUnwindInfo(m_object_file, sect, sect_extab));
+      m_arm_unwind_up.reset(new ArmUnwindInfo(*object_file, sect, sect_extab));
     }
   }
 }
@@ -148,8 +151,7 @@ UnwindTable::GetUncachedFuncUnwindersCon
 
 void UnwindTable::Dump(Stream &s) {
   std::lock_guard<std::mutex> guard(m_mutex);
-  s.Printf("UnwindTable for '%s':\n",
-           m_object_file.GetFileSpec().GetPath().c_str());
+  s.Format("UnwindTable for '{0}':\n", m_module.GetFileSpec());
   const_iterator begin = m_unwinds.begin();
   const_iterator end = m_unwinds.end();
   for (const_iterator pos = begin; pos != end; ++pos) {
@@ -179,10 +181,10 @@ ArmUnwindInfo *UnwindTable::GetArmUnwind
   return m_arm_unwind_up.get();
 }
 
-ArchSpec UnwindTable::GetArchitecture() {
-  return m_object_file.GetArchitecture();
-}
+ArchSpec UnwindTable::GetArchitecture() { return m_module.GetArchitecture(); }
 
 bool UnwindTable::GetAllowAssemblyEmulationUnwindPlans() {
-  return m_object_file.AllowAssemblyEmulationUnwindPlans();
+  if (ObjectFile *object_file = m_module.GetObjectFile())
+    return object_file->AllowAssemblyEmulationUnwindPlans();
+  return false;
 }




More information about the lldb-commits mailing list