X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=sim%2Fcommon%2Fnrun.c;h=cbf7b5e2e14762f88492f711a13ef66ce16d2ff1;hb=a435742a7fb32f6320ce0e6074e2500e28378104;hp=379f4ddf14d581cf22dca5edd6f60daefd60a5cd;hpb=e4d013fc0f3df3200be2dca48ed2e330e8a4ddf9;p=deliverable%2Fbinutils-gdb.git
diff --git a/sim/common/nrun.c b/sim/common/nrun.c
index 379f4ddf14..cbf7b5e2e1 100644
--- a/sim/common/nrun.c
+++ b/sim/common/nrun.c
@@ -1,5 +1,5 @@
/* New version of run front end support for simulators.
- Copyright (C) 1997, 2004, 2007, 2008, 2009 Free Software Foundation, Inc.
+ Copyright (C) 1997-2020 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
@@ -14,7 +14,23 @@ 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, see . */
+/* Need to be before general includes, to pick up e.g. _GNU_SOURCE. */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include
+#include
+
+/* For strsignal. */
+#ifdef HAVE_STRING_H
+#include
+#else
+#ifdef HAVE_STRINGS_H
+#include
+#endif
+#endif
+
#include "sim-main.h"
#include "bfd.h"
@@ -32,7 +48,7 @@ static void usage (void);
extern host_callback default_callback;
-static char *myname;
+static const char *myname;
static SIM_DESC sd;
@@ -49,7 +65,7 @@ cntrl_c (int sig)
int
main (int argc, char **argv)
{
- char *name;
+ const char *name;
char **prog_argv = NULL;
struct bfd *prog_bfd;
enum sim_stop reason;
@@ -57,9 +73,7 @@ main (int argc, char **argv)
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
@@ -84,7 +98,7 @@ main (int argc, char **argv)
/* 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 == BIG_ENDIAN
+ = (CURRENT_TARGET_BYTE_ORDER == BFD_ENDIAN_BIG
? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE);
/* Was there a program to run? */
@@ -101,11 +115,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 ()));
@@ -154,10 +168,10 @@ 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
+ else
{
do
{
@@ -174,35 +188,36 @@ main (int argc, char **argv)
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 */
-
+
/* remain on signals in oe mode */
} while ((reason == sim_stopped) &&
(STATE_ENVIRONMENT (sd) == OPERATING_ENVIRONMENT));
-
+
}
/* Print any stats the simulator collected. */
if (STATE_VERBOSE_P (sd))
sim_info (sd, 0);
-
+
/* Shutdown the simulator. */
sim_close (sd, 0);
-
+
/* If reason is sim_exited, then sigrc holds the exit code which we want
to return. If reason is sim_stopped or sim_signalled, then sigrc holds
the signal that the simulator received; we want to return that to
indicate failure. */
-
+
/* 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:
@@ -218,7 +233,7 @@ main (int argc, char **argv)
}
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);