sim: watchpoints: use common sim_pc_get
authorMike Frysinger <vapier@gentoo.org>
Mon, 23 Mar 2015 04:44:54 +0000 (00:44 -0400)
committerMike Frysinger <vapier@gentoo.org>
Sat, 6 Feb 2021 17:12:51 +0000 (12:12 -0500)
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.

25 files changed:
sim/ChangeLog
sim/README-HACKING
sim/avr/ChangeLog
sim/avr/interp.c
sim/bfin/ChangeLog
sim/bfin/interp.c
sim/common/ChangeLog
sim/common/sim-events.c
sim/common/sim-events.h
sim/common/sim-watch.c
sim/common/sim-watch.h
sim/frv/ChangeLog
sim/frv/sim-if.c
sim/iq2000/ChangeLog
sim/iq2000/sim-if.c
sim/m32r/ChangeLog
sim/m32r/sim-if.c
sim/mips/ChangeLog
sim/mips/interp.c
sim/mn10300/ChangeLog
sim/mn10300/interp.c
sim/moxie/ChangeLog
sim/moxie/interp.c
sim/v850/ChangeLog
sim/v850/interp.c

index e98229177aa578fa705f384b130c8faf1c0ce25e..0c53c9646610d01566b87779cbe38803c74924df 100644 (file)
@@ -1,3 +1,7 @@
+2021-02-06  Mike Frysinger  <vapier@gentoo.org>
+
+       * README-HACKING: Replace STATE_WATCHPOINTS with CPU_PC_FETCH.
+
 2021-02-06  Mike Frysinger  <vapier@gentoo.org>
 
        * configure.ac (HDEFINES): Delete AC_SUBST call.
index 9953f99fc81d0534a4caaa43b25b28ec497dd8c6..2f985bd2e7f9a3297dddcb03d7663c5f7c0fe28c 100644 (file)
@@ -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:
index 505e284ce3b58621d357b9fdb56435df4f21a33a..b67888b9ec559f90d79d2a21459f61b6a590dba6 100644 (file)
@@ -1,3 +1,7 @@
+2021-02-06  Mike Frysinger  <vapier@gentoo.org>
+
+       * interp.c (sim_open): Delete call to STATE_WATCHPOINTS.
+
 2021-02-06  Mike Frysinger  <vapier@gentoo.org>
 
        * configure: Regenerate.
index ba89eb532d9bf0d0d9485d57f63358575320d811..cce84a97f220fb23cd5bc86cef64b39ba7f34623 100644 (file)
@@ -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);
index ee76d3eb9922277e2af24330274fa5c1707c45a0..7643141ab2872cb77ce3357464170b057aadb28b 100644 (file)
@@ -1,3 +1,7 @@
+2021-02-06  Mike Frysinger  <vapier@gentoo.org>
+
+       * interp.c (sim_open): Delete call to STATE_WATCHPOINTS.
+
 2021-02-06  Mike Frysinger  <vapier@gentoo.org>
 
        * configure: Regenerate.
index ef23de3ede76534217466e60230e4cd0cde7c4b1..ceb5939f4e6b10281a6c426d8020d1ad294f3545 100644 (file)
@@ -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);
index 1351cd05d48e7b987c20853be3bfe9a0196eabcc..ba0febf73ac01e7c1f3944e0eac2e0bd613b2f02 100644 (file)
@@ -1,3 +1,14 @@
+2021-02-06  Mike Frysinger  <vapier@gentoo.org>
+
+       * 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  <vapier@gentoo.org>
 
        * acinclude.m4 (SIM_AC_COMMON): Replace AC_CONFIG_HEADER with
index 6dd0474d91ace9a341eafe80e15a943b2ea4b730..207c8674d168ce94ccefa0175d68fd9682282f1a 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "sim-main.h"
 #include "sim-assert.h"
+#include "sim-cpu.h"
 #include "libiberty.h"
 
 #include <string.h>
@@ -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);
index 823fd8c946c07decd6c4b1d89310b17da53abbb8..7a5fc9665d2118799ee290a811df7bb4f19dd73a 100644 (file)
@@ -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.
index 9ccd472465a81233efbe813edf5f0605c7330593..8630b063bb65967144d600fe81c36b293d273f80 100644 (file)
@@ -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,
index 52a8d12795dc1d974bc322f95eb366f80c9e0d9e..bbe2029c08f23d8b8d715707b6c607d07e4f794f 100644 (file)
@@ -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? */
index 47c4bea280eb3096d57c973390edbf3f72edb279..1223fe17176b5379d3d9f5f7efc959c299a1142d 100644 (file)
@@ -1,3 +1,7 @@
+2021-02-06  Mike Frysinger  <vapier@gentoo.org>
+
+       * sim-if.c (sim_open): Delete call to STATE_WATCHPOINTS.
+
 2021-02-06  Mike Frysinger  <vapier@gentoo.org>
 
        * configure: Regenerate.
index bea84002cd3a919b5e73fc2cd018093a23957f1f..45cbd1618a4126d7062b5a6da375bef7de2c7562 100644 (file)
@@ -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);
index d5816bf2a36e3a0f6101f62d2487c32ed0c1cbac..7ab017fd46bb91e971f33a4163ad0bb769e86dd0 100644 (file)
@@ -1,3 +1,7 @@
+2021-02-06  Mike Frysinger  <vapier@gentoo.org>
+
+       * sim-if.c (sim_open): Delete call to STATE_WATCHPOINTS.
+
 2021-02-06  Mike Frysinger  <vapier@gentoo.org>
 
        * configure: Regenerate.
index de90e731c1a62306a8713783dfb464f50a2571d8..496b10659ea9394d01b26cb50a1f54115f3fc4a2 100644 (file)
@@ -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);
index b3b5823c5108d5f44d1b5885e9d655d993b4d7ec..42c35060a09008ae7f609149a496e5ba5cd813d8 100644 (file)
@@ -1,3 +1,7 @@
+2021-02-06  Mike Frysinger  <vapier@gentoo.org>
+
+       * sim-if.c (sim_open): Delete call to STATE_WATCHPOINTS.
+
 2021-02-06  Mike Frysinger  <vapier@gentoo.org>
 
        * configure: Regenerate.
index 2d2f5e47cb4c0490bf050308cea9234d182ee282..58d46946eb72e3609bfa46963856c4cc6ba50015 100644 (file)
@@ -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);
index 1fb767c43b454abc1f82af4c698a832d031f4044..b3da89b070f277d60430bbb06ac9ae3c27781d13 100644 (file)
@@ -1,3 +1,7 @@
+2021-02-06  Mike Frysinger  <vapier@gentoo.org>
+
+       * interp.c (sim_open): Delete call to STATE_WATCHPOINTS.
+
 2021-02-06  Mike Frysinger  <vapier@gentoo.org>
 
        * configure: Regenerate.
index 852f362eb40d6891eb69d19f53d58899d88dacb5..fd93a12f69a08975133a8d2a83f65d2ffc21cd98 100644 (file)
@@ -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.  */
index 44f8cbed4f9dc39b6542c4f63c55a9628ba6f047..7eefac9e78fde612b371cc2005b6b721d60e458d 100644 (file)
@@ -1,3 +1,7 @@
+2021-02-06  Mike Frysinger  <vapier@gentoo.org>
+
+       * interp.c (sim_open): Delete call to STATE_WATCHPOINTS.
+
 2021-02-06  Mike Frysinger  <vapier@gentoo.org>
 
        * 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.
-
index c41797a855bf1f52a7f46204408b027e6885d802..1c9c6905afcb54ce5aa7bd8cc464f6f708ceec29 100644 (file)
@@ -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;
 
index 193933dc6538ea2aa1db9fcc4afb81f491f5619a..a1206bd319a06b82ddc7d3a131924b7aa0b9967a 100644 (file)
@@ -1,3 +1,7 @@
+2021-02-06  Mike Frysinger  <vapier@gentoo.org>
+
+       * interp.c (sim_open): Delete call to STATE_WATCHPOINTS.
+
 2021-02-06  Mike Frysinger  <vapier@gentoo.org>
 
        * configure: Regenerate.
index 87e1c157542c17d81886c421486557b1bc6eedca..da97397c506020928a78489de88f36cb0bde64c8 100644 (file)
@@ -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);
index 5085030e67df5f8514fe814b388eec55e19a8dd9..d981a027b58747b5b2759a3a2918ec5ad71ed5cc 100644 (file)
@@ -1,3 +1,7 @@
+2021-02-06  Mike Frysinger  <vapier@gentoo.org>
+
+       * interp.c (sim_open): Delete call to STATE_WATCHPOINTS.
+
 2021-02-06  Mike Frysinger  <vapier@gentoo.org>
 
        * configure: Regenerate.
index 24d7ddc297d389e4d4ff2c6a488d05c0d801e1e9..76ecab7f7bfddfe91d4c46676f535d60216ef00c 100644 (file)
@@ -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;