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.
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.).
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
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
You can simply do this
print {var1,var2,var3,var4}
This will do the job.