This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
[python] add gdb_datadir support
- From: Tom Tromey <tromey at redhat dot com>
- To: Project Archer <archer at sourceware dot org>
- Date: Tue, 18 Nov 2008 12:45:58 -0700
- Subject: [python] add gdb_datadir support
- Reply-to: tromey at redhat dot com
This patch comes from SÃrgio's syscall branch. It gives gdb a notion
of a "datadir", where auxiliary data files can be installed.
We'll use this on the Python branch to install and find a standard
library of gdb-specific Python code.
I think this is probably better than installing things into the global
Python library directory, because the code in question will generally
be specific to gdb -- that is, it won't run in a generic Python
interpreter.
Tom
2008-11-18 Sergio Durigan Junior <sergiodj@linux.vnet.ibm.com>
* defs.h (gdb_datadir): New variable.
* main.c: Add gdb_datadir variable to store the current GDB datadir.
(captured_main): Add the GDB datadir relocatable handler.
* maint.c: Create the "maintanence set gdb_datadir" command.
* configure, config.in: Regenerate.
* configure.ac: Support for relocatable GDB datadir.
* Makefile.in (GDB_DATADIR_PATH): New variable.
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 9329892..91b5ab2 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -172,6 +172,9 @@ LIBICONV = @LIBICONV@
TARGET_SYSTEM_ROOT = @TARGET_SYSTEM_ROOT@
TARGET_SYSTEM_ROOT_DEFINE = @TARGET_SYSTEM_ROOT_DEFINE@
+# Did the user give us a --with-gdb-datadir option?
+GDB_DATADIR_PATH = @GDB_DATADIR_PATH@
+
# Helper code from gnulib.
LIBGNU = gnulib/libgnu.a
INCGNU = -I$(srcdir)/gnulib -Ignulib
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 677a6ae..8970ab3 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -118,6 +118,36 @@ case ${debugdir} in
;;
esac
+# GDB's datadir relocation
+
+gdbdatadir=${datadir}/gdb
+
+AC_ARG_WITH([gdb-datadir],
+ [AS_HELP_STRING([--with-gdb-datadir],
+ [look for global separate data files in this path [DATADIR/gdb]])], [gdbdatadir="${withval}"])
+
+AC_DEFINE_DIR(GDB_DATADIR, gdbdatadir,
+ [Global directory for GDB data files. ])
+
+if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then
+ if test "x$prefix" = xNONE; then
+ test_prefix=/usr/local
+ else
+ test_prefix=$prefix
+ fi
+else
+ test_prefix=$exec_prefix
+fi
+
+case ${gdbdatadir} in
+ "${test_prefix}"|"${test_prefix}/"*|\
+ '${exec_prefix}'|'${exec_prefix}/'*)
+ AC_DEFINE(GDB_DATADIR_RELOCATABLE, 1, [Define if GDB datadir should be relocated when GDB is moved.])
+ ;;
+esac
+GDB_DATADIR_PATH=${gdbdatadir}
+AC_SUBST(GDB_DATADIR_PATH)
+
AC_CONFIG_SUBDIRS(doc testsuite)
# Check whether to support alternative target configurations
diff --git a/gdb/defs.h b/gdb/defs.h
index 23a6599..49a09d4 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -151,6 +151,9 @@ extern int dbx_commands;
/* System root path, used to find libraries etc. */
extern char *gdb_sysroot;
+/* GDB datadir, used to store data files. */
+extern char *gdb_datadir;
+
/* Search path for separate debug files. */
extern char *debug_file_directory;
diff --git a/gdb/main.c b/gdb/main.c
index c7155b1..a53002d 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -64,6 +64,9 @@ int dbx_commands = 0;
/* System root path, used to find libraries etc. */
char *gdb_sysroot = 0;
+/* GDB datadir, used to store data files. */
+char *gdb_datadir = 0;
+
struct ui_file *gdb_stdout;
struct ui_file *gdb_stderr;
struct ui_file *gdb_stdlog;
@@ -272,6 +275,40 @@ captured_main (void *data)
}
}
+#ifdef GDB_DATADIR_RELOCATABLE
+ gdb_datadir = make_relative_prefix (argv[0], BINDIR, GDB_DATADIR);
+ if (gdb_datadir)
+ {
+ struct stat s;
+ int res = 0;
+
+ if (stat (gdb_datadir, &s) == 0)
+ if (S_ISDIR (s.st_mode))
+ res = 1;
+
+ if (res == 0)
+ {
+ xfree (gdb_datadir);
+ gdb_datadir = xstrdup (GDB_DATADIR);
+ }
+ }
+ else
+ gdb_datadir = xstrdup (GDB_DATADIR);
+#else
+ gdb_datadir = xstrdup (GDB_DATADIR);
+#endif /* GDB_DATADIR_RELOCATABLE */
+
+ /* Canonicalize the GDB's datadir path. */
+ if (*gdb_datadir)
+ {
+ char *canon_debug = lrealpath (gdb_datadir);
+ if (canon_debug)
+ {
+ xfree (gdb_datadir);
+ gdb_datadir = canon_debug;
+ }
+ }
+
/* There will always be an interpreter. Either the one passed into
this captured main, or one specified by the user at start up, or
the console. Initialize the interpreter to the one requested by
diff --git a/gdb/maint.c b/gdb/maint.c
index e64d4fe..a5c6ba0 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -880,4 +880,12 @@ When enabled GDB is profiled."),
show_maintenance_profile_p,
&maintenance_set_cmdlist,
&maintenance_show_cmdlist);
+ add_setshow_filename_cmd ("gdb_datadir", class_maintenance,
+ &gdb_datadir, _("Set GDB's datadir path."),
+ _("Show GDB's datadir path."),
+ _("\
+When set, GDB uses the specified path to search for data files."),
+ NULL, NULL,
+ &maintenance_set_cmdlist,
+ &maintenance_show_cmdlist);
}