Debugging with GDB Manual (5900-1473; WDB 6.2; January 2011)

Table Of Contents
1.8 Printing Variable Values
The last line displayed looks a little odd in the listing above; we can examine the variables
lquote and rquote to see if they are in fact the new left and right quotes we specified.
We use the command p (print) to view their values.
((gdb)) p lquote
$1 = 0x35d40 "<QUOTE>"
((gdb)) p rquote
$2 = 0x35d50 "<UNQUOTE>"
1.9 Listing Source Code
lquote and rquote are indeed the new left and right quotes. To look at some context,
we can display ten lines of source surrounding the current line with the l (list)
command.
((gdb)) l
533 xfree(rquote);
534
535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
: xstrdup (lq);
536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
: xstrdup (rq);
537
538 len_lquote = strlen(rquote);
539 len_rquote = strlen(lquote);
540 }
541
542 void
Let us step past the two lines that set len_lquote and len_rquote, and then examine
the values of those variables.
((gdb)) n
539 len_rquote = strlen(lquote);
((gdb)) n
540 }
((gdb)) p len_lquote
$3 = 9
((gdb)) p len_rquote
$4 = 7
1.10 Setting Variable Values During a Session
That certainly looks wrong, assuming len_lquote and len_rquote are meant to be
the lengths of lquote and rquote respectively. We can set them to better values using
the p command, since it can print the value of any expression―and that expression can
include subroutine calls and assignments.
((gdb)) p len_lquote=strlen(lquote)
$5 = 7
1.8 Printing Variable Values 21