[Lldb-commits] [PATCH] D48463: Prevent dead locking when calling PrintAsync

Raphael Isemann via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Jun 21 16:21:08 PDT 2018


teemperor created this revision.

While working on the `expr` completion, I've encountered the issue that sometimes lldb
deadlocks when doing input/output. The underlying cause for this is that we seem to expect
that we can always call `Debugger::PrintAsync` from any point of lldb and that this call will
always return at some point.

However this is not always the case. For example, when calling the completion handler, we
obviously hold locks that make the console IO thread safe. The expression parsing
code then tries to parse the user expression to provide possible completions. It's possible
that while parsing our expression, we hit a case where some code decides to print
information to the debugger output (for example to inform the user that some functionality
has failed unexpectedly). If this call now happens from another thread, then even our
recursive_mutex won't protect us and we get a deadlock.

To prevent this issue in the future, this patch introduces the notion of delayed output scopes,
that essentially act as safe zones in which all calls to PrintAsync for a given debugger
are safe independently of the locking inside the IOHandlers or related issues. While printing in
this scope, we queue messages and then actually print them once we leave the scope.

So far I only use this feature in the Editline code (because that's the case where it solves my problem
with the deadlocked expr completion), but it might be more fitting in another place.


https://reviews.llvm.org/D48463

Files:
  include/lldb/Core/Debugger.h
  source/Core/Debugger.cpp
  source/Core/IOHandler.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48463.152397.patch
Type: text/x-patch
Size: 6568 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180621/99d5eefd/attachment-0001.bin>


More information about the lldb-commits mailing list