Is there any command in GDB to directly find out the value of a particular element(say 20th) in a linked list?
1 Answer
You can make an appropriate user-defined function (in gdb). For example, suppose that you get to the next element in your linked list by accessing ->next, we can create a function xyzzy as follows (from gdb's prompt):
define xyzzy
set $current = $arg0
set $ii = $arg1
while ($ii > 0)
set $ii = $ii - 1
set $current = $current->next
end
print (something appropriate with $current)
end
You have then created a function which takes two arguments. The first is an element in your linked list and the second is the number of ->nexts that you are to follow. You'll need to put something appropriate in the print line.