* PATCH: Use target values for signals in simulator
@ 2005-11-23 19:56 mitchell
2005-11-25 19:11 ` Daniel Jacobowitz
0 siblings, 1 reply; 8+ messages in thread
From: mitchell @ 2005-11-23 19:56 UTC (permalink / raw)
To: gdb-patches
At present, when the GDB simulators report signals to GDB, they use
the host signal numbers. That leads to the problem that different
hosts have different sets of signals, so things like:
#ifndef SIGTRAP
#define SIGTRAP 5
#endif
appear in some the simulators -- and the ones that don't won't build
on some systems, notably Windows.
The #ifdef hack works, in practice, but isn't really correct; we don't
know that no other signal has the value 5. Also, some of the
simulators translate a simulated SIGBUS as SIGSEGV on systems without
SIGBUS, meaning that the behavior of the simulator depends on the host
system -- clearly undesirable.
There's been a comment about this problem in gdbsim_wait for some
time. Both the comment and Daniel Jacobowitz suggest that the right
solution is for the simulator to communicate with GDB using the
TARGET_SIGNAL_* enumeration in gdb/signals.h. Then, there's no need
for the #ifdefs, and no host dependency.
This patch implements that change.
The principal risk with this patch is that I may have failed to
translate from one of the various simulator's internal representation
of a signal to the appropriate TARGET_SIGNAL_ value. However, because
TARGET_SIGNAL_* uses the conventional UNIX values for signals to the
extent there are conventions (like, TARGET_SIGNAL_SEGV is 11 and
TARGET_SIGNAL_TRAP is 5) it's unlikely that any places I missed will
actually matter.
In other words, the simulators were already translating to the host
signal numbers, which, in practice, are very likely to match up with
TARGET_SIGNAL_* -- especially since most of the simulators generate a
pretty limited set of signals. So, if I missed a spot, it's very
likely that the values are correct anyhow. Therefore, I think this
patch is pretty safe.
I will of course clean up any fall-out. (I realize the ChangeLog
below will require separation into the ChangeLogs in the various
subdirectories.) I tested this patch by debugging PowerPC EABI
programs in simulation.
OK to apply?
Thanks,
--
2005-11-16 Mark Mitchell <mark@codesourcery.com>
* gdb/remote-sim.c (gdbsim_wait): Don't use target_signal_to_host
or target_signal_from_host.
* sim/arm/wrapper.c (gdb/signals.h): Include it.
(SIGTRAP): Don't define it.
(SIGBUS): Likewise.
(sim_stop_reason): Use TARGET_SIGNAL_*.
* sim/common/sim-reason.c (sim_stop_reason): Use
sim_signal_to_target, not sim_signal_to_host.
* sim/common/sim-signal.c (sim_signal_to_host): Fix typo.
(sim_signal_to_target): New function.
* sim/common/sim-signal.h: Declare it.
* sim/d10v/interp.c (gdb/signals.h): Include it.
(sim_stop_reason): Use TARGET_SIGNAL_*.
* sim/erc32/interf.c: (gdb/signals.h): Include it.
(sim_stop_reason): Use TARGET_SIGNAL_*.
* sim/ppc/sim_calls.c (gdb/signals.h): Include it.
(sim_stop_reason): Use TARGET_SIGNAL_*.
Index: gdb/remote-sim.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-sim.c,v
retrieving revision 1.49
retrieving revision 1.49.6.1
diff -c -5 -p -r1.49 -r1.49.6.1
*** gdb/remote-sim.c 19 Jun 2005 20:08:37 -0000 1.49
--- gdb/remote-sim.c 17 Nov 2005 06:22:44 -0000 1.49.6.1
*************** gdbsim_wait (ptid_t ptid, struct target_
*** 672,683 ****
prev_sigint = osa.sa_handler;
}
#else
prev_sigint = signal (SIGINT, gdbsim_cntrl_c);
#endif
! sim_resume (gdbsim_desc, resume_step,
! target_signal_to_host (resume_siggnal));
signal (SIGINT, prev_sigint);
resume_step = 0;
sim_stop_reason (gdbsim_desc, &reason, &sigrc);
--- 672,682 ----
prev_sigint = osa.sa_handler;
}
#else
prev_sigint = signal (SIGINT, gdbsim_cntrl_c);
#endif
! sim_resume (gdbsim_desc, resume_step, resume_siggnal);
signal (SIGINT, prev_sigint);
resume_step = 0;
sim_stop_reason (gdbsim_desc, &reason, &sigrc);
*************** gdbsim_wait (ptid_t ptid, struct target_
*** 688,715 ****
status->value.integer = sigrc;
break;
case sim_stopped:
switch (sigrc)
{
! case SIGABRT:
quit ();
break;
! case SIGINT:
! case SIGTRAP:
default:
status->kind = TARGET_WAITKIND_STOPPED;
! /* The signal in sigrc is a host signal. That probably
! should be fixed. */
! status->value.sig = target_signal_from_host (sigrc);
break;
}
break;
case sim_signalled:
status->kind = TARGET_WAITKIND_SIGNALLED;
! /* The signal in sigrc is a host signal. That probably
! should be fixed. */
! status->value.sig = target_signal_from_host (sigrc);
break;
case sim_running:
case sim_polling:
/* FIXME: Is this correct? */
break;
--- 687,710 ----
status->value.integer = sigrc;
break;
case sim_stopped:
switch (sigrc)
{
! case TARGET_SIGNAL_ABRT:
quit ();
break;
! case TARGET_SIGNAL_INT:
! case TARGET_SIGNAL_TRAP:
default:
status->kind = TARGET_WAITKIND_STOPPED;
! status->value.sig = sigrc;
break;
}
break;
case sim_signalled:
status->kind = TARGET_WAITKIND_SIGNALLED;
! status->value.sig = sigrc;
break;
case sim_running:
case sim_polling:
/* FIXME: Is this correct? */
break;
Index: sim/arm/wrapper.c
===================================================================
RCS file: /cvs/src/src/sim/arm/wrapper.c,v
retrieving revision 1.30
retrieving revision 1.30.8.1
diff -c -5 -p -r1.30 -r1.30.8.1
*** sim/arm/wrapper.c 12 May 2005 07:36:59 -0000 1.30
--- sim/arm/wrapper.c 17 Nov 2005 06:22:44 -0000 1.30.8.1
***************
*** 35,52 ****
#include "dbg_rdi.h"
#include "ansidecl.h"
#include "sim-utils.h"
#include "run-sim.h"
#include "gdb/sim-arm.h"
!
! #ifndef SIGTRAP
! #define SIGTRAP 5
! #endif
!
! #ifndef SIGBUS
! #define SIGBUS SIGSEGV
! #endif
host_callback *sim_callback;
static struct ARMul_State *state;
--- 35,45 ----
#include "dbg_rdi.h"
#include "ansidecl.h"
#include "sim-utils.h"
#include "run-sim.h"
#include "gdb/sim-arm.h"
! #include "gdb/signals.h"
host_callback *sim_callback;
static struct ARMul_State *state;
*************** sim_stop_reason (sd, reason, sigrc)
*** 908,932 ****
int *sigrc;
{
if (stop_simulator)
{
*reason = sim_stopped;
! *sigrc = SIGINT;
}
else if (state->EndCondition == 0)
{
*reason = sim_exited;
*sigrc = state->Reg[0] & 255;
}
else
{
*reason = sim_stopped;
if (state->EndCondition == RDIError_BreakpointReached)
! *sigrc = SIGTRAP;
else if ( state->EndCondition == RDIError_DataAbort
|| state->EndCondition == RDIError_AddressException)
! *sigrc = SIGBUS;
else
*sigrc = 0;
}
}
--- 901,925 ----
int *sigrc;
{
if (stop_simulator)
{
*reason = sim_stopped;
! *sigrc = TARGET_SIGNAL_INT;
}
else if (state->EndCondition == 0)
{
*reason = sim_exited;
*sigrc = state->Reg[0] & 255;
}
else
{
*reason = sim_stopped;
if (state->EndCondition == RDIError_BreakpointReached)
! *sigrc = TARGET_SIGNAL_TRAP;
else if ( state->EndCondition == RDIError_DataAbort
|| state->EndCondition == RDIError_AddressException)
! *sigrc = TARGET_SIGNAL_BUS;
else
*sigrc = 0;
}
}
Index: sim/common/sim-reason.c
===================================================================
RCS file: /cvs/src/src/sim/common/sim-reason.c,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.98.1
diff -c -5 -p -r1.1.1.1 -r1.1.1.1.98.1
*** sim/common/sim-reason.c 16 Apr 1999 01:34:58 -0000 1.1.1.1
--- sim/common/sim-reason.c 17 Nov 2005 06:22:44 -0000 1.1.1.1.98.1
*************** sim_stop_reason (SIM_DESC sd, enum sim_s
*** 33,57 ****
switch (*reason)
{
case sim_exited :
*sigrc = engine->sigrc;
break;
- case sim_signalled :
- /* ??? See the comment below case `sim_signalled' in
- gdb/remote-sim.c:gdbsim_wait.
- ??? Consider the case of the target requesting that it
- kill(2) itself with SIGNAL. That SIGNAL, being target
- specific, will not correspond to either of the SIM_SIGNAL
- enum nor the HOST_SIGNAL. A mapping from TARGET_SIGNAL to
- HOST_SIGNAL is needed. */
- *sigrc = sim_signal_to_host (sd, engine->sigrc);
- break;
case sim_stopped :
! /* The gdb/simulator interface calls for us to return the host
! version of the signal which gdb then converts into the
! target's version. This is obviously a bit clumsy. */
! *sigrc = sim_signal_to_host (sd, engine->sigrc);
break;
default :
abort ();
}
}
--- 33,45 ----
switch (*reason)
{
case sim_exited :
*sigrc = engine->sigrc;
break;
case sim_stopped :
! case sim_signalled :
! *sigrc = sim_signal_to_target (sd, engine->sigrc);
break;
default :
abort ();
}
}
Index: sim/common/sim-signal.c
===================================================================
RCS file: /cvs/src/src/sim/common/sim-signal.c,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.98.1
diff -c -5 -p -r1.1.1.1 -r1.1.1.1.98.1
*** sim/common/sim-signal.c 16 Apr 1999 01:34:59 -0000 1.1.1.1
--- sim/common/sim-signal.c 17 Nov 2005 06:22:44 -0000 1.1.1.1.98.1
*************** sim_signal_to_host (SIM_DESC sd, SIM_SIG
*** 75,85 ****
return SIGXCPU;
#endif
break;
case SIM_SIGFPE:
! #ifdef SIGXCPU
return SIGFPE;
#endif
break;
case SIM_SIGNONE:
--- 75,85 ----
return SIGXCPU;
#endif
break;
case SIM_SIGFPE:
! #ifdef SIGFPE
return SIGFPE;
#endif
break;
case SIM_SIGNONE:
*************** sim_signal_to_host (SIM_DESC sd, SIM_SIG
*** 92,96 ****
--- 92,135 ----
return SIGHUP; /* FIXME: Suggestions? */
#else
return 1;
#endif
}
+
+ int
+ sim_signal_to_target (SIM_DESC sd, SIM_SIGNAL sig)
+ {
+ switch (sig)
+ {
+ case SIM_SIGINT :
+ return TARGET_SIGNAL_INT;
+
+ case SIM_SIGABRT :
+ return TARGET_SIGNAL_ABRT;
+
+ case SIM_SIGILL :
+ return TARGET_SIGNAL_ILL;
+
+ case SIM_SIGTRAP :
+ return TARGET_SIGNAL_TRAP;
+
+ case SIM_SIGBUS :
+ return TARGET_SIGNAL_BUS;
+
+ case SIM_SIGSEGV
+ return TARGET_SIGNAL_SEGV;
+
+ case SIM_SIGXCPU :
+ return TARGET_SIGNAL_XCPU;
+
+ case SIM_SIGFPE:
+ return TARGET_SIGNAL_FPE;
+ break;
+
+ case SIM_SIGNONE:
+ return TARGET_SIGNAL_0;
+ break;
+ }
+
+ sim_io_eprintf (sd, "sim_signal_to_host: unknown signal: %d\n", sig);
+ return TARGET_SIGNAL_HUP;
+ }
Index: sim/common/sim-signal.h
===================================================================
RCS file: /cvs/src/src/sim/common/sim-signal.h,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.98.1
diff -c -5 -p -r1.1.1.1 -r1.1.1.1.98.1
*** sim/common/sim-signal.h 16 Apr 1999 01:34:59 -0000 1.1.1.1
--- sim/common/sim-signal.h 17 Nov 2005 06:22:44 -0000 1.1.1.1.98.1
*************** with this program; if not, write to the
*** 19,28 ****
--- 19,30 ----
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#ifndef SIM_SIGNAL_H
#define SIM_SIGNAL_H
+ #include "gdb/signals.h"
+
/* Signals we use.
This provides a layer between our values and host/target values. */
typedef enum {
SIM_SIGNONE = 64,
*************** typedef enum {
*** 43,49 ****
--- 45,52 ----
/* simulation aborted */
SIM_SIGABRT
} SIM_SIGNAL;
int sim_signal_to_host (SIM_DESC sd, SIM_SIGNAL);
+ enum target_signal sim_signal_to_target (SIM_DESC sd, SIM_SIGNAL);
#endif /* SIM_SIGNAL_H */
Index: sim/d10v/interp.c
===================================================================
RCS file: /cvs/src/src/sim/d10v/interp.c,v
retrieving revision 1.16
retrieving revision 1.16.16.1
diff -c -5 -p -r1.16 -r1.16.16.1
*** sim/d10v/interp.c 29 Jun 2004 00:54:00 -0000 1.16
--- sim/d10v/interp.c 17 Nov 2005 06:22:44 -0000 1.16.16.1
***************
*** 4,13 ****
--- 4,14 ----
#include "gdb/callback.h"
#include "gdb/remote-sim.h"
#include "d10v_sim.h"
#include "gdb/sim-d10v.h"
+ #include "gdb/signals.h"
enum _leftright { LEFT_FIRST, RIGHT_FIRST };
static char *myname;
static SIM_OPEN_KIND sim_kind;
*************** sim_stop_reason (sd, reason, sigrc)
*** 1275,1295 ****
*sigrc = GPR (0);
break;
case SIG_D10V_BUS:
*reason = sim_stopped;
! #ifdef SIGBUS
! *sigrc = SIGBUS;
! #else
! *sigrc = SIGSEGV;
! #endif
break;
default: /* some signal */
*reason = sim_stopped;
if (stop_simulator && !State.exception)
! *sigrc = SIGINT;
else
*sigrc = State.exception;
break;
}
--- 1276,1292 ----
*sigrc = GPR (0);
break;
case SIG_D10V_BUS:
*reason = sim_stopped;
! *reson = TARGET_SIGNAL_BUS;
break;
default: /* some signal */
*reason = sim_stopped;
if (stop_simulator && !State.exception)
! *sigrc = TARGET_SIGNAL_INT;
else
*sigrc = State.exception;
break;
}
Index: sim/erc32/interf.c
===================================================================
RCS file: /cvs/src/src/sim/erc32/interf.c,v
retrieving revision 1.5
retrieving revision 1.5.10.1
diff -c -5 -p -r1.5 -r1.5.10.1
*** sim/erc32/interf.c 7 Mar 2005 11:09:05 -0000 1.5
--- sim/erc32/interf.c 17 Nov 2005 06:22:44 -0000 1.5.10.1
***************
*** 31,40 ****
--- 31,41 ----
#include "bfd.h"
#include <dis-asm.h>
#include "sim-config.h"
#include "gdb/remote-sim.h"
+ #include "gdb/signals.h"
#define PSR_CWP 0x7
#define VAL(x) strtol(x,(char **)NULL,0)
*************** sim_stop_reason(sd, reason, sigrc)
*** 384,403 ****
{
switch (simstat) {
case CTRL_C:
*reason = sim_stopped;
! *sigrc = SIGINT;
break;
case OK:
case TIME_OUT:
case BPT_HIT:
*reason = sim_stopped;
! #ifdef _WIN32
! #define SIGTRAP 5
! #endif
! *sigrc = SIGTRAP;
break;
case ERROR:
*sigrc = 0;
*reason = sim_exited;
}
--- 385,401 ----
{
switch (simstat) {
case CTRL_C:
*reason = sim_stopped;
! *sigrc = TARGET_SIGNAL_INT;
break;
case OK:
case TIME_OUT:
case BPT_HIT:
*reason = sim_stopped;
! *sigrc = TARGET_SIGNAL_TRAP;
break;
case ERROR:
*sigrc = 0;
*reason = sim_exited;
}
Index: sim/ppc/sim_calls.c
===================================================================
RCS file: /cvs/src/src/sim/ppc/sim_calls.c,v
retrieving revision 1.11
retrieving revision 1.11.10.1
diff -c -5 -p -r1.11 -r1.11.10.1
*** sim/ppc/sim_calls.c 11 Nov 2004 21:58:57 -0000 1.11
--- sim/ppc/sim_calls.c 17 Nov 2005 06:22:44 -0000 1.11.10.1
***************
*** 42,51 ****
--- 42,52 ----
#include "libiberty.h"
#include "bfd.h"
#include "gdb/callback.h"
#include "gdb/remote-sim.h"
+ #include "gdb/signals.h"
/* Define the rate at which the simulator should poll the host
for a quit. */
#ifndef POLL_QUIT_INTERVAL
#define POLL_QUIT_INTERVAL 0x20
*************** sim_stop_reason (SIM_DESC sd, enum sim_s
*** 195,211 ****
switch (status.reason) {
case was_continuing:
*reason = sim_stopped;
if (status.signal == 0)
! *sigrc = SIGTRAP;
else
*sigrc = status.signal;
break;
case was_trap:
*reason = sim_stopped;
! *sigrc = SIGTRAP;
break;
case was_exited:
*reason = sim_exited;
*sigrc = status.signal;
break;
--- 196,212 ----
switch (status.reason) {
case was_continuing:
*reason = sim_stopped;
if (status.signal == 0)
! *sigrc = TARGET_SIGNAL_TRAP;
else
*sigrc = status.signal;
break;
case was_trap:
*reason = sim_stopped;
! *sigrc = TARGET_SIGNAL_TRAP;
break;
case was_exited:
*reason = sim_exited;
*sigrc = status.signal;
break;
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH: Use target values for signals in simulator
2005-11-23 19:56 PATCH: Use target values for signals in simulator mitchell
@ 2005-11-25 19:11 ` Daniel Jacobowitz
2005-11-25 20:16 ` Mark Mitchell
2005-11-25 23:33 ` Mark Kettenis
0 siblings, 2 replies; 8+ messages in thread
From: Daniel Jacobowitz @ 2005-11-25 19:11 UTC (permalink / raw)
To: Mark Mitchell; +Cc: gdb-patches
On Wed, Nov 23, 2005 at 06:58:06PM -0000, mitchell@mail.codesourcery.com wrote:
> The principal risk with this patch is that I may have failed to
> translate from one of the various simulator's internal representation
> of a signal to the appropriate TARGET_SIGNAL_ value. However, because
> TARGET_SIGNAL_* uses the conventional UNIX values for signals to the
> extent there are conventions (like, TARGET_SIGNAL_SEGV is 11 and
> TARGET_SIGNAL_TRAP is 5) it's unlikely that any places I missed will
> actually matter.
>
> In other words, the simulators were already translating to the host
> signal numbers, which, in practice, are very likely to match up with
> TARGET_SIGNAL_* -- especially since most of the simulators generate a
> pretty limited set of signals. So, if I missed a spot, it's very
> likely that the values are correct anyhow. Therefore, I think this
> patch is pretty safe.
You missed sim/ppc/psim.c:cntrl_c_simulation. Of course there's also
psim_max_iterations_exceeded, which uses signal -1... let's just ignore
that for the moment...
Other than that, I think it plausibly likely that you got everything.
Does anyone object to this change? This has been a long-standing wart.
--
Daniel Jacobowitz
CodeSourcery, LLC
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH: Use target values for signals in simulator
2005-11-25 19:11 ` Daniel Jacobowitz
@ 2005-11-25 20:16 ` Mark Mitchell
2005-11-28 22:26 ` Daniel Jacobowitz
2005-11-25 23:33 ` Mark Kettenis
1 sibling, 1 reply; 8+ messages in thread
From: Mark Mitchell @ 2005-11-25 20:16 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: gdb-patches
Daniel Jacobowitz wrote:
> You missed sim/ppc/psim.c:cntrl_c_simulation. Of course there's also
> psim_max_iterations_exceeded, which uses signal -1... let's just ignore
> that for the moment...
Thanks; I'll update in the obvious way, assuming that I get the
thumbs-up for checkin.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
(916) 791-8304
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH: Use target values for signals in simulator
2005-11-25 19:11 ` Daniel Jacobowitz
2005-11-25 20:16 ` Mark Mitchell
@ 2005-11-25 23:33 ` Mark Kettenis
1 sibling, 0 replies; 8+ messages in thread
From: Mark Kettenis @ 2005-11-25 23:33 UTC (permalink / raw)
To: drow; +Cc: mark, gdb-patches
> Date: Fri, 25 Nov 2005 13:25:14 -0500
> From: Daniel Jacobowitz <drow@false.org>
>
> On Wed, Nov 23, 2005 at 06:58:06PM -0000, mitchell@mail.codesourcery.com wrote:
> Other than that, I think it plausibly likely that you got everything.
> Does anyone object to this change? This has been a long-standing wart.
I'm all for it; thanks for doing the work Mark!
Mark
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH: Use target values for signals in simulator
2005-11-25 20:16 ` Mark Mitchell
@ 2005-11-28 22:26 ` Daniel Jacobowitz
2005-11-28 22:43 ` Mark Mitchell
0 siblings, 1 reply; 8+ messages in thread
From: Daniel Jacobowitz @ 2005-11-28 22:26 UTC (permalink / raw)
To: Mark Mitchell; +Cc: gdb-patches
On Fri, Nov 25, 2005 at 10:39:22AM -0800, Mark Mitchell wrote:
> Daniel Jacobowitz wrote:
>
> > You missed sim/ppc/psim.c:cntrl_c_simulation. Of course there's also
> > psim_max_iterations_exceeded, which uses signal -1... let's just ignore
> > that for the moment...
>
> Thanks; I'll update in the obvious way, assuming that I get the
> thumbs-up for checkin.
OK with that change.
--
Daniel Jacobowitz
CodeSourcery, LLC
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH: Use target values for signals in simulator
2005-11-28 22:26 ` Daniel Jacobowitz
@ 2005-11-28 22:43 ` Mark Mitchell
2005-11-29 13:03 ` Hans-Peter Nilsson
0 siblings, 1 reply; 8+ messages in thread
From: Mark Mitchell @ 2005-11-28 22:43 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 368 bytes --]
Daniel Jacobowitz wrote:
> OK with that change.
Here's the version I checked in, for the record.
Perhaps I can also take this opportunity to ping:
http://sources.redhat.com/ml/gdb-patches/2005-11/msg00255.html
which was unrelated changes to the PPC simulator to build on Windows?
Thanks,
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
(916) 791-8304
[-- Attachment #2: gdb.patch --]
[-- Type: text/plain, Size: 14784 bytes --]
2005-11-28 Mark Mitchell <mark@codesourcery.com>
* remote-sim.c (gdbsim_wait): Pass target signal numbers to
sim_resume. Expect target signal numbers from sim_stop_reason.
2005-11-23 Mark Mitchell <mark@codesourcery.com>
* wrapper.c (gdb/signals.h): Include it.
(SIGTRAP): Don't define.
(SIGBUS): Likewise.
(sim_stop_reason): Use TARGET_SIGNAL_* instead of SIG*.
2005-11-28 Mark Mitchell <mark@codesourcery.com>
* sim-reason.c (sim_stop_reason): Use
sim_signal_to_target, not sim_signal_to_host.
* sim-signal.c (sim_signal_to_host): Fix typo.
(sim_signal_to_target): New function.
2005-11-28 Mark Mitchell <mark@codesourcery.com>
* interp.c (gdb/signals.h): Include it.
(sim_stop_reason): Use TARGET_SIGNAL_*.
2005-11-28 Mark Mitchell <mark@codesourcery.com>
* interf.c: (gdb/signals.h): Include it.
(sim_stop_reason): Use TARGET_SIGNAL_*.
2005-11-28 Mark Mitchell <mark@codesourcery.com>
* sim_calls.c (gdb/signals.h): Include it.
(sim_stop_reason): Use TARGET_SIGNAL_*.
* psim.c (cntrl_c_simulation): Use TARGET_SIGNAL_*.
Index: gdb/remote-sim.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-sim.c,v
retrieving revision 1.49
diff -c -5 -p -r1.49 remote-sim.c
*** gdb/remote-sim.c 19 Jun 2005 20:08:37 -0000 1.49
--- gdb/remote-sim.c 28 Nov 2005 18:29:28 -0000
*************** gdbsim_wait (ptid_t ptid, struct target_
*** 672,683 ****
prev_sigint = osa.sa_handler;
}
#else
prev_sigint = signal (SIGINT, gdbsim_cntrl_c);
#endif
! sim_resume (gdbsim_desc, resume_step,
! target_signal_to_host (resume_siggnal));
signal (SIGINT, prev_sigint);
resume_step = 0;
sim_stop_reason (gdbsim_desc, &reason, &sigrc);
--- 672,682 ----
prev_sigint = osa.sa_handler;
}
#else
prev_sigint = signal (SIGINT, gdbsim_cntrl_c);
#endif
! sim_resume (gdbsim_desc, resume_step, resume_siggnal);
signal (SIGINT, prev_sigint);
resume_step = 0;
sim_stop_reason (gdbsim_desc, &reason, &sigrc);
*************** gdbsim_wait (ptid_t ptid, struct target_
*** 688,715 ****
status->value.integer = sigrc;
break;
case sim_stopped:
switch (sigrc)
{
! case SIGABRT:
quit ();
break;
! case SIGINT:
! case SIGTRAP:
default:
status->kind = TARGET_WAITKIND_STOPPED;
! /* The signal in sigrc is a host signal. That probably
! should be fixed. */
! status->value.sig = target_signal_from_host (sigrc);
break;
}
break;
case sim_signalled:
status->kind = TARGET_WAITKIND_SIGNALLED;
! /* The signal in sigrc is a host signal. That probably
! should be fixed. */
! status->value.sig = target_signal_from_host (sigrc);
break;
case sim_running:
case sim_polling:
/* FIXME: Is this correct? */
break;
--- 687,710 ----
status->value.integer = sigrc;
break;
case sim_stopped:
switch (sigrc)
{
! case TARGET_SIGNAL_ABRT:
quit ();
break;
! case TARGET_SIGNAL_INT:
! case TARGET_SIGNAL_TRAP:
default:
status->kind = TARGET_WAITKIND_STOPPED;
! status->value.sig = sigrc;
break;
}
break;
case sim_signalled:
status->kind = TARGET_WAITKIND_SIGNALLED;
! status->value.sig = sigrc;
break;
case sim_running:
case sim_polling:
/* FIXME: Is this correct? */
break;
Index: sim/arm/wrapper.c
===================================================================
RCS file: /cvs/src/src/sim/arm/wrapper.c,v
retrieving revision 1.30
diff -c -5 -p -r1.30 wrapper.c
*** sim/arm/wrapper.c 12 May 2005 07:36:59 -0000 1.30
--- sim/arm/wrapper.c 28 Nov 2005 18:29:29 -0000
***************
*** 35,52 ****
#include "dbg_rdi.h"
#include "ansidecl.h"
#include "sim-utils.h"
#include "run-sim.h"
#include "gdb/sim-arm.h"
!
! #ifndef SIGTRAP
! #define SIGTRAP 5
! #endif
!
! #ifndef SIGBUS
! #define SIGBUS SIGSEGV
! #endif
host_callback *sim_callback;
static struct ARMul_State *state;
--- 35,45 ----
#include "dbg_rdi.h"
#include "ansidecl.h"
#include "sim-utils.h"
#include "run-sim.h"
#include "gdb/sim-arm.h"
! #include "gdb/signals.h"
host_callback *sim_callback;
static struct ARMul_State *state;
*************** sim_stop_reason (sd, reason, sigrc)
*** 908,932 ****
int *sigrc;
{
if (stop_simulator)
{
*reason = sim_stopped;
! *sigrc = SIGINT;
}
else if (state->EndCondition == 0)
{
*reason = sim_exited;
*sigrc = state->Reg[0] & 255;
}
else
{
*reason = sim_stopped;
if (state->EndCondition == RDIError_BreakpointReached)
! *sigrc = SIGTRAP;
else if ( state->EndCondition == RDIError_DataAbort
|| state->EndCondition == RDIError_AddressException)
! *sigrc = SIGBUS;
else
*sigrc = 0;
}
}
--- 901,925 ----
int *sigrc;
{
if (stop_simulator)
{
*reason = sim_stopped;
! *sigrc = TARGET_SIGNAL_INT;
}
else if (state->EndCondition == 0)
{
*reason = sim_exited;
*sigrc = state->Reg[0] & 255;
}
else
{
*reason = sim_stopped;
if (state->EndCondition == RDIError_BreakpointReached)
! *sigrc = TARGET_SIGNAL_TRAP;
else if ( state->EndCondition == RDIError_DataAbort
|| state->EndCondition == RDIError_AddressException)
! *sigrc = TARGET_SIGNAL_BUS;
else
*sigrc = 0;
}
}
Index: sim/common/sim-reason.c
===================================================================
RCS file: /cvs/src/src/sim/common/sim-reason.c,v
retrieving revision 1.1.1.1
diff -c -5 -p -r1.1.1.1 sim-reason.c
*** sim/common/sim-reason.c 16 Apr 1999 01:34:58 -0000 1.1.1.1
--- sim/common/sim-reason.c 28 Nov 2005 18:29:31 -0000
*************** sim_stop_reason (SIM_DESC sd, enum sim_s
*** 33,57 ****
switch (*reason)
{
case sim_exited :
*sigrc = engine->sigrc;
break;
- case sim_signalled :
- /* ??? See the comment below case `sim_signalled' in
- gdb/remote-sim.c:gdbsim_wait.
- ??? Consider the case of the target requesting that it
- kill(2) itself with SIGNAL. That SIGNAL, being target
- specific, will not correspond to either of the SIM_SIGNAL
- enum nor the HOST_SIGNAL. A mapping from TARGET_SIGNAL to
- HOST_SIGNAL is needed. */
- *sigrc = sim_signal_to_host (sd, engine->sigrc);
- break;
case sim_stopped :
! /* The gdb/simulator interface calls for us to return the host
! version of the signal which gdb then converts into the
! target's version. This is obviously a bit clumsy. */
! *sigrc = sim_signal_to_host (sd, engine->sigrc);
break;
default :
abort ();
}
}
--- 33,45 ----
switch (*reason)
{
case sim_exited :
*sigrc = engine->sigrc;
break;
case sim_stopped :
! case sim_signalled :
! *sigrc = sim_signal_to_target (sd, engine->sigrc);
break;
default :
abort ();
}
}
Index: sim/common/sim-signal.c
===================================================================
RCS file: /cvs/src/src/sim/common/sim-signal.c,v
retrieving revision 1.1.1.1
diff -c -5 -p -r1.1.1.1 sim-signal.c
*** sim/common/sim-signal.c 16 Apr 1999 01:34:59 -0000 1.1.1.1
--- sim/common/sim-signal.c 28 Nov 2005 18:29:31 -0000
*************** sim_signal_to_host (SIM_DESC sd, SIM_SIG
*** 75,85 ****
return SIGXCPU;
#endif
break;
case SIM_SIGFPE:
! #ifdef SIGXCPU
return SIGFPE;
#endif
break;
case SIM_SIGNONE:
--- 75,85 ----
return SIGXCPU;
#endif
break;
case SIM_SIGFPE:
! #ifdef SIGFPE
return SIGFPE;
#endif
break;
case SIM_SIGNONE:
*************** sim_signal_to_host (SIM_DESC sd, SIM_SIG
*** 92,96 ****
--- 92,135 ----
return SIGHUP; /* FIXME: Suggestions? */
#else
return 1;
#endif
}
+
+ int
+ sim_signal_to_target (SIM_DESC sd, SIM_SIGNAL sig)
+ {
+ switch (sig)
+ {
+ case SIM_SIGINT :
+ return TARGET_SIGNAL_INT;
+
+ case SIM_SIGABRT :
+ return TARGET_SIGNAL_ABRT;
+
+ case SIM_SIGILL :
+ return TARGET_SIGNAL_ILL;
+
+ case SIM_SIGTRAP :
+ return TARGET_SIGNAL_TRAP;
+
+ case SIM_SIGBUS :
+ return TARGET_SIGNAL_BUS;
+
+ case SIM_SIGSEGV
+ return TARGET_SIGNAL_SEGV;
+
+ case SIM_SIGXCPU :
+ return TARGET_SIGNAL_XCPU;
+
+ case SIM_SIGFPE:
+ return TARGET_SIGNAL_FPE;
+ break;
+
+ case SIM_SIGNONE:
+ return TARGET_SIGNAL_0;
+ break;
+ }
+
+ sim_io_eprintf (sd, "sim_signal_to_host: unknown signal: %d\n", sig);
+ return TARGET_SIGNAL_HUP;
+ }
Index: sim/common/sim-signal.h
===================================================================
RCS file: /cvs/src/src/sim/common/sim-signal.h,v
retrieving revision 1.1.1.1
diff -c -5 -p -r1.1.1.1 sim-signal.h
*** sim/common/sim-signal.h 16 Apr 1999 01:34:59 -0000 1.1.1.1
--- sim/common/sim-signal.h 28 Nov 2005 18:29:31 -0000
*************** with this program; if not, write to the
*** 19,28 ****
--- 19,30 ----
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#ifndef SIM_SIGNAL_H
#define SIM_SIGNAL_H
+ #include "gdb/signals.h"
+
/* Signals we use.
This provides a layer between our values and host/target values. */
typedef enum {
SIM_SIGNONE = 64,
*************** typedef enum {
*** 43,49 ****
--- 45,52 ----
/* simulation aborted */
SIM_SIGABRT
} SIM_SIGNAL;
int sim_signal_to_host (SIM_DESC sd, SIM_SIGNAL);
+ enum target_signal sim_signal_to_target (SIM_DESC sd, SIM_SIGNAL);
#endif /* SIM_SIGNAL_H */
Index: sim/d10v/interp.c
===================================================================
RCS file: /cvs/src/src/sim/d10v/interp.c,v
retrieving revision 1.16
diff -c -5 -p -r1.16 interp.c
*** sim/d10v/interp.c 29 Jun 2004 00:54:00 -0000 1.16
--- sim/d10v/interp.c 28 Nov 2005 18:29:31 -0000
***************
*** 4,13 ****
--- 4,14 ----
#include "gdb/callback.h"
#include "gdb/remote-sim.h"
#include "d10v_sim.h"
#include "gdb/sim-d10v.h"
+ #include "gdb/signals.h"
enum _leftright { LEFT_FIRST, RIGHT_FIRST };
static char *myname;
static SIM_OPEN_KIND sim_kind;
*************** sim_stop_reason (sd, reason, sigrc)
*** 1275,1295 ****
*sigrc = GPR (0);
break;
case SIG_D10V_BUS:
*reason = sim_stopped;
! #ifdef SIGBUS
! *sigrc = SIGBUS;
! #else
! *sigrc = SIGSEGV;
! #endif
break;
default: /* some signal */
*reason = sim_stopped;
if (stop_simulator && !State.exception)
! *sigrc = SIGINT;
else
*sigrc = State.exception;
break;
}
--- 1276,1292 ----
*sigrc = GPR (0);
break;
case SIG_D10V_BUS:
*reason = sim_stopped;
! *reson = TARGET_SIGNAL_BUS;
break;
default: /* some signal */
*reason = sim_stopped;
if (stop_simulator && !State.exception)
! *sigrc = TARGET_SIGNAL_INT;
else
*sigrc = State.exception;
break;
}
Index: sim/erc32/interf.c
===================================================================
RCS file: /cvs/src/src/sim/erc32/interf.c,v
retrieving revision 1.5
diff -c -5 -p -r1.5 interf.c
*** sim/erc32/interf.c 7 Mar 2005 11:09:05 -0000 1.5
--- sim/erc32/interf.c 28 Nov 2005 18:29:31 -0000
***************
*** 31,40 ****
--- 31,41 ----
#include "bfd.h"
#include <dis-asm.h>
#include "sim-config.h"
#include "gdb/remote-sim.h"
+ #include "gdb/signals.h"
#define PSR_CWP 0x7
#define VAL(x) strtol(x,(char **)NULL,0)
*************** sim_stop_reason(sd, reason, sigrc)
*** 384,403 ****
{
switch (simstat) {
case CTRL_C:
*reason = sim_stopped;
! *sigrc = SIGINT;
break;
case OK:
case TIME_OUT:
case BPT_HIT:
*reason = sim_stopped;
! #ifdef _WIN32
! #define SIGTRAP 5
! #endif
! *sigrc = SIGTRAP;
break;
case ERROR:
*sigrc = 0;
*reason = sim_exited;
}
--- 385,401 ----
{
switch (simstat) {
case CTRL_C:
*reason = sim_stopped;
! *sigrc = TARGET_SIGNAL_INT;
break;
case OK:
case TIME_OUT:
case BPT_HIT:
*reason = sim_stopped;
! *sigrc = TARGET_SIGNAL_TRAP;
break;
case ERROR:
*sigrc = 0;
*reason = sim_exited;
}
Index: sim/ppc/psim.c
===================================================================
RCS file: /cvs/src/src/sim/ppc/psim.c,v
retrieving revision 1.5
diff -c -5 -p -r1.5 psim.c
*** sim/ppc/psim.c 20 Apr 2005 22:33:08 -0000 1.5
--- sim/ppc/psim.c 28 Nov 2005 18:29:32 -0000
*************** cntrl_c_simulation(void *data)
*** 570,580 ****
{
psim *system = data;
psim_halt(system,
psim_nr_cpus(system),
was_continuing,
! SIGINT);
}
INLINE_PSIM\
(void)
psim_stop(psim *system)
--- 570,580 ----
{
psim *system = data;
psim_halt(system,
psim_nr_cpus(system),
was_continuing,
! TARGET_SIGNAL_INT);
}
INLINE_PSIM\
(void)
psim_stop(psim *system)
Index: sim/ppc/sim_calls.c
===================================================================
RCS file: /cvs/src/src/sim/ppc/sim_calls.c,v
retrieving revision 1.11
diff -c -5 -p -r1.11 sim_calls.c
*** sim/ppc/sim_calls.c 11 Nov 2004 21:58:57 -0000 1.11
--- sim/ppc/sim_calls.c 28 Nov 2005 18:29:32 -0000
***************
*** 42,51 ****
--- 42,52 ----
#include "libiberty.h"
#include "bfd.h"
#include "gdb/callback.h"
#include "gdb/remote-sim.h"
+ #include "gdb/signals.h"
/* Define the rate at which the simulator should poll the host
for a quit. */
#ifndef POLL_QUIT_INTERVAL
#define POLL_QUIT_INTERVAL 0x20
*************** sim_stop_reason (SIM_DESC sd, enum sim_s
*** 195,211 ****
switch (status.reason) {
case was_continuing:
*reason = sim_stopped;
if (status.signal == 0)
! *sigrc = SIGTRAP;
else
*sigrc = status.signal;
break;
case was_trap:
*reason = sim_stopped;
! *sigrc = SIGTRAP;
break;
case was_exited:
*reason = sim_exited;
*sigrc = status.signal;
break;
--- 196,212 ----
switch (status.reason) {
case was_continuing:
*reason = sim_stopped;
if (status.signal == 0)
! *sigrc = TARGET_SIGNAL_TRAP;
else
*sigrc = status.signal;
break;
case was_trap:
*reason = sim_stopped;
! *sigrc = TARGET_SIGNAL_TRAP;
break;
case was_exited:
*reason = sim_exited;
*sigrc = status.signal;
break;
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH: Use target values for signals in simulator
2005-11-28 22:43 ` Mark Mitchell
@ 2005-11-29 13:03 ` Hans-Peter Nilsson
2005-11-29 14:08 ` Mark Mitchell
0 siblings, 1 reply; 8+ messages in thread
From: Hans-Peter Nilsson @ 2005-11-29 13:03 UTC (permalink / raw)
To: Mark Mitchell; +Cc: Daniel Jacobowitz, gdb-patches
On Mon, 28 Nov 2005, Mark Mitchell wrote:
> Daniel Jacobowitz wrote:
>
> > OK with that change.
>
> Here's the version I checked in, for the record.
(Sent as attachment, so I can't quote in pine...)
Something went generally wrong.
For cris-elf, I see (cutnpaste):
gcc -c
/home/hp/combined/combined/sim/cris/../common/sim-signal.c
-DHAVE_CONFIG_H -DWITH_DEFAULT_MODEL='"crisv32"' -DPROFILE=1\
-DWITH_PROFILE=-1 -DWITH_ALIGNMENT=NONSTRICT_ALIGNMENT
-DWITH_ENVIRONMENT=ALL_ENVIRONMENT
-DWITH_HOST_BYTE_ORDER=LITTLE_EN\
DIAN -DWITH_SCACHE=16384 -I.
-I/home/hp/combined/combined/sim/cris -I../common
-I/home/hp/combined/combined/sim/cris\
/../common -I../../include
-I/home/hp/combined/combined/sim/cris/../../include -I../../bfd
-I/home/hp/combined/combined/sim/cris/\
../../bfd -I../../opcodes
-I/home/hp/combined/combined/sim/cris/../../opcodes -I../../intl
-I/home/hp/combined/combined/sim/cris/\
../../intl -g -O2
/home/hp/combined/combined/sim/common/sim-signal.c:100: error: conflicting types for `sim_signal_to_target'
/home/hp/combined/combined/sim/common/sim-signal.h:50: error: previous declaration of `sim_signal_to_target'
/home/hp/combined/combined/sim/common/sim-signal.c: In function `sim_signal_to_target':
/home/hp/combined/combined/sim/common/sim-signal.c:119: error: syntax error before "return"
make[5]: *** [sim-signal.o] Error 1
To wit:
sim-signal.h:
enum target_signal sim_signal_to_target (SIM_DESC sd, SIM_SIGNAL);
sim-signal.c:
int
sim_signal_to_target (SIM_DESC sd, SIM_SIGNAL sig)
I guess you attached and committed the wrong version. There's
an obvious syntax error; missing ":" on one case line, see
above.
brgds, H-P
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: PATCH: Use target values for signals in simulator
2005-11-29 13:03 ` Hans-Peter Nilsson
@ 2005-11-29 14:08 ` Mark Mitchell
0 siblings, 0 replies; 8+ messages in thread
From: Mark Mitchell @ 2005-11-29 14:08 UTC (permalink / raw)
To: Hans-Peter Nilsson; +Cc: Daniel Jacobowitz, gdb-patches
[-- Attachment #1: Type: text/plain, Size: 186 bytes --]
> Something went generally wrong.
Fixed with this patch; tested by building a cross GDB for cris-elf.
Thanks,
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
(916) 791-8304
[-- Attachment #2: gdb.patch --]
[-- Type: text/plain, Size: 1336 bytes --]
2005-11-28 Mark Mitchell <mark@codesourcery.com>
* sim-signal.c (sim_signal_to_target): Fix typos.
Index: sim-signal.c
===================================================================
RCS file: /cvs/src/src/sim/common/sim-signal.c,v
retrieving revision 1.2
diff -c -5 -p -r1.2 sim-signal.c
*** sim-signal.c 28 Nov 2005 18:33:03 -0000 1.2
--- sim-signal.c 29 Nov 2005 02:42:28 -0000
*************** sim_signal_to_host (SIM_DESC sd, SIM_SIG
*** 93,103 ****
#else
return 1;
#endif
}
! int
sim_signal_to_target (SIM_DESC sd, SIM_SIGNAL sig)
{
switch (sig)
{
case SIM_SIGINT :
--- 93,103 ----
#else
return 1;
#endif
}
! enum target_signal
sim_signal_to_target (SIM_DESC sd, SIM_SIGNAL sig)
{
switch (sig)
{
case SIM_SIGINT :
*************** sim_signal_to_target (SIM_DESC sd, SIM_S
*** 113,123 ****
return TARGET_SIGNAL_TRAP;
case SIM_SIGBUS :
return TARGET_SIGNAL_BUS;
! case SIM_SIGSEGV
return TARGET_SIGNAL_SEGV;
case SIM_SIGXCPU :
return TARGET_SIGNAL_XCPU;
--- 113,123 ----
return TARGET_SIGNAL_TRAP;
case SIM_SIGBUS :
return TARGET_SIGNAL_BUS;
! case SIM_SIGSEGV :
return TARGET_SIGNAL_SEGV;
case SIM_SIGXCPU :
return TARGET_SIGNAL_XCPU;
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2005-11-29 2:44 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-23 19:56 PATCH: Use target values for signals in simulator mitchell
2005-11-25 19:11 ` Daniel Jacobowitz
2005-11-25 20:16 ` Mark Mitchell
2005-11-28 22:26 ` Daniel Jacobowitz
2005-11-28 22:43 ` Mark Mitchell
2005-11-29 13:03 ` Hans-Peter Nilsson
2005-11-29 14:08 ` Mark Mitchell
2005-11-25 23:33 ` Mark Kettenis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox