Then one day after having wasted a lot of time, in recompile and rerun, I decided to use GDB scripts (which I had known since long, but had never used). And it is really fun now. I save a lot of time in debugging.
A sample script that I used to count the number of elements in a linked list (which we use a lot in our code) is below:
define cntList
set $l = $arg0
set $i = 0
if ($l == 0)
printf "NULL list found\n"
else
set $n = $l
while ($n != 0)
set $i = $i+1
set $n = $n->next
end
end
printf "list size %d\n", $i
end
document cntList
count the number of elements in the list
Usage: cntList
end
No comments:
Post a Comment