summaryrefslogtreecommitdiff
path: root/lldb/source/Host/common/MainLoopBase.cpp
AgeCommit message (Collapse)Author
2025-10-27Avoid stalls when MainLoop::Interrupt fails to wake up the MainLoop (#164905)jimingham
Turns out there's a bug in the current lldb sources that if you fork, set the stdio file handles to close on exec and then exec lldb with some commands and the `--batch` flag, lldb will stall on exit. The first cause of the bug is that the Python session handler - and probably other places in lldb - think 0, 1, and 2 HAVE TO BE the stdio file handles, and open and close and dup them as needed. NB: I am NOT trying to fix that bug. I'm not convinced running the lldb driver headless is worth a lot of effort, it's just as easy to redirect them to /dev/null, which does work. But I would like to keep lldb from stalling on the way out when this happens. The reason we stall is that we have a MainLoop waiting for signals, and we try to Interrupt it, but because stdio was closed, the interrupt pipe for the MainLoop gets the file descriptor 0, which gets closed by the Python session handler if you run some script command. So the Interrupt fails. We were running the Write to the interrupt pipe wrapped in `llvm::cantFail`, but in a no asserts build that just drops the error on the floor. So then lldb went on to call std::thread::join on the still active MainLoop, and that stalls I made Interrupt (and AddCallback & AddPendingCallback) return a bool for "interrupt success" instead. All the places where code was requesting termination, I added checks for that failure, and skip the std::thread::join call on the MainLoop thread, since that is almost certainly going to stall at this point. I didn't do the same for the Windows MainLoop, as I don't know if/when the WSASetEvent call can fail, so I always return true here. I also didn't turn the test off for Windows. According to the Python docs all the API's I used should work on Windows... If that turns out not to be true I'll make the test Darwin/Unix only.
2024-11-19[lldb] Add timed callbacks to the MainLoop class (#112895)Pavel Labath
The motivating use case is being able to "time out" certain operations (by adding a timed callback which will force the termination of the loop), but the design is flexible enough to accomodate other use cases as well (e.g. running a periodic task in the background). The implementation builds on the existing "pending callback" mechanism, by associating a time point with each callback -- every time the loop wakes up, it runs all of the callbacks which are past their point, and it also makes sure to sleep only until the next callback is scheduled to run. I've done some renaming as names like "TriggerPendingCallbacks" were no longer accurate -- the function may no longer cause any callbacks to be called (it may just cause the main loop thread to recalculate the time it wants to sleep).
2022-09-06[lldb] Enable the insertion of "pending callbacks" to MainLoops from other ↵Pavel Labath
threads This will be used as a replacement for selecting over a pipe fd, which does not work on windows. The posix implementation still uses a pipe under the hood, while the windows version uses windows event handles. The idea is that, instead of writing to a pipe, one just inserts a callback, which does whatever you wanted to do after the bytes come out the read end of the pipe. Differential Revision: https://reviews.llvm.org/D131160
2022-08-19[lldb] Use WSAEventSelect for MainLoop polling on windowsPavel Labath
This patch switches the MainLoop class to use the WSAEventSelect mechanism to wait for multiple sockets to become readable. The motivation for doing that is that this allows us to wait for other kinds of events as well (as long as they can be converted to WSAEvents). This will allow us to avoid (abstract away) pipe-based multiplexing mechanisms in the generic code, since pipes cannot be combined with sockets on windows. Since the windows implementation will now look completely different than the posix (file descriptor-based) implementations, I have split the MainLoop class into two (MainLoopPosix and MainLoopWindows), with the common code going into MainLoopBase. Differential Revision: https://reviews.llvm.org/D131159