lkml.org 
[lkml]   [2013]   [Jan]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v5 02/20] scripts/gdb: Add cache for type objects
Date
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


\
 
 \ /
  Last update: 2013-01-29 14:21    [W:0.140 / U:0.892 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site