Disable signals at LLDB initialization
At present the suggestion of doing this in a breakpoint command on main
is the most elegant solution available.
gdb had this view of the world where all processes, no matter what system they might be on, magically responded to UNIX signals. So it made sense to say what was going to happen when the process got a SIGINT, say, before you even had a process. In lldb, the process, when it gets created, will tell us what its signals are and their default behaviors. That's lovely, except it means now there is no natural place to store configuration options for signal behaviors before you have a process. This is just something that has to get added.
The ability to trigger off of "process life-cycle events", not just "process launch" but "process exit" and "shared library load" etc would be a great addition. This feature is something it would be great to file an enhancement request (http://bugreport.apple.com/) for, since bugs like that act as votes for features.
BTW, target.process.extra-startup-command
does something entirely different. It allows you to prepend some commands to the sequence lldb sends to its debug agent (e.g. debugserver) before we start running. Its main use is to turn on more debugserver logging.
Since I regularly return to this question in order to configure this, I finally ended up creating a small script to do it automatically:
import lldb
import threading
class ProcessEventListener(threading.Thread):
def __init__(self, debugger):
super(ProcessEventListener, self).__init__()
self._listener = debugger.GetListener()
self._debugger = debugger
self._interpreter = debugger.GetCommandInterpreter()
self._handled = set()
def _suppress_signals(self, process):
signals = process.GetUnixSignals()
signals.SetShouldStop(11, False)
def run(self):
while True:
event = lldb.SBEvent()
if not self._listener.PeekAtNextEvent(event):
continue
process = self._interpreter.GetProcess()
if process and not process.GetUniqueID() in self._handled:
self._suppress_signals(process)
self._handled.add(process.GetUniqueID())
def __lldb_init_module(debugger, *rest):
listener_thread = ProcessEventListener(debugger)
listener_thread.start()
To use, put it in something like ignore_signals.py
and reference it from .lldbinit
:
command script import ~/ignore_signals.py
I suspect this can be improved further, so I've put it up on GitHub as well in case anyone would like to contribute.