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.
20 return ptr == gdb.Value(0).cast(ptr.type)
23 return long(p['lo']) + (long(p['hi']) << 64)
25 class QemuCommand(gdb.Command):
26 '''Prefix for QEMU debug support commands'''
28 gdb.Command.__init__(self, 'qemu', gdb.COMMAND_DATA,
29 gdb.COMPLETE_NONE, True)
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 long(ptr) in self.seen:
51 def print_item(self, ptr, offset = gdb.Value(0), level = 0):
52 self.seen.add(long(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 long(addr + (size - 1)),
74 gdb.write('%s alias: %s@%016x (@ %s)\n' %
76 alias['name'].string(),
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']