My software uses the SIGUSR2 signal and I am using LLDB (under Xcode 4.6.2) as my debugger. I would like to disable LLDB from stoping at SIGUSR2 and have been doing so using the command:
process handle --pass true --stop false --notify true SIGUSR2
I am looking for a way to have LLDB always execute this command at startup. I have looked into adding something along the lines of settings append target.process.extra-startup-command process
in my .lldbinit, but while this changes the value of the target.process.extra-startup-command setting (as evidenced by the settings show
command), I am uncertain if/how I can use this setting to always execute the process handle
command to disable the SIGUSR2 signal.
I am aware of the "solution" posted here: Permanently configuring LLDB (in Xcode 4.3.2) not to stop on signals. I am looking however for a more elegant solution, if one exists.
In lldb you can set breakpoints by typing either break or b followed by information on where you want the program to pause. After the b command, you can put either: a function name (e.g., b my_subroutine ) a line number (e.g., b 12 )
LLDB (low-level debugger) is part of LLVM The LLVM compiler (low level virtual machine) creates programming languages. LLDB is Apple's “from the ground up” replacement for GDB. The LLDB debugger is analogous to GDB: (The GNU Project Debugger).
LLDB is a debugging component used in the LLVM project which was developed by the LLVM developer group. Xcode uses the LLDB as the default debugging tool. The full form of LLDB is Low-level debugger. Breakpoints help a developer to stop the execution of the program at any point.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With