From 0a62e7ae6c1974599f128a8c00221bbfbf6c6d83 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Wed, 15 Sep 2021 23:07:49 +0200 Subject: gdb_plugins: Add $mmio_ptr function. --- gdb_plugins/mmio.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/gdb_plugins/mmio.py b/gdb_plugins/mmio.py index 25ebcc3..ea367c7 100644 --- a/gdb_plugins/mmio.py +++ b/gdb_plugins/mmio.py @@ -1,3 +1,4 @@ +import gdb import gdb.xmethod class RefWorker(gdb.xmethod.XMethodWorker): @@ -65,3 +66,28 @@ class Matcher(gdb.xmethod.XMethodMatcher): return method.worker(ptr_type) gdb.xmethod.register_xmethod_matcher(None, Matcher(), replace = True) + +def get_mmio_ptr_type(pt): + if pt.name.startswith('mmio_ptr<'): + return pt.template_argument(0) + + for field in pt.fields(): + if not field.is_base_class: + continue + + t = get_mmio_ptr_type(field.type) + + if t is not None: + return t + + return None + +class MMIOPtr(gdb.Function): + def __init__(self): + gdb.Function.__init__(self, 'mmio_ptr') + + def invoke(self, obj): + t = get_mmio_ptr_type(obj.type) + return obj['p'].cast(t.pointer()) + +MMIOPtr() -- cgit v1.2.3