728747363306fdc97738f943a030114bd8ab8302
[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 symbol:
19         symbol_val = symbol.value().derefence
20         field_val = symbol_val[field]
21         if field_val.type.code == gdb.TYPE_CODE_INT:
22             val = int(field_val)
23             res = (match == val)
24         if (field_val.type.code == gdb.TYPE_CODE_STRING)
25            or (filed_val.type.code == gdb.TYPE_CODE_ARRAY):
26             val = str (field_val)
27             res = (match == val)
28         if (field_val.type.code == gdb.TYPE_CODE_TYPEDEF):
29             val = str (field_val)
30             res = match in val
31
32         if res:
33             if pfield is None:
34                 print symbol_val
35             else:
36                 print symbol_val[pfield]
37         symbol = symbol_val["next"]
38
39