aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
diff options
context:
space:
mode:
authorjimingham <jingham@apple.com>2025-10-27 11:38:10 -0700
committerGitHub <noreply@github.com>2025-10-27 11:38:10 -0700
commit88558d52c71081d5c6c372f87fb454a89747c5dd (patch)
tree09c34edd1d8eeef2e9938818bf984495c70278b6 /lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h
parent263377a17570e1cbe6eeae9ffa5ce02f240839ef (diff)
downloadllvm-88558d52c71081d5c6c372f87fb454a89747c5dd.zip
llvm-88558d52c71081d5c6c372f87fb454a89747c5dd.tar.gz
llvm-88558d52c71081d5c6c372f87fb454a89747c5dd.tar.bz2
Avoid stalls when MainLoop::Interrupt fails to wake up the MainLoop (#164905)
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.
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/SWIGPythonBridge.h')
0 files changed, 0 insertions, 0 deletions