aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/gdb/linux/utils.py
diff options
context:
space:
mode:
authorJan Kiszka <jan.kiszka@siemens.com>2015-02-17 16:46:38 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-02-17 17:34:53 -0500
commit2b514827ef06fd69e1739e7f367712619dee7784 (patch)
treec222ab179c1a2af790106882f1b560d417281891 /scripts/gdb/linux/utils.py
parent3ee7b3fa2cd0182628cca8d9bb5ce2d4722e8dc5 (diff)
scripts/gdb: add cache for type objects
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> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Jason Wessel <jason.wessel@windriver.com> Cc: Andi Kleen <andi@firstfloor.org> Cc: Ben Widawsky <ben@bwidawsk.net> Cc: Borislav Petkov <bp@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts/gdb/linux/utils.py')
-rw-r--r--scripts/gdb/linux/utils.py34
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
14import gdb
15
16
17class 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