Capturing LLDB session output to a log file from a batch file in batch mode?

I have written a bash script to redirect gdb console output to a log file in batch mode and use it to capture the call stack of threads in a running process. This is the script using gdb to do the logging:

procID=$(pgrep “myProc”)
if [[ -n “$procID” ]]; then
TIME_STAMP=$(date +%b-%d-%H-%M-%S)
echo “Capturing thread information of $proc process ($procID)…”
cat << EOF > “$CMD_FILE”
set pagination off
set confirm off
set logging off
set print pretty on
set logging file /tmp/$LOG_FILE
set logging on
attach $procID
info thread
thread apply all backtrace

"$GDB_PATH" -x "$CMD_FILE" > /dev/null
if [[ ! -f "/tmp/$LOG_FILE" ]]; then
    echo "GDB log file /tmp/$LOG_FILE is not generated"



I am trying to do the same with lldb but cannot find all the corresponding commands.
I think I can use the following commands to attach to the process and dump the thread info, but I do not know how to set up the output log file.

process attach --pid $procID
thread list
thread backtrace all
process detach

Any help is appreciated.

Is session save <file> maybe what you’re looking for?

~> lldb
(lldb) expr 1 + 1
(int) $0 = 2
(lldb) session save my.log
Session's transcripts saved to my.log
(lldb) ^D
~> cat my.log
(lldb) expr 1 + 1
(int) $0 = 2
(lldb) session save my.log

(Also there is an actual LLDB subforum where these questions probably get a quicker answer :slight_smile: )