From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20582 invoked by alias); 6 Dec 2004 16:54:29 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 20130 invoked from network); 6 Dec 2004 16:54:13 -0000 Received: from unknown (HELO krynn.se.axis.com) (212.209.10.221) by sourceware.org with SMTP; 6 Dec 2004 16:54:13 -0000 Received: from ignucius.se.axis.com (ignucius.se.axis.com [10.83.5.18]) by krynn.se.axis.com (8.12.9/8.12.9/Debian-5local0.1) with ESMTP id iB6GsCAD003490; Mon, 6 Dec 2004 17:54:12 +0100 Received: from ignucius.se.axis.com (localhost [127.0.0.1]) by ignucius.se.axis.com (8.12.8p1/8.12.8/Debian-2woody1) with ESMTP id iB6GsCdD005079; Mon, 6 Dec 2004 17:54:12 +0100 Received: (from hp@localhost) by ignucius.se.axis.com (8.12.8p1/8.12.8/Debian-2woody1) id iB6GsCAe005075; Mon, 6 Dec 2004 17:54:12 +0100 Date: Mon, 06 Dec 2004 17:39:00 -0000 Message-Id: <200412061654.iB6GsCAe005075@ignucius.se.axis.com> From: Hans-Peter Nilsson To: gdb-patches@sources.redhat.com Subject: [RFA:] sim --sysroot=... option. X-SW-Source: 2004-12/txt/msg00165.txt.bz2 Note that this only affects users of cb_syscall: frv-sim, m32r-sim, mn10300-sim and the to-be-submitted cris-sim. (No regressions in results for those simulators, FWIW; right, mn10300-sim doesn't have any sim testsuite at all.) Testcases are in the CRIS C simulator testsuite. Unfortunately I didn't find any documentation files other than run.1. Using per-syscall path adjustments in callback.c works and would cover more simulators, but seems to me a less clean solution. If other simulators want a working --sysroot=x as well, I suggest they either make an overhaul to start using cb_syscall (so they get the get_path calls), or that get_path be made global and that those simulators be changed to use it instead of their local equivalent. Ok to commit? * 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 (main): If simulator_sysroot is not empty, chdir there. * run.c (main): Ditto. * sim-config.h (simulator_sysroot): Declare. Index: nrun.c =================================================================== RCS file: /cvs/src/src/sim/common/nrun.c,v retrieving revision 1.4 diff -c -p -r1.4 nrun.c *** nrun.c 23 Jun 2003 18:03:17 -0000 1.4 --- nrun.c 6 Dec 2004 16:43:23 -0000 *************** *** 1,5 **** /* New version of run front end support for simulators. ! Copyright (C) 1997 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 --- 1,5 ---- /* New version of run front end support for simulators. ! 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 *************** main (int argc, char **argv) *** 117,122 **** --- 117,132 ---- 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) { Index: run.1 =================================================================== RCS file: /cvs/src/src/sim/common/run.1,v retrieving revision 1.2 diff -c -p -r1.2 run.1 *** run.1 30 Nov 2000 01:54:16 -0000 1.2 --- run.1 6 Dec 2004 16:52:08 -0000 *************** *** 1,4 **** ! .\" Copyright (c) 1993 Free Software Foundation .\" See section COPYING for conditions for redistribution .TH run 1 "13oct1993" "GNU Tools" "GNU Tools" .de BP --- 1,4 ---- ! .\" Copyright (c) 1993, 2004 Free Software Foundation .\" See section COPYING for conditions for redistribution .TH run 1 "13oct1993" "GNU Tools" "GNU Tools" .de BP *************** run\(em\&Simulator front-end *** 21,26 **** --- 21,28 ---- .IR freq "\|]" .RB "[\|" \-m .IR memory "\|]" + .RB "[\|" \--sysroot + .IR filepath "\|]" .I program .ad b .hy 1 *************** Set the memory size for the emulated mac *** 71,76 **** --- 73,88 ---- .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" Index: run.c =================================================================== RCS file: /cvs/src/src/sim/common/run.c,v retrieving revision 1.16 diff -c -p -r1.16 run.c *** run.c 29 Jun 2004 00:54:00 -0000 1.16 --- run.c 6 Dec 2004 16:43:23 -0000 *************** main (ac, av) *** 233,238 **** --- 233,248 ---- if (sim_create_inferior (sd, abfd, prog_args, NULL) == SIM_RC_FAIL) exit (1); + /* 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); + } + #ifdef SIM_HAVE_ENVIRONMENT /* NOTE: An old simulator supporting the operating environment MUST provide sim_set_trace() and not sim_trace(). That way Index: sim-config.h =================================================================== RCS file: /cvs/src/src/sim/common/sim-config.h,v retrieving revision 1.2 diff -c -p -r1.2 sim-config.h *** sim-config.h 23 Nov 2002 01:12:05 -0000 1.2 --- sim-config.h 6 Dec 2004 16:43:23 -0000 *************** *** 1,6 **** /* The common simulator framework for GDB, the GNU Debugger. ! Copyright 2002 Free Software Foundation, Inc. Contributed by Andrew Cagney and Red Hat. --- 1,6 ---- /* The common simulator framework for GDB, the GNU Debugger. ! Copyright 2002, 2004 Free Software Foundation, Inc. Contributed by Andrew Cagney and Red Hat. *************** enum sim_environment { *** 371,376 **** --- 371,379 ---- ? 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. Index: sim-options.c =================================================================== RCS file: /cvs/src/src/sim/common/sim-options.c,v retrieving revision 1.7 diff -c -p -r1.7 sim-options.c *** sim-options.c 10 Jul 2004 00:40:25 -0000 1.7 --- sim-options.c 6 Dec 2004 16:43:23 -0000 *************** *** 1,5 **** /* Simulator option handling. ! Copyright (C) 1996, 1997 Free Software Foundation, Inc. Contributed by Cygnus Support. This file is part of GDB, the GNU debugger. --- 1,5 ---- /* Simulator option handling. ! Copyright (C) 1996, 1997, 2004 Free Software Foundation, Inc. Contributed by Cygnus Support. This file is part of GDB, the GNU debugger. *************** typedef enum { *** 115,120 **** --- 115,121 ---- #endif OPTION_LOAD_LMA, OPTION_LOAD_VMA, + OPTION_SYSROOT } STANDARD_OPTIONS; static const OPTION standard_options[] = *************** static const OPTION standard_options[] = *** 205,210 **** --- 206,216 ---- '\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 } }; *************** standard_option_handler (SIM_DESC sd, si *** 441,446 **** --- 447,460 ---- 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; Index: syscall.c =================================================================== RCS file: /cvs/src/src/sim/common/syscall.c,v retrieving revision 1.3 diff -c -p -r1.3 syscall.c *** syscall.c 10 May 2004 16:18:03 -0000 1.3 --- syscall.c 6 Dec 2004 16:43:23 -0000 *************** *** 38,43 **** --- 38,48 ---- #ifdef HAVE_STDLIB_H #include #endif + #ifdef HAVE_STRING_H + #include + #elif defined (HAVE_STRINGS_H) + #include + #endif #ifdef HAVE_UNISTD_H #include #endif *************** *** 68,73 **** --- 73,82 ---- #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. */ *************** get_string (cb, sc, buf, buflen, addr) *** 101,107 **** /* 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. If an error occurs, no buffer is left malloc'd. */ static int --- 110,117 ---- /* 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, but prepended with ! simulator_sysroot if the string starts with '/'. If an error occurs, no buffer is left malloc'd. */ static int *************** get_path (cb, sc, addr, bufp) *** 113,122 **** { char *buf = xmalloc (MAX_PATH_LEN); int result; ! result = get_string (cb, sc, buf, MAX_PATH_LEN, addr); if (result == 0) ! *bufp = buf; else free (buf); return result; --- 123,149 ---- { char *buf = xmalloc (MAX_PATH_LEN); int result; + int sysroot_len = strlen (simulator_sysroot); ! result = get_string (cb, sc, buf, MAX_PATH_LEN - sysroot_len, addr); if (result == 0) ! { ! /* 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; brgds, H-P