[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v8 03/19] gdbstub: Introduce GDBFeatureBuilder
From: |
Akihiko Odaki |
Subject: |
[PATCH v8 03/19] gdbstub: Introduce GDBFeatureBuilder |
Date: |
Sat, 16 Sep 2023 17:01:20 +0900 |
GDBFeatureBuilder unifies the logic to generate dynamic GDBFeature.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
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 071021415a..d9ef2ccbff 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);
@@ -44,6 +49,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);
+
+int 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 fd73d6d257..d63f6c0d9d 100644
--- a/gdbstub/gdbstub.c
+++ b/gdbstub/gdbstub.c
@@ -420,6 +420,65 @@ static const char *get_feature_xml(const char *p, const
char **newp,
return 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);
+}
+
+int 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);
+ }
+
+ return 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.42.0
- [PATCH v8 00/19] plugins: Allow to read registers, Akihiko Odaki, 2023/09/16
- [PATCH v8 01/19] gdbstub: Add num_regs member to GDBFeature, Akihiko Odaki, 2023/09/16
- [PATCH v8 03/19] gdbstub: Introduce GDBFeatureBuilder,
Akihiko Odaki <=
- [PATCH v8 02/19] gdbstub: Introduce gdb_find_static_feature(), Akihiko Odaki, 2023/09/16
- [PATCH v8 04/19] target/arm: Use GDBFeature for dynamic XML, Akihiko Odaki, 2023/09/16
- [PATCH v8 05/19] target/ppc: Use GDBFeature for dynamic XML, Akihiko Odaki, 2023/09/16
- [PATCH v8 06/19] target/riscv: Use GDBFeature for dynamic XML, Akihiko Odaki, 2023/09/16
- [PATCH v8 07/19] gdbstub: Use GDBFeature for gdb_register_coprocessor, Akihiko Odaki, 2023/09/16
- [PATCH v8 08/19] gdbstub: Use GDBFeature for GDBRegisterState, Akihiko Odaki, 2023/09/16
- [PATCH v8 10/19] gdbstub: Simplify XML lookup, Akihiko Odaki, 2023/09/16
- [PATCH v8 11/19] gdbstub: Infer number of core registers from XML, Akihiko Odaki, 2023/09/16
- [PATCH v8 09/19] gdbstub: Change gdb_get_reg_cb and gdb_set_reg_cb, Akihiko Odaki, 2023/09/16
- [PATCH v8 12/19] hw/core/cpu: Remove gdb_get_dynamic_xml member, Akihiko Odaki, 2023/09/16