2 # SPDX-License-Identifier: GPL-2.0-or-later
4 import os
, sys
, xml
.etree
.ElementTree
6 def writeliteral(indent
, bytes
):
7 sys
.stdout
.write(' ' * indent
)
13 sys
.stdout
.write('\n')
14 sys
.stdout
.write(' ' * indent
)
19 sys
.stdout
.write('\\"')
21 sys
.stdout
.write('\\\\')
23 sys
.stdout
.write('\\n"')
25 elif c
>= 32 and c
< 127:
26 sys
.stdout
.write(c
.to_bytes(1, 'big').decode())
28 sys
.stdout
.write(f
'\{c:03o}')
33 sys
.stdout
.write('#include "qemu/osdep.h"\n' \
34 '#include "exec/gdbstub.h"\n' \
36 'const GDBFeature gdb_static_features[] = {\n')
38 for input in sys
.argv
[1:]:
39 with
open(input, 'rb') as file:
42 parser
= xml
.etree
.ElementTree
.XMLPullParser(['start', 'end'])
44 events
= parser
.read_events()
45 event
, element
= next(events
)
47 sys
.stderr
.write(f
'unexpected event: {event}\n')
49 if element
.tag
!= 'feature':
50 sys
.stderr
.write(f
'unexpected start tag: {element.tag}\n')
53 feature_name
= element
.attrib
['name']
58 for event
, element
in events
:
60 if element
.tag
!= tags
[len(tags
) - 1]:
61 sys
.stderr
.write(f
'unexpected end tag: {element.tag}\n')
65 if element
.tag
== 'feature':
67 elif event
== 'start':
68 if len(tags
) < 2 and element
.tag
== 'reg':
69 if 'regnum' in element
.attrib
:
70 regnum
= int(element
.attrib
['regnum'])
72 regnames
.append(element
.attrib
['name'])
73 regnums
.append(regnum
)
76 tags
.append(element
.tag
)
78 raise Exception(f
'unexpected event: {event}\n')
81 sys
.stderr
.write('unterminated feature tag\n')
84 base_reg
= min(regnums
)
85 num_regs
= max(regnums
) - base_reg
+ 1 if len(regnums
) else 0
87 sys
.stdout
.write(' {\n')
88 writeliteral(8, bytes(os
.path
.basename(input), 'utf-8'))
89 sys
.stdout
.write(',\n')
91 sys
.stdout
.write(',\n')
92 writeliteral(8, bytes(feature_name
, 'utf-8'))
93 sys
.stdout
.write(',\n (const char * const []) {\n')
95 for index
, regname
in enumerate(regnames
):
96 sys
.stdout
.write(f
' [{regnums[index] - base_reg}] =\n')
97 writeliteral(16, bytes(regname
, 'utf-8'))
98 sys
.stdout
.write(',\n')
100 sys
.stdout
.write(f
' }},\n {num_regs},\n }},\n')
102 sys
.stdout
.write(' { NULL }\n};\n')