sim: unify gettext/intl probing logic
[deliverable/binutils-gdb.git] / sim / common / sim-events.c
index b80dbd635169722fc07f0b724dbe6e45595f6fea..5a5798d102a8c1f03a97ecf8267cad674b8be338 100644 (file)
@@ -1,6 +1,6 @@
 /* The common simulator framework for GDB, the GNU Debugger.
 
-   Copyright 2002-2014 Free Software Foundation, Inc.
+   Copyright 2002-2021 Free Software Foundation, Inc.
 
    Contributed by Andrew Cagney and Red Hat.
 
 #ifndef _SIM_EVENTS_C_
 #define _SIM_EVENTS_C_
 
+/* This must come before any other includes.  */
+#include "defs.h"
+
 #include "sim-main.h"
 #include "sim-assert.h"
+#include "sim-cpu.h"
+#include "libiberty.h"
 
-#ifdef HAVE_STRING_H
 #include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
-
-#ifdef HAVE_STDLIB_H
 #include <stdlib.h>
-#endif
-
 #include <signal.h> /* For SIGPROCMASK et al. */
 
 typedef enum {
@@ -75,6 +70,9 @@ typedef enum {
   watch_sim_le_4,
   watch_sim_le_8,
 
+  /* pc */
+  watch_pc,
+
   /* wallclock */
   watch_clock,
 
@@ -140,21 +138,14 @@ struct _sim_event {
 
 #define _ETRACE sd, NULL
 
-#undef ETRACE_P
-#define ETRACE_P (WITH_TRACE && STATE_EVENTS (sd)->trace)
-
 #undef ETRACE
 #define ETRACE(ARGS) \
 do \
   { \
-    if (ETRACE_P) \
+    if (STRACE_EVENTS_P (sd)) \
       { \
         if (STRACE_DEBUG_P (sd)) \
-         { \
-           const char *file; \
-           SIM_FILTER_PATH (file, __FILE__); \
-           trace_printf (sd, NULL, "%s:%d: ", file, __LINE__); \
-         } \
+         trace_printf (sd, NULL, "%s:%d: ", lbasename (__FILE__), __LINE__); \
         trace_printf  ARGS; \
       } \
   } \
@@ -409,7 +400,7 @@ update_time_from_event (SIM_DESC sd)
       events->time_of_event = current_time - 1;
       events->time_from_event = -1;
     }
-  if (ETRACE_P)
+  if (STRACE_EVENTS_P (sd))
     {
       sim_event *event;
       int i;
@@ -481,10 +472,7 @@ sim_events_schedule (SIM_DESC sd,
                     sim_event_handler *handler,
                     void *data)
 {
-  va_list dummy;
-  memset (&dummy, 0, sizeof dummy);
-  return sim_events_schedule_vtracef (sd, delta_time, handler, data,
-                                     NULL, dummy);
+  return sim_events_schedule_tracef (sd, delta_time, handler, data, NULL);
 }
 #endif
 
@@ -521,7 +509,7 @@ sim_events_schedule_vtracef (SIM_DESC sd,
   new_event->data = data;
   new_event->handler = handler;
   new_event->watching = watch_timer;
-  if (fmt == NULL || !ETRACE_P || vasprintf (&new_event->trace, fmt, ap) < 0)
+  if (fmt == NULL || !STRACE_EVENTS_P (sd) || vasprintf (&new_event->trace, fmt, ap) < 0)
     new_event->trace = NULL;
   insert_sim_event (sd, new_event, delta_time);
   ETRACE ((_ETRACE,
@@ -561,7 +549,7 @@ sim_events_schedule_after_signal (SIM_DESC sd,
   if (events->nr_held > MAX_NR_SIGNAL_SIM_EVENTS)
     {
       sim_engine_abort (NULL, NULL, NULL_CIA,
-                       "sim_events_schedule_after_signal - buffer oveflow");
+                       "sim_events_schedule_after_signal - buffer overflow");
     }
 
   new_event->data = data;
@@ -624,12 +612,51 @@ 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,
                      void *host_addr,
                      int nr_bytes,
-                     int byte_order,
+                     enum bfd_endian byte_order,
                      int is_within,
                      unsigned64 lb,
                      unsigned64 ub,
@@ -641,7 +668,7 @@ sim_events_watch_sim (SIM_DESC sd,
   /* type */
   switch (byte_order)
     {
-    case 0:
+    case BFD_ENDIAN_UNKNOWN:
       switch (nr_bytes)
        {
        case 1: new_event->watching = watch_sim_host_1; break;
@@ -651,7 +678,7 @@ sim_events_watch_sim (SIM_DESC sd,
        default: sim_io_error (sd, "sim_events_watch_sim - invalid nr bytes");
        }
       break;
-    case BIG_ENDIAN:
+    case BFD_ENDIAN_BIG:
       switch (nr_bytes)
        {
        case 1: new_event->watching = watch_sim_be_1; break;
@@ -661,7 +688,7 @@ sim_events_watch_sim (SIM_DESC sd,
        default: sim_io_error (sd, "sim_events_watch_sim - invalid nr bytes");
        }
       break;
-    case LITTLE_ENDIAN:
+    case BFD_ENDIAN_LITTLE:
       switch (nr_bytes)
        {
        case 1: new_event->watching = watch_sim_le_1; break;
@@ -708,7 +735,7 @@ sim_events_watch_core (SIM_DESC sd,
                       address_word core_addr,
                       unsigned core_map,
                       int nr_bytes,
-                      int byte_order,
+                      enum bfd_endian byte_order,
                       int is_within,
                       unsigned64 lb,
                       unsigned64 ub,
@@ -720,7 +747,7 @@ sim_events_watch_core (SIM_DESC sd,
   /* type */
   switch (byte_order)
     {
-    case 0:
+    case BFD_ENDIAN_UNKNOWN:
       switch (nr_bytes)
        {
        case 1: new_event->watching = watch_core_targ_1; break;
@@ -730,7 +757,7 @@ sim_events_watch_core (SIM_DESC sd,
        default: sim_io_error (sd, "sim_events_watch_core - invalid nr bytes");
        }
       break;
-    case BIG_ENDIAN:
+    case BFD_ENDIAN_BIG:
       switch (nr_bytes)
        {
        case 1: new_event->watching = watch_core_be_1; break;
@@ -740,7 +767,7 @@ sim_events_watch_core (SIM_DESC sd,
        default: sim_io_error (sd, "sim_events_watch_core - invalid nr bytes");
        }
       break;
-    case LITTLE_ENDIAN:
+    case BFD_ENDIAN_LITTLE:
       switch (nr_bytes)
        {
        case 1: new_event->watching = watch_core_le_1; break;
@@ -981,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);
This page took 0.045863 seconds and 4 git commands to generate.