diff options
Diffstat (limited to 'scripts/gdb/linux/utils.py')
| -rw-r--r-- | scripts/gdb/linux/utils.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/scripts/gdb/linux/utils.py b/scripts/gdb/linux/utils.py new file mode 100644 index 000000000000..f88361130e4c --- /dev/null +++ b/scripts/gdb/linux/utils.py | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | # | ||
| 2 | # gdb helper commands and functions for Linux kernel debugging | ||
| 3 | # | ||
| 4 | # common utilities | ||
| 5 | # | ||
| 6 | # Copyright (c) Siemens AG, 2011-2013 | ||
| 7 | # | ||
| 8 | # Authors: | ||
| 9 | # Jan Kiszka <jan.kiszka@siemens.com> | ||
| 10 | # | ||
| 11 | # This work is licensed under the terms of the GNU GPL version 2. | ||
| 12 | # | ||
| 13 | |||
| 14 | import gdb | ||
| 15 | |||
| 16 | |||
| 17 | class CachedType: | ||
| 18 | def __init__(self, name): | ||
| 19 | self._type = None | ||
| 20 | self._name = name | ||
| 21 | |||
| 22 | def _new_objfile_handler(self, event): | ||
| 23 | self._type = None | ||
| 24 | gdb.events.new_objfile.disconnect(self._new_objfile_handler) | ||
| 25 | |||
| 26 | def get_type(self): | ||
| 27 | if self._type is None: | ||
| 28 | self._type = gdb.lookup_type(self._name) | ||
| 29 | if self._type is None: | ||
| 30 | raise gdb.GdbError( | ||
| 31 | "cannot resolve type '{0}'".format(self._name)) | ||
| 32 | if hasattr(gdb, 'events') and hasattr(gdb.events, 'new_objfile'): | ||
| 33 | gdb.events.new_objfile.connect(self._new_objfile_handler) | ||
| 34 | return self._type | ||
