[Lldb-commits] [PATCH] D123746: [lldb] Prevent crash when adding a stop hook with --shlib

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Apr 13 17:03:02 PDT 2022

JDevlieghere created this revision.
JDevlieghere added a reviewer: mib.
Herald added a project: All.
JDevlieghere requested review of this revision.

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




Index: lldb/test/Shell/Commands/command-stop-hook-no-target.test
--- /dev/null
+++ lldb/test/Shell/Commands/command-stop-hook-no-target.test
@@ -0,0 +1,3 @@
+# RUN: %lldb -b -o 'target stop-hook add --name test --shlib test' -o 'bt' | FileCheck %s
+# CHECK: Stop hook #1 added
Index: lldb/source/Symbol/SymbolContext.cpp
--- lldb/source/Symbol/SymbolContext.cpp
+++ lldb/source/Symbol/SymbolContext.cpp
@@ -960,8 +960,8 @@
     // 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;

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123746.422695.patch
Type: text/x-patch
Size: 1030 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220414/156f578d/attachment.bin>

More information about the lldb-commits mailing list