Messages in this thread Patch in this message |  | | From | Jan Kiszka <> | Subject | [PATCH v5 02/20] scripts/gdb: Add cache for type objects | Date | Tue, 29 Jan 2013 13:37:45 +0100 |
| |
Type lookups are very slow in gdb-python which is often noticeable when iterating over a number of objects. Introduce the helper class CachedType that keeps a reference to a gdb.Type object but also refreshes it after an object file has been loaded.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> --- scripts/gdb/utils.py | 21 +++++++++++++++++++++ 1 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/scripts/gdb/utils.py b/scripts/gdb/utils.py index f75eae6..fdff85e 100644 --- a/scripts/gdb/utils.py +++ b/scripts/gdb/utils.py @@ -15,3 +15,24 @@ import gdb import re gdb_version = re.sub("^[^0-9]*", "", gdb.VERSION) + + +class CachedType: + _type = None + + def _new_objfile_handler(self, event): + self._type = None + gdb.events.new_objfile.disconnect(self._new_objfile_handler) + + def __init__(self, name): + self._name = name + + def get_type(self): + if self._type == None: + self._type = gdb.lookup_type(self._name) + if self._type == None: + raise gdb.GdbError("cannot resolve " \ + "type '%s'" % self._name) + gdb.events.new_objfile.connect( + self._new_objfile_handler) + return self._type -- 1.7.3.4
|  |