[suspended patch#4 7/8] set auto-load local-gdbinit warn-and-*
Jan Kratochvil
jan.kratochvil@redhat.com
Thu Apr 5 21:09:00 GMT 2012
Hi,
just a re-post. warn-and-* has been changed to separate "set auto-load
local-gdbinit-warning".
Jan
gdb/
2012-04-05 Jan Kratochvil <jan.kratochvil@redhat.com>
* NEWS (set auto-load local-gdbinit-warning): New description.
* auto-load.c (auto_load_local_gdbinit_warning)
(show_auto_load_local_gdbinit_warning): New.
(_initialize_auto_load): Register "set auto-load local-gdbinit-warning"
and "show auto-load local-gdbinit-warning".
* auto-load.h (auto_load_local_gdbinit_warning): New declaration.
* main.c: Include readline/tilde.h.
(get_init_files): Add parameter local_gdbinit_stat, describe it in the
comment. New variable localinit_stat. Remove variable cwdbuf.
(captured_main): New variable local_gdbinit_stat. Scan CMDARG_VEC and
print warnings according to AUTO_LOAD_LOCAL_GDBINIT_WARNING.
(print_gdb_help): Update the get_init_files caller.
gdb/doc/
2012-04-05 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.texinfo (Startup): Mention local gdbinit is deprecated.
(Auto-loading): Provide new local-gdbinit-warning sample output.
Update multitable column widths. Include new refefences for
"set auto-load local-gdbinit-warning"
and "show auto-load local-gdbinit-warning" there.
(Current Directory Init File): Mention also
"set auto-load local-gdbinit-warning"
and "show auto-load local-gdbinit-warning".
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -145,6 +145,11 @@ set auto-load local-gdbinit on|off
show auto-load local-gdbinit
Control loading of init file (.gdbinit) from current directory.
+set auto-load local-gdbinit-warning on|off
+show auto-load local-gdbinit-warning
+ Control printing deprecation warning for loading of init file (.gdbinit) from
+ current directory.
+
set auto-load libthread-db on|off
show auto-load libthread-db
Control auto-loading of inferior specific thread debugging shared library.
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -90,6 +90,10 @@ int global_auto_load = 1;
/* Auto-load .gdbinit file from the current directory? */
int auto_load_local_gdbinit = 1;
+/* Print warning on attempted auto-load of .gdbinit file from the current
+ directory? */
+int auto_load_local_gdbinit_warning = 0;
+
/* Absolute pathname to the current directory .gdbinit, if it exists. */
char *auto_load_local_gdbinit_pathname = NULL;
@@ -107,6 +111,20 @@ show_auto_load_local_gdbinit (struct ui_file *file, int from_tty,
value);
}
+/* "show" command for the auto_load_local_gdbinit_warning configuration
+ variable. */
+
+static void
+show_auto_load_local_gdbinit_warning (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c,
+ const char *value)
+{
+ fprintf_filtered (file, _("Printing deprecation warning for attempted "
+ "auto-loading of .gdbinit script from current "
+ "directory is %s.\n"),
+ value);
+}
+
/* Directory list safe to hold auto-loaded files. It is not checked for
absolute paths but they are strongly recommended. It is initialized by
_initialize_auto_load. */
@@ -1015,6 +1033,20 @@ This options has security implications for untrusted inferiors."),
Usage: info auto-load local-gdbinit"),
auto_load_info_cmdlist_get ());
+ add_setshow_boolean_cmd ("local-gdbinit-warning", class_support,
+ &auto_load_local_gdbinit_warning, _("\
+Enable or disable printing warnings for .gdbinit script in current directory."),
+ _("\
+Show whether printing warnings for .gdbinit script in current directory \
+is enabled."),
+ _("\
+GDB prints a warning when it finds .gdbinit script in current directory\n\
+as these files have been deprecated. Whether it is loaded or not depends\n\
+on 'set auto-load local-gdbinit'."),
+ NULL, show_auto_load_local_gdbinit_warning,
+ auto_load_set_cmdlist_get (),
+ auto_load_show_cmdlist_get ());
+
auto_load_safe_path = xstrdup (DEFAULT_AUTO_LOAD_SAFE_PATH);
auto_load_safe_path_vec_update ();
add_setshow_optional_filename_cmd ("safe-path", class_support,
--- a/gdb/auto-load.h
+++ b/gdb/auto-load.h
@@ -33,6 +33,7 @@ struct script_language
extern int global_auto_load;
extern int auto_load_local_gdbinit;
+extern int auto_load_local_gdbinit_warning;
extern char *auto_load_local_gdbinit_pathname;
extern int auto_load_local_gdbinit_loaded;
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -1294,6 +1294,11 @@ init file, one generic in your home directory, and another, specific
to the program you are debugging, in the directory where you invoke
@value{GDBN}.
+This feature is deprecated, please use @ref{objfile-gdb.gdb file}
+instead. The canned sequence of commands will be then specific for loaded
+@var{objfile}---typically the main executable---after converting an init file in
+the current directory into the @var{objfile}-gdb.gdb file..
+
@item
If the command line specified a program to debug, or a process to
attach to, or a core file, @value{GDBN} loads any auto-loaded
@@ -20743,6 +20748,8 @@ gdb-scripts: Auto-loading of canned sequences of commands scripts is on.
libthread-db: Auto-loading of inferior specific libthread_db is on.
local-gdbinit: Auto-loading of .gdbinit script from current directory is on.
python-scripts: Auto-loading of Python scripts is on.
+local-gdbinit-warning: Printing deprecation warning for attempted auto-loading
+ of .gdbinit script from current directory is off.
safe-path: List of directories from which it is safe to auto-load files
is /usr/local.
@end smallexample
@@ -20810,6 +20817,10 @@ These are @value{GDBN} control commands for the auto-loading:
@tab Show setting of init file in the current directory.
@item @xref{info auto-load local-gdbinit}.
@tab Show state of init file in the current directory.
+@item @xref{set auto-load local-gdbinit-warning}.
+@tab Control warning for init file in the current directory.
+@item @xref{show auto-load local-gdbinit-warning}.
+@tab Show setting of warning for init file in the current directory.
@item @xref{set auto-load libthread-db}.
@tab Control for thread debugging library.
@item @xref{show auto-load libthread-db}.
@@ -20859,6 +20870,22 @@ current directory is enabled or disabled.
@item info auto-load local-gdbinit
Print whether canned sequences of commands from init file in the
current directory have been auto-loaded.
+
+@anchor{set auto-load local-gdbinit-warning}
+@kindex set auto-load local-gdbinit-warning
+@item set auto-load local-gdbinit-warning [on|off]
+Enable or disable printing warnings for an init file in the current directory.
+
+The warning is given before loading (@samp{set auto-load local-gdbinit} is
+enabled) or when declining to load (@samp{set auto-load local-gdbinit} is
+disabled) an init file in the current directory. The @samp{local-gdbinit}
+feature is deprecated in favor of @xref{objfile-gdb.gdb file}.
+
+@anchor{show auto-load local-gdbinit-warning}
+@kindex show auto-load local-gdbinit-warning
+@item show auto-load local-gdbinit-warning
+Show whether printing warnings for init file in the current directory is
+enabled or disabled.
@end table
@node libthread_db.so.1 file
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -42,6 +42,7 @@
#include "python/python.h"
#include "objfiles.h"
#include "auto-load.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
@@ -146,23 +147,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])
@@ -180,12 +184,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)
{
@@ -197,11 +201,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;
}
@@ -211,6 +214,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
@@ -303,6 +308,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;
@@ -755,7 +761,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
@@ -944,16 +951,72 @@ captured_main (void *data)
{
auto_load_local_gdbinit_pathname = gdb_realpath (local_gdbinit);
- if (!inhibit_gdbinit && auto_load_local_gdbinit
- && file_is_auto_load_safe (local_gdbinit,
- _("auto-load: Loading .gdbinit "
- "file \"%s\".\n"),
- local_gdbinit))
+ if (!inhibit_gdbinit
+ && (auto_load_local_gdbinit || auto_load_local_gdbinit_warning))
{
- auto_load_local_gdbinit_loaded = 1;
+ /* Verify whether user has already specified `-x ./.gdbinit'. */
+ for (i = 0; VEC_iterate (cmdarg_s, cmdarg_vec, i, cmdarg_p); i++)
+ if (cmdarg_p->type == CMDARG_FILE)
+ {
+ struct cleanup *old_cleanups;
+ char *file;
+ int fd;
+
+ file = tilde_expand (cmdarg_p->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;
+
+ /* Ensure memcmp works even with fields padding.
+ LOCAL_GDBINIT_STAT is already pre-cleared. */
+ memset (&statbuf, 0, sizeof (statbuf));
+
+ if (fstat (fd, &statbuf) == 0
+ && memcmp (&statbuf, &local_gdbinit_stat,
+ sizeof (statbuf)) == 0)
+ local_gdbinit = NULL;
- catch_command_errors (source_script, local_gdbinit, 0,
- RETURN_MASK_ALL);
+ close (fd);
+ if (local_gdbinit == NULL)
+ break;
+ }
+ }
+
+ if (local_gdbinit)
+ {
+ const char adv[] = N_("Use script associated with inferior "
+ "executable file instead. "
+ "See also 'set auto-load local-gdbinit'. "
+ "You may also use 'gdb -x .gdbinit ...'.");
+ if (auto_load_local_gdbinit && auto_load_local_gdbinit_warning)
+ warning (_("Reading of .gdbinit files in current directory "
+ "has been deprecated and will be removed in "
+ "a future version of GDB. %s"),
+ _(adv));
+ if (!auto_load_local_gdbinit)
+ {
+ gdb_assert (auto_load_local_gdbinit_warning);
+ warning (_("Ignoring file .gdbinit in current directory "
+ "as it has been deprecated. %s"),
+ _(adv));
+ }
+ else if (file_is_auto_load_safe (local_gdbinit,
+ _("auto-load: Loading .gdbinit "
+ "file \"%s\".\n"),
+ local_gdbinit))
+ {
+ auto_load_local_gdbinit_loaded = 1;
+ catch_command_errors (source_script, local_gdbinit, 0,
+ RETURN_MASK_ALL);
+ }
+ }
}
}
@@ -1025,7 +1088,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\
More information about the Gdb-patches
mailing list