gdb python:如何遍历结构内的内核链接列表 [英] gdb python : How to iterate through a kernel linked list inside a structure

查看:150
本文介绍了gdb python:如何遍历结构内的内核链接列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用gdb-python脚本,我正在尝试打印包括内核数据结构和列表(例如struct list_head)的数据结构, 结构是

using gdb-python script, i am trying to print data structure which includes kernel data structures and lists(e.g. struct list_head), the structure is

struct my_struct {
  struct my_hardware_context ahw;
  struct net_device *netdev;
  struct pci_dev *pdev;
  struct list_head mac_list;
  struct list_head wait_list;
  ....
  ....
};

因此,在迭代此结构my_struct时,如何识别此结构内部存在一个链表,因为gdb手册中没有任何TYPE_CODE_常量用于链表,如果被标识,在标识后如何在迭代该列表时打印已取消引用的结构. 我在此链接

So while iterating this struct my_struct, how to identify there is a linked list inside this structure as There is no any TYPE_CODE_ constant for Linked list in gdb manual and if identified, after identification how to print the dereferenced struct while iterating the list. i am using code of scottt in this link gdb-python : Parsing structure's each field and print them with proper value, if exists

推荐答案

只有您(程序员)知道这是一个链表.即使C编译器也不知道,因此gdb也无法知道.

Only you, the programmer, know that this is a linked list. Even the C compiler does not, so therefore there is no way for gdb to know.

您可以编写一个漂亮的打印机,将这些字段视为链接列表.最简单的方法是将这些知识编码到打印机中.也就是说,让打印机的子级"方法遍历链表.

You can write a pretty-printer that treats these fields as linked lists. The simplest way is to just code this knowledge into your printer. That is, have the printer's "children" method iterate over the linked list.

可能还有其他方法,例如为list_head类型创建一个单独的漂亮打印机.

There may be other ways, for example creating a separate pretty-printer for the list_head type.

这篇关于gdb python:如何遍历结构内的内核链接列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆