GDB打印整个指针树

时间:2018-10-31 11:35:55

标签: gdb

让最懒的链接列表如下:

#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);

我在https://stackoverflow.com/a/46289993中读到,print *values_是对print values_的改进,然后是print values_->firstprint values_->next

但是我不知道如何使用单个$i = {first = 0x?????? {i_ = 4}, next = 0x?????? {first = 0x?????? {i_ = 8}, next = 0x0}}命令以类似gdb的方式结束。

https://stackoverflow.com/a/16493871/1737973https://sourceware.org/gdb/current/onlinedocs/gdb/Pretty-Printing.html。有没有比这些最懒的方法?

1 个答案:

答案 0 :(得分:0)

您可以做些(未经测试的)谎言:

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

,然后使用(gdb) plist values_