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:
if [[ -n “$procID” ]]; then
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
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" fi
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.
Any help is appreciated.