aboutsummaryrefslogtreecommitdiff
path: root/sim/common/nrun.c
diff options
context:
space:
mode:
Diffstat (limited to 'sim/common/nrun.c')
-rw-r--r--sim/common/nrun.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/sim/common/nrun.c b/sim/common/nrun.c
index 8dfa946..d0c43e6 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 Free Software Foundation, Inc.
+ Copyright (C) 1997, 2004 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
@@ -24,6 +24,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
extern char **environ;
#endif
+#ifdef HAVE_UNISTD_H
+/* For chdir. */
+#include <unistd.h>
+#endif
+
static void usage (void);
extern host_callback default_callback;
@@ -117,6 +122,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)
{