[all-commits] [llvm/llvm-project] 04de24: [lldb/IOHandler] Improve synchronization between I...

Jonas Devlieghere via All-commits all-commits at lists.llvm.org
Mon Jan 20 11:18:15 PST 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 04de24e690d3ff23bf63bc3901765cd8f07723f3
      https://github.com/llvm/llvm-project/commit/04de24e690d3ff23bf63bc3901765cd8f07723f3
  Author: Jonas Devlieghere <jonas at devlieghere.com>
  Date:   2020-01-20 (Mon, 20 Jan 2020)

  Changed paths:
    M lldb/include/lldb/Core/Debugger.h
    A lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_callback_command_source/Makefile
    A lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_callback_command_source/TestBreakpointCallbackCommandSource.py
    A lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_callback_command_source/main.c
    A lldb/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_callback_command_source/source.lldb
    M lldb/source/Core/Debugger.cpp

  Log Message:
  -----------
  [lldb/IOHandler] Improve synchronization between IO handlers.

The way the IO handlers are currently managed by the debugger is wrong. The
implementation lacks proper synchronization between RunIOHandlerSync and
RunIOHandlers. The latter is meant to be run by the "main thread", while the
former is meant to be run synchronously, potentially from a different thread.

Imagine a scenario where RunIOHandlerSync is called from a different thread
than RunIOHandlers. Both functions manipulate the debugger's IOHandlerStack.
Although the push and pop operations are synchronized, the logic to activate,
deactivate and run IO handlers is not.

While investigating PR44352, I noticed some weird behavior in the Editline
implementation. One of its members (m_editor_status) was modified from another
thread. This happened because the main thread, while running RunIOHandlers
ended up execution the IOHandlerEditline created by the breakpoint callback
thread. Even worse, due to the lack of synchronization within the IO handler
implementation, both threads ended up executing the same IO handler.

Most of the time, the IO handlers don't need to run synchronously. The
exception is sourcing commands from external files, like the .lldbinit file.

I've added a (recursive) mutex to prevent another thread from messing with the
IO handlers wile another thread is running one synchronously. It has to be
recursive, because we might have to source another file when encountering a
command source in the original file.

Differential revision: https://reviews.llvm.org/D72748




More information about the All-commits mailing list