From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Received: (qmail 11466 invoked from network); 9 Jan 2003 17:37:59 -0000 Received: from unknown (HELO crack.them.org) (65.125.64.184) by 209.249.29.67 with SMTP; 9 Jan 2003 17:37:59 -0000 Received: from nevyn.them.org ([66.93.61.169] ident=mail) by crack.them.org with asmtp (Exim 3.12 #1 (Debian)) id 18WiVV-0002LK-00; Thu, 09 Jan 2003 13:38:26 -0600 Received: from drow by nevyn.them.org with local (Exim 3.36 #1 (Debian)) id 18Wgd8-0007AU-00; Thu, 09 Jan 2003 12:38:10 -0500 Date: Thu, 09 Jan 2003 17:37:00 -0000 From: Daniel Jacobowitz To: gdb-patches@sources.redhat.com, Dan Kegel Subject: PATCH: --with-sysroot for GDB Message-ID: <20030109173810.GA19919@nevyn.them.org> Mail-Followup-To: gdb-patches@sources.redhat.com, Dan Kegel Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.1i X-SW-Source: 2003-01/txt/msg00368.txt.bz2 [Copied to Dan K. 'cause I know he'll like it :)] Both binutils and GCC now support (although GCC's support isn't quite finished yet, working on it...) a mechanism called "sysroot" for handling cross environments. The basic principal is that anything that would normally access the "target" filesystem does so just as if it were a native debugger running on $target, but prefixes all paths with the value of the sysroot prefix. We use $target/usr/include, $target/etc/ld.so.conf, $target/lib, et cetera. This is really great for people using, for instance, gdbserver to debug a remote GNU/Linux installation. I bet the QNX people could use this, too. Free bonus: as long as the sysroot is actually within $exec_prefix (otherwise the relocation functions don't work right), it will move along with the binary. You can pick up the whole tree, drop it somewhere else, and keep using it; no rebuild, no reconfigure. Here's a patch to do the same thing in GDB. Right now all it sets is solib-absolute-prefix; that's because I can't think of anything else it should affect, but if you have any ideas speak right up. It also documents solib-absolute-prefix and solib-search-path, which have been conspicuously missing from the manual for some time. Thoughts? I'll look to apply this in a couple of days if no one objects to the way I implemented it. -- Daniel Jacobowitz MontaVista Software Debian GNU/Linux Developer 2003-01-09 Daniel Jacobowitz * Makefile.in (TARGET_SYSTEM_ROOT, TARGET_SYSTEM_ROOT_DEFINE): New variables. (main.o): Custom rule which uses $(TARGET_SYSTEM_ROOT_DEFINE). * configure.in: Add --with-sysroot. * main.c (gdb_sysroot): New variable. (captured_main): Initialize gdb_sysroot. * defs.h (gdb_sysroot): New extern declaration. 2003-01-09 Daniel Jacobowitz * gdb.texinfo (Files): Document solib-absolute-prefix and solib-search-path. Index: Makefile.in =================================================================== RCS file: /cvs/src/src/gdb/Makefile.in,v retrieving revision 1.310 diff -u -p -r1.310 Makefile.in --- Makefile.in 6 Jan 2003 20:45:30 -0000 1.310 +++ Makefile.in 9 Jan 2003 17:29:16 -0000 @@ -136,6 +136,10 @@ INTL_CFLAGS = -I$(INTL_DIR) -I$(INTL_SRC # Where is the ICONV library? This can be empty if libc has iconv. LIBICONV = @LIBICONV@ +# Did the user give us a --with-sysroot option? +TARGET_SYSTEM_ROOT = @TARGET_SYSTEM_ROOT@ +TARGET_SYSTEM_ROOT_DEFINE = @TARGET_SYSTEM_ROOT_DEFINE@ + # # CLI sub directory definitons # @@ -1402,6 +1406,11 @@ hpux-thread.o: $(srcdir)/hpux-thread.c $(CC) -c $(INTERNAL_CFLAGS) -I$(srcdir)/osf-share \ -I$(srcdir)/osf-share/HP800 -I/usr/include/dce \ $(srcdir)/hpux-thread.c + +# main.o needs an explicit build rule to get TARGET_SYSTEM_ROOT and BINDIR. +main.o: main.c + $(CC) -c $(INTERNAL_CFLAGS) $(TARGET_SYSTEM_ROOT_DEFINE) \ + -DBINDIR=\"$(bindir)\" $(srcdir)/main.c # FIXME: Procfs.o gets -Wformat errors because things like pid_t don't # match output format strings. Index: configure.in =================================================================== RCS file: /cvs/src/src/gdb/configure.in,v retrieving revision 1.116 diff -u -p -r1.116 configure.in --- configure.in 4 Jan 2003 23:47:12 -0000 1.116 +++ configure.in 9 Jan 2003 17:29:18 -0000 @@ -851,6 +851,38 @@ fi dnl Handle optional features that can be enabled. +AC_ARG_WITH(sysroot, +[ --with-sysroot[=DIR] Search for usr/lib et al within DIR.], +[ + case ${with_sysroot} in + yes) AC_ERROR(with-sysroot must specify path) ;; + *) TARGET_SYSTEM_ROOT=$with_sysroot ;; + esac + + TARGET_SYSTEM_ROOT_DEFINE='-DTARGET_SYSTEM_ROOT=\"$(TARGET_SYSTEM_ROOT)\"' + + if test "x$exec_prefix" = xNONE; then + if test "x$prefix" = xNONE; then + test_prefix=/usr/local + else + test_prefix=$prefix + fi + else + test_prefix=$exec_prefix + fi + case ${TARGET_SYSTEM_ROOT} in + ${test_prefix}*) + t="$TARGET_SYSTEM_ROOT_DEFINE -DTARGET_SYSTEM_ROOT_RELOCATABLE" + TARGET_SYSTEM_ROOT_DEFINE="$t" + ;; + esac +], [ + TARGET_SYSTEM_ROOT= + TARGET_SYSTEM_ROOT_DEFINE='-DTARGET_SYSTEM_ROOT=\"\"' +]) +AC_SUBST(TARGET_SYSTEM_ROOT) +AC_SUBST(TARGET_SYSTEM_ROOT_DEFINE) + # NOTE: Don't add -Wall or -Wunused, they both include # -Wunused-parameter which reports bogus warnings. # NOTE: If you add to this list, remember to update Index: defs.h =================================================================== RCS file: /cvs/src/src/gdb/defs.h,v retrieving revision 1.107 diff -u -p -r1.107 defs.h --- defs.h 6 Jan 2003 18:49:08 -0000 1.107 +++ defs.h 9 Jan 2003 17:29:18 -0000 @@ -169,6 +169,9 @@ extern int xdb_commands; /* enable dbx commands if set */ extern int dbx_commands; +/* System root path, used to find libraries etc. */ +extern char *gdb_sysroot; + extern int quit_flag; extern int immediate_quit; extern int sevenbit_strings; Index: main.c =================================================================== RCS file: /cvs/src/src/gdb/main.c,v retrieving revision 1.20 diff -u -p -r1.20 main.c --- main.c 26 Sep 2002 17:46:04 -0000 1.20 +++ main.c 9 Jan 2003 17:29:18 -0000 @@ -65,6 +65,9 @@ int xdb_commands = 0; /* Whether dbx commands will be handled */ int dbx_commands = 0; +/* System root path, used to find libraries etc. */ +char *gdb_sysroot = 0; + struct ui_file *gdb_stdout; struct ui_file *gdb_stderr; struct ui_file *gdb_stdlog; @@ -200,6 +203,29 @@ captured_main (void *data) /* initialize error() */ error_init (); + + /* Set the sysroot path. */ +#ifdef TARGET_SYSTEM_ROOT_RELOCATABLE + gdb_sysroot = make_relative_prefix (argv[0], BINDIR, TARGET_SYSTEM_ROOT); + if (gdb_sysroot) + { + struct stat s; + int res = stat (gdb_sysroot, &s) == 0 && S_ISDIR (s.st_mode); + if (!res) + { + free (gdb_sysroot); + gdb_sysroot = TARGET_SYSTEM_ROOT; + } + } + else + gdb_sysroot = TARGET_SYSTEM_ROOT; +#else +#if defined (TARGET_SYSTEM_ROOT) + gdb_sysroot = TARGET_SYSTEM_ROOT; +#else + gdb_sysroot = ""; +#endif +#endif /* Parse arguments and options. */ { Index: solib.c =================================================================== RCS file: /cvs/src/src/gdb/solib.c,v retrieving revision 1.51 diff -u -p -r1.51 solib.c --- solib.c 9 Dec 2002 00:59:26 -0000 1.51 +++ solib.c 9 Jan 2003 17:29:19 -0000 @@ -875,6 +875,10 @@ For other (relative) files, you can add add_show_from_set (c, &showlist); set_cmd_completer (c, filename_completer); + /* Set the default value of "solib-absolute-prefix" from the sysroot, if + one is set. */ + solib_absolute_prefix = xstrdup (gdb_sysroot); + c = add_set_cmd ("solib-search-path", class_support, var_string, (char *) &solib_search_path, "Set the search path for loading non-absolute shared library symbol files.\n\ Index: doc/gdb.texinfo =================================================================== RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v retrieving revision 1.136 diff -u -p -r1.136 gdb.texinfo --- doc/gdb.texinfo 5 Jan 2003 04:34:39 -0000 1.136 +++ doc/gdb.texinfo 9 Jan 2003 17:29:23 -0000 @@ -9719,6 +9719,49 @@ Mb). Display the current autoloading size threshold, in megabytes. @end table +Shared libraries are also supported in many cross or remote debugging +configurations. A copy of the target's libraries need to be present on the +host system; they need to be the same as the target libraries, although the +copies on the target can be stripped as long as the copies on the host are +not. + +You need to tell @value{GDBN} where the target libraries are, so that it can +load the correct copies---otherwise, it may try to load the host's libraries. +@value{GDBN} has two variables to specify the search directories for target +libraries. + +@table @code +@kindex set solib-absolute-prefix +@item set solib-absolute-prefix @var{path} +If this variable is set, @var{path} will be used as a prefix for any +absolute shared library paths; many runtime loaders store the absolute +paths to the shared library in the target program's memory. If you use +@samp{solib-absolute-prefix} to find shared libraries, they need to be laid +out in the same way that they are on the target, with e.g.@: a +@file{/usr/lib} hierarchy under @var{path}. + +You can set the default value of @samp{solib-absolute-prefix} by using the +configure-time @samp{--with-sysroot} option. + +@kindex show solib-absolute-prefix +@item show solib-absolute-prefix +Display the current shared library prefix. + +@kindex set solib-search-path +@item set solib-search-path @var{path} +If this variable is set, @var{path} is a colon-separated list of directories +to search for shared libraries. @samp{solib-search-path} is used after +@samp{solib-absolute-prefix} fails to locate the library, or if the path to +the library is relative instead of absolute. If you want to use +@samp{solib-search-path} instead of @samp{solib-absolute-prefix}, be sure to +set @samp{solib-absolute-prefix} to a nonexistant directory to prevent +@value{GDBN} from finding your host's libraries. + +@kindex show solib-search-path +@item show solib-search-path +Display the current shared library search path. +@end table + @node Symbol Errors @section Errors reading symbol files