diff options
Diffstat (limited to 'contrib/scripts/gdb-iterate-dll.py')
-rw-r--r-- | contrib/scripts/gdb-iterate-dll.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/contrib/scripts/gdb-iterate-dll.py b/contrib/scripts/gdb-iterate-dll.py new file mode 100644 index 000000000..388ef6e11 --- /dev/null +++ b/contrib/scripts/gdb-iterate-dll.py | |||
@@ -0,0 +1,43 @@ | |||
1 | from __future__ import print_function | ||
2 | from __future__ import unicode_literals | ||
3 | from builtins import str | ||
4 | from gdb import * | ||
5 | |||
6 | |||
7 | def search_dll(head, field, match, pfield): | ||
8 | """ | ||
9 | Search in a DLL by iterates over it. | ||
10 | |||
11 | head: name of the symbol denoting the head of the DLL | ||
12 | field: the field that should be search for match | ||
13 | match: the mathing value for field | ||
14 | pfield: the field whose value is to be printed for matched elements; None to | ||
15 | print all fields of the matched elemented | ||
16 | """ | ||
17 | |||
18 | (symbol, _) = lookup_symbol(head) | ||
19 | if symbol is None: | ||
20 | print("Can't find symbol: " + head) | ||
21 | return | ||
22 | symbol_val = symbol.value() | ||
23 | while symbol_val: | ||
24 | symbol_val_def = symbol_val.dereference() | ||
25 | field_val = symbol_val_def[field] | ||
26 | if field_val.type.code == gdb.TYPE_CODE_INT: | ||
27 | val = int(field_val) | ||
28 | res = (match == val) | ||
29 | elif (field_val.type.code == gdb.TYPE_CODE_STRING) or (field_val.type.code == gdb.TYPE_CODE_ARRAY): | ||
30 | val = str(field_val) | ||
31 | res = (match == val) | ||
32 | elif (field_val.type.code == gdb.TYPE_CODE_TYPEDEF): | ||
33 | val = str(field_val) | ||
34 | res = match in val | ||
35 | else: | ||
36 | continue | ||
37 | |||
38 | if res: | ||
39 | if pfield is None: | ||
40 | print(symbol_val_def) | ||
41 | else: | ||
42 | print(symbol_val_def[pfield]) | ||
43 | symbol_val = symbol_val_def["next"] | ||