Reputation: 1841
I have some simple gdb defines that I would like to implement in lldb. I use a small wrapper script that actually generates the gdb defines and then loads them when I launch gdb. The simplest is
define rm
run $LIBLIST $KEXTRAS $EXTRAS
end
Which just defines a custom rm command that runs the binary with command line arguments determined in the wrapper script.
I'd like to emulate that in lldb. I've tried writing python scripts, and I can get them to load and run, but it seems like the command is run under the python interpreter so that the debugger is not catching events (like a CTRL-C to break to the debugger).
This is what I've currently got:
import os
import lldb
def __lldb_init_module(debugger, dict):
debugger.HandleCommand('command script add -f $PYPKG.rm_command rm')
def rm_command( debugger, command, result, internal_dict):
debugger.HandleCommand( 'run $LIBLIST $KEXTRAS $EXTRAS' )
I've also tried using debugger.GetSelectedTarget().Launch, but I get pretty much the same thing. The closest I've gotten is specifying the lldb.eLaunchFlagStopAtEntry LaunchFlag and then having to continue in llvm after the script returns. That's close, but it is kind of annoying to need to enter two commands.
How do I launch a process from a lldb script so that it can debugged as if the run command was used in lldb itself?
(For this example I know I could just pass the command line arguments on lldb's command line, but more complex examples combine arguments from the script with values I'd like to specify when I am debugging)
(Also I know you can create an alias for a one liner like this one, but I have some more complex scripts that would not be possible as an alias)
Upvotes: 1
Views: 985
Reputation: 27110
This is lldb's SIGINT handler fighting with the Python one while we are running the Python interpreter. lldb will have to do something cleverer to figure out which handler to dispatch to.
Fortunately, there is a workaround which is to make sure your command just starts the target running, then returns command to the lldb command interpreter. The way to do that is to make sure the debugger is running execution control commands in "Asynchronous mode" for the run command. You don't want to permanently so do something like:
def runcmd(debugger, command, result, internal_dict):
old_val = debugger.GetAsync()
debugger.SetAsync(True)
debugger.HandleCommand("run")
debugger.SetAsync(old_val)
Upvotes: 2