本文介绍了在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打印整个链表?

解决方案

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

  define plist 
set var $ n = $ arg0-> head
while $ n
printf%d,$ n-> data
set var $ n = $ n-> next
end
end
$ b(gdb)plist myList

您可以将 plist 插入〜/ .gdbinit / p>

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 sayI defined a list

list_t* myList;

How can I use GDB to print the whole linked list?

解决方案

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

这篇关于在gdb中打印整个链表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-07 16:05