[Lldb-commits] [lldb] [LLDB][ELF CORE] Only display a stop reason when there is a valid signo (PR #172781)
Jacob Lalonde via lldb-commits
lldb-commits at lists.llvm.org
Thu Jan 8 10:29:59 PST 2026
https://github.com/Jlalond updated https://github.com/llvm/llvm-project/pull/172781
>From 58f2b4d3669231e4da2d8897761de9da46b6593a Mon Sep 17 00:00:00 2001
From: Jacob Lalonde <jalalonde at fb.com>
Date: Tue, 16 Dec 2025 11:27:58 -0800
Subject: [PATCH 1/3] Have ThreadELFCore not emit a stop reason for signo == 0
---
.../Plugins/Process/elf-core/ThreadElfCore.cpp | 9 +++++++++
.../Process/elf-core/ThreadElfCoreTest.cpp | 17 +++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
index 7015c3c65cc7d..61f6ab0e45593 100644
--- a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
@@ -276,6 +276,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)
+ return false;
+
SetStopInfo(StopInfo::CreateStopReasonWithSignal(*this, m_signo));
return true;
}
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());
+}
>From dc30ce63fc018ab798893942e4a9fb67ebe6a34e Mon Sep 17 00:00:00 2001
From: Jacob Lalonde <jalalonde at fb.com>
Date: Wed, 7 Jan 2026 14:59:47 -0800
Subject: [PATCH 2/3] Also check for the siginfo_t bytes are empty before
failing out to handle cases where the NT_SIGINFO data is not handled by the
target platform
---
lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
index 61f6ab0e45593..eae53ad5c11c7 100644
--- a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
@@ -282,7 +282,7 @@ bool ThreadElfCore::CalculateStopInfo() {
// 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)
+ if (m_signo == 0 && m_siginfo_bytes.empty())
return false;
SetStopInfo(StopInfo::CreateStopReasonWithSignal(*this, m_signo));
>From 1ff41d2e0abeb0baa0b8aac6d2edf5072b756eb0 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde <jalalonde at fb.com>
Date: Thu, 8 Jan 2026 10:26:38 -0800
Subject: [PATCH 3/3] Fix tests that expect a description, or signal of 0
---
.../on-core-load/TestStopHookOnCoreLoad.py | 14 ++++++++++----
.../postmortem/netbsd-core/TestNetBSDCore.py | 6 ++----
.../Register/Core/x86-32-linux-multithread.test | 6 +++---
.../Register/Core/x86-32-netbsd-multithread.test | 8 ++++----
.../Register/Core/x86-64-linux-multithread.test | 6 +++---
.../Register/Core/x86-64-netbsd-multithread.test | 8 ++++----
6 files changed, 26 insertions(+), 22 deletions(-)
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..41815e418e59c 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
@@ -2,9 +2,9 @@
Test that stop hooks fire on core load (first stop)
"""
+import os
import lldb
-import os
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
@@ -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..8c2dc8bf31485 100644
--- a/lldb/test/API/functionalities/postmortem/netbsd-core/TestNetBSDCore.py
+++ b/lldb/test/API/functionalities/postmortem/netbsd-core/TestNetBSDCore.py
@@ -2,8 +2,8 @@
Test NetBSD core file debugging.
"""
-import signal
import os
+import signal
import lldb
from lldbsuite.test.decorators import *
@@ -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
More information about the lldb-commits
mailing list