23b4b5fc7d92bd71eeda2d03f7b689cb207f8625
[oweals/gnunet.git] / contrib / gdb-iterate-dll.py
1 from gdb import *
2
3 def iterate_dll (head, field, match, pfield):
4     """
5     Iterates over a DLL data structure
6
7     head: name of the symbol denoting the head of the DLL
8     field: the field that should be search for match
9     match: the mathing value for field
10     pfield: the field whose value is to be printed for matched elements; None to
11       print all fields of the matched elemented
12     """
13
14     (symbol, _) = lookup_symbol (head)
15     if symbol is None:
16         print "Can't find symbol: " + head
17         return    
18     while not symbol:
19         symbol_val = symbol.value().derefence
20         if match == symbol_val[field]:
21             if pfield is None:
22                 print symbol_val
23             else:
24                 print symbol_val[pfield]
25         symbol = symbol_val["next"]
26
27