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
+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"
/* 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
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. */
/* 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;
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(). */
}
}
+ 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
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)
/* 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++)
{
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\
--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);