0
用gdb的Python腳本中,我試圖打印數據結構,其中包括內核數據結構和列表(例如結構LIST_HEAD), 結構GDB的Python:如何通過內核鏈表迭代結構
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_不變,鑑定後如何打印解除引用的結構,而迭代名單。 我在此鏈接中使用scottt代碼gdb-python : Parsing structure's each field and print them with proper value, if exists
@Tromey,我無法實現這一點。因爲要打印內核列表的內容(例如,mac_list或wait_list等),它需要使用正確的類型進行類型轉換。 例如對於wait_list這將是這樣的: '(GDB)P *(qlcnic_wait_event_t *)(((結構my_struct *)dev_base->下一步 - >私法).wait_list)' 我發現這種類型(qlcnic_wait_event_t)從源代碼手動進行類型轉換。 有沒有什麼辦法以編程方式獲取每個列表的相應類型?你可以請求提供樣品嗎?並有'list_for_each_entry'宏在gdb python中實現? –
gdb沒有list_for_each_entry。也許有人會用python來。 gdb只能看到編譯器看到的內容,所以它沒有辦法猜測鏈表的正確類型。你可以以某種方式提供你自己。 –