From 4c0d76b9c420bb29cb3365c5edc9c78c50d2b231 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 23 Mar 2015 00:44:54 -0400 Subject: [PATCH] sim: watchpoints: use common sim_pc_get Few arches implement STATE_WATCHPOINTS()->pc while all of them implement sim_pc_get. Lets switch the sim-watch core for monitoring pc events to the sim_pc_get API so this module works for all ports, and then we can delete this old back channel of snooping in the port's cpu state -- the code needs the pointer to the pc storage so that it can read out bytes and compare them to the watchrange. This also fixes the logic on multi-cpu sims by removing the limitation of only being able to watch CPU0's state. --- sim/ChangeLog | 4 +++ sim/README-HACKING | 4 +-- sim/avr/ChangeLog | 4 +++ sim/avr/interp.c | 6 ----- sim/bfin/ChangeLog | 4 +++ sim/bfin/interp.c | 6 ----- sim/common/ChangeLog | 11 ++++++++ sim/common/sim-events.c | 58 +++++++++++++++++++++++++++++++++++++++++ sim/common/sim-events.h | 11 ++++++++ sim/common/sim-watch.c | 16 +++++------- sim/common/sim-watch.h | 1 - sim/frv/ChangeLog | 4 +++ sim/frv/sim-if.c | 8 ------ sim/iq2000/ChangeLog | 4 +++ sim/iq2000/sim-if.c | 8 ------ sim/m32r/ChangeLog | 4 +++ sim/m32r/sim-if.c | 8 ------ sim/mips/ChangeLog | 4 +++ sim/mips/interp.c | 1 - sim/mn10300/ChangeLog | 5 +++- sim/mn10300/interp.c | 1 - sim/moxie/ChangeLog | 4 +++ sim/moxie/interp.c | 2 -- sim/v850/ChangeLog | 4 +++ sim/v850/interp.c | 1 - 25 files changed, 129 insertions(+), 54 deletions(-) diff --git a/sim/ChangeLog b/sim/ChangeLog index e98229177aa..0c53c964661 100644 --- a/sim/ChangeLog +++ b/sim/ChangeLog @@ -1,3 +1,7 @@ +2021-02-06 Mike Frysinger + + * README-HACKING: Replace STATE_WATCHPOINTS with CPU_PC_FETCH. + 2021-02-06 Mike Frysinger * configure.ac (HDEFINES): Delete AC_SUBST call. diff --git a/sim/README-HACKING b/sim/README-HACKING index 9953f99fc81..2f985bd2e7f 100644 --- a/sim/README-HACKING +++ b/sim/README-HACKING @@ -267,8 +267,8 @@ And in your insn fetcher: PROFILE_COUNT_CORE (cpu, target_addr, size_in_bytes, map_exec); To use the PC profiling code, you simply have to tell the system where to find -your simulator's PC. So in your sim_open() function: - STATE_WATCHPOINTS (sd)->pc = address_of_cpu0_pc; +your simulator's PC. So in your model initialization function: + CPU_PC_FETCH (cpu) = function_that_fetches_the_pc; To profile branches, in every location where a branch insn is executed, call one of the related helpers: diff --git a/sim/avr/ChangeLog b/sim/avr/ChangeLog index 505e284ce3b..b67888b9ec5 100644 --- a/sim/avr/ChangeLog +++ b/sim/avr/ChangeLog @@ -1,3 +1,7 @@ +2021-02-06 Mike Frysinger + + * interp.c (sim_open): Delete call to STATE_WATCHPOINTS. + 2021-02-06 Mike Frysinger * configure: Regenerate. diff --git a/sim/avr/interp.c b/sim/avr/interp.c index ba89eb532d9..cce84a97f22 100644 --- a/sim/avr/interp.c +++ b/sim/avr/interp.c @@ -1690,12 +1690,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb, return 0; } - { - /* XXX: Only first core gets profiled ? */ - SIM_CPU *cpu = STATE_CPU (sd, 0); - STATE_WATCHPOINTS (sd)->pc = &cpu->pc; - } - if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK) { free_state (sd); diff --git a/sim/bfin/ChangeLog b/sim/bfin/ChangeLog index ee76d3eb992..7643141ab28 100644 --- a/sim/bfin/ChangeLog +++ b/sim/bfin/ChangeLog @@ -1,3 +1,7 @@ +2021-02-06 Mike Frysinger + + * interp.c (sim_open): Delete call to STATE_WATCHPOINTS. + 2021-02-06 Mike Frysinger * configure: Regenerate. diff --git a/sim/bfin/interp.c b/sim/bfin/interp.c index ef23de3ede7..ceb5939f4e6 100644 --- a/sim/bfin/interp.c +++ b/sim/bfin/interp.c @@ -729,12 +729,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *callback, return 0; } - { - /* XXX: Only first core gets profiled ? */ - SIM_CPU *cpu = STATE_CPU (sd, 0); - STATE_WATCHPOINTS (sd)->pc = &PCREG; - } - if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK) { free_state (sd); diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog index 1351cd05d48..ba0febf73ac 100644 --- a/sim/common/ChangeLog +++ b/sim/common/ChangeLog @@ -1,3 +1,14 @@ +2021-02-06 Mike Frysinger + + * sim-events.c: Include sim-cpu.h. + (sim_event_watchpoints): Define watch_pc. + (sim_events_watch_pc): New function. + (WATCH_SIM): Handle watch_pc. + * sim-events.h (sim_events_watch_pc): New prototype. + * sim-watch.c (schedule_watchpoint): Replace sim_events_watch_sim with + sim_events_watch_pc. + * sim-watch.h (sim_watchpoints): Delete pc. + 2021-02-06 Mike Frysinger * acinclude.m4 (SIM_AC_COMMON): Replace AC_CONFIG_HEADER with diff --git a/sim/common/sim-events.c b/sim/common/sim-events.c index 6dd0474d91a..207c8674d16 100644 --- a/sim/common/sim-events.c +++ b/sim/common/sim-events.c @@ -25,6 +25,7 @@ #include "sim-main.h" #include "sim-assert.h" +#include "sim-cpu.h" #include "libiberty.h" #include @@ -66,6 +67,9 @@ typedef enum { watch_sim_le_4, watch_sim_le_8, + /* pc */ + watch_pc, + /* wallclock */ watch_clock, @@ -608,6 +612,45 @@ sim_events_watch_clock (SIM_DESC sd, #endif +#if EXTERN_SIM_EVENTS_P +sim_event * +sim_events_watch_pc (SIM_DESC sd, + int is_within, + unsigned64 lb, + unsigned64 ub, + sim_event_handler *handler, + void *data) +{ + sim_events *events = STATE_EVENTS (sd); + sim_event *new_event = sim_events_zalloc (sd); + /* type */ + new_event->watching = watch_pc; + /* handler */ + new_event->data = data; + new_event->handler = handler; + /* data */ + new_event->lb = lb; + new_event->lb64 = lb; + new_event->ub = ub; + new_event->ub64 = ub; + new_event->is_within = (is_within != 0); + /* insert */ + new_event->next = events->watchpoints; + events->watchpoints = new_event; + events->work_pending = 1; + ETRACE ((_ETRACE, + "event watching pc at %ld - tag 0x%lx - pc 0x%lx..0x%lx, handler 0x%lx, data 0x%lx\n", + (long)sim_events_time (sd), + (long)new_event, + (long)new_event->lb, + (long)new_event->ub, + (long)new_event->handler, + (long)new_event->data)); + return new_event; +} +#endif + + #if EXTERN_SIM_EVENTS_P sim_event * sim_events_watch_sim (SIM_DESC sd, @@ -965,6 +1008,21 @@ sim_watch_valid (SIM_DESC sd, } #undef WATCH_SIM + case watch_pc: + { + int c; + + for (c = 0; c < MAX_NR_PROCESSORS; ++c) + { + sim_cpu *cpu = STATE_CPU (sd, c); + sim_cia cia = sim_pc_get (cpu); + + if (to_do->is_within == (cia >= to_do->lb64 && cia <= to_do->ub64)) + return 1; + } + return 0; + } + case watch_clock: /* wallclock */ { unsigned long elapsed_time = sim_events_elapsed_time (sd); diff --git a/sim/common/sim-events.h b/sim/common/sim-events.h index 823fd8c946c..7a5fc9665d2 100644 --- a/sim/common/sim-events.h +++ b/sim/common/sim-events.h @@ -149,6 +149,17 @@ extern sim_event *sim_events_watch_clock void *data); +/* Schedule an event when a PC matches a range. */ + +extern sim_event *sim_events_watch_pc +(SIM_DESC sd, + int is_within, + unsigned64 lb, + unsigned64 ub, + sim_event_handler *handler, + void *data); + + /* Schedule an event when the test (IS_WITHIN == (VAL >= LB && VAL <= UB)) of the NR_BYTES value at HOST_ADDR with BYTE_ORDER endian is true. diff --git a/sim/common/sim-watch.c b/sim/common/sim-watch.c index 9ccd472465a..8630b063bb6 100644 --- a/sim/common/sim-watch.c +++ b/sim/common/sim-watch.c @@ -167,18 +167,16 @@ schedule_watchpoint (SIM_DESC sd, sim_watch_point *point) { sim_watchpoints *watch = STATE_WATCHPOINTS (sd); + switch (point->type) { case pc_watchpoint: - point->event = sim_events_watch_sim (sd, - watch->pc, - sizeof (sim_cia), - HOST_BYTE_ORDER, - point->is_within, - point->arg0, point->arg1, - /* PC in arg0..arg1 */ - handle_watchpoint, - point); + point->event = sim_events_watch_pc (sd, + point->is_within, + point->arg0, point->arg1, + /* PC in arg0..arg1 */ + handle_watchpoint, + point); return SIM_RC_OK; case clock_watchpoint: point->event = sim_events_watch_clock (sd, diff --git a/sim/common/sim-watch.h b/sim/common/sim-watch.h index 52a8d12795d..bbe2029c08f 100644 --- a/sim/common/sim-watch.h +++ b/sim/common/sim-watch.h @@ -49,7 +49,6 @@ typedef struct _sim_watchpoints { address/size of the program-counter */ /* FIXME: In the future this shall be generalized so that any of the N processors M registers can be watched */ - void *pc; /* Pointer to the handler for interrupt watchpoints */ /* FIXME: can this be done better? */ diff --git a/sim/frv/ChangeLog b/sim/frv/ChangeLog index 47c4bea280e..1223fe17176 100644 --- a/sim/frv/ChangeLog +++ b/sim/frv/ChangeLog @@ -1,3 +1,7 @@ +2021-02-06 Mike Frysinger + + * sim-if.c (sim_open): Delete call to STATE_WATCHPOINTS. + 2021-02-06 Mike Frysinger * configure: Regenerate. diff --git a/sim/frv/sim-if.c b/sim/frv/sim-if.c index bea84002cd3..45cbd1618a4 100644 --- a/sim/frv/sim-if.c +++ b/sim/frv/sim-if.c @@ -61,14 +61,6 @@ sim_open (kind, callback, abfd, argv) return 0; } -#if 0 /* FIXME: pc is in mach-specific struct */ - /* FIXME: watchpoints code shouldn't need this */ - { - SIM_CPU *current_cpu = STATE_CPU (sd, 0); - STATE_WATCHPOINTS (sd)->pc = &(PC); - } -#endif - if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK) { free_state (sd); diff --git a/sim/iq2000/ChangeLog b/sim/iq2000/ChangeLog index d5816bf2a36..7ab017fd46b 100644 --- a/sim/iq2000/ChangeLog +++ b/sim/iq2000/ChangeLog @@ -1,3 +1,7 @@ +2021-02-06 Mike Frysinger + + * sim-if.c (sim_open): Delete call to STATE_WATCHPOINTS. + 2021-02-06 Mike Frysinger * configure: Regenerate. diff --git a/sim/iq2000/sim-if.c b/sim/iq2000/sim-if.c index de90e731c1a..496b10659ea 100644 --- a/sim/iq2000/sim-if.c +++ b/sim/iq2000/sim-if.c @@ -67,14 +67,6 @@ sim_open (kind, callback, abfd, argv) return 0; } -#if 0 /* FIXME: pc is in mach-specific struct */ - /* FIXME: watchpoints code shouldn't need this */ - { - SIM_CPU *current_cpu = STATE_CPU (sd, 0); - STATE_WATCHPOINTS (sd)->pc = &(PC); - } -#endif - if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK) { free_state (sd); diff --git a/sim/m32r/ChangeLog b/sim/m32r/ChangeLog index b3b5823c510..42c35060a09 100644 --- a/sim/m32r/ChangeLog +++ b/sim/m32r/ChangeLog @@ -1,3 +1,7 @@ +2021-02-06 Mike Frysinger + + * sim-if.c (sim_open): Delete call to STATE_WATCHPOINTS. + 2021-02-06 Mike Frysinger * configure: Regenerate. diff --git a/sim/m32r/sim-if.c b/sim/m32r/sim-if.c index 2d2f5e47cb4..58d46946eb7 100644 --- a/sim/m32r/sim-if.c +++ b/sim/m32r/sim-if.c @@ -61,14 +61,6 @@ sim_open (kind, callback, abfd, argv) return 0; } -#if 0 /* FIXME: pc is in mach-specific struct */ - /* FIXME: watchpoints code shouldn't need this */ - { - SIM_CPU *current_cpu = STATE_CPU (sd, 0); - STATE_WATCHPOINTS (sd)->pc = &(PC); - } -#endif - if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK) { free_state (sd); diff --git a/sim/mips/ChangeLog b/sim/mips/ChangeLog index 1fb767c43b4..b3da89b070f 100644 --- a/sim/mips/ChangeLog +++ b/sim/mips/ChangeLog @@ -1,3 +1,7 @@ +2021-02-06 Mike Frysinger + + * interp.c (sim_open): Delete call to STATE_WATCHPOINTS. + 2021-02-06 Mike Frysinger * configure: Regenerate. diff --git a/sim/mips/interp.c b/sim/mips/interp.c index 852f362eb40..fd93a12f69a 100644 --- a/sim/mips/interp.c +++ b/sim/mips/interp.c @@ -355,7 +355,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb, cpu = STATE_CPU (sd, 0); /* FIXME */ /* FIXME: watchpoints code shouldn't need this */ - STATE_WATCHPOINTS (sd)->pc = &(PC); STATE_WATCHPOINTS (sd)->interrupt_handler = interrupt_event; /* Initialize the mechanism for doing insn profiling. */ diff --git a/sim/mn10300/ChangeLog b/sim/mn10300/ChangeLog index 44f8cbed4f9..7eefac9e78f 100644 --- a/sim/mn10300/ChangeLog +++ b/sim/mn10300/ChangeLog @@ -1,3 +1,7 @@ +2021-02-06 Mike Frysinger + + * interp.c (sim_open): Delete call to STATE_WATCHPOINTS. + 2021-02-06 Mike Frysinger * configure: Regenerate. @@ -1573,4 +1577,3 @@ Mon Nov 25 12:46:38 1996 Jeffrey A Law (law@cygnus.com) * Makefile.in, config.in, configure, configure.in: New files. * gencode.c, interp.c, mn10300_sim.h, simops.c: New files. - diff --git a/sim/mn10300/interp.c b/sim/mn10300/interp.c index c41797a855b..1c9c6905afc 100644 --- a/sim/mn10300/interp.c +++ b/sim/mn10300/interp.c @@ -102,7 +102,6 @@ sim_open (SIM_OPEN_KIND kind, /* FIXME: should be better way of setting up interrupts. For moment, only support watchpoints causing a breakpoint (gdb halt). */ - STATE_WATCHPOINTS (sd)->pc = &(PC); STATE_WATCHPOINTS (sd)->interrupt_handler = NULL; STATE_WATCHPOINTS (sd)->interrupt_names = NULL; diff --git a/sim/moxie/ChangeLog b/sim/moxie/ChangeLog index 193933dc653..a1206bd319a 100644 --- a/sim/moxie/ChangeLog +++ b/sim/moxie/ChangeLog @@ -1,3 +1,7 @@ +2021-02-06 Mike Frysinger + + * interp.c (sim_open): Delete call to STATE_WATCHPOINTS. + 2021-02-06 Mike Frysinger * configure: Regenerate. diff --git a/sim/moxie/interp.c b/sim/moxie/interp.c index 87e1c157542..da97397c506 100644 --- a/sim/moxie/interp.c +++ b/sim/moxie/interp.c @@ -1203,8 +1203,6 @@ sim_open (SIM_OPEN_KIND kind, host_callback *cb, return 0; } - STATE_WATCHPOINTS (sd)->pc = &cpu.asregs.regs[PC_REGNO]; - if (sim_pre_argv_init (sd, argv[0]) != SIM_RC_OK) { free_state (sd); diff --git a/sim/v850/ChangeLog b/sim/v850/ChangeLog index 5085030e67d..d981a027b58 100644 --- a/sim/v850/ChangeLog +++ b/sim/v850/ChangeLog @@ -1,3 +1,7 @@ +2021-02-06 Mike Frysinger + + * interp.c (sim_open): Delete call to STATE_WATCHPOINTS. + 2021-02-06 Mike Frysinger * configure: Regenerate. diff --git a/sim/v850/interp.c b/sim/v850/interp.c index 24d7ddc297d..76ecab7f7bf 100644 --- a/sim/v850/interp.c +++ b/sim/v850/interp.c @@ -202,7 +202,6 @@ sim_open (SIM_OPEN_KIND kind, simulator = sd; /* FIXME: should be better way of setting up interrupts */ - STATE_WATCHPOINTS (sd)->pc = &(PC); STATE_WATCHPOINTS (sd)->interrupt_handler = do_interrupt; STATE_WATCHPOINTS (sd)->interrupt_names = interrupt_names; -- 2.39.2