[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 07/25] gdbstub: Introduce GDBFeatureBuilder
From: |
Akihiko Odaki |
Subject: |
[PATCH v3 07/25] gdbstub: Introduce GDBFeatureBuilder |
Date: |
Wed, 16 Aug 2023 22:39:17 +0900 |
GDBFeatureBuilder unifies the logic to generate dynamic GDBFeature.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
include/exec/gdbstub.h | 20 ++++++++++++++
gdbstub/gdbstub.c | 59 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 79 insertions(+)
diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h
index d0dcc99ed4..1f4608d4f9 100644
--- a/include/exec/gdbstub.h
+++ b/include/exec/gdbstub.h
@@ -16,6 +16,11 @@ typedef struct GDBFeature {
int num_regs;
} GDBFeature;
+typedef struct GDBFeatureBuilder {
+ GDBFeature *feature;
+ GPtrArray *xml;
+} GDBFeatureBuilder;
+
/* Get or set a register. Returns the size of the register. */
typedef int (*gdb_get_reg_cb)(CPUArchState *env, GByteArray *buf, int reg);
@@ -34,6 +39,21 @@ void gdb_register_coprocessor(CPUState *cpu,
*/
int gdbserver_start(const char *port_or_device);
+void gdb_feature_builder_init(GDBFeatureBuilder *builder, GDBFeature *feature,
+ const char *name, const char *xmlname);
+
+void gdb_feature_builder_append_tag(const GDBFeatureBuilder *builder,
+ const char *format, ...)
+ G_GNUC_PRINTF(2, 3);
+
+void gdb_feature_builder_append_reg(const GDBFeatureBuilder *builder,
+ const char *name,
+ int bitsize,
+ const char *type,
+ const char *group);
+
+void gdb_feature_builder_end(const GDBFeatureBuilder *builder);
+
const GDBFeature *gdb_find_static_feature(const char *xmlname);
void gdb_set_stop_cpu(CPUState *cpu);
diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
index 293e8ea439..32e88de431 100644
--- a/gdbstub/gdbstub.c
+++ b/gdbstub/gdbstub.c
@@ -414,6 +414,65 @@ static const char *get_feature_xml(const char *p, const
char **newp,
return name ? gdb_static_features[i].xml : NULL;
}
+void gdb_feature_builder_init(GDBFeatureBuilder *builder, GDBFeature *feature,
+ const char *name, const char *xmlname)
+{
+ char *header = g_markup_printf_escaped(
+ "<?xml version=\"1.0\"?>"
+ "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">"
+ "<feature name=\"%s\">",
+ name);
+
+ builder->feature = feature;
+ builder->xml = g_ptr_array_new();
+ g_ptr_array_add(builder->xml, header);
+ feature->xmlname = xmlname;
+ feature->num_regs = 0;
+}
+
+void gdb_feature_builder_append_tag(const GDBFeatureBuilder *builder,
+ const char *format, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+ g_ptr_array_add(builder->xml, g_markup_vprintf_escaped(format, ap));
+ va_end(ap);
+}
+
+void gdb_feature_builder_append_reg(const GDBFeatureBuilder *builder,
+ const char *name,
+ int bitsize,
+ const char *type,
+ const char *group)
+{
+ if (group) {
+ gdb_feature_builder_append_tag(
+ builder,
+ "<reg name=\"%s\" bitsize=\"%d\" type=\"%s\" group=\"%s\"/>",
+ name, bitsize, type, group);
+ } else {
+ gdb_feature_builder_append_tag(
+ builder, "<reg name=\"%s\" bitsize=\"%d\" type=\"%s\"/>",
+ name, bitsize, type);
+ }
+
+ builder->feature->num_regs++;
+}
+
+void gdb_feature_builder_end(const GDBFeatureBuilder *builder)
+{
+ g_ptr_array_add(builder->xml, (void *)"</feature>");
+ g_ptr_array_add(builder->xml, NULL);
+
+ builder->feature->xml = g_strjoinv(NULL, (void *)builder->xml->pdata);
+
+ for (guint i = 0; i < builder->xml->len - 2; i++) {
+ g_free(g_ptr_array_index(builder->xml, i));
+ }
+
+ g_ptr_array_free(builder->xml, TRUE);
+}
+
const GDBFeature *gdb_find_static_feature(const char *xmlname)
{
const GDBFeature *feature;
--
2.41.0
- [PATCH v3 00/25] plugins: Allow to read registers, Akihiko Odaki, 2023/08/16
- [PATCH v3 02/25] gdbstub: Introduce GDBFeature structure, Akihiko Odaki, 2023/08/16
- [PATCH v3 01/25] contrib/plugins: Use GRWLock in execlog, Akihiko Odaki, 2023/08/16
- [PATCH v3 03/25] gdbstub: Add num_regs member to GDBFeature, Akihiko Odaki, 2023/08/16
- [PATCH v3 04/25] gdbstub: Introduce gdb_find_static_feature(), Akihiko Odaki, 2023/08/16
- [PATCH v3 05/25] target/arm: Move the reference to arm-core.xml, Akihiko Odaki, 2023/08/16
- [PATCH v3 06/25] hw/core/cpu: Replace gdb_core_xml_file with gdb_core_feature, Akihiko Odaki, 2023/08/16
- [PATCH v3 07/25] gdbstub: Introduce GDBFeatureBuilder,
Akihiko Odaki <=
- [PATCH v3 08/25] target/arm: Use GDBFeature for dynamic XML, Akihiko Odaki, 2023/08/16
- [PATCH v3 09/25] target/ppc: Use GDBFeature for dynamic XML, Akihiko Odaki, 2023/08/16
- [PATCH v3 10/25] target/riscv: Use GDBFeature for dynamic XML, Akihiko Odaki, 2023/08/16
- [PATCH v3 11/25] gdbstub: Use GDBFeature for gdb_register_coprocessor, Akihiko Odaki, 2023/08/16
- [PATCH v3 12/25] gdbstub: Use GDBFeature for GDBRegisterState, Akihiko Odaki, 2023/08/16
- [PATCH v3 13/25] hw/core/cpu: Return static value with gdb_arch_name(), Akihiko Odaki, 2023/08/16
- [PATCH v3 14/25] gdbstub: Dynamically allocate target.xml buffer, Akihiko Odaki, 2023/08/16
- [PATCH v3 15/25] gdbstub: Simplify XML lookup, Akihiko Odaki, 2023/08/16
- [PATCH v3 16/25] hw/core/cpu: Remove gdb_get_dynamic_xml member, Akihiko Odaki, 2023/08/16
- [PATCH v3 17/25] gdbstub: Add members to identify registers to GDBFeature, Akihiko Odaki, 2023/08/16