From d9b1deff13c53333118cb48324a95bbf099b0f2b Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 13 Jan 2021 05:58:27 -0500 Subject: sim: watch: add basic default handler that traps The default watchpoint handler is NULL. That means any port that sets the STATE_WATCHPOINTS->pc field will crash if you try to use the --watch options but don't configure the interrupt handler. In the past, you had to setup STATE_WATCHPOINTS->pc if you wanted to support PC profiling, and while that was fixed a while ago, we have a lot of ports who still configure it. We already add a default set of interrupts (just "int") if the port doesn't define any. Let's also add a default handler that raises a SIGTRAP. When connected to gdb, this is a breakpoint which is what people would expect. When running standalone, it'll abort the sim, but it's unclear whether there's anything better to do there. This really is just to make the watchpoint module more usable out of the box for most ports with very little setup, at least inside of gdb. --- sim/common/ChangeLog | 6 ++++++ sim/common/sim-watch.c | 13 ++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'sim') diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog index 76d86ea..3571c95 100644 --- a/sim/common/ChangeLog +++ b/sim/common/ChangeLog @@ -1,5 +1,11 @@ 2021-01-13 Mike Frysinger + * sim-watch.c (default_interrupt_handler): Define. + (sim_watchpoint_install): Set default interrupt_handler to new + default_interrupt_handler. + +2021-01-13 Mike Frysinger + * sim-watch.c (do_watchpoint_create): Parse arg+1 and assign to arg1. 2021-01-13 Mike Frysinger diff --git a/sim/common/sim-watch.c b/sim/common/sim-watch.c index 29ac982..6d17729 100644 --- a/sim/common/sim-watch.c +++ b/sim/common/sim-watch.c @@ -376,7 +376,16 @@ static const OPTION watchpoint_options[] = static const char *default_interrupt_names[] = { "int", 0, }; - +/* This default handler is "good enough" for targets that just want to trap into + gdb when watchpoints are hit, and have only configured STATE_WATCHPOINTS pc & + sizeof_pc fields. */ +static void +default_interrupt_handler (SIM_DESC sd, void *data) +{ + sim_cpu *cpu = STATE_CPU (sd, 0); + address_word cia = CPU_PC_GET (cpu); + sim_engine_halt (sd, cpu, NULL, cia, sim_stopped, SIM_SIGTRAP); +} SIM_RC sim_watchpoint_install (SIM_DESC sd) @@ -389,6 +398,8 @@ sim_watchpoint_install (SIM_DESC sd) /* fill in some details */ if (watch->interrupt_names == NULL) watch->interrupt_names = default_interrupt_names; + if (watch->interrupt_handler == NULL) + watch->interrupt_handler = default_interrupt_handler; watch->nr_interrupts = 0; while (watch->interrupt_names[watch->nr_interrupts] != NULL) watch->nr_interrupts++; -- cgit v1.1