[PATCH v5 02/20] scripts/gdb: Add cache for type objects
From: Jan Kiszka
Date: Tue Jan 29 2013 - 07:38:50 EST
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@xxxxxxxxxxx>
---
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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/