aboutsummaryrefslogtreecommitdiff
path: root/sim
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
parent9888440ad603c44db4908229b7ce827ca7a16eb4 (diff)
downloadgdb-027e2a04f1bb48ef6839b4cdb83f11164db4c42d.zip
gdb-027e2a04f1bb48ef6839b4cdb83f11164db4c42d.tar.gz
gdb-027e2a04f1bb48ef6839b4cdb83f11164db4c42d.tar.bz2
* 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')
-rw-r--r--sim/common/ChangeLog12
-rw-r--r--sim/common/nrun.c17
-rw-r--r--sim/common/run.114
-rw-r--r--sim/common/sim-config.h5
-rw-r--r--sim/common/sim-options.c16
-rw-r--r--sim/common/syscall.c33
6 files changed, 90 insertions, 7 deletions
diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog
index a046a96..bc71bc9 100644
--- a/sim/common/ChangeLog
+++ b/sim/common/ChangeLog
@@ -1,5 +1,17 @@
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
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)
{
diff --git a/sim/common/run.1 b/sim/common/run.1
index ad11210..7de3c7a 100644
--- a/sim/common/run.1
+++ b/sim/common/run.1
@@ -1,4 +1,4 @@
-.\" 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
@@ -21,6 +21,8 @@ run\(em\&Simulator front-end
.IR freq "\|]"
.RB "[\|" \-m
.IR memory "\|]"
+.RB "[\|" \--sysroot
+.IR filepath "\|]"
.I program
.ad b
.hy 1
@@ -71,6 +73,16 @@ Set the memory size for the emulated machine to two to the power
.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"
diff --git a/sim/common/sim-config.h b/sim/common/sim-config.h
index f874b88..9d4d254 100644
--- a/sim/common/sim-config.h
+++ b/sim/common/sim-config.h
@@ -1,6 +1,6 @@
/* 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.
@@ -371,6 +371,9 @@ enum sim_environment {
? 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.
diff --git a/sim/common/sim-options.c b/sim/common/sim-options.c
index 789ec2a..397652c 100644
--- a/sim/common/sim-options.c
+++ b/sim/common/sim-options.c
@@ -1,5 +1,5 @@
/* 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.
@@ -115,6 +115,7 @@ typedef enum {
#endif
OPTION_LOAD_LMA,
OPTION_LOAD_VMA,
+ OPTION_SYSROOT
} STANDARD_OPTIONS;
static const OPTION standard_options[] =
@@ -205,6 +206,11 @@ 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 }
};
@@ -441,6 +447,14 @@ standard_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt,
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;
diff --git a/sim/common/syscall.c b/sim/common/syscall.c
index 04dc71e..76b32ba 100644
--- a/sim/common/syscall.c
+++ b/sim/common/syscall.c
@@ -38,6 +38,11 @@
#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
@@ -68,6 +73,10 @@
#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. */
@@ -101,7 +110,8 @@ get_string (cb, sc, buf, buflen, addr)
/* 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
@@ -113,10 +123,27 @@ get_path (cb, sc, addr, bufp)
{
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;