[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 03/24] gdbstub: Add num_regs member to GDBFeature
From: |
Akihiko Odaki |
Subject: |
[RFC PATCH 03/24] gdbstub: Add num_regs member to GDBFeature |
Date: |
Mon, 31 Jul 2023 17:43:30 +0900 |
Currently the number of registers exposed to GDB is written as magic
numbers in code. Derive the number of registers GDB actually see from
XML files to replace the magic numbers in code later.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
include/exec/gdbstub.h | 1 +
scripts/feature_to_c.py | 46 +++++++++++++++++++++++++++++++++++++++--
2 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h
index bd5bc91dda..22e5add5b1 100644
--- a/include/exec/gdbstub.h
+++ b/include/exec/gdbstub.h
@@ -13,6 +13,7 @@
typedef struct GDBFeature {
const char *xmlname;
const char *xml;
+ int num_regs;
} GDBFeature;
diff --git a/scripts/feature_to_c.py b/scripts/feature_to_c.py
index 5a5b49367b..8eb8c81cf8 100755
--- a/scripts/feature_to_c.py
+++ b/scripts/feature_to_c.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
-import os, sys
+import os, sys, xml.etree.ElementTree
def writeliteral(indent, bytes):
sys.stdout.write(' ' * indent)
@@ -35,10 +35,52 @@ def writeliteral(indent, bytes):
with open(input, 'rb') as file:
read = file.read()
+ parser = xml.etree.ElementTree.XMLPullParser(['start', 'end'])
+ parser.feed(read)
+ events = parser.read_events()
+ event, element = next(events)
+ if event != 'start':
+ sys.stderr.write(f'unexpected event: {event}\n')
+ exit(1)
+ if element.tag != 'feature':
+ sys.stderr.write(f'unexpected start tag: {element.tag}\n')
+ exit(1)
+
+ regnum = 0
+ regnums = []
+ tags = ['feature']
+ for event, element in events:
+ if event == 'end':
+ if element.tag != tags[len(tags) - 1]:
+ sys.stderr.write(f'unexpected end tag: {element.tag}\n')
+ exit(1)
+
+ tags.pop()
+ if element.tag == 'feature':
+ break
+ elif event == 'start':
+ if len(tags) < 2 and element.tag == 'reg':
+ if 'regnum' in element.attrib:
+ regnum = int(element.attrib['regnum'])
+
+ regnums.append(regnum)
+ regnum += 1
+
+ tags.append(element.tag)
+ else:
+ raise Exception(f'unexpected event: {event}\n')
+
+ if len(tags):
+ sys.stderr.write('unterminated feature tag\n')
+ exit(1)
+
+ base_reg = min(regnums)
+ num_regs = max(regnums) - base_reg + 1 if len(regnums) else 0
+
sys.stdout.write(' {\n')
writeliteral(8, bytes(os.path.basename(input), 'utf-8'))
sys.stdout.write(',\n')
writeliteral(8, read)
- sys.stdout.write('\n },\n')
+ sys.stdout.write(f',\n {num_regs},\n }},\n')
sys.stdout.write(' { NULL }\n};\n')
--
2.41.0
- [RFC PATCH 00/24] plugins: Allow to read registers, Akihiko Odaki, 2023/07/31
- [RFC PATCH 01/24] contrib/plugins: Use GRWLock in execlog, Akihiko Odaki, 2023/07/31
- [RFC PATCH 02/24] gdbstub: Introduce GDBFeature structure, Akihiko Odaki, 2023/07/31
- [RFC PATCH 03/24] gdbstub: Add num_regs member to GDBFeature,
Akihiko Odaki <=
- [RFC PATCH 04/24] gdbstub: Introduce gdb_find_static_feature(), Akihiko Odaki, 2023/07/31
- [RFC PATCH 05/24] target/arm: Move the reference to arm-core.xml, Akihiko Odaki, 2023/07/31
- [RFC PATCH 06/24] hw/core/cpu: Replace gdb_core_xml_file with gdb_core_feature, Akihiko Odaki, 2023/07/31
- [RFC PATCH 08/24] target/ppc: Use GDBFeature for dynamic XML, Akihiko Odaki, 2023/07/31
- [RFC PATCH 07/24] target/arm: Use GDBFeature for dynamic XML, Akihiko Odaki, 2023/07/31