64

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  
jww
  • 97,681
  • 90
  • 411
  • 885
Rao Garimella
  • 649
  • 1
  • 5
  • 3

4 Answers4

67

You can simply do this

print {var1,var2,var3,var4}

This will do the job.

vikasmk
  • 956
  • 6
  • 12
46

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
  • 796
  • 4
  • 8
  • 1
    I like this answer. One niche problem with it is that it only supports up to 64-bit integers: `That operation is not available on integers of more than 8 bytes.` (GCC on AMD64 has emulated `__int128_t` on some platforms.) Of course, you can shift and cast. – Conrad Meyer Dec 12 '19 at 17:37
29

Use Macros:

For example to continue to next break point and print

(gdb) define prm 

Type commands for definition of prm. End with a line saying just end.

>continue
>print var1
>print var2
>print var3
>end

(gdb) prm
$5 = 0
$6 = 10
$7 = -1
OhBeWise
  • 5,350
  • 3
  • 32
  • 60
Manas Jagadev
  • 399
  • 3
  • 2
2

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
  • 15,374
  • 7
  • 43
  • 52