/* 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 {
watch_sim_le_4,
watch_sim_le_8,
+ /* pc */
+ watch_pc,
+
/* wallclock */
watch_clock,
#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; \
} \
} \
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;
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
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,
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;
#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,
/* type */
switch (byte_order)
{
- case 0:
+ case BFD_ENDIAN_UNKNOWN:
switch (nr_bytes)
{
case 1: new_event->watching = watch_sim_host_1; break;
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;
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;
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,
/* type */
switch (byte_order)
{
- case 0:
+ case BFD_ENDIAN_UNKNOWN:
switch (nr_bytes)
{
case 1: new_event->watching = watch_core_targ_1; break;
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;
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;
}
#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);