gdb python : How to iterate through a kernel linked list inside a structure

早过忘川 提交于 2019-12-24 20:48:46

问题


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;
  ....
  ....
};

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


回答1:


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.

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



来源:https://stackoverflow.com/questions/16834166/gdb-python-how-to-iterate-through-a-kernel-linked-list-inside-a-structure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!