[Lldb-commits] [PATCH] D75454: [lldb] Make sure we don't drop asynchronous output when sourcing files

Pavel Labath via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Mar 2 06:59:18 PST 2020


labath created this revision.
labath added reviewers: JDevlieghere, clayborg.
Herald added a project: LLDB.

If a command from a sourced file produces asynchronous output, this
output often does not make its way to the user. This happens because the
asynchronous output machinery relies on the iohandler stack to ensure
the output does not interfere with the things the iohandler is doing.

However, if this happens near the end of the command stream then by the
time the asynchronous output is produced we may already have already
started tearing down the sourcing session. Specifically, we may already
pop the relevant iohandler, leaving the stack empty.

This patch makes sure this kind of output gets printed by adding a
fallback to IOHandlerStack::PrintAsync to print the output directly if
the stack is empty. This is safe because if we have no iohandlers then
there is nothing to synchronize.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75454

Files:
  lldb/source/Core/IOHandler.cpp
  lldb/test/Shell/Commands/command-thread-select.test


Index: lldb/test/Shell/Commands/command-thread-select.test
===================================================================
--- /dev/null
+++ lldb/test/Shell/Commands/command-thread-select.test
@@ -0,0 +1,17 @@
+# RUN: %clang_host -g %S/Inputs/main.c -o %t
+# RUN: %lldb %t -s %s -o exit | FileCheck %s
+
+b main
+# CHECK-LABEL: b main
+# CHECK: Breakpoint 1: where = {{.*}}`main
+
+run
+# CHECK-LABEL: run
+# CHECK: Process {{.*}} stopped
+# CHECK: stop reason = breakpoint 1
+# CHECK:   frame #0: {{.*}}`main at main.c
+
+thread select 1
+# CHECK-LABEL: thread select 1
+# CHECK: stop reason = breakpoint 1
+# CHECK:   frame #0: {{.*}}`main at main.c
Index: lldb/source/Core/IOHandler.cpp
===================================================================
--- lldb/source/Core/IOHandler.cpp
+++ lldb/source/Core/IOHandler.cpp
@@ -125,6 +125,8 @@
     std::lock_guard<std::recursive_mutex> guard(m_mutex);
     if (m_top)
       m_top->PrintAsync(stream, s, len);
+    else
+      stream->Write(s, len);
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75454.247633.patch
Type: text/x-patch
Size: 1019 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200302/c8e4e0fc/attachment-0001.bin>


More information about the lldb-commits mailing list