This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: PATCH: --with-sysroot for GDB
- From: Elena Zannoni <ezannoni at redhat dot com>
- To: Daniel Jacobowitz <drow at mvista dot com>
- Cc: gdb-patches at sources dot redhat dot com, Dan Kegel <dank at kegel dot com>
- Date: Thu, 9 Jan 2003 14:21:07 -0500
- Subject: Re: PATCH: --with-sysroot for GDB
- References: <20030109173810.GA19919@nevyn.them.org>
Daniel Jacobowitz writes:
> [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.
main.c ok, except for.... see below:
>
> --
> Daniel Jacobowitz
> MontaVista Software Debian GNU/Linux Developer
>
> 2003-01-09 Daniel Jacobowitz <drow@mvista.com>
>
> * 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 <drow@mvista.com>
>
> * 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);
please split this statement into an if + assignment.