O'Reilly logo

The Art of Debugging with GDB and DDD by Peter Jay Salzman, Norman Matloff

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Advanced Inspection and Setting of Variables

Our tree example here has greater complexity, and thus, more sophisticated methods are needed. We'll take a look at some here.

Inspection in GDB

In earlier chapters you have used GDB's basic print command. How might you use it here? Well, the main work is obviously done in insert(), so that would be a good place to start. While running GDB within the while loop in that function, you could issue a set of three GDB commands each time you hit a breakpoint:

(gdb) p tmp->val
$1 = 12
(gdb) p tmp->left
$2 = (struct node *) 0x8049698
(gdb) p tmp->right
$3 = (struct node *) 0x0

(Recall from Chapter 1 that the output from GDB is labeled $1, $2, and so on, with these quantities collectively called the value history ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required