0

Let a laziest linked list like:

#include <assert.h>

[...]

struct value {
  int i_;
};

struct values {
  struct value * first;
  struct values * next;
};

[...]

struct values values_;

[...]

assert(values_ != NULL);
assert(values_->first != NULL);
assert(values_->first->i_ == 4);
assert(values_->next != NULL);
assert(values_->next->first != NULL);
assert(values_->next->first->i_ == 8);
assert(values_->next->next == NULL);

I read in https://stackoverflow.com/a/46289993 that print *values_ is an improvement over print values_, then print values_->first and print values_->next.

But I don't know how to end up with something like $i = {first = 0x?????? {i_ = 4}, next = 0x?????? {first = 0x?????? {i_ = 8}, next = 0x0}} using a single gdb command.

There is https://stackoverflow.com/a/16493871/1737973 and https://sourceware.org/gdb/current/onlinedocs/gdb/Pretty-Printing.html. Is there any laziest way than those?

1737973
  • 159
  • 18
  • 42

1 Answers1

0

You could do something lie this (untested):

(gdb) define plist
set var $h = $0
while $h != 0
 print *$h
 set var $h = $h->next
end
end

and then use (gdb) plist values_.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362