简体   繁体   English

在gdb中打印整个链表?

[英]Print the whole linked list in gdb?

I have a linked list 我有一个链表

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;

with this structure, let say I defined a list 有了这个结构,就说我定义了一个列表

list_t* myList;

How can I use GDB to print the whole linked list? 如何使用GDB打印整个链表?

This should work (but untested): 这应该工作(但未经测试):

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

(gdb) plist myList

You could put plist into ~/.gdbinit 你可以将plist放入~/.gdbinit

GDB is scriptable in Python. GDB可以用Python编写脚本。 You can define your own pretty-printers and do other useful things. 您可以定义自己的漂亮打印机并执行其他有用的操作。

Better yet, use a standard container, GDB now supports printing those natively. 更好的是,使用标准容器,GDB现在支持本地打印。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM