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')
56 for event
, element
in events
:
58 if element
.tag
!= tags
[len(tags
) - 1]:
59 sys
.stderr
.write(f
'unexpected end tag: {element.tag}\n')
63 if element
.tag
== 'feature':
65 elif event
== 'start':
66 if len(tags
) < 2 and element
.tag
== 'reg':
67 if 'regnum' in element
.attrib
:
68 regnum
= int(element
.attrib
['regnum'])
70 regnums
.append(regnum
)
73 tags
.append(element
.tag
)
75 raise Exception(f
'unexpected event: {event}\n')
78 sys
.stderr
.write('unterminated feature tag\n')
81 base_reg
= min(regnums
)
82 num_regs
= max(regnums
) - base_reg
+ 1 if len(regnums
) else 0
84 sys
.stdout
.write(' {\n')
85 writeliteral(8, bytes(os
.path
.basename(input), 'utf-8'))
86 sys
.stdout
.write(',\n')
88 sys
.stdout
.write(f
',\n {num_regs},\n }},\n')
90 sys
.stdout
.write(' { NULL }\n};\n')