[Lldb-commits] [lldb] r356361 - Reinitialize UnwindTable when the SymbolFile changes

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Mon Mar 18 03:45:02 PDT 2019


Author: labath
Date: Mon Mar 18 03:45:02 2019
New Revision: 356361

URL: http://llvm.org/viewvc/llvm-project?rev=356361&view=rev
Log:
Reinitialize UnwindTable when the SymbolFile changes

Summary:
This is a preparatory step to enable adding of unwind plans by symbol
file plugins.

Although at the surface it seems that currently symbol files have
nothing to do with unwinding, this isn't entirely correct even now. The
mere act of adding a symbol file can have the effect of making more
sections (typically .debug_frame) available to the unwinding machinery,
so that it can have more unwind strategies to choose from.

Up until now, we've had a bug, which went largely unnoticed, where
unwind info in the manually added symbols files (target symbols add) was
being ignored during unwinding. Reinitializing the UnwindTable fixes
that bug too.

Reviewers: clayborg, jasonmolenda, alexshap

Subscribers: jdoerfert, lldb-commits

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

Added:
    lldb/trunk/lit/SymbolFile/Inputs/
    lldb/trunk/lit/SymbolFile/Inputs/target-symbols-add-unwind.c
    lldb/trunk/lit/SymbolFile/target-symbols-add-unwind.test
Modified:
    lldb/trunk/include/lldb/Core/Module.h
    lldb/trunk/source/Core/Module.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=356361&r1=356360&r2=356361&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Module.h (original)
+++ lldb/trunk/include/lldb/Core/Module.h Mon Mar 18 03:45:02 2019
@@ -706,7 +706,7 @@ public:
   ///     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; }
+  UnwindTable &GetUnwindTable();
 
   llvm::VersionTuple GetVersion();
 
@@ -1105,8 +1105,9 @@ 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
+  llvm::Optional<UnwindTable> m_unwind_table; ///< 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>

Added: lldb/trunk/lit/SymbolFile/Inputs/target-symbols-add-unwind.c
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/SymbolFile/Inputs/target-symbols-add-unwind.c?rev=356361&view=auto
==============================================================================
--- lldb/trunk/lit/SymbolFile/Inputs/target-symbols-add-unwind.c (added)
+++ lldb/trunk/lit/SymbolFile/Inputs/target-symbols-add-unwind.c Mon Mar 18 03:45:02 2019
@@ -0,0 +1 @@
+void _start() {}

Added: lldb/trunk/lit/SymbolFile/target-symbols-add-unwind.test
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/SymbolFile/target-symbols-add-unwind.test?rev=356361&view=auto
==============================================================================
--- lldb/trunk/lit/SymbolFile/target-symbols-add-unwind.test (added)
+++ lldb/trunk/lit/SymbolFile/target-symbols-add-unwind.test Mon Mar 18 03:45:02 2019
@@ -0,0 +1,26 @@
+# TODO: When it's possible to run "image show-unwind" without a running
+# process, we can remove the unsupported line below, and hard-code an ELF
+# triple in the test.
+# UNSUPPORTED: system-windows, system-darwin
+
+# RUN: cd %T
+# RUN: %clang %S/Inputs/target-symbols-add-unwind.c -nostdlib -g \
+# RUN:   -fno-unwind-tables -o target-symbols-add-unwind.debug
+# RUN: llvm-objcopy --strip-debug target-symbols-add-unwind.debug \
+# RUN:   target-symbols-add-unwind.stripped
+# RUN: %lldb target-symbols-add-unwind.stripped -s %s -o quit | FileCheck %s
+
+process launch --stop-at-entry
+image show-unwind -n _start
+# CHECK-LABEL: image show-unwind -n _start
+# CHECK-NOT: debug_frame UnwindPlan:
+
+target symbols add -s target-symbols-add-unwind.stripped target-symbols-add-unwind.debug
+# CHECK-LABEL: target symbols add
+# CHECK: symbol file {{.*}} has been added to {{.*}}
+
+image show-unwind -n _start
+# CHECK-LABEL: image show-unwind -n _start
+# CHECK: debug_frame UnwindPlan:
+# CHECK-NEXT: This UnwindPlan originally sourced from DWARF CFI
+# CHECK-NEXT: This UnwindPlan is sourced from the compiler: yes.

Modified: lldb/trunk/source/Core/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Module.cpp?rev=356361&r1=356360&r2=356361&view=diff
==============================================================================
--- lldb/trunk/source/Core/Module.cpp (original)
+++ lldb/trunk/source/Core/Module.cpp Mon Mar 18 03:45:02 2019
@@ -1300,6 +1300,12 @@ void Module::SectionFileAddressesChanged
     sym_vendor->SectionFileAddressesChanged();
 }
 
+UnwindTable &Module::GetUnwindTable() {
+  if (!m_unwind_table)
+    m_unwind_table.emplace(*this);
+  return *m_unwind_table;
+}
+
 SectionList *Module::GetUnifiedSectionList() {
   if (!m_sections_up)
     m_sections_up = llvm::make_unique<SectionList>();
@@ -1446,6 +1452,10 @@ void Module::SetSymbolFileFileSpec(const
         // one
         obj_file->ClearSymtab();
 
+        // Clear the unwind table too, as that may also be affected by the
+        // symbol file information.
+        m_unwind_table.reset();
+
         // The symbol file might be a directory bundle ("/tmp/a.out.dSYM")
         // instead of a full path to the symbol file within the bundle
         // ("/tmp/a.out.dSYM/Contents/Resources/DWARF/a.out"). So we need to

Modified: lldb/trunk/source/Symbol/UnwindTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/UnwindTable.cpp?rev=356361&r1=356360&r2=356361&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/UnwindTable.cpp (original)
+++ lldb/trunk/source/Symbol/UnwindTable.cpp Mon Mar 18 03:45:02 2019
@@ -46,7 +46,7 @@ void UnwindTable::Initialize() {
   if (!object_file)
     return;
 
-  SectionList *sl = object_file->GetSectionList();
+  SectionList *sl = m_module.GetSectionList();
   if (!sl)
     return;
 




More information about the lldb-commits mailing list