【问题标题】:Print the whole linked list in gdb?在 gdb 中打印整个链表?
【发布时间】:2013-05-10 10:18:14
【问题描述】:

我有一个链表

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 打印整个链表?

【问题讨论】:

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


【解决方案1】:

这应该可以工作(但未经测试):

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

【讨论】:

  • @TimothyLeung 在(gdb) 提示符处剪切/粘贴代码,或使用编辑器将代码放入~/.gdbinit
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-14
    • 1970-01-01
    • 1970-01-01
    • 2021-12-21
    • 2021-01-23
    • 1970-01-01
    • 2017-07-10
    相关资源
    最近更新 更多