Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatted printing in GDB

Tags:

c

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?

like image 274
brianmearns Avatar asked Jan 12 '12 19:01

brianmearns


People also ask

What does print do in GDB?

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).

What is Ptype in GDB?

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.

How do I list breakpoints in GDB?

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.

How do I set variables in GDB?

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.


1 Answers

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

like image 61
Sangeeth Saravanaraj Avatar answered Oct 17 '22 05:10

Sangeeth Saravanaraj