target/arm/vfp_helper: Extract vfp_set_fpscr_to_host()
[qemu/ar7.git] / scripts / qemugdb / mtree.py
blob3030a60d3f317b16cd3181bf230e93bb78cb44a0
1 #!/usr/bin/python
3 # GDB debugging support
5 # Copyright 2012 Red Hat, Inc. and/or its affiliates
7 # Authors:
8 # Avi Kivity <avi@redhat.com>
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
15 import gdb
17 def isnull(ptr):
18 return ptr == gdb.Value(0).cast(ptr.type)
20 def int128(p):
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.
25 '''
26 if p.type.code == gdb.TYPE_CODE_STRUCT:
27 return int(p['lo']) + (int(p['hi']) << 64)
28 else:
29 return int(("%s" % p), 16)
31 class MtreeCommand(gdb.Command):
32 '''Display the memory tree hierarchy'''
33 def __init__(self):
34 gdb.Command.__init__(self, 'qemu mtree', gdb.COMMAND_DATA,
35 gdb.COMPLETE_NONE)
36 self.queue = []
37 def invoke(self, arg, from_tty):
38 self.seen = set()
39 self.queue_root('address_space_memory')
40 self.queue_root('address_space_io')
41 self.process_queue()
42 def queue_root(self, varname):
43 ptr = gdb.parse_and_eval(varname)['root']
44 self.queue.append(ptr)
45 def process_queue(self):
46 while self.queue:
47 ptr = self.queue.pop(0)
48 if int(ptr) in self.seen:
49 continue
50 self.print_item(ptr)
51 def print_item(self, ptr, offset = gdb.Value(0), level = 0):
52 self.seen.add(int(ptr))
53 addr = ptr['addr']
54 addr += offset
55 size = int128(ptr['size'])
56 alias = ptr['alias']
57 klass = ''
58 if not isnull(alias):
59 klass = ' (alias)'
60 elif not isnull(ptr['ops']):
61 klass = ' (I/O)'
62 elif bool(ptr['ram']):
63 klass = ' (RAM)'
64 gdb.write('%s%016x-%016x %s%s (@ %s)\n'
65 % (' ' * level,
66 int(addr),
67 int(addr + (size - 1)),
68 ptr['name'].string(),
69 klass,
70 ptr,
72 gdb.STDOUT)
73 if not isnull(alias):
74 gdb.write('%s alias: %s@%016x (@ %s)\n' %
75 (' ' * level,
76 alias['name'].string(),
77 int(ptr['alias_offset']),
78 alias,
80 gdb.STDOUT)
81 self.queue.append(alias)
82 subregion = ptr['subregions']['tqh_first']
83 level += 1
84 while not isnull(subregion):
85 self.print_item(subregion, addr, level)
86 subregion = subregion['subregions_link']['tqe_next']