This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: --with-sysroot for GDB

[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/, $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  <>

	(main.o): Custom rule which uses $(TARGET_SYSTEM_ROOT_DEFINE).
	* 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

RCS file: /cvs/src/src/gdb/,v
retrieving revision 1.310
diff -u -p -r1.310
---	6 Jan 2003 20:45:30 -0000	1.310
+++	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.
+# Did the user give us a --with-sysroot option?
 # 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 \
+# main.o needs an explicit build rule to get TARGET_SYSTEM_ROOT and BINDIR.
+main.o: main.c
+		-DBINDIR=\"$(bindir)\" $(srcdir)/main.c
 # FIXME: Procfs.o gets -Wformat errors because things like pid_t don't
 # match output format strings.
RCS file: /cvs/src/src/gdb/,v
retrieving revision 1.116
diff -u -p -r1.116
---	4 Jan 2003 23:47:12 -0000	1.116
+++	9 Jan 2003 17:29:18 -0000
@@ -851,6 +851,38 @@ fi
 dnl Handle optional features that can be enabled.
+[  --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
+ 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
+ ${test_prefix}*)
+   ;;
+ esac
+], [
 # 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.  */
+  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;
+#if defined (TARGET_SYSTEM_ROOT)
+  gdb_sysroot = TARGET_SYSTEM_ROOT;
+  gdb_sysroot = "";
   /* 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
+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
+@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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]