[Lldb-commits] [lldb] 3dd1a3d - [LLDB][ELF CORE] Only display a stop reason when there is a valid signo (#172781)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Feb 17 10:17:35 PST 2026
Author: Jacob Lalonde
Date: 2026-02-17T10:17:31-08:00
New Revision: 3dd1a3ddcb757fa92a18fa504383fc4481bc2d43
URL: https://github.com/llvm/llvm-project/commit/3dd1a3ddcb757fa92a18fa504383fc4481bc2d43
DIFF: https://github.com/llvm/llvm-project/commit/3dd1a3ddcb757fa92a18fa504383fc4481bc2d43.diff
LOG: [LLDB][ELF CORE] Only display a stop reason when there is a valid signo (#172781)
This patch fixes where ELF cores will report all threads as `STOP REASON
0`.
This was/is a large personal annoyance of mine; added a test to verify a
default elf core process/thread has no valid stop reason.
Added:
Modified:
lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
lldb/test/API/commands/target/stop-hooks/on-core-load/TestStopHookOnCoreLoad.py
lldb/test/API/functionalities/postmortem/netbsd-core/TestNetBSDCore.py
lldb/test/Shell/Register/Core/x86-32-linux-multithread.test
lldb/test/Shell/Register/Core/x86-32-netbsd-multithread.test
lldb/test/Shell/Register/Core/x86-64-linux-multithread.test
lldb/test/Shell/Register/Core/x86-64-netbsd-multithread.test
lldb/unittests/Process/elf-core/ThreadElfCoreTest.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
index fb54f630d7918..418ead28795c2 100644
--- a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
@@ -261,6 +261,15 @@ bool ThreadElfCore::CalculateStopInfo() {
}
}
+ // The above code references the siginfo_t bytes from the NT_SIGINFO note.
+ // This is not the only way to get a signo in an ELF core, and so
+ // ThreadELFCore has a m_signo variable for these cases, which is populated
+ // with a non-zero value when there is no NT_SIGINFO note. However if this is
+ // 0, it's the default value and we have no valid signal and should not report
+ // a stop info.
+ if (m_signo == 0 && m_siginfo_bytes.empty())
+ return false;
+
SetStopInfo(StopInfo::CreateStopReasonWithSignal(*this, m_signo));
return true;
}
diff --git a/lldb/test/API/commands/target/stop-hooks/on-core-load/TestStopHookOnCoreLoad.py b/lldb/test/API/commands/target/stop-hooks/on-core-load/TestStopHookOnCoreLoad.py
index fa142de949057..05db47c8ff148 100644
--- a/lldb/test/API/commands/target/stop-hooks/on-core-load/TestStopHookOnCoreLoad.py
+++ b/lldb/test/API/commands/target/stop-hooks/on-core-load/TestStopHookOnCoreLoad.py
@@ -50,6 +50,12 @@ def do_test(self, core_path, stop_thread):
result = lldb.SBCommandReturnObject()
self.dbg.GetCommandInterpreter().HandleCommand("report_command", result)
print(f"Command Output: '{result.GetOutput}'")
- self.assertIn(
- f"Stop Threads: {stop_thread}", result.GetOutput(), "Ran the stop hook"
- )
+
+ thread = target.process.GetThreadAtIndex(0)
+ # ELF Cores used to report stop reason 0 for all threads, but now that they're
+ # filtered we only want to check if the stop_hook was run on threads with
+ # stop reasons.
+ if thread.is_stopped:
+ self.assertIn(
+ f"Stop Threads: {stop_thread}", result.GetOutput(), "Ran the stop hook"
+ )
diff --git a/lldb/test/API/functionalities/postmortem/netbsd-core/TestNetBSDCore.py b/lldb/test/API/functionalities/postmortem/netbsd-core/TestNetBSDCore.py
index ff1ef21e02e31..e5217458a5ad7 100644
--- a/lldb/test/API/functionalities/postmortem/netbsd-core/TestNetBSDCore.py
+++ b/lldb/test/API/functionalities/postmortem/netbsd-core/TestNetBSDCore.py
@@ -172,9 +172,7 @@ def check_stack(self, process, pid, filename):
# thread 1 should have no signal
thread = process.GetThreadByID(1)
- self.assertStopReason(thread.GetStopReason(), lldb.eStopReasonSignal)
- self.assertEqual(thread.GetStopReasonDataCount(), 1)
- self.assertEqual(thread.GetStopReasonDataAtIndex(0), 0)
+ self.assertFalse(thread.is_stopped)
@skipIfLLVMTargetMissing("AArch64")
def test_aarch64_thread_signaled(self):
diff --git a/lldb/test/Shell/Register/Core/x86-32-linux-multithread.test b/lldb/test/Shell/Register/Core/x86-32-linux-multithread.test
index 972e10844a5aa..c8f22e7003694 100644
--- a/lldb/test/Shell/Register/Core/x86-32-linux-multithread.test
+++ b/lldb/test/Shell/Register/Core/x86-32-linux-multithread.test
@@ -2,9 +2,9 @@
thread list
# CHECK: * thread #1: tid = 330633, 0x080492d2, name = 'a.out', stop reason = SIGSEGV: address not mapped to object (fault address=0x0)
-# CHECK-NEXT: thread #2: tid = 330634, 0x080492dd, stop reason = signal 0
-# CHECK-NEXT: thread #3: tid = 330635, 0x080492dd, stop reason = signal 0
-# CHECK-NEXT: thread #4: tid = 330632, 0xf7f59549, stop reason = signal 0
+# CHECK-NEXT: thread #2: tid = 330634, 0x080492dd
+# CHECK-NEXT: thread #3: tid = 330635, 0x080492dd
+# CHECK-NEXT: thread #4: tid = 330632, 0xf7f59549
register read --all
# CHECK-DAG: ecx = 0x01010101
diff --git a/lldb/test/Shell/Register/Core/x86-32-netbsd-multithread.test b/lldb/test/Shell/Register/Core/x86-32-netbsd-multithread.test
index 16425e7ef807c..56479b3d62c4f 100644
--- a/lldb/test/Shell/Register/Core/x86-32-netbsd-multithread.test
+++ b/lldb/test/Shell/Register/Core/x86-32-netbsd-multithread.test
@@ -1,10 +1,10 @@
# RUN: %lldb -b -s %s -c %p/Inputs/x86-32-netbsd-multithread.core | FileCheck %s
thread list
-# CHECK: * thread #1: tid = 2, 0x08048db9, stop reason = signal SIGSEGV
-# CHECK-NEXT: thread #2: tid = 4, 0x08048dbf, stop reason = signal 0
-# CHECK-NEXT: thread #3: tid = 3, 0x08048dbf, stop reason = signal 0
-# CHECK-NEXT: thread #4: tid = 1, 0xf876a147, stop reason = signal 0
+# CHECK: * thread #1: tid = 2, 0x08048db9, stop reason = signal SIGSEGV
+# CHECK-NEXT: thread #2: tid = 4, 0x08048dbf
+# CHECK-NEXT: thread #3: tid = 3, 0x08048dbf
+# CHECK-NEXT: thread #4: tid = 1, 0xf876a147
register read --all
diff --git a/lldb/test/Shell/Register/Core/x86-64-linux-multithread.test b/lldb/test/Shell/Register/Core/x86-64-linux-multithread.test
index 5bea84813b44f..891b6ff358382 100644
--- a/lldb/test/Shell/Register/Core/x86-64-linux-multithread.test
+++ b/lldb/test/Shell/Register/Core/x86-64-linux-multithread.test
@@ -2,9 +2,9 @@
thread list
# CHECK: * thread #1: tid = 329384, 0x0000000000401262, name = 'a.out', stop reason = SIGSEGV: address not mapped to object (fault address=0x0)
-# CHECK-NEXT: thread #2: tid = 329385, 0x000000000040126d, stop reason = signal 0
-# CHECK-NEXT: thread #3: tid = 329386, 0x000000000040126d, stop reason = signal 0
-# CHECK-NEXT: thread #4: tid = 329383, 0x00007fcf5582f762, stop reason = signal 0
+# CHECK-NEXT: thread #2: tid = 329385, 0x000000000040126d
+# CHECK-NEXT: thread #3: tid = 329386, 0x000000000040126d
+# CHECK-NEXT: thread #4: tid = 329383, 0x00007fcf5582f762
register read --all
# CHECK-DAG: ecx = 0x04040404
diff --git a/lldb/test/Shell/Register/Core/x86-64-netbsd-multithread.test b/lldb/test/Shell/Register/Core/x86-64-netbsd-multithread.test
index d4d0cfd1f613a..7cb7187ce3be2 100644
--- a/lldb/test/Shell/Register/Core/x86-64-netbsd-multithread.test
+++ b/lldb/test/Shell/Register/Core/x86-64-netbsd-multithread.test
@@ -1,10 +1,10 @@
# RUN: %lldb -b -s %s -c %p/Inputs/x86-64-netbsd-multithread.core | FileCheck %s
thread list
-# CHECK: * thread #1: tid = 2, 0x0000000000400f82, stop reason = signal SIGSEGV
-# CHECK-NEXT: thread #2: tid = 4, 0x0000000000400f88, stop reason = signal 0
-# CHECK-NEXT: thread #3: tid = 3, 0x0000000000400f88, stop reason = signal 0
-# CHECK-NEXT: thread #4: tid = 1, 0x0000791280ca1faa, stop reason = signal 0
+# CHECK: * thread #1: tid = 2, 0x0000000000400f82, stop reason = signal SIGSEGV
+# CHECK-NEXT: thread #2: tid = 4, 0x0000000000400f88
+# CHECK-NEXT: thread #3: tid = 3, 0x0000000000400f88
+# CHECK-NEXT: thread #4: tid = 1, 0x0000791280ca1faa
register read --all
# CHECK-DAG: ecx = 0x04040404
diff --git a/lldb/unittests/Process/elf-core/ThreadElfCoreTest.cpp b/lldb/unittests/Process/elf-core/ThreadElfCoreTest.cpp
index 288729b447060..68919945198d4 100644
--- a/lldb/unittests/Process/elf-core/ThreadElfCoreTest.cpp
+++ b/lldb/unittests/Process/elf-core/ThreadElfCoreTest.cpp
@@ -181,3 +181,20 @@ TEST_F(ElfCoreTest, PopulatePrStatusTest) {
ASSERT_EQ(prstatus_opt->pr_pgrp, static_cast<uint32_t>(getpgrp()));
ASSERT_EQ(prstatus_opt->pr_sid, static_cast<uint32_t>(getsid(gettid())));
}
+
+TEST_F(ElfCoreTest, NoStopReasonWhenNoPrStatus) {
+ ArchSpec arch{HostInfo::GetTargetTriple()};
+ lldb::DebuggerSP debugger_sp = Debugger::CreateInstance();
+ ASSERT_TRUE(debugger_sp);
+
+ lldb::TargetSP target_sp = CreateTarget(debugger_sp, arch);
+ ASSERT_TRUE(target_sp);
+
+ lldb::ListenerSP listener_sp(Listener::MakeListener("dummy"));
+ lldb::ProcessSP process_sp =
+ std::make_shared<DummyProcess>(target_sp, listener_sp);
+ ASSERT_TRUE(process_sp);
+ lldb::ThreadSP thread_sp = CreateThread(process_sp);
+ ASSERT_TRUE(thread_sp);
+ ASSERT_FALSE(thread_sp->ThreadStoppedForAReason());
+}
More information about the lldb-commits
mailing list