3 # GDB debugging support
5 # Copyright 2012 Red Hat, Inc. and/or its affiliates
10 # This work is licensed under the terms of the GNU GPL, version 2 or
11 # later. See the COPYING file in the top-level directory.
13 # 'qemu mtree' -- display the memory hierarchy
18 return ptr == gdb.Value(0).cast(ptr.type)
21 '''Read an Int128 type to a python integer.
23 QEMU can be built with native Int128 support so we need to detect
24 if the value is a structure or the native type.
26 if p.type.code == gdb.TYPE_CODE_STRUCT:
27 return int(p['lo']) + (int(p['hi']) << 64)
29 return int(("%s" % p), 16)
31 class MtreeCommand(gdb.Command):
32 '''Display the memory tree hierarchy'''
34 gdb.Command.__init__(self, 'qemu mtree', gdb.COMMAND_DATA,
37 def invoke(self, arg, from_tty):
39 self.queue_root('address_space_memory')
40 self.queue_root('address_space_io')
42 def queue_root(self, varname):
43 ptr = gdb.parse_and_eval(varname)['root']
44 self.queue.append(ptr)
45 def process_queue(self):
47 ptr = self.queue.pop(0)
48 if int(ptr) in self.seen:
51 def print_item(self, ptr, offset = gdb.Value(0), level = 0):
52 self.seen.add(int(ptr))
55 size = int128(ptr['size'])
60 elif not isnull(ptr['ops']):
62 elif bool(ptr['ram']):
64 gdb.write('%s%016x-%016x %s%s (@ %s)\n'
67 int(addr + (size - 1)),
74 gdb.write('%s alias: %s@%016x (@ %s)\n' %
76 alias['name'].string(),
77 int(ptr['alias_offset']),
81 self.queue.append(alias)
82 subregion = ptr['subregions']['tqh_first']
84 while not isnull(subregion):
85 self.print_item(subregion, addr, level)
86 subregion = subregion['subregions_link']['tqe_next']