Skip to content

Commit 956af7d

Browse files
akihikodakistsquad
authored andcommitted
gdbstub: Introduce GDBFeature structure
Before this change, the information from a XML file was stored in an array that is not descriptive. Introduce a dedicated structure type to make it easier to understand and to extend with more fields. Signed-off-by: Akihiko Odaki <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Reviewed-by: Alex Bennée <[email protected]> Reviewed-by: Richard Henderson <[email protected]> Message-Id: <[email protected]> Signed-off-by: Alex Bennée <[email protected]> Message-Id: <[email protected]>
1 parent 1063693 commit 956af7d

File tree

7 files changed

+63
-79
lines changed

7 files changed

+63
-79
lines changed

MAINTAINERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2842,7 +2842,7 @@ F: include/exec/gdbstub.h
28422842
F: include/gdbstub/*
28432843
F: gdb-xml/
28442844
F: tests/tcg/multiarch/gdbstub/
2845-
F: scripts/feature_to_c.sh
2845+
F: scripts/feature_to_c.py
28462846
F: scripts/probe-gdb-support.py
28472847

28482848
Memory API

gdbstub/gdbstub.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,11 @@ static const char *get_feature_xml(const char *p, const char **newp,
408408
}
409409
}
410410
/* Is it one of the encoded gdb-xml/ files? */
411-
for (int i = 0; xml_builtin[i][0]; i++) {
412-
const char *name = xml_builtin[i][0];
411+
for (int i = 0; gdb_static_features[i].xmlname; i++) {
412+
const char *name = gdb_static_features[i].xmlname;
413413
if ((strncmp(name, p, len) == 0) &&
414414
strlen(name) == len) {
415-
return xml_builtin[i][1];
415+
return gdb_static_features[i].xml;
416416
}
417417
}
418418

include/exec/gdbstub.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
#define GDB_WATCHPOINT_READ 3
1111
#define GDB_WATCHPOINT_ACCESS 4
1212

13+
typedef struct GDBFeature {
14+
const char *xmlname;
15+
const char *xml;
16+
} GDBFeature;
17+
1318

1419
/* Get or set a register. Returns the size of the register. */
1520
typedef int (*gdb_get_reg_cb)(CPUArchState *env, GByteArray *buf, int reg);
@@ -48,7 +53,7 @@ void gdb_set_stop_cpu(CPUState *cpu);
4853
*/
4954
bool gdb_has_xml(void);
5055

51-
/* in gdbstub-xml.c, generated by scripts/feature_to_c.sh */
52-
extern const char *const xml_builtin[][2];
56+
/* in gdbstub-xml.c, generated by scripts/feature_to_c.py */
57+
extern const GDBFeature gdb_static_features[];
5358

5459
#endif

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3693,7 +3693,7 @@ common_all = static_library('common',
36933693
dependencies: common_all.dependencies(),
36943694
name_suffix: 'fa')
36953695

3696-
feature_to_c = find_program('scripts/feature_to_c.sh')
3696+
feature_to_c = find_program('scripts/feature_to_c.py')
36973697

36983698
if targetos == 'darwin'
36993699
entitlement = find_program('scripts/entitlement.sh')

scripts/feature_to_c.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python3
2+
# SPDX-License-Identifier: GPL-2.0-or-later
3+
4+
import os, sys
5+
6+
def writeliteral(indent, bytes):
7+
sys.stdout.write(' ' * indent)
8+
sys.stdout.write('"')
9+
quoted = True
10+
11+
for c in bytes:
12+
if not quoted:
13+
sys.stdout.write('\n')
14+
sys.stdout.write(' ' * indent)
15+
sys.stdout.write('"')
16+
quoted = True
17+
18+
if c == b'"'[0]:
19+
sys.stdout.write('\\"')
20+
elif c == b'\\'[0]:
21+
sys.stdout.write('\\\\')
22+
elif c == b'\n'[0]:
23+
sys.stdout.write('\\n"')
24+
quoted = False
25+
elif c >= 32 and c < 127:
26+
sys.stdout.write(c.to_bytes(1, 'big').decode())
27+
else:
28+
sys.stdout.write(f'\{c:03o}')
29+
30+
if quoted:
31+
sys.stdout.write('"')
32+
33+
sys.stdout.write('#include "qemu/osdep.h"\n' \
34+
'#include "exec/gdbstub.h"\n' \
35+
'\n'
36+
'const GDBFeature gdb_static_features[] = {\n')
37+
38+
for input in sys.argv[1:]:
39+
with open(input, 'rb') as file:
40+
read = file.read()
41+
42+
sys.stdout.write(' {\n')
43+
writeliteral(8, bytes(os.path.basename(input), 'utf-8'))
44+
sys.stdout.write(',\n')
45+
writeliteral(8, read)
46+
sys.stdout.write('\n },\n')
47+
48+
sys.stdout.write(' { NULL }\n};\n')

scripts/feature_to_c.sh

Lines changed: 0 additions & 69 deletions
This file was deleted.

stubs/gdbstub.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "qemu/osdep.h"
2-
#include "exec/gdbstub.h" /* xml_builtin */
2+
#include "exec/gdbstub.h" /* gdb_static_features */
33

4-
const char *const xml_builtin[][2] = {
5-
{ NULL, NULL }
4+
const GDBFeature gdb_static_features[] = {
5+
{ NULL }
66
};

0 commit comments

Comments
 (0)