From 7349ff92c20df6a9f4ea3e53383d99622960d74d Mon Sep 17 00:00:00 2001 From: Jan Kratochvil Date: Fri, 11 May 2012 18:20:26 +0000 Subject: [PATCH] gdb/ Implement multi-component --with-auto-load-dir. * NEWS (set auto-load scripts-directory, --with-auto-load-dir): New entries. (--with-auto-load-safe-path): Update the default value description. * auto-load.c (auto_load_dir, set_auto_load_dir, show_auto_load_dir): New. (auto_load_objfile_script): Add DEBUG_AUTO_LOAD output. Remove GDB_DATADIR NULL check. Replace GDB_DATADIR/auto-load by AUTO_LOAD_DIR. Support $ddir and multiple components in it. (_initialize_auto_load): Initialize also auto_load_dir. Install new "set auto-load scripts-directory". * config.in: Regenerate. * configure: Regenerate. * configure.ac (--with-auto-load-dir): New configure option. (--auto-load-safe-path): Change the default to --with-auto-load-dir. gdb/doc/ Implement multi-component --with-auto-load-dir. * gdb.texinfo (Auto-loading): New references for 'set auto-load scripts-directory' and 'show auto-load scripts-directory'. (Auto-loading safe path): Describe the new default. Move $ddir substituation reference to 'objfile-gdb.py file'. (objfile-gdb.py file): Describe script-name alias. Change real-name to script-name. Describe new 'set auto-load scripts-directory' and 'show auto-load scripts-directory'. --- gdb/ChangeLog | 18 ++++++++ gdb/NEWS | 14 ++++++- gdb/auto-load.c | 100 +++++++++++++++++++++++++++++++++++++++----- gdb/config.in | 3 ++ gdb/configure | 34 ++++++++++++++- gdb/configure.ac | 14 ++++++- gdb/doc/ChangeLog | 12 ++++++ gdb/doc/gdb.texinfo | 56 +++++++++++++++++++------ 8 files changed, 223 insertions(+), 28 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index fec1f8a55ec..35acb6e42c1 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,21 @@ +2012-05-11 Jan Kratochvil + + Implement multi-component --with-auto-load-dir. + * NEWS (set auto-load scripts-directory, --with-auto-load-dir): New + entries. + (--with-auto-load-safe-path): Update the default value description. + * auto-load.c (auto_load_dir, set_auto_load_dir, show_auto_load_dir): + New. + (auto_load_objfile_script): Add DEBUG_AUTO_LOAD output. Remove + GDB_DATADIR NULL check. Replace GDB_DATADIR/auto-load by + AUTO_LOAD_DIR. Support $ddir and multiple components in it. + (_initialize_auto_load): Initialize also auto_load_dir. Install new + "set auto-load scripts-directory". + * config.in: Regenerate. + * configure: Regenerate. + * configure.ac (--with-auto-load-dir): New configure option. + (--auto-load-safe-path): Change the default to --with-auto-load-dir. + 2012-05-11 Jan Kratochvil Provide $ddir substitution for --with-auto-load-safe-path. diff --git a/gdb/NEWS b/gdb/NEWS index c7f9824a5e2..e6b7bbf2faa 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -172,6 +172,12 @@ set auto-load libthread-db on|off show auto-load libthread-db Control auto-loading of inferior specific thread debugging shared library. +set auto-load scripts-directory [:...] + Set a list of directories from which to load auto-loaded scripts. + Automatically loaded Python scripts and GDB scripts are located in one + of the directories listed by this option. + The delimiter (':' above) may differ according to the host platform. + set auto-load safe-path [:...] show auto-load safe-path Set a list of directories from which it is safe to auto-load files. @@ -183,10 +189,14 @@ show debug auto-load * New configure options +--with-auto-load-dir + Configure default value for the 'set auto-load scripts-directory' + setting above. It defaults to '$ddir/auto-load', $ddir representing + GDB's data directory (available via show data-directory). + --with-auto-load-safe-path Configure default value for the 'set auto-load safe-path' setting - above. It defaults to '$ddir/auto-load', $ddir representing GDB's - data directory (available via show data-directory). + above. It defaults to the --with-auto-load-dir setting. --without-auto-load-safe-path Set 'set auto-load safe-path' to '/', effectively disabling this diff --git a/gdb/auto-load.c b/gdb/auto-load.c index 171c9b1e200..5ee117f13df 100644 --- a/gdb/auto-load.c +++ b/gdb/auto-load.c @@ -108,6 +108,35 @@ show_auto_load_local_gdbinit (struct ui_file *file, int from_tty, value); } +/* Directory list from which to load auto-loaded scripts. It is not checked + for absolute paths but they are strongly recommended. It is initialized by + _initialize_auto_load. */ +static char *auto_load_dir; + +/* "set" command for the auto_load_dir configuration variable. */ + +static void +set_auto_load_dir (char *args, int from_tty, struct cmd_list_element *c) +{ + /* Setting the variable to "" resets it to the compile time defaults. */ + if (auto_load_dir[0] == '\0') + { + xfree (auto_load_dir); + auto_load_dir = xstrdup (AUTO_LOAD_DIR); + } +} + +/* "show" command for the auto_load_dir configuration variable. */ + +static void +show_auto_load_dir (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + fprintf_filtered (file, _("List of directories from which to load " + "auto-loaded scripts 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. */ @@ -602,6 +631,9 @@ auto_load_objfile_script (struct objfile *objfile, input = fopen (filename, "r"); debugfile = filename; + if (debug_auto_load) + fprintf_unfiltered (gdb_stdlog, _("auto-load: Attempted file \"%s\" %s.\n"), + debugfile, input ? _("exists") : _("does not exist")); if (!input) { @@ -612,6 +644,12 @@ auto_load_objfile_script (struct objfile *objfile, debugdir_vec = dirnames_to_char_ptr_vec (debug_file_directory); make_cleanup_free_char_ptr_vec (debugdir_vec); + if (debug_auto_load) + fprintf_unfiltered (gdb_stdlog, + _("auto-load: Searching 'set debug-file-directory' " + "path \"%s\".\n"), + debug_file_directory); + for (ix = 0; VEC_iterate (char_ptr, debugdir_vec, ix, debugdir); ++ix) { /* Also try the same file in the separate debug info directory. */ @@ -623,24 +661,53 @@ auto_load_objfile_script (struct objfile *objfile, make_cleanup (xfree, debugfile); input = fopen (debugfile, "r"); + if (debug_auto_load) + fprintf_unfiltered (gdb_stdlog, _("auto-load: Attempted file " + "\"%s\" %s.\n"), + debugfile, + input ? _("exists") : _("does not exist")); if (input != NULL) break; } } - if (!input && gdb_datadir) + if (!input) { + VEC (char_ptr) *vec; + int ix; + char *dir; + /* Also try the same file in a subdirectory of gdb's data directory. */ - debugfile = xmalloc (strlen (gdb_datadir) + strlen (filename) - + strlen ("/auto-load") + 1); - strcpy (debugfile, gdb_datadir); - strcat (debugfile, "/auto-load"); - /* FILENAME is absolute, so we don't need a "/" here. */ - strcat (debugfile, filename); - - make_cleanup (xfree, debugfile); - input = fopen (debugfile, "r"); + + vec = dirnames_to_char_ptr_vec (auto_load_dir); + make_cleanup_free_char_ptr_vec (vec); + + if (debug_auto_load) + fprintf_unfiltered (gdb_stdlog, _("auto-load: Searching 'set auto-load " + "scripts-directory' path \"%s\".\n"), + auto_load_dir); + + for (ix = 0; VEC_iterate (char_ptr, vec, ix, dir); ++ix) + { + debugfile = xstrdup (dir); + substitute_path_component (&debugfile, "$ddir", gdb_datadir); + debugfile = xrealloc (debugfile, (strlen (debugfile) + + strlen (filename) + 1)); + + /* FILENAME is absolute, so we don't need a "/" here. */ + strcat (debugfile, filename); + + make_cleanup (xfree, debugfile); + input = fopen (debugfile, "r"); + if (debug_auto_load) + fprintf_unfiltered (gdb_stdlog, _("auto-load: Attempted file " + "\"%s\" %s.\n"), + debugfile, + input ? _("exists") : _("does not exist")); + if (input != NULL) + break; + } } if (input) @@ -1056,6 +1123,19 @@ This options has security implications for untrusted inferiors."), Usage: info auto-load local-gdbinit"), auto_load_info_cmdlist_get ()); + auto_load_dir = xstrdup (AUTO_LOAD_DIR); + add_setshow_optional_filename_cmd ("scripts-directory", class_support, + &auto_load_dir, _("\ +Set the list of directories from which to load auto-loaded scripts."), _("\ +Show the list of directories from which to load auto-loaded scripts."), _("\ +Automatically loaded Python scripts and GDB scripts are located in one of the\n\ +directories listed by this option. This option is ignored for the kinds of\n\ +scripts having 'set auto-load ... off'. Directories listed here need to be\n\ +present also in the 'set auto-load safe-path' option."), + set_auto_load_dir, show_auto_load_dir, + auto_load_set_cmdlist_get (), + auto_load_show_cmdlist_get ()); + auto_load_safe_path = xstrdup (AUTO_LOAD_SAFE_PATH); auto_load_safe_path_vec_update (); add_setshow_optional_filename_cmd ("safe-path", class_support, diff --git a/gdb/config.in b/gdb/config.in index f98ea424407..a3bd8dddd1a 100644 --- a/gdb/config.in +++ b/gdb/config.in @@ -3,6 +3,9 @@ /* Define if building universal (internal helper macro) */ #undef AC_APPLE_UNIVERSAL_BUILD +/* Directories from which to load auto-loaded scripts. */ +#undef AUTO_LOAD_DIR + /* Directories safe to hold auto-loaded files. */ #undef AUTO_LOAD_SAFE_PATH diff --git a/gdb/configure b/gdb/configure index 934f5c1cf7f..ec0d30b1935 100755 --- a/gdb/configure +++ b/gdb/configure @@ -778,6 +778,7 @@ enable_largefile with_separate_debug_dir with_gdb_datadir with_relocated_sources +with_auto_load_dir with_auto_load_safe_path enable_targets enable_64_bit_bfd @@ -1485,9 +1486,13 @@ Optional Packages: [DATADIR/gdb] --with-relocated-sources=PATH automatically relocate this path for source files + --with-auto-load-dir=PATH + directories from which to load auto-loaded scripts, + use '$ddir' for -data-directory [$ddir/auto-load] --with-auto-load-safe-path=PATH directories safe to hold auto-loaded files, use - $ddir for --with-gdb-datadir path [$ddir/auto-load] + $ddir for --with-gdb-datadir path + [--with-auto-load-dir] --without-auto-load-safe-path do not restrict auto-loaded files locations --with-libunwind-ia64 use libunwind frame unwinding for ia64 targets @@ -4959,6 +4964,31 @@ _ACEOF fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for default auto-load directory" >&5 +$as_echo_n "checking for default auto-load directory... " >&6; } + +# Check whether --with-auto-load-dir was given. +if test "${with_auto_load_dir+set}" = set; then : + withval=$with_auto_load_dir; +else + with_auto_load_dir='$ddir/auto-load' +fi + +escape_dir=`echo $with_auto_load_dir | sed 's/[$]ddir\>/\\\\\\\\\\\\&/g'` + + test "x$prefix" = xNONE && prefix="$ac_default_prefix" + test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' + ac_define_dir=`eval echo $escape_dir` + ac_define_dir=`eval echo $ac_define_dir` + +cat >>confdefs.h <<_ACEOF +#define AUTO_LOAD_DIR "$ac_define_dir" +_ACEOF + + +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_auto_load_dir" >&5 +$as_echo "$with_auto_load_dir" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for default auto-load safe-path" >&5 $as_echo_n "checking for default auto-load safe-path... " >&6; } @@ -4968,7 +4998,7 @@ if test "${with_auto_load_safe_path+set}" = set; then : with_auto_load_safe_path="/" fi else - with_auto_load_safe_path='$ddir/auto-load' + with_auto_load_safe_path="$with_auto_load_dir" fi escape_dir=`echo $with_auto_load_safe_path | sed 's/[$]ddir\>/\\\\\\\\\\\\&/g'` diff --git a/gdb/configure.ac b/gdb/configure.ac index 1a889d9c697..97cd6eeeb7c 100644 --- a/gdb/configure.ac +++ b/gdb/configure.ac @@ -136,16 +136,26 @@ AS_HELP_STRING([--with-relocated-sources=PATH], [automatically relocate this pat [Relocated directory for source files. ]) ]) +AC_MSG_CHECKING([for default auto-load directory]) +AC_ARG_WITH(auto-load-dir, +AS_HELP_STRING([--with-auto-load-dir=PATH], + [directories from which to load auto-loaded scripts, use '$ddir' for -data-directory @<:@$ddir/auto-load@:>@]),, + [with_auto_load_dir='$ddir/auto-load']) +escape_dir=`echo $with_auto_load_dir | sed 's/[[$]]ddir\>/\\\\\\\\\\\\&/g'` +AC_DEFINE_DIR(AUTO_LOAD_DIR, escape_dir, + [Directories from which to load auto-loaded scripts.]) +AC_MSG_RESULT([$with_auto_load_dir]) + AC_MSG_CHECKING([for default auto-load safe-path]) AC_ARG_WITH(auto-load-safe-path, AS_HELP_STRING([--with-auto-load-safe-path=PATH], - [directories safe to hold auto-loaded files, use $ddir for --with-gdb-datadir path @<:@$ddir/auto-load@:>@]) + [directories safe to hold auto-loaded files, use $ddir for --with-gdb-datadir path @<:@--with-auto-load-dir@:>@]) AS_HELP_STRING([--without-auto-load-safe-path], [do not restrict auto-loaded files locations]), [if test "$with_auto_load_safe_path" = "no"; then with_auto_load_safe_path="/" fi], -[with_auto_load_safe_path='$ddir/auto-load']) +[with_auto_load_safe_path="$with_auto_load_dir"]) escape_dir=`echo $with_auto_load_safe_path | sed 's/[[$]]ddir\>/\\\\\\\\\\\\&/g'` AC_DEFINE_DIR(AUTO_LOAD_SAFE_PATH, escape_dir, [Directories safe to hold auto-loaded files.]) diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 9cdc2ba147f..d8fb693de76 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,15 @@ +2012-05-11 Jan Kratochvil + + Implement multi-component --with-auto-load-dir. + * gdb.texinfo (Auto-loading): New references + for 'set auto-load scripts-directory' + and 'show auto-load scripts-directory'. + (Auto-loading safe path): Describe the new default. Move $ddir + substituation reference to 'objfile-gdb.py file'. + (objfile-gdb.py file): Describe script-name alias. Change real-name to + script-name. Describe new 'set auto-load scripts-directory' + and 'show auto-load scripts-directory'. + 2012-05-11 Jan Kratochvil Provide $ddir substitution for --with-auto-load-safe-path. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index eab977490e0..7a23c699507 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -21009,6 +21009,8 @@ local-gdbinit: Auto-loading of .gdbinit script from current directory python-scripts: Auto-loading of Python scripts is on. safe-path: List of directories from which it is safe to auto-load files is $ddir/auto-load. +scripts-directory: List of directories from which to load auto-loaded scripts + is $ddir/auto-load. @end smallexample @anchor{info auto-load} @@ -21069,6 +21071,10 @@ These are @value{GDBN} control commands for the auto-loading: @tab Show setting of @value{GDBN} Python scripts. @item @xref{info auto-load python-scripts}. @tab Show state of @value{GDBN} Python scripts. +@item @xref{set auto-load scripts-directory}. +@tab Control for @value{GDBN} auto-loaded scripts location. +@item @xref{show auto-load scripts-directory}. +@tab Show @value{GDBN} auto-loaded scripts location. @item @xref{set auto-load local-gdbinit}. @tab Control for init file in the current directory. @item @xref{show auto-load local-gdbinit}. @@ -21245,15 +21251,13 @@ loading and execution of scripts. Multiple entries may be delimited by the host platform path separator in use. @end table -This variable defaults to @file{$ddir/auto-load}. The default @code{set +This variable defaults to what @code{--with-auto-load-dir} has been configured +to (@pxref{with-auto-load-dir}). @file{$ddir} substituation applies the same +as for @xref{set auto-load scripts-directory}. +The default @code{set auto-load safe-path} value can be also overriden by @value{GDBN} configuration option @option{--with-auto-load-safe-path}. -Any used string @file{$ddir} will get replaced by @var{data-directory} which is -determined at @value{GDBN} startup (@pxref{Data Files}). @file{$ddir} must be -be placed as a directory component --- either alone or delimited by @file{/} or -@file{\} directory separators, depending on the host platform. - Setting this variable to @file{/} disables this security protection, corresponding @value{GDBN} configuration option is @option{--without-auto-load-safe-path}. @@ -25449,7 +25453,7 @@ registering objfile-specific pretty-printers. @cindex @file{@var{objfile}-gdb.py} When a new object file is read, @value{GDBN} looks for -a file named @file{@var{objfile}-gdb.py}, +a file named @file{@var{objfile}-gdb.py} (we call it @var{script-name} below), where @var{objfile} is the object file's real name, formed by ensuring that the file name is absolute, following all symlinks, and resolving @code{.} and @code{..} components. If this file exists and is @@ -25457,14 +25461,42 @@ readable, @value{GDBN} will evaluate it as a Python script. If this file does not exist, and if the parameter @code{debug-file-directory} is set (@pxref{Separate Debug Files}), -then @value{GDBN} will look for @var{real-name} in all of the +then @value{GDBN} will look for @var{script-name} in all of the directories mentioned in the value of @code{debug-file-directory}. Finally, if this file does not exist, then @value{GDBN} will look for -a file named @file{@var{data-directory}/auto-load/@var{real-name}}, where -@var{data-directory} is @value{GDBN}'s data directory (available via -@code{show data-directory}, @pxref{Data Files}), and @var{real-name} -is the object file's real name, as described above. +@var{script-name} file in all of the directories specified by: + +@table @code +@anchor{set auto-load scripts-directory} +@kindex set auto-load scripts-directory +@item set auto-load scripts-directory @r{[}@var{directories}@r{]} +Control @value{GDBN} auto-loaded scripts location. Multiple directory entries +may be delimited by the host platform path separator in use +(@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS). + +Each entry here needs to be covered also by the security setting +@code{set auto-load safe-path} (@pxref{set auto-load safe-path}). + +@anchor{with-auto-load-dir} +This variable defaults to @file{$ddir/auto-load}. The default @code{set +auto-load safe-path} value can be also overriden by @value{GDBN} configuration +option @option{--with-auto-load-dir}. + +Any used string @file{$ddir} will get replaced by @var{data-directory} which is +determined at @value{GDBN} startup (@pxref{Data Files}). @file{$ddir} must be +be placed as a directory component --- either alone or delimited by @file{/} or +@file{\} directory separators, depending on the host platform. + +The list of directories uses path separator (@samp{:} on GNU and Unix +systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly +to the @env{PATH} environment variable. + +@anchor{show auto-load scripts-directory} +@kindex show auto-load scripts-directory +@item show auto-load scripts-directory +Show @value{GDBN} auto-loaded scripts location. +@end table @value{GDBN} does not track which files it has already auto-loaded this way. @value{GDBN} will load the associated script every time the corresponding -- 2.30.2