[Lldb-commits] [lldb] 64d9b23 - [lldb] Prevent crash when adding a stop hook with --shlib

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Thu Apr 14 11:00:26 PDT 2022


Author: Jonas Devlieghere
Date: 2022-04-14T11:00:21-07:00
New Revision: 64d9b233b9905a951b450eff5b258707a35e110f

URL: https://github.com/llvm/llvm-project/commit/64d9b233b9905a951b450eff5b258707a35e110f
DIFF: https://github.com/llvm/llvm-project/commit/64d9b233b9905a951b450eff5b258707a35e110f.diff

LOG: [lldb] Prevent crash when adding a stop hook with --shlib

Currently, lldb crashes when adding a stop hook with --shlib because we
unconditionally use the target in SymbolContextSpecifier::AddSpecification.
This patch prevents the crash and add a test.

rdar://68524781

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

Added: 
    lldb/test/Shell/Commands/command-stop-hook-no-target.test

Modified: 
    lldb/source/Symbol/SymbolContext.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Symbol/SymbolContext.cpp b/lldb/source/Symbol/SymbolContext.cpp
index 2985a39462aae..33999fabca434 100644
--- a/lldb/source/Symbol/SymbolContext.cpp
+++ b/lldb/source/Symbol/SymbolContext.cpp
@@ -960,8 +960,9 @@ bool SymbolContextSpecifier::AddSpecification(const char *spec_string,
     // See if we can find the Module, if so stick it in the SymbolContext.
     FileSpec module_file_spec(spec_string);
     ModuleSpec module_spec(module_file_spec);
-    lldb::ModuleSP module_sp(
-        m_target_sp->GetImages().FindFirstModule(module_spec));
+    lldb::ModuleSP module_sp =
+        m_target_sp ? m_target_sp->GetImages().FindFirstModule(module_spec)
+                    : nullptr;
     m_type |= eModuleSpecified;
     if (module_sp)
       m_module_sp = module_sp;

diff  --git a/lldb/test/Shell/Commands/command-stop-hook-no-target.test b/lldb/test/Shell/Commands/command-stop-hook-no-target.test
new file mode 100644
index 0000000000000..ee9ded164d745
--- /dev/null
+++ b/lldb/test/Shell/Commands/command-stop-hook-no-target.test
@@ -0,0 +1,4 @@
+# RUN: %clang_host -g %S/Inputs/main.c -o %t
+# RUN: %lldb -b -o 'target stop-hook add --name test --shlib test -o "p 95000 + 126"' -o 'file %t' -o 'b main' -o 'r' 2>&1 | FileCheck %s
+# CHECK: Stop hook #1 added
+# CHECK-NOT: 95126


        


More information about the lldb-commits mailing list