2 # GDB debugging support
4 # Copyright 2012 Red Hat, Inc. and/or its affiliates
7 # Avi Kivity <avi@redhat.com>
9 # This work is licensed under the terms of the GNU GPL, version 2 or
10 # later. See the COPYING file in the top-level directory.
12 # 'qemu mtree' -- display the memory hierarchy
17 return ptr
== gdb
.Value(0).cast(ptr
.type)
20 '''Read an Int128 type to a python integer.
22 QEMU can be built with native Int128 support so we need to detect
23 if the value is a structure or the native type.
25 if p
.type.code
== gdb
.TYPE_CODE_STRUCT
:
26 return int(p
['lo']) + (int(p
['hi']) << 64)
28 return int(("%s" % p
), 16)
30 class MtreeCommand(gdb
.Command
):
31 '''Display the memory tree hierarchy'''
33 gdb
.Command
.__init
__(self
, 'qemu mtree', gdb
.COMMAND_DATA
,
36 def invoke(self
, arg
, from_tty
):
38 self
.queue_root('address_space_memory')
39 self
.queue_root('address_space_io')
41 def queue_root(self
, varname
):
42 ptr
= gdb
.parse_and_eval(varname
)['root']
43 self
.queue
.append(ptr
)
44 def process_queue(self
):
46 ptr
= self
.queue
.pop(0)
47 if int(ptr
) in self
.seen
:
50 def print_item(self
, ptr
, offset
= gdb
.Value(0), level
= 0):
51 self
.seen
.add(int(ptr
))
54 size
= int128(ptr
['size'])
59 elif not isnull(ptr
['ops']):
61 elif bool(ptr
['ram']):
63 gdb
.write('%s%016x-%016x %s%s (@ %s)\n'
66 int(addr
+ (size
- 1)),
73 gdb
.write('%s alias: %s@%016x (@ %s)\n' %
75 alias
['name'].string(),
76 int(ptr
['alias_offset']),
80 self
.queue
.append(alias
)
81 subregion
= ptr
['subregions']['tqh_first']
83 while not isnull(subregion
):
84 self
.print_item(subregion
, addr
, level
)
85 subregion
= subregion
['subregions_link']['tqe_next']