使用gdb-python脚本,我尝试打印包含内核数据结构和列表的数据结构(例如结构list_head),结构是
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_常量,如果识别了,在识别之后,如何在迭代列表时打印解引用的结构。我在这个链接gdb-python : Parsing structure's each field and print them with proper value, if exists中使用了scottt的代码
发布于 2013-05-30 22:46:29
只有你,程序员,知道这是一个链表。即使是C编译器也不知道,因此gdb没有办法知道。
您可以编写一个漂亮的打印机,将这些字段视为链表。最简单的方法是将这些知识编码到您的打印机中。也就是说,让打印机的“子”方法遍历链表。
可能还有其他方法,例如为list_head类型创建单独的漂亮打印机。
https://stackoverflow.com/questions/16834166
复制相似问题