I want to run something like the following command from a script:
lldb -f /path/to/my/file -o command1 -o command2 ... -o detach
Is there any way to exit lldb after execution without entering interactive mode? Passing in -o exit or -o quit fails with "Aborting after_file command execution, command: 'quit' failed." Running the above command with or without exit/quit leaves the terminal at the lldb prompt, which prevents me from just running this command and redirecting the output to somewhere on disk.
The end goal of this is to get the output of my command on-demand when certain things happen. There isn't a Python interpreter on this platform, so that isn't an option. Any suggestions?
Type quit to exit the lldb session.
To stop your program while it is running, type "(ctrl) + c" (hold down the ctrl key and press c). gdb will stop your program at whatever line it has just executed. From here you can examine variables and move through your program. To specify other places where gdb should stop, see the section on breakpoints below.
lldb-server provides the server counterpart of the LLVM debugger. The server runs and monitors the debugged program, while the user interfaces with it via a client, either running locally or connecting remotely. All of the code in the LLDB project is available under the Apache 2.0 License with LLVM exceptions.
This seems to work for me:
$ xcrun lldb /bin/ls -o "b malloc" -o "run" -o "script import os; os._exit(1)"
(lldb) target create "/bin/ls"
Current executable set to '/bin/ls' (x86_64).
(lldb) b malloc
Breakpoint 1: 3 locations.
(lldb) run
Process 640 launched: '/bin/ls' (x86_64)
(lldb) script import os; os._exit(1)
Process 640 stopped
* thread #1: tid = 0x11033, 0x00007fff9374136b libsystem_malloc.dylibmalloc, stop reason = breakpoint 1.2
frame #0: 0x00007fff9374136b libsystem_malloc.dylib
malloc
libsystem_malloc.dylib`malloc:
-> 0x7fff9374136b: pushq %rbp
0x7fff9374136c: movq %rsp, %rbp
0x7fff9374136f: pushq %rbx
0x7fff93741370: pushq %rax
$ (back to the prompt)
It's kind of gross, but the key to the castle is:
-o "script import os; os._exit(1)"
sys.exit(1) won't work (we catch it and stop it from exiting LLDB), but os._exit() is an open freebie. Consider this a bug at will.
Yeah, that's just a bug. The "-o" commands are all gathered up and given to a sub-interpreter to execute before starting up the interactive interpreter. Unfortunately, "quit" was just quitting the sub-interpreter. That's fixed in TOT lldb, should make it into an official Apple release before too long.
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