llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Jacob Lalonde (Jlalond)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/172781.diff


2 Files Affected:

- (modified) lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp (+9) 
- (modified) lldb/unittests/Process/elf-core/ThreadElfCoreTest.cpp (+17) 


``````````diff
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());
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/172781
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to