[Lldb-commits] [lldb] [lldb][test] Fix race condition in test_stop-hook.cpp (PR #227284)

via lldb-commits lldb-commits at lists.llvm.org
Tue Sep 29 05:02:37 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: David Spickett (DavidSpickett)

<details>
<summary>Changes</summary>

This test has been failing on AArch64 Linux recently. Either with SIGSEGV or SIGABRT (less often that one).

I could reproduce it locally by varying system load, and got this out of a core file:
```
* thread #<!-- -->1, name = 'test_python_sto', stop reason = SIGSEGV: address not mapped to object (fault address=0xc17d18317552db80)
   * frame #<!-- -->0: 0x0000ef7dc72ac6cc libc.so.6`__GI_memchr at memchr.S:68
     frame #<!-- -->1: 0x0000ef7dc727cf4c libc.so.6`_IO_getline_info(fp=0x0000b9b53a8bd180, buf="\xa9\xb4\t\xce}\xef", n=<unavailable>
, delim=10, extract_delim=1, eof=0x0000000000000000) at iogetline.c:85:17
     frame #<!-- -->2: 0x0000ef7dc727bdc4 libc.so.6`_IO_fgets(buf="\xa9\xb4\t\xce}\xef", n=<unavailable>, fp=0x0000b9b53a8bd180) at io
fgets.c:53:11
     frame #<!-- -->3: 0x0000ef7dc80f2b80 liblldb.so.24.0git`lldb_private::IOHandlerEditline::GetLine(std::__cxx11::basic_string<char,
 std::char_traits<char>, std::allocator<char>>&, bool&) + 996
     frame #<!-- -->4: 0x0000ef7dc80f41f4 liblldb.so.24.0git`lldb_private::IOHandlerEditline::Run() + 180
     frame #<!-- -->5: 0x0000ef7dc80bf614 liblldb.so.24.0git`lldb_private::Debugger::RunIOHandlers() + 128
     frame #<!-- -->6: 0x0000ef7dc80ccee8 liblldb.so.24.0git`std::_Function_handler<void* (), lldb_private::Debugger::StartIOHandlerTh
read()::$_0>::_M_invoke(std::_Any_data const&) + 28
     frame #<!-- -->7: 0x0000ef7dc81e1608 liblldb.so.24.0git`lldb_private::HostNativeThreadBase::ThreadCreateTrampoline(void*) + 124
     frame #<!-- -->8: 0x0000ef7dc72903c8 libc.so.6`start_thread(arg=0x000000000080e640) at pthread_create.c:442:8
     frame #<!-- -->9: 0x0000ef7dc72f9fdc libc.so.6`thread_start at clone.S:79
```
What's happening is that the interpreter's input stream is set to stream A, then we reset it to the default, then close stream A. There may still be reads from stream A in flight when we close it, which lead to the crash.

The solution is to wait on the interpreter thread to finish whatever it's doing. SBDebuger::Destroy does that.

Normally that would be called by driver.cpp but it can be called on already destroyed objects. So for this test we'll call it twice, but that's not a problem.

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


1 Files Affected:

- (modified) lldb/test/API/api/multithreaded/test_stop-hook.cpp (+4-1) 


``````````diff
diff --git a/lldb/test/API/api/multithreaded/test_stop-hook.cpp b/lldb/test/API/api/multithreaded/test_stop-hook.cpp
index 9c754d131214d..975d013c16d03 100644
--- a/lldb/test/API/api/multithreaded/test_stop-hook.cpp
+++ b/lldb/test/API/api/multithreaded/test_stop-hook.cpp
@@ -110,7 +110,10 @@ void test(SBDebugger &dbg, std::vector<std::string> args) {
     }
     ~Cleanup() {
       fclose(m_write_end);
-      m_dbg.SetInputFileHandle(m_file, false);
+      // Normally driver.cpp would do this, but we must do it now so that
+      // any in-progress reads from the input handle are finished before
+      // we close it.
+      SBDebugger::Destroy(m_dbg);
       fclose(m_read_end);
     }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/227284


More information about the lldb-commits mailing list