From 027e2a04f1bb48ef6839b4cdb83f11164db4c42d Mon Sep 17 00:00:00 2001 From: Hans-Peter Nilsson Date: Wed, 8 Dec 2004 00:40:30 +0000 Subject: * run.1: Document --sysroot=filepath. * sim-options.c (STANDARD_OPTIONS): New member OPTION_SYSROOT. (standard_options): Support --sysroot=. (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. --- sim/common/nrun.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'sim/common/nrun.c') 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 +#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) { -- cgit v1.2.1