I wish to print the variable in a function (which is called multiple times ) to be printed each time the function is invoked.
Is it possible to do this automatically through gdb ?? Something like conditional printing ...
something like ..
void func()
{
if( t == 0 )
x = z+1;
else
x = p+2;
}
I want the variable to be printed when t == 0 and ignore otherwise ..
Use conditional breakpoints to conditionally stop program execution. Breakpoints normally stop the execution every time a certain line or function is reached. However, using the condition keyword, a breakpoint will only be activated if a certain condition is true.
The usual way to examine data in your program is with the print command (abbreviated p ), or its synonym inspect . It evaluates and prints the value of an expression of the language your program is written in (see section Using GDB with Different Languages).
Use the set variable (gdb) and the assign (dbx) commands to change the value associated with a variable, memory address, or expression that is accessible according to the scope and visibility rules of the language. The expression can be any expression that is valid in the current context.
The ptype [ARG] command will print the type. Show activity on this post.
This can be done with a combination of the commands breakpoint
, condition
, and commands
.
breakpoint func
condition t == 0
.
commands
info locals
end
or specific variables with:
commands
print t
print z
print x
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With