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 '''Read an Int128 type to a python integer.
26 QEMU can be built with native Int128 support so we need to detect
27 if the value is a structure or the native type.
29 if p
.type.code
== gdb
.TYPE_CODE_STRUCT
:
30 return int(p
['lo']) + (int(p
['hi']) << 64)
32 return int(("%s" % p
), 16)
34 class MtreeCommand(gdb
.Command
):
35 '''Display the memory tree hierarchy'''
37 gdb
.Command
.__init
__(self
, 'qemu mtree', gdb
.COMMAND_DATA
,
40 def invoke(self
, arg
, from_tty
):
42 self
.queue_root('address_space_memory')
43 self
.queue_root('address_space_io')
45 def queue_root(self
, varname
):
46 ptr
= gdb
.parse_and_eval(varname
)['root']
47 self
.queue
.append(ptr
)
48 def process_queue(self
):
50 ptr
= self
.queue
.pop(0)
51 if int(ptr
) in self
.seen
:
54 def print_item(self
, ptr
, offset
= gdb
.Value(0), level
= 0):
55 self
.seen
.add(int(ptr
))
58 size
= int128(ptr
['size'])
63 elif not isnull(ptr
['ops']):
65 elif bool(ptr
['ram']):
67 gdb
.write('%s%016x-%016x %s%s (@ %s)\n'
70 int(addr
+ (size
- 1)),
77 gdb
.write('%s alias: %s@%016x (@ %s)\n' %
79 alias
['name'].string(),
80 int(ptr
['alias_offset']),
84 self
.queue
.append(alias
)
85 subregion
= ptr
['subregions']['tqh_first']
87 while not isnull(subregion
):
88 self
.print_item(subregion
, addr
, level
)
89 subregion
= subregion
['subregions_link']['tqe_next']