tags:

views:

240

answers:

2

Hi

I want to execute the very simple command

print var1, var2, var3, var4

in gdb to examine the values of the vars from time to time.

I don't want to use display because it clutters up my view.

How can I do this? Right now all I can do is

p var1
p var2
p var3
p var4

Worse, when I want to do it again, I have to do all four commands again

A: 

There may be a simpler solution, but you might be able to put together something using GDB macros: http://www.ibm.com/developerworks/aix/library/au-gdb.html

Edward Loper
+3  A: 

Use the printf command. It's a bit of a hassle, but it gives good control over the formatting. From the command line:

(gdb) help printf
printf "printf format string", arg1, arg2, arg3, ..., argn
This is useful for formatted output in user-defined commands.

The format string is like in C (%d for normal size ints, %s for null terminated strings, etc.).

TGV
Thanks TGV and Edward
Rao Garimella