Search code examples
cgdb

Formatted printing in GDB


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?


Solution

  • If you have a definition int i = 5;, you can print the value of i with formatted printing this way:

    (gdb) printf "Val of my object: %d\n", i

    Value of my object: 5

    (gdb)