sh is sufficient, does not seem to require bash specifically
[oweals/gnunet.git] / contrib / gdb-iterate-dll.py
1 from gdb import *
2
3 def search_dll (head, field, match, pfield):
4     """
5     Search in a DLL by iterates over it.
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     symbol_val = symbol.value()
19     while symbol_val:
20         symbol_val_def = symbol_val.dereference()
21         field_val = symbol_val_def[field]
22         if field_val.type.code == gdb.TYPE_CODE_INT:
23             val = int(field_val)
24             res = (match == val)
25         elif (field_val.type.code == gdb.TYPE_CODE_STRING) or (field_val.type.code == gdb.TYPE_CODE_ARRAY):
26             val = str (field_val)
27             res = (match == val)
28         elif (field_val.type.code == gdb.TYPE_CODE_TYPEDEF):
29             val = str (field_val)
30             res = match in val
31         else:
32             continue
33
34         if res:
35             if pfield is None:
36                 print symbol_val_def
37             else:
38                 print symbol_val_def[pfield]
39         symbol_val = symbol_val_def["next"]
40
41