在gdb中打印整个链表?

时间:2013-05-10 10:18:14

标签: c++ debugging ubuntu data-structures gdb

我有一个链表

struct node {
    data_t data;
    node_t *next;
};

typedef struct {
    node_t *head;
    node_t *foot;
    node_t *curr;   // for iterator
    unsigned int size;
} list_t;
用这种结构说吧 我定义了一个列表

list_t* myList;

如何使用GDB打印整个链表?

2 个答案:

答案 0 :(得分:11)

这应该有效(但未经测试):

define plist
  set var $n = $arg0->head
  while $n
    printf "%d ", $n->data
    set var $n = $n->next
  end
end

(gdb) plist myList

您可以将plist加入~/.gdbinit

答案 1 :(得分:2)

GDB可以用Python编写脚本。你可以define your own pretty-printers做其他有用的事情。

更好的是,使用标准容器,GDB现在支持本地打印。

相关问题