I'm using gdb with the -x parameter in order to debug without having to interactively continue at each breakpoint.
[root@StackOverflow.com] $ cat gdb_cmds_01
b SomeSourceFile.cpp:123
commands
bt
cont
end
I'm then attaching to a process that uses SomeSourceFile.cpp in it's execution:
[root@StackOverflow.com] $ gdb -p 'pidof SomeRunningProgram' -x gdb_cmds_01
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-92.el6)
...
<GDB outputs a set S of backtraces as instructed by gdb_cmds_01>
Now, Let SomeSourceFile.cpp:123 contain a line like:
if (foo(person, &place, *time) == "Alice") { ... <do stuff > ... }
And then Suppose I want to break on SomeSourceFile:123 only if the return of foo(...)
is not equal to "Alice".
Based on: How to inspect the return value of a function in GDB?, I know that gdb can inspect the return value of a function.
And https://sourceware.org/gdb/onlinedocs/gdb/Break-Commands.html tells me that I can inspect the value of a variable non-interactively:
<...>
For example, here is how you could use breakpoint commands to print the value of x at entry to foo whenever x is positive.
break foo if x>0
commands
silent
printf "x is %d\n",x
cont
end
<...>
I have tried something like:
[root@StackOverflow.com] $ cat gdb_cmds_01
b SomeSourceFile.cpp:123 if foo(person, &place, *time) != "Alice"
commands
bt
cont
end
But GDB spits out:
gdb_cmds_01:1: Error in sourced command file:
No symbol "place" in current context.
Can this be worked around?
In order to break on SomeSourceFile.cpp:123 only when foo(...) != "Alice"
, can I also inspect the return value of a function non-interactively?
In other words, I want to see only a subset R of the set of backtraces S such that for all backtraces b in R, the return of foo(...)
is always unequal to "Alice".