aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerome Guitton <guitton@adacore.com>2009-01-28 15:01:00 +0000
committerJerome Guitton <guitton@adacore.com>2009-01-28 15:01:00 +0000
commit16e7150e45f1220e9aafb85a80b967b43f93d75b (patch)
treed32a16cdfb91a052da606685f6191eff3a49b924
parent159073e6aa7586b0bc132f4e5f1c578c137b158b (diff)
downloadgdb-16e7150e45f1220e9aafb85a80b967b43f93d75b.zip
gdb-16e7150e45f1220e9aafb85a80b967b43f93d75b.tar.gz
gdb-16e7150e45f1220e9aafb85a80b967b43f93d75b.tar.bz2
2009-01-28 Daniel Jacobowitz <dan@codesourcery.com>
Jerome Guitton <guitton@adacore.com> * configure, config.in: Regenerated. * configure.ac: Add --with-system-gdbinit. * main.c (get_init_files): New. (captured_main): Use get_init_files. Load system gdbinit before $HOME/.gdbinit. (print_gdb_help): Print location of init files.
-rw-r--r--gdb/config.in7
-rwxr-xr-xgdb/configure44
-rw-r--r--gdb/configure.ac28
-rw-r--r--gdb/main.c150
4 files changed, 198 insertions, 31 deletions
diff --git a/gdb/config.in b/gdb/config.in
index bceba76..6aaf77a 100644
--- a/gdb/config.in
+++ b/gdb/config.in
@@ -655,6 +655,13 @@
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
+/* System-wide gdbinit file. */
+#undef SYSTEM_GDBINIT
+
+/* Define if the system-wide gdbinit file should be relocated when GDB is
+ moved. */
+#undef SYSTEM_GDBINIT_RELOCATABLE
+
/* Define if <thread_db.h> has the TD_NOTALLOC error code. */
#undef THREAD_DB_HAS_TD_NOTALLOC
diff --git a/gdb/configure b/gdb/configure
index 59681f5..ede5504 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -895,6 +895,7 @@ Optional Packages:
on systems with version 2 of the GNU C library
(use with caution on other system)
--with-sysroot=DIR Search for usr/lib et al within DIR.
+ --with-system-gdbinit=file Automatically load a system-wide gdbinit file
--with-tcl directory containing tcl configuration (tclConfig.sh)
--with-tk directory containing tk configuration (tkConfig.sh)
--with-x use the X Window System
@@ -19482,6 +19483,49 @@ fi;
+system_gdbinit=
+
+# Check whether --with-system-gdbinit or --without-system-gdbinit was given.
+if test "${with_system_gdbinit+set}" = set; then
+ withval="$with_system_gdbinit"
+ system_gdbinit=${withval}
+fi;
+
+
+ test "x$prefix" = xNONE && prefix="$ac_default_prefix"
+ test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
+ ac_define_dir=`eval echo $system_gdbinit`
+ ac_define_dir=`eval echo $ac_define_dir`
+
+cat >>confdefs.h <<_ACEOF
+#define SYSTEM_GDBINIT "$ac_define_dir"
+_ACEOF
+
+
+
+if test "x$prefix" = xNONE; then
+ test_prefix=$ac_default_prefix
+else
+ test_prefix=$prefix
+fi
+if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then
+ test_exec_prefix=$test_prefix
+else
+ test_exec_prefix=$exec_prefix
+fi
+case ${system_gdbinit} in
+ "${test_prefix}"|"${test_prefix}/"*|\
+ "${test_exec_prefix}"|"${test_exec_prefix}/"*|\
+ '${prefix}'|'${prefix}/'*|\
+ '${exec_prefix}'|'${exec_prefix}/'*)
+
+cat >>confdefs.h <<\_ACEOF
+#define SYSTEM_GDBINIT_RELOCATABLE 1
+_ACEOF
+
+ ;;
+esac
+
# Check whether --enable-werror or --disable-werror was given.
if test "${enable_werror+set}" = set; then
enableval="$enable_werror"
diff --git a/gdb/configure.ac b/gdb/configure.ac
index 56d40ad..c07eb10 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -1489,6 +1489,34 @@ AC_ARG_WITH(sysroot,
AC_SUBST(TARGET_SYSTEM_ROOT)
AC_SUBST(TARGET_SYSTEM_ROOT_DEFINE)
+system_gdbinit=
+AC_ARG_WITH(system-gdbinit,
+[ --with-system-gdbinit=file Automatically load a system-wide gdbinit file],
+[system_gdbinit=${withval}])
+
+AC_DEFINE_DIR(SYSTEM_GDBINIT, system_gdbinit,
+ [System-wide gdbinit file.])
+
+if test "x$prefix" = xNONE; then
+ test_prefix=$ac_default_prefix
+else
+ test_prefix=$prefix
+fi
+if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then
+ test_exec_prefix=$test_prefix
+else
+ test_exec_prefix=$exec_prefix
+fi
+case ${system_gdbinit} in
+ "${test_prefix}"|"${test_prefix}/"*|\
+ "${test_exec_prefix}"|"${test_exec_prefix}/"*|\
+ '${prefix}'|'${prefix}/'*|\
+ '${exec_prefix}'|'${exec_prefix}/'*)
+ AC_DEFINE(SYSTEM_GDBINIT_RELOCATABLE, 1,
+ [Define if the system-wide gdbinit file should be relocated when GDB is moved.])
+ ;;
+esac
+
AC_ARG_ENABLE(werror,
[ --enable-werror treat compile warnings as errors],
[case "${enableval}" in
diff --git a/gdb/main.c b/gdb/main.c
index 0eb9596..5d4640b 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -83,6 +83,9 @@ int return_child_result_value = -1;
/* Whether to enable writing into executable and core files */
extern int write_files;
+/* GDB as it has been invoked from the command line (i.e. argv[0]). */
+static char *gdb_program_name;
+
static void print_gdb_help (struct ui_file *);
/* These two are used to set the external editor commands when gdb is farming
@@ -90,6 +93,82 @@ static void print_gdb_help (struct ui_file *);
extern char *external_editor_command;
+/* Compute the locations of init files that GDB should source and return
+ them in SYSTEM_GDBINIT, HOME_GDBINIT, LOCAL_GDBINIT. If there is
+ no system gdbinit (resp. home gdbinit and local gdbinit) to be loaded,
+ then SYSTEM_GDBINIT (resp. HOME_GDBINIT and LOCAL_GDBINIT) is set to
+ NULL. */
+static void
+get_init_files (char **system_gdbinit,
+ char **home_gdbinit,
+ char **local_gdbinit)
+{
+ static char *sysgdbinit = NULL;
+ static char *homeinit = NULL;
+ static char *localinit = NULL;
+ static int initialized = 0;
+
+ if (!initialized)
+ {
+ struct stat homebuf, cwdbuf, s;
+ char *homedir, *relocated_sysgdbinit;
+
+ sysgdbinit = SYSTEM_GDBINIT;
+ if (!sysgdbinit [0] || stat (sysgdbinit, &s) != 0)
+ sysgdbinit = NULL;
+
+#ifdef SYSTEM_GDBINIT_RELOCATABLE
+ relocated_sysgdbinit = make_relative_prefix (gdb_program_name, BINDIR,
+ SYSTEM_GDBINIT);
+ if (relocated_sysgdbinit)
+ {
+ struct stat s;
+ int res = 0;
+
+ if (stat (relocated_sysgdbinit, &s) == 0)
+ sysgdbinit = relocated_sysgdbinit;
+ else
+ xfree (relocated_sysgdbinit);
+ }
+#endif
+
+ homedir = getenv ("HOME");
+
+ /* If the .gdbinit file in the current directory is the same as
+ the $HOME/.gdbinit file, it should not be sourced. homebuf
+ and cwdbuf are used in that purpose. Make sure that the stats
+ are zero in case one of them fails (this guarantees that they
+ won't match if either exists). */
+
+ memset (&homebuf, 0, sizeof (struct stat));
+ memset (&cwdbuf, 0, sizeof (struct stat));
+
+ if (homedir)
+ {
+ homeinit = xstrprintf ("%s/%s", homedir, gdbinit);
+ if (stat (homeinit, &homebuf) != 0)
+ {
+ xfree (homeinit);
+ homeinit = NULL;
+ }
+ }
+
+ if (stat (gdbinit, &cwdbuf) == 0)
+ {
+ if (!homeinit
+ || memcmp ((char *) &homebuf, (char *) &cwdbuf,
+ sizeof (struct stat)))
+ localinit = gdbinit;
+ }
+
+ initialized = 1;
+ }
+
+ *system_gdbinit = sysgdbinit;
+ *home_gdbinit = homeinit;
+ *local_gdbinit = localinit;
+}
+
/* Call command_loop. If it happens to return, pass that through as a
non-zero return status. */
@@ -156,8 +235,10 @@ captured_main (void *data)
/* Number of elements used. */
int ndir;
- struct stat homebuf, cwdbuf;
- char *homedir;
+ /* gdb init files. */
+ char *system_gdbinit;
+ char *home_gdbinit;
+ char *local_gdbinit;
int i;
@@ -196,6 +277,8 @@ captured_main (void *data)
gdb_stdtargerr = gdb_stderr; /* for moment */
gdb_stdtargin = gdb_stdin; /* for moment */
+ gdb_program_name = xstrdup (argv[0]);
+
if (! getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)))
/* Don't use *_filtered or warning() (which relies on
current_target) until after initialize_all_files(). */
@@ -274,6 +357,8 @@ captured_main (void *data)
}
}
+ get_init_files (&system_gdbinit, &home_gdbinit, &local_gdbinit);
+
/* 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
@@ -685,33 +770,20 @@ Excess command line arguments ignored. (%s%s)\n"),
quit_pre_print = error_pre_print;
warning_pre_print = _("\nwarning: ");
+ /* Read and execute the system-wide gdbinit file, if it exists.
+ This is done *before* all the command line arguments are
+ processed; it sets global parameters, which are independent of
+ what file you are debugging or what directory you are in. */
+ if (system_gdbinit && !inhibit_gdbinit)
+ catch_command_errors (source_script, system_gdbinit, 0, RETURN_MASK_ALL);
+
/* Read and execute $HOME/.gdbinit file, if it exists. This is done
*before* all the command line arguments are processed; it sets
global parameters, which are independent of what file you are
debugging or what directory you are in. */
- homedir = getenv ("HOME");
- if (homedir)
- {
- char *homeinit = xstrprintf ("%s/%s", homedir, gdbinit);
- if (!inhibit_gdbinit)
- {
- catch_command_errors (source_script, homeinit, 0, RETURN_MASK_ALL);
- }
-
- /* Do stats; no need to do them elsewhere since we'll only
- need them if homedir is set. Make sure that they are
- zero in case one of them fails (this guarantees that they
- won't match if either exists). */
-
- memset (&homebuf, 0, sizeof (struct stat));
- memset (&cwdbuf, 0, sizeof (struct stat));
-
- stat (homeinit, &homebuf);
- stat (gdbinit, &cwdbuf); /* We'll only need this if
- homedir was set. */
- xfree (homeinit);
- }
+ if (home_gdbinit && !inhibit_gdbinit)
+ catch_command_errors (source_script, home_gdbinit, 0, RETURN_MASK_ALL);
/* Now perform all the actions indicated by the arguments. */
if (cdarg != NULL)
@@ -779,13 +851,8 @@ Can't attach to process and specify a core file at the same time."));
/* Read the .gdbinit file in the current directory, *if* it isn't
the same as the $HOME/.gdbinit file (it should exist, also). */
-
- if (!homedir
- || memcmp ((char *) &homebuf, (char *) &cwdbuf, sizeof (struct stat)))
- if (!inhibit_gdbinit)
- {
- catch_command_errors (source_script, gdbinit, 0, RETURN_MASK_ALL);
- }
+ if (local_gdbinit && !inhibit_gdbinit)
+ catch_command_errors (source_script, local_gdbinit, 0, RETURN_MASK_ALL);
for (i = 0; i < ncmd; i++)
{
@@ -857,6 +924,12 @@ gdb_main (struct captured_main_args *args)
static void
print_gdb_help (struct ui_file *stream)
{
+ char *system_gdbinit;
+ char *home_gdbinit;
+ char *local_gdbinit;
+
+ get_init_files (&system_gdbinit, &home_gdbinit, &local_gdbinit);
+
fputs_unfiltered (_("\
This is the GNU debugger. Usage:\n\n\
gdb [options] [executable-file [core-file or process-id]]\n\
@@ -919,6 +992,21 @@ Options:\n\n\
--xdb XDB compatibility mode.\n\
"), stream);
fputs_unfiltered (_("\n\
+At startup, GDB reads the following init files and executes their commands:\n\
+"), stream);
+ if (system_gdbinit)
+ fprintf_unfiltered (stream, _("\
+ * system-wide init file: %s\n\
+"), system_gdbinit);
+ if (home_gdbinit)
+ fprintf_unfiltered (stream, _("\
+ * user-specific init file: %s\n\
+"), home_gdbinit);
+ if (local_gdbinit)
+ fprintf_unfiltered (stream, _("\
+ * local init file: ./%s\n\
+"), local_gdbinit);
+ fputs_unfiltered (_("\n\
For more information, type \"help\" from within GDB, or consult the\n\
GDB manual (available as on-line info or a printed manual).\n\
"), stream);