Noeud:Examining Variables - Print, Noeud « Next »:, Noeud « Previous »:One Step at a Time - Step+Next, Noeud « Up »:An example debugging session using gdb



Examining Variables - Print

So now we are at an if statement. This is the one that is going wrong, so let's examine it. The only thing we can check is argc, so let's do that.

     (gdb) print argc
     $1 = 2
     (gdb)
     

This is slightly cryptic, so let's look a bit deeper at it. The answer is 2, which is what we expect for argc with one argument given (one element for the name of the program, one for the argument).

The $1 is the identifier given this value in gdbs 'value history'. This works like the history in a shell, storing the values you have looked at ready for you to refer back to later.

FIXME

For instance, if you printed a complicated expression such as myptr+i*sizeof(struct mystruct) to get the result $27 = 0xffffeb2c, then to see the contents of that structure you could use print *$27 instead of repeating the calculation or copying the hex address.

Use show values to see the last ten values in the history, or show values n to show the ten values centred on history item number n.