I am in the process of debugging a C++ program. I want to log all times the program goes through a specific breakpoint and capture the stack alongside some variable values. This happens multiple times, and want to collect this into a log file and process it after the execution. At the same time, I don't want the execution to go through the whole thing and want to observe the output and stop it at an appropriate time.
What I do is I run the program and attach gdb. Then in order to log the output I do the following:
(gdb) set trace-commands on
(gdb) set pagination off
(gdb) set logging overwrite on
(gdb) set logging file gdb.log
(gdb) set logging on
(gdb) break function_name
(gdb) commands
> print *variable_name
> backtrace
> continue
> end
Then I continue, and the process resumes execution. In the cli I can see the variable value and the backtrace output. In the gdb.log file I can see the variable value but not the backtrace.
If I type backtrace in the CLI, I can see its output being redirected in the gdb.log file. What doesn't seem to work is logging output of backtrace when invoked through the "commands" macro(?).
Can someone help me out? Thank you
gdb -x <command_file>
. Then those commands are executed consistently from file.