From 7a53fca9ab607772925c7df0794516a993a5c747 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Sun, 25 Jul 2021 17:56:35 +0200 Subject: [PATCH] LOCAL: target/xtensa: allow tweaking the list of registers sent to GDB This commit introduces two environment variables which can be used to adjust the list of registers sent from QEMU to GDB: * If QEMU_XTENSA_CORE_REGS_ONLY is set, only non-privileged registers will be sent to GDB. This behavior is compatible with Espressif builds of GDB up to esp-2021r1. * If QEMU_XTENSA_COUNT_WINDOW_REGS is set, QEMU will send window registers (a0-a15) to GDB. Enable this if you don't have a build of GDB which considers a0-a15 to be raw registers. --- target/xtensa/gdbstub.c | 6 ++++++ target/xtensa/helper.c | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/target/xtensa/gdbstub.c b/target/xtensa/gdbstub.c index fe435bac26..d571c0b6b3 100644 --- a/target/xtensa/gdbstub.c +++ b/target/xtensa/gdbstub.c @@ -46,6 +46,12 @@ void xtensa_count_regs(const XtensaConfig *config, unsigned i; bool count_core_regs = true; + /* Espressif local: allow changing the behavior here based on QEMU_XTENSA_COUNT_WINDOW_REGS + * environment variable. + */ + const char* count_window_regs_env = getenv("QEMU_XTENSA_COUNT_WINDOW_REGS"); + bool count_window_regs = count_window_regs_env != NULL && strcmp(count_window_regs_env, "0") != 0; + for (i = 0; config->gdb_regmap.reg[i].targno >= 0; ++i) { if (config->gdb_regmap.reg[i].type != xtRegisterTypeTieState && config->gdb_regmap.reg[i].type != xtRegisterTypeMapped && diff --git a/target/xtensa/helper.c b/target/xtensa/helper.c index ca214b948a..32b95d0370 100644 --- a/target/xtensa/helper.c +++ b/target/xtensa/helper.c @@ -185,6 +185,15 @@ static void xtensa_core_class_init(ObjectClass *oc, void *data) * in the gdb/xtensa-config.c inside gdb source tree or inside gdb overlay. */ cc->gdb_num_core_regs = config->gdb_regmap.num_regs; + + /* Espressif local: allow changing the behavior here using + * QEMU_XTENSA_CORE_REGS_ONLY environment variable, to support different + * GDB builds + */ + const char* core_regs_only = getenv("QEMU_XTENSA_CORE_REGS_ONLY"); + if (core_regs_only != NULL && strcmp(core_regs_only, "0") != 0) { + cc->gdb_num_core_regs = config->gdb_regmap.num_core_regs; + } } void xtensa_register_core(XtensaConfigList *node)