summaryrefslogtreecommitdiff
path: root/sim/common/nrun.c
diff options
context:
space:
mode:
authorHans-Peter Nilsson <hp@axis.com>2004-12-08 00:40:30 +0000
committerHans-Peter Nilsson <hp@axis.com>2004-12-08 00:40:30 +0000
commit027e2a04f1bb48ef6839b4cdb83f11164db4c42d (patch)
treee8ddde668df755ea4511f8cad9718f1e5885b8f3 /sim/common/nrun.c
parent9888440ad603c44db4908229b7ce827ca7a16eb4 (diff)
downloadbinutils-gdb-027e2a04f1bb48ef6839b4cdb83f11164db4c42d.tar.gz
* run.1: Document --sysroot=filepath.
* sim-options.c (STANDARD_OPTIONS): New member OPTION_SYSROOT. (standard_options): Support --sysroot=<path>. (standard_option_handler): Handle OPTION_SYSROOT. * syscall.c (simulator_sysroot): Define, initialized empty. (get_path): Prepend simulator_sysroot to absolute file path. [HAVE_STRING_H]: Include string.h. [!HAVE_STRING_H && HAVE_STRINGS_H]: Include strings.h. * nrun.c [HAVE_UNISTD_H]: Include unistd.h. (main): If simulator_sysroot is not empty, chdir there. * sim-config.h (simulator_sysroot): Declare.
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 8dfa94658b0..d0c43e6ad93 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)
{