X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=sim%2Fcommon%2Fnrun.c;h=6616cc1d1e470a77ebbed46885d9f0cd023ae1b3;hb=8b8c7c9f49992750f66f81b4601d593a3858d98c;hp=2f13b1f91bbf2f164bf996984677355855575525;hpb=5b64ad42d36e6d487e1f7287d37fbc243a178e72;p=deliverable%2Fbinutils-gdb.git diff --git a/sim/common/nrun.c b/sim/common/nrun.c index 2f13b1f91b..6616cc1d1e 100644 --- a/sim/common/nrun.c +++ b/sim/common/nrun.c @@ -1,21 +1,35 @@ /* New version of run front end support for simulators. - Copyright (C) 1997 Free Software Foundation, Inc. + Copyright (C) 1997-2016 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +You should have received a copy of the GNU General Public License +along with this program. If not, see . */ + +/* Need to be before general includes, to pick up e.g. _GNU_SOURCE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include + +/* For strsignal. */ +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif + #include "sim-main.h" #include "bfd.h" @@ -24,11 +38,16 @@ with this program; if not, write to the Free Software Foundation, Inc., extern char **environ; #endif +#ifdef HAVE_UNISTD_H +/* For chdir. */ +#include +#endif + static void usage (void); extern host_callback default_callback; -static char *myname; +static const char *myname; static SIM_DESC sd; @@ -45,17 +64,15 @@ cntrl_c (int sig) int main (int argc, char **argv) { - char *name; + const char *name; char **prog_argv = NULL; - struct _bfd *prog_bfd; + struct bfd *prog_bfd; enum sim_stop reason; int sigrc = 0; int single_step = 0; RETSIGTYPE (*prev_sigint) (); - myname = argv[0] + strlen (argv[0]); - while (myname > argv[0] && myname[-1] != '/') - --myname; + myname = lbasename (argv[0]); /* INTERNAL: When MYNAME is `step', single step the simulator instead of allowing it to run free. The sole purpose of this @@ -77,6 +94,12 @@ main (int argc, char **argv) abort (); } + /* We can't set the endianness in the callback structure until + sim_config is called, which happens in sim_open. */ + default_callback.target_endian + = (CURRENT_TARGET_BYTE_ORDER == BFD_ENDIAN_BIG + ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE); + /* Was there a program to run? */ prog_argv = STATE_PROG_ARGV (sd); prog_bfd = STATE_PROG_BFD (sd); @@ -91,11 +114,11 @@ main (int argc, char **argv) prog_bfd = bfd_openr (name, 0); if (prog_bfd == NULL) { - fprintf (stderr, "%s: can't open \"%s\": %s\n", + fprintf (stderr, "%s: can't open \"%s\": %s\n", myname, name, bfd_errmsg (bfd_get_error ())); exit (1); } - if (!bfd_check_format (prog_bfd, bfd_object)) + if (!bfd_check_format (prog_bfd, bfd_object)) { fprintf (stderr, "%s: \"%s\" is not an object file: %s\n", myname, name, bfd_errmsg (bfd_get_error ())); @@ -117,6 +140,16 @@ main (int argc, char **argv) sim_create_inferior (sd, prog_bfd, prog_argv, NULL); #endif + /* To accommodate relative file paths, chdir to sysroot now. We + mustn't do this until BFD has opened the program, else we wouldn't + find the executable if it has a relative file path. */ + if (simulator_sysroot[0] != '\0' && chdir (simulator_sysroot) < 0) + { + fprintf (stderr, "%s: can't change directory to \"%s\"\n", + myname, simulator_sysroot); + exit (1); + } + /* Run/Step the program. */ if (single_step) { @@ -134,35 +167,39 @@ main (int argc, char **argv) /* remain on breakpoint or signals in oe mode*/ while (((reason == sim_signalled) && (sigrc == sim_signal_to_host (sd, SIM_SIGTRAP))) || - ((reason == sim_stopped) && + ((reason == sim_stopped) && (STATE_ENVIRONMENT (sd) == OPERATING_ENVIRONMENT))); } - else do + else { + do + { #if defined (HAVE_SIGACTION) && defined (SA_RESTART) - struct sigaction sa, osa; - sa.sa_handler = cntrl_c; - sigemptyset (&sa.sa_mask); - sa.sa_flags = 0; - sigaction (SIGINT, &sa, &osa); - prev_sigint = osa.sa_handler; + struct sigaction sa, osa; + sa.sa_handler = cntrl_c; + sigemptyset (&sa.sa_mask); + sa.sa_flags = 0; + sigaction (SIGINT, &sa, &osa); + prev_sigint = osa.sa_handler; #else - prev_sigint = signal (SIGINT, cntrl_c); + prev_sigint = signal (SIGINT, cntrl_c); #endif - sim_resume (sd, 0, sigrc); - signal (SIGINT, prev_sigint); - sim_stop_reason (sd, &reason, &sigrc); + sim_resume (sd, 0, sigrc); + signal (SIGINT, prev_sigint); + sim_stop_reason (sd, &reason, &sigrc); - if ((reason == sim_stopped) && - (sigrc == sim_signal_to_host (sd, SIM_SIGINT))) - break; /* exit on control-C */ + if ((reason == sim_stopped) && + (sigrc == sim_signal_to_host (sd, SIM_SIGINT))) + break; /* exit on control-C */ - /* remain on signals in oe mode */ - } while ((reason == sim_stopped) && - (STATE_ENVIRONMENT (sd) == OPERATING_ENVIRONMENT)); + /* remain on signals in oe mode */ + } while ((reason == sim_stopped) && + (STATE_ENVIRONMENT (sd) == OPERATING_ENVIRONMENT)); + } /* Print any stats the simulator collected. */ - sim_info (sd, 0); + if (STATE_VERBOSE_P (sd)) + sim_info (sd, 0); /* Shutdown the simulator. */ sim_close (sd, 0); @@ -172,18 +209,14 @@ main (int argc, char **argv) the signal that the simulator received; we want to return that to indicate failure. */ -#ifdef SIM_H8300 /* FIXME: Ugh. grep for SLEEP in compile.c */ - if (sigrc == SIGILL) - abort (); - sigrc = 0; -#else /* Why did we stop? */ switch (reason) { case sim_signalled: case sim_stopped: if (sigrc != 0) - fprintf (stderr, "program stopped with signal %d.\n", sigrc); + fprintf (stderr, "program stopped with signal %d (%s).\n", sigrc, + strsignal (sigrc)); break; case sim_exited: @@ -194,13 +227,12 @@ main (int argc, char **argv) break; } -#endif return sigrc; } static void -usage () +usage (void) { fprintf (stderr, "Usage: %s [options] program [program args]\n", myname); fprintf (stderr, "Run `%s --help' for full list of options.\n", myname);