Question

I have a lengthy program with several variables i want to check up on periodically. rather than typing

print var1 
print var2
print var2

and so on, ho can I either get output for multiple variables from one print (I tried print var1, var2, var3 but that didn't work.)

or

How can I write my own function to do the same thing as repetitiously typing print for each available?

is there any easier way?

Was it helpful?

Solution

You were close enough

print (var1, var2, ...)

Incidentally, you can use p as a shorthand for print:

p (var1, var2, ...)

If you simply want to monitor those variables for changes, then you need to watch them:

watch var1
watch var2

This way, any time the value of var1 etc. changes, GDB will notify you and print old and new value.

OTHER TIPS

There are several ways, but what you are looking for is probably display command.

Do:

display var1
display var2
display var3

Then just debug as usual and the values will be printed whenever debugger stops.

If you need to do this in many session you can write command to a script and source it in gdb.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top