1

Is there any command in GDB to directly find out the value of a particular element(say 20th) in a linked list?

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.