[patch 7.4] Deprecate local .gdbinit [Re: [patch] New set auto-load-local-gdbinit + disable it by default]

Jan Kratochvil
2012-01-17T14:46:15Z

On Tue, 17 Jan 2012 14:39:13 +0100, Joel Brobecker wrote:
> If we do move forward on that change, I think we should do it more
> gradually:
> 1. We start by emitting a warning when seeing a local .gdbinit file,
> but otherwise read it.
> 2. We stop reading them once a release with the warning is out.

Like still into the 7.4 branch?

No regressions for gdb_7_4-branch on
{x86_64,x86_64-m32,i686}-fedorarawhide-linux-gnu.

OTOH TBH I do not think from #gdb etc. users in general use very every GDB
release with the current rapid release cycles.

Thanks,
Jan

gdb/
2012-01-17 Jan Kratochvil <jan.kratochvil@redhat.com>

Deprecate reading of file .gdbinit in current directory.
* NEWS: New entry.
* main.c: Include readline/tilde.h.
(get_init_files): New parameter local_gdbinit_stat. Describe it in the
function comment. Change local variable cwdbuf to localinit_stat.
(captured_main): New variable local_gdbinit_stat, initialize it by
get_init_files. Check local_gdbinit duplicity against CMDARG. New
warning before calling catch_command_errors for local_gdbinit.
(print_gdb_help): Update the get_init_files caller. New message for
"local init file".

--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -22,6 +22,10 @@
watchpoints are slower than real hardware watchpoints but are
significantly faster than gdb software watchpoints.

+* Automatic reading of file .gdbinit in current directory has been deprecated
+ and it will be removed in gdb-7.5.
+ Use explicit 'gdb -x .gdbinit ...' command instead.
+
* Python scripting

** The register_pretty_printer function in module gdb.printing now takes
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -41,6 +41,7 @@
#include "cli/cli-cmds.h"
#include "python/python.h"
#include "objfiles.h"
+#include "readline/tilde.h"

/* The selected interpreter. This will be used as a set command
variable, so it should always be malloc'ed - since
@@ -152,23 +153,26 @@ relocate_gdb_directory (const char *initial, int flag)
}

/* 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. */
+ return them in SYSTEM_GDBINIT, HOME_GDBINIT, LOCAL_GDBINIT and
+ LOCAL_GDBINIT_STAT. 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, LOCAL_GDBINIT_STAT is
+ zeroed. */
+
static void
get_init_files (char **system_gdbinit,
char **home_gdbinit,
- char **local_gdbinit)
+ char **local_gdbinit, struct stat *local_gdbinit_stat)
{
static char *sysgdbinit = NULL;
static char *homeinit = NULL;
static char *localinit = NULL;
+ static struct stat localinit_stat;
static int initialized = 0;

if (!initialized)
{
- struct stat homebuf, cwdbuf, s;
+ struct stat homebuf, s;
char *homedir, *relocated_sysgdbinit;

if (SYSTEM_GDBINIT[0])
@@ -186,12 +190,12 @@ get_init_files (char **system_gdbinit,

/* 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). */
+ and localinit_stat 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));
+ memset (&localinit_stat, 0, sizeof (struct stat));

if (homedir)
{
@@ -203,11 +207,10 @@ get_init_files (char **system_gdbinit,
}
}

- if (stat (gdbinit, &cwdbuf) == 0)
+ if (stat (gdbinit, &localinit_stat) == 0)
{
if (!homeinit
- || memcmp ((char *) &homebuf, (char *) &cwdbuf,
- sizeof (struct stat)))
+ || memcmp (&homebuf, &localinit_stat, sizeof (struct stat)))
localinit = gdbinit;
}

@@ -217,6 +220,8 @@ get_init_files (char **system_gdbinit,
*system_gdbinit = sysgdbinit;
*home_gdbinit = homeinit;
*local_gdbinit = localinit;
+ if (local_gdbinit_stat)
+ *local_gdbinit_stat = localinit_stat;
}

/* Call command_loop. If it happens to return, pass that through as a
@@ -293,6 +298,7 @@ captured_main (void *data)
char *system_gdbinit;
char *home_gdbinit;
char *local_gdbinit;
+ struct stat local_gdbinit_stat;

int i;
int save_auto_load;
@@ -727,7 +733,8 @@ captured_main (void *data)
/* Lookup gdbinit files. Note that the gdbinit file name may be
overriden during file initialization, so get_init_files should be
called after gdb_init. */
- get_init_files (&system_gdbinit, &home_gdbinit, &local_gdbinit);
+ get_init_files (&system_gdbinit, &home_gdbinit, &local_gdbinit,
+ &local_gdbinit_stat);

/* Do these (and anything which might call wrap_here or *_filtered)
after initialize_all_files() but before the interpreter has been
@@ -899,7 +906,45 @@ captured_main (void *data)
/* Read the .gdbinit file in the current directory, *if* it isn't
the same as the $HOME/.gdbinit file (it should exist, also). */
if (local_gdbinit && !inhibit_gdbinit)
- catch_command_errors (source_script, local_gdbinit, 0, RETURN_MASK_ALL);
+ {
+ for (i = 0; i < ncmd; i++)
+ if (cmdarg[i].type == CMDARG_FILE)
+ {
+ struct cleanup *old_cleanups;
+ char *file;
+ int fd;
+
+ file = tilde_expand (cmdarg[i].string);
+ old_cleanups = make_cleanup (xfree, file);
+
+ fd = openp (source_path, OPF_TRY_CWD_FIRST, file, O_RDONLY, NULL);
+
+ do_cleanups (old_cleanups);
+
+ if (fd != -1)
+ {
+ struct stat statbuf;
+
+ if (fstat (fd, &statbuf) == 0
+ && memcmp (&statbuf, &local_gdbinit_stat,
+ sizeof (statbuf)) == 0)
+ local_gdbinit = NULL;
+
+ close (fd);
+ if (local_gdbinit == NULL)
+ break;
+ }
+ }
+
+ if (local_gdbinit)
+ {
+ warning (_("Automatic reading of file .gdbinit in current directory "
+ "has been deprecated and it will be removed in gdb-7.5. "
+ "Use explicit 'gdb -x .gdbinit ...' command instead."));
+ catch_command_errors (source_script, local_gdbinit, 0,
+ RETURN_MASK_ALL);
+ }
+ }

/* Now that all .gdbinit's have been read and all -d options have been
processed, we can read any scripts mentioned in SYMARG.
@@ -966,7 +1011,7 @@ print_gdb_help (struct ui_file *stream)
char *home_gdbinit;
char *local_gdbinit;

- get_init_files (&system_gdbinit, &home_gdbinit, &local_gdbinit);
+ get_init_files (&system_gdbinit, &home_gdbinit, &local_gdbinit, NULL);

fputs_unfiltered (_("\
This is the GNU debugger. Usage:\n\n\
@@ -1042,7 +1087,7 @@ At startup, GDB reads the following init files and executes their commands:\n\
"), home_gdbinit);
if (local_gdbinit)
fprintf_unfiltered (stream, _("\
- * local init file: ./%s\n\
+ * local init file (it will no longer be read by default since gdb-7.5): ./%s\n\
"), local_gdbinit);
fputs_unfiltered (_("\n\
For more information, type \"help\" from within GDB, or consult the\n\