Commit 2b514827 authored by Jan Kiszka's avatar Jan Kiszka Committed by Linus Torvalds
Browse files

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's avatarJan Kiszka <>
Cc: Thomas Gleixner <>
Cc: Jason Wessel <>
Cc: Andi Kleen <>
Cc: Ben Widawsky <>
Cc: Borislav Petkov <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 3ee7b3fa
# gdb helper commands and functions for Linux kernel debugging
# common utilities
# Copyright (c) Siemens AG, 2011-2013
# Authors:
# Jan Kiszka <>
# This work is licensed under the terms of the GNU GPL version 2.
import gdb
class CachedType:
def __init__(self, name):
self._type = None
self._name = name
def _new_objfile_handler(self, event):
self._type = None
def get_type(self):
if self._type is None:
self._type = gdb.lookup_type(self._name)
if self._type is None:
raise gdb.GdbError(
"cannot resolve type '{0}'".format(self._name))
if hasattr(gdb, 'events') and hasattr(, 'new_objfile'):
return self._type
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment