How can I exit lldb after running commands with -o

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 a way to exit lldb after execution without entering interactive mode? Passing to -o exit or -o quit fails with the error "Cancel execution of the after_file command, command:" quit "failed". Executing the above command with or without exiting leaves the terminal at the lldb command line, which prevents me from simply running that command and redirecting the output somewhere to disk.

The ultimate goal of this is to get my team's output on demand when certain things happen. There is no Python interpreter on this platform, so this is not an option. Any suggestions?


source to share

2 answers

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"

The current executable is set to '/ bin / ls' (x86_64).

(lldb) b malloc

Breakpoint 1: 3.

(lldb) run

Starting process 640: '/ bin / ls' (x86_64)

(lldb) script import os; os._exit (1)

Process 640 stopped * thread # 1: tid = 0x11033, 0x00007fff9374136b libsystem_malloc.dylib malloc, stop reason = breakpoint 1.2 frame #0: 0x00007fff9374136b libsystem_malloc.dylib

malloc libsystem_malloc.dylib`malloc: -> 0x7fff9374136b: pushq% rbp 0x7fff9374136c: movq% rqx670: push% rqx770 push% rbp913 push% rbp0713 push% rbp0713% rbp% rbp% rbp% rq713% rbp% rq713 ​​0% rbp 0% 0% rbp913413 0% rbp 0

$ (back to invitation)

It's rough, but the key to the lock is:

-o "script import os; os._exit(1)"


sys.exit (1) won't work (we'll catch it and stop it from exiting LLDB), but os._exit () is an open freebie. Think about it by mistake.



Yes, it's just a mistake. The "-o" commands are built and passed to the sub-interpreter for execution before starting the interactive interpreter. Unfortunately "quit" just got away from the sub-interpreter. What's fixed in TOT lldb should make it an official Apple release for too long.



All Articles