* 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.
2004-12-08 Hans-Peter Nilsson <hp@axis.com>
+ * 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.
+
* aclocal.m4 (SIM_AC_OUTPUT): Substitute @cgen_breaks@ for "break
cgen_rtx_error" in a CGEN-generated simulator.
* gdbinit.in: Break on sim_core_signal too. Have autoconf
/* 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
extern char **environ;
#endif
+#ifdef HAVE_UNISTD_H
+/* For chdir. */
+#include <unistd.h>
+#endif
+
static void usage (void);
extern host_callback default_callback;
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)
{
-.\" Copyright (c) 1993 Free Software Foundation
+.\" Copyright (c) 1993, 2004 Free Software Foundation
.\" See section COPYING for conditions for redistribution
.TH run 1 "13oct1993" "GNU Tools" "GNU Tools"
.de BP
.IR freq "\|]"
.RB "[\|" \-m
.IR memory "\|]"
+.RB "[\|" \--sysroot
+.IR filepath "\|]"
.I program
.ad b
.hy 1
.IR memory .
The default value is 19, emulating a board with 524288 bytes of memory.
+.TP
+.BI \--sysroot " filepath"
+Prepend
+.IR filepath
+to all simulator system calls that pass absolute file paths.
+Change working directory to
+.IR filepath
+at program start. Not all simulators support this option; those
+that don't, will ignore it.
+
.PP
.SH "SEE ALSO"
/* The common simulator framework for GDB, the GNU Debugger.
- Copyright 2002 Free Software Foundation, Inc.
+ Copyright 2002, 2004 Free Software Foundation, Inc.
Contributed by Andrew Cagney and Red Hat.
? WITH_ENVIRONMENT \
: USER_ENVIRONMENT)
+/* To be prepended to simulator calls with absolute file paths and
+ chdir:ed at startup. */
+extern char *simulator_sysroot;
/* Callback & Modulo Memory.
/* Simulator option handling.
- Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 2004 Free Software Foundation, Inc.
Contributed by Cygnus Support.
This file is part of GDB, the GNU debugger.
#endif
OPTION_LOAD_LMA,
OPTION_LOAD_VMA,
+ OPTION_SYSROOT
} STANDARD_OPTIONS;
static const OPTION standard_options[] =
'\0', NULL, "", standard_option_handler, "" },
#endif
+ { {"sysroot", required_argument, NULL, OPTION_SYSROOT},
+ '\0', "SYSROOT",
+ "Root for system calls with absolute file-names and cwd at start",
+ standard_option_handler },
+
{ {NULL, no_argument, NULL, 0}, '\0', NULL, NULL, NULL }
};
exit (0);
/* FIXME: 'twould be nice to do something similar if gdb. */
break;
+
+ case OPTION_SYSROOT:
+ /* Don't leak memory in the odd event that there's lots of
+ --sysroot=... options. */
+ if (simulator_sysroot[0] != '\0' && arg[0] != '\0')
+ free (simulator_sysroot);
+ simulator_sysroot = xstrdup (arg);
+ break;
}
return SIM_RC_OK;
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#elif defined (HAVE_STRINGS_H)
+#include <strings.h>
+#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#define TWORD long
#define TADDR unsigned long
+/* Path to be prepended to syscalls with absolute paths, and to be
+ chdir:ed at startup, if not empty. */
+char *simulator_sysroot = "";
+
/* Utility of cb_syscall to fetch a path name or other string from the target.
The result is 0 for success or a host errno value. */
/* Utility of cb_syscall to fetch a path name.
The buffer is malloc'd and the address is stored in BUFP.
- The result is that of get_string.
+ The result is that of get_string, but prepended with
+ simulator_sysroot if the string starts with '/'.
If an error occurs, no buffer is left malloc'd. */
static int
{
char *buf = xmalloc (MAX_PATH_LEN);
int result;
+ int sysroot_len = strlen (simulator_sysroot);
- result = get_string (cb, sc, buf, MAX_PATH_LEN, addr);
+ result = get_string (cb, sc, buf, MAX_PATH_LEN - sysroot_len, addr);
if (result == 0)
- *bufp = buf;
+ {
+ /* Prepend absolute paths with simulator_sysroot. Relative paths
+ are supposed to be relative to a chdir within that path, but at
+ this point unknown where. */
+ if (simulator_sysroot[0] != '\0' && *buf == '/')
+ {
+ /* Considering expected rareness of syscalls with absolute
+ file paths (compared to relative file paths and insn
+ execution), it does not seem worthwhile to rearrange things
+ to get rid of the string moves here; we'd need at least an
+ extra call to check the initial '/' in the path. */
+ memmove (buf + sysroot_len, buf, sysroot_len);
+ memcpy (buf, simulator_sysroot, sysroot_len);
+ }
+
+ *bufp = buf;
+ }
else
free (buf);
return result;