Some targets, including x86, have no GDB register named "pc" (x86 uses eip/rip). When the GDB register lookup fails for "$pc" in HMP expressions, fall back to CPUClass::get_pc so that "p $pc", "x $pc" etc. work without relying on the legacy MonitorDef table.
This prepares for the eventual removal of MonitorDef while making $pc available immediately for all targets that implement get_pc. Signed-off-by: Marc-André Lureau <[email protected]> --- monitor/hmp.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/monitor/hmp.c b/monitor/hmp.c index 10e19e417aba..0a74247ca66a 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -402,7 +402,7 @@ void hmp_help_cmd(MonitorHMP *mon, const char *name) * Set @pval to the value in the register identified by @name. * return %true if the register is found, %false otherwise. */ -static bool gdb_get_register(MonitorHMP *hmp, int64_t *pval, const char *name) +static bool get_register(MonitorHMP *hmp, int64_t *pval, const char *name) { g_autoptr(GArray) regs = NULL; CPUState *cs = monitor_hmp_get_cpu(hmp); @@ -435,6 +435,10 @@ static bool gdb_get_register(MonitorHMP *hmp, int64_t *pval, const char *name) } return true; } + if (!strcmp(name, "pc") && cs->cc->get_pc) { + *pval = cs->cc->get_pc(cs); + return true; + } return false; } @@ -526,7 +530,7 @@ static int64_t expr_unary(MonitorHMP *mon) pch++; } *q = 0; - if (!gdb_get_register(mon, ®, buf) + if (!get_register(mon, ®, buf) && get_monitor_def(mon, ®, buf) < 0) { expr_error(mon, "unknown register"); } -- 2.55.0.543.g5ebe2ebe4ea8
