aboutsummaryrefslogtreecommitdiff
path: root/sim
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2021-01-13 05:58:27 -0500
committerMike Frysinger <vapier@gentoo.org>2021-01-13 21:53:11 -0500
commitd9b1deff13c53333118cb48324a95bbf099b0f2b (patch)
treeb650df9a337606b5dc30d39338f0fb54775de71f /sim
parent8f66807b98f7634c43149ea62e454ea8f877691d (diff)
downloadgdb-d9b1deff13c53333118cb48324a95bbf099b0f2b.zip
gdb-d9b1deff13c53333118cb48324a95bbf099b0f2b.tar.gz
gdb-d9b1deff13c53333118cb48324a95bbf099b0f2b.tar.bz2
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.
Diffstat (limited to 'sim')
-rw-r--r--sim/common/ChangeLog6
-rw-r--r--sim/common/sim-watch.c13
2 files changed, 18 insertions, 1 deletions
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 <vapier@gentoo.org>
+ * sim-watch.c (default_interrupt_handler): Define.
+ (sim_watchpoint_install): Set default interrupt_handler to new
+ default_interrupt_handler.
+
+2021-01-13 Mike Frysinger <vapier@gentoo.org>
+
* sim-watch.c (do_watchpoint_create): Parse arg+1 and assign to arg1.
2021-01-13 Mike Frysinger <vapier@gentoo.org>
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++;