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
Get The Art of Debugging with GDB, DDD, and Eclipse now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.