I'd like to do printf
style printing from GDB
. For instance, I want to print a variable value, but with some text to describe what it is. Can it be done, and if so, can you give an example?
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).
Description. This command prints a detailed description of a type, or the type of the last value in the command history. This command is similar to whatis , but whatis prints just the name of the type.
You can see these breakpoints with the GDB maintenance command `maint info breakpoints' . Using the same format as `info breakpoints' , display both the breakpoints you've set explicitly, and those GDB is using for internal purposes. Internal breakpoints are shown with negative breakpoint numbers.
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.
You can very much use printf
in gdb
as follows:
(gdb) printf "%s", x
Hello world
(gdb)
You can do it by using call
also
(gdb) call printf("%s", x)
Hello world
(gdb)
I prefer the former one!
http://beej.us/guide/bggdb/ is a simple and good reference for gdb
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