3 # GDB debugging support
5 # Copyright 2012 Red Hat, Inc. and/or its affiliates
8 # Avi Kivity <avi@redhat.com>
10 # This work is licensed under the terms of the GNU GPL, version 2. See
11 # the COPYING file in the top-level directory.
13 # Contributions after 2012-01-13 are licensed under the terms of the
14 # GNU GPL, version 2 or (at your option) any later version.
16 # 'qemu mtree' -- display the memory hierarchy
21 return ptr == gdb.Value(0).cast(ptr.type)
24 return int(p['lo']) + (int(p['hi']) << 64)
26 class MtreeCommand(gdb.Command):
27 '''Display the memory tree hierarchy'''
29 gdb.Command.__init__(self, 'qemu mtree', gdb.COMMAND_DATA,
32 def invoke(self, arg, from_tty):
34 self.queue_root('address_space_memory')
35 self.queue_root('address_space_io')
37 def queue_root(self, varname):
38 ptr = gdb.parse_and_eval(varname)['root']
39 self.queue.append(ptr)
40 def process_queue(self):
42 ptr = self.queue.pop(0)
43 if int(ptr) in self.seen:
46 def print_item(self, ptr, offset = gdb.Value(0), level = 0):
47 self.seen.add(int(ptr))
50 size = int128(ptr['size'])
55 elif not isnull(ptr['ops']):
57 elif bool(ptr['ram']):
59 gdb.write('%s%016x-%016x %s%s (@ %s)\n'
62 int(addr + (size - 1)),
69 gdb.write('%s alias: %s@%016x (@ %s)\n' %
71 alias['name'].string(),
76 self.queue.append(alias)
77 subregion = ptr['subregions']['tqh_first']
79 while not isnull(subregion):
80 self.print_item(subregion, addr, level)
81 subregion = subregion['subregions_link']['tqe_next']