[Lldb-commits] [PATCH] D122716: [lldb/linux] Handle main thread exits

Pavel Labath via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Mar 30 03:41:59 PDT 2022


labath created this revision.
labath added reviewers: mgorny, DavidSpickett.
Herald added a subscriber: krytarowski.
Herald added a project: All.
labath requested review of this revision.
Herald added a project: LLDB.

This patch handles the situation where the main thread exits (through
the SYS_exit syscall). In this case, the process as a whole continues
running until all of the other threads exit, or one of them issues an
exit_group syscall.

The patch consists of two changes:

- a moderate redesign of the handling of thread exit (WIFEXITED) events. Previously, we were removing (forgetting) a thread once we received the WIFEXITED (or WIFSIGNALED) event. This was problematic for the main thread, since the main thread WIFEXITED event (which is better thought of as a process-wide event) gets reported only after the entire process exits. This resulted in deadlocks, where we were waiting for the process to stop (because we still considered the main thread "live").

  This patch changes the logic such that the main thread is removed as soon as its PTRACE_EVENT_EXIT (the pre-exit) event is received. At this point we can consider the thread gone (for most purposes). As a corrolary, I needed to add special logic to catch process-wide exit events in the cases where we don't have the main thread around.

- The second part of the patch is the removal of the assumptions that the main thread is always available. This generally meant replacing the uses of GetThreadByID(process_id) with GetCurrentThread() in various process-wide operations (such as memory reads).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122716

Files:
  lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
  lldb/test/API/functionalities/thread/main_thread_exit/Makefile
  lldb/test/API/functionalities/thread/main_thread_exit/TestMainThreadExit.py
  lldb/test/API/functionalities/thread/main_thread_exit/main.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122716.419093.patch
Type: text/x-patch
Size: 9661 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220330/fc93de91/attachment-0001.bin>


More information about the lldb-commits mailing list