[Lldb-commits] [lldb] r360409 - FuncUnwinders: Add a new "SymbolFile" unwind plan

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Fri May 10 00:54:38 PDT 2019


Author: labath
Date: Fri May 10 00:54:37 2019
New Revision: 360409

URL: http://llvm.org/viewvc/llvm-project?rev=360409&view=rev
Log:
FuncUnwinders: Add a new "SymbolFile" unwind plan

Summary:
some unwind formats are specific to a single symbol file and so it does
not make sense for their parsing code live in the general Symbol library
(as is the case with eh_frame for instance). This is the case for the
unwind information in breakpad files, but the same will probably be true
for PDB unwind info (once we are able to parse that).

This patch adds the ability to fetch an unwind plan provided by a symbol
file plugin, as discussed in the RFC at
<http://lists.llvm.org/pipermail/lldb-dev/2019-February/014703.html>.
I've kept the set of changes to a minimum, as there is no way to test
them until we have a symbol file which implements this API -- that is
comming in a follow-up patch, which will also implicitly test this
change.

The interesting part here is the introduction of the
"RegisterInfoResolver" interface. The reason for this is that breakpad
needs to be able to resolve register names (which are present as strings
in the file) into register enums so that it can construct the unwind
plan. This is normally done via the RegisterContext class, handing this
over to the SymbolFile plugin would mean that it has full access to the
debugged process, which is not something we want it to have. So instead,
I create a facade, which only provides the ability to query register
names, and hide the RegisterContext behind the facade.

Also note that this only adds the ability to dump the unwind plan
created by the symbol file plugin -- the plan is not used for unwinding
yet -- this will be added in a third patch, which will add additional
tests which makes sure the unwinding works as a whole.

Reviewers: jasonmolenda, clayborg

Subscribers: markmentovai, amccarth, lldb-commits

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

Modified:
    lldb/trunk/include/lldb/Symbol/FuncUnwinders.h
    lldb/trunk/include/lldb/Symbol/SymbolFile.h
    lldb/trunk/include/lldb/Symbol/UnwindTable.h
    lldb/trunk/source/Commands/CommandObjectTarget.cpp
    lldb/trunk/source/Symbol/FuncUnwinders.cpp
    lldb/trunk/source/Symbol/SymbolFile.cpp
    lldb/trunk/source/Symbol/UnwindTable.cpp

Modified: lldb/trunk/include/lldb/Symbol/FuncUnwinders.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/FuncUnwinders.h?rev=360409&r1=360408&r2=360409&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/FuncUnwinders.h (original)
+++ lldb/trunk/include/lldb/Symbol/FuncUnwinders.h Fri May 10 00:54:37 2019
@@ -90,6 +90,8 @@ public:
 
   lldb::UnwindPlanSP GetArmUnwindUnwindPlan(Target &target);
 
+  lldb::UnwindPlanSP GetSymbolFileUnwindPlan(Thread &thread);
+
   lldb::UnwindPlanSP GetArchDefaultUnwindPlan(Thread &thread);
 
   lldb::UnwindPlanSP GetArchDefaultAtFuncEntryUnwindPlan(Thread &thread);
@@ -120,6 +122,7 @@ private:
 
   std::vector<lldb::UnwindPlanSP> m_unwind_plan_compact_unwind;
   lldb::UnwindPlanSP m_unwind_plan_arm_unwind_sp;
+  lldb::UnwindPlanSP m_unwind_plan_symbol_file_sp;
   lldb::UnwindPlanSP m_unwind_plan_fast_sp;
   lldb::UnwindPlanSP m_unwind_plan_arch_default_sp;
   lldb::UnwindPlanSP m_unwind_plan_arch_default_at_func_entry_sp;
@@ -131,8 +134,8 @@ private:
       m_tried_unwind_plan_eh_frame_augmented : 1,
       m_tried_unwind_plan_debug_frame_augmented : 1,
       m_tried_unwind_plan_compact_unwind : 1,
-      m_tried_unwind_plan_arm_unwind : 1, m_tried_unwind_fast : 1,
-      m_tried_unwind_arch_default : 1,
+      m_tried_unwind_plan_arm_unwind : 1, m_tried_unwind_plan_symbol_file : 1,
+      m_tried_unwind_fast : 1, m_tried_unwind_arch_default : 1,
       m_tried_unwind_arch_default_at_func_entry : 1;
 
   Address m_first_non_prologue_insn;

Modified: lldb/trunk/include/lldb/Symbol/SymbolFile.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/SymbolFile.h?rev=360409&r1=360408&r2=360409&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/SymbolFile.h (original)
+++ lldb/trunk/include/lldb/Symbol/SymbolFile.h Fri May 10 00:54:37 2019
@@ -223,6 +223,18 @@ public:
   /// for this module have been changed.
   virtual void SectionFileAddressesChanged() {}
 
+  struct RegisterInfoResolver {
+    virtual ~RegisterInfoResolver(); // anchor
+
+    virtual const RegisterInfo *ResolveName(llvm::StringRef name) const = 0;
+    virtual const RegisterInfo *ResolveNumber(lldb::RegisterKind kind,
+                                              uint32_t number) const = 0;
+  };
+  virtual lldb::UnwindPlanSP
+  GetUnwindPlan(const Address &address, const RegisterInfoResolver &resolver) {
+    return nullptr;
+  }
+
   virtual void Dump(Stream &s) {}
 
 protected:

Modified: lldb/trunk/include/lldb/Symbol/UnwindTable.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/UnwindTable.h?rev=360409&r1=360408&r2=360409&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/UnwindTable.h (original)
+++ lldb/trunk/include/lldb/Symbol/UnwindTable.h Fri May 10 00:54:37 2019
@@ -33,6 +33,7 @@ public:
   lldb_private::CompactUnwindInfo *GetCompactUnwindInfo();
 
   ArmUnwindInfo *GetArmUnwindInfo();
+  SymbolFile *GetSymbolFile();
 
   lldb::FuncUnwindersSP GetFuncUnwindersContainingAddress(const Address &addr,
                                                           SymbolContext &sc);

Modified: lldb/trunk/source/Commands/CommandObjectTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectTarget.cpp?rev=360409&r1=360408&r2=360409&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectTarget.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectTarget.cpp Fri May 10 00:54:37 2019
@@ -3591,6 +3591,14 @@ protected:
         result.GetOutputStream().Printf("\n");
       }
 
+      if (UnwindPlanSP symfile_plan_sp =
+              func_unwinders_sp->GetSymbolFileUnwindPlan(*thread)) {
+        result.GetOutputStream().Printf("Symbol file UnwindPlan:\n");
+        symfile_plan_sp->Dump(result.GetOutputStream(), thread.get(),
+                              LLDB_INVALID_ADDRESS);
+        result.GetOutputStream().Printf("\n");
+      }
+
       UnwindPlanSP compact_unwind_sp =
           func_unwinders_sp->GetCompactUnwindUnwindPlan(*target);
       if (compact_unwind_sp) {

Modified: lldb/trunk/source/Symbol/FuncUnwinders.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/FuncUnwinders.cpp?rev=360409&r1=360408&r2=360409&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/FuncUnwinders.cpp (original)
+++ lldb/trunk/source/Symbol/FuncUnwinders.cpp Fri May 10 00:54:37 2019
@@ -13,11 +13,13 @@
 #include "lldb/Symbol/CompactUnwindInfo.h"
 #include "lldb/Symbol/DWARFCallFrameInfo.h"
 #include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Symbol/SymbolFile.h"
 #include "lldb/Symbol/UnwindPlan.h"
 #include "lldb/Symbol/UnwindTable.h"
 #include "lldb/Target/ABI.h"
 #include "lldb/Target/ExecutionContext.h"
 #include "lldb/Target/Process.h"
+#include "lldb/Target/RegisterContext.h"
 #include "lldb/Target/RegisterNumber.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Target/Thread.h"
@@ -42,7 +44,8 @@ FuncUnwinders::FuncUnwinders(UnwindTable
       m_tried_unwind_plan_eh_frame_augmented(false),
       m_tried_unwind_plan_debug_frame_augmented(false),
       m_tried_unwind_plan_compact_unwind(false),
-      m_tried_unwind_plan_arm_unwind(false), m_tried_unwind_fast(false),
+      m_tried_unwind_plan_arm_unwind(false),
+      m_tried_unwind_plan_symbol_file(false), m_tried_unwind_fast(false),
       m_tried_unwind_arch_default(false),
       m_tried_unwind_arch_default_at_func_entry(false),
       m_first_non_prologue_insn() {}
@@ -147,6 +150,38 @@ UnwindPlanSP FuncUnwinders::GetArmUnwind
   return m_unwind_plan_arm_unwind_sp;
 }
 
+namespace {
+class RegisterContextToInfo: public SymbolFile::RegisterInfoResolver {
+public:
+  RegisterContextToInfo(RegisterContext &ctx) : m_ctx(ctx) {}
+
+  const RegisterInfo *ResolveName(llvm::StringRef name) const {
+    return m_ctx.GetRegisterInfoByName(name);
+  }
+  const RegisterInfo *ResolveNumber(lldb::RegisterKind kind,
+                                    uint32_t number) const {
+    return m_ctx.GetRegisterInfo(kind, number);
+  }
+
+private:
+  RegisterContext &m_ctx;
+};
+} // namespace
+
+UnwindPlanSP FuncUnwinders::GetSymbolFileUnwindPlan(Thread &thread) {
+  std::lock_guard<std::recursive_mutex> guard(m_mutex);
+  if (m_unwind_plan_symbol_file_sp.get() || m_tried_unwind_plan_symbol_file)
+    return m_unwind_plan_symbol_file_sp;
+
+  m_tried_unwind_plan_symbol_file = true;
+  if (SymbolFile *symfile = m_unwind_table.GetSymbolFile()) {
+    m_unwind_plan_symbol_file_sp = symfile->GetUnwindPlan(
+        m_range.GetBaseAddress(),
+        RegisterContextToInfo(*thread.GetRegisterContext()));
+  }
+  return m_unwind_plan_symbol_file_sp;
+}
+
 UnwindPlanSP FuncUnwinders::GetEHFrameAugmentedUnwindPlan(Target &target,
                                                           Thread &thread) {
   std::lock_guard<std::recursive_mutex> guard(m_mutex);

Modified: lldb/trunk/source/Symbol/SymbolFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolFile.cpp?rev=360409&r1=360408&r2=360409&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/SymbolFile.cpp (original)
+++ lldb/trunk/source/Symbol/SymbolFile.cpp Fri May 10 00:54:37 2019
@@ -168,3 +168,5 @@ void SymbolFile::AssertModuleLock() {
          "Module is not locked");
 #endif
 }
+
+SymbolFile::RegisterInfoResolver::~RegisterInfoResolver() = default;

Modified: lldb/trunk/source/Symbol/UnwindTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/UnwindTable.cpp?rev=360409&r1=360408&r2=360409&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/UnwindTable.cpp (original)
+++ lldb/trunk/source/Symbol/UnwindTable.cpp Fri May 10 00:54:37 2019
@@ -18,6 +18,7 @@
 #include "lldb/Symbol/FuncUnwinders.h"
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Symbol/SymbolContext.h"
+#include "lldb/Symbol/SymbolVendor.h"
 
 // There is one UnwindTable object per ObjectFile. It contains a list of Unwind
 // objects -- one per function, populated lazily -- for the ObjectFile. Each
@@ -181,6 +182,12 @@ ArmUnwindInfo *UnwindTable::GetArmUnwind
   return m_arm_unwind_up.get();
 }
 
+SymbolFile *UnwindTable::GetSymbolFile() {
+  if (SymbolVendor *vendor = m_module.GetSymbolVendor())
+    return vendor->GetSymbolFile();
+  return nullptr;
+}
+
 ArchSpec UnwindTable::GetArchitecture() { return m_module.GetArchitecture(); }
 
 bool UnwindTable::GetAllowAssemblyEmulationUnwindPlans() {




More information about the lldb-commits mailing list