gdb/gdb-autoload-23of28.patch

425 lines
18 KiB
Diff

http://sourceware.org/ml/gdb-cvs/2012-05/msg00081.html
### src/gdb/ChangeLog 2012/05/11 18:13:22 1.14237
### src/gdb/ChangeLog 2012/05/11 18:20:25 1.14238
## -1,5 +1,23 @@
2012-05-11 Jan Kratochvil <jan.kratochvil@redhat.com>
+ 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 <jan.kratochvil@redhat.com>
+
Provide $ddir substitution for --with-auto-load-safe-path.
* NEWS (--with-auto-load-safe-path, --without-auto-load-safe-path): New
entries.
Index: gdb-7.4.50.20120120/gdb/NEWS
===================================================================
--- gdb-7.4.50.20120120.orig/gdb/NEWS 2012-05-14 14:18:01.000000000 +0200
+++ gdb-7.4.50.20120120/gdb/NEWS 2012-05-14 14:18:29.712985871 +0200
@@ -67,6 +67,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 <dir1>[:<dir2>...]
+ 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 <dir1>[:<dir2>...]
show auto-load safe-path
Set a list of directories from which it is safe to auto-load files.
@@ -309,10 +315,14 @@ show trace-stop-notes
* 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
Index: gdb-7.4.50.20120120/gdb/auto-load.c
===================================================================
--- gdb-7.4.50.20120120.orig/gdb/auto-load.c 2012-05-14 14:18:01.000000000 +0200
+++ gdb-7.4.50.20120120/gdb/auto-load.c 2012-05-14 14:18:29.713985869 +0200
@@ -108,6 +108,35 @@ show_auto_load_local_gdbinit (struct ui_
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
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
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
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 f
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,
Index: gdb-7.4.50.20120120/gdb/config.in
===================================================================
--- gdb-7.4.50.20120120.orig/gdb/config.in 2012-05-14 14:18:01.000000000 +0200
+++ gdb-7.4.50.20120120/gdb/config.in 2012-05-14 14:18:29.713985869 +0200
@@ -7,6 +7,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
Index: gdb-7.4.50.20120120/gdb/configure
===================================================================
--- gdb-7.4.50.20120120.orig/gdb/configure 2012-05-14 14:18:01.000000000 +0200
+++ gdb-7.4.50.20120120/gdb/configure 2012-05-14 14:21:13.068849103 +0200
@@ -955,6 +955,7 @@ with_separate_debug_dir
with_gdb_datadir
with_relocated_sources
with_rpm
+with_auto_load_dir
with_auto_load_safe_path
enable_targets
enable_64_bit_bfd
@@ -1667,9 +1668,13 @@ Optional Packages:
automatically relocate this path for source files
--with-rpm query rpm database for missing debuginfos (yes/no,
def. auto=librpm.so)
+ --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 use libunwind frame unwinding support
@@ -8483,6 +8488,31 @@ $as_echo "$as_me: WARNING: $RPM_PKG_ERRO
fi
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; }
@@ -8492,7 +8522,7 @@ if test "${with_auto_load_safe_path+set}
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'`
Index: gdb-7.4.50.20120120/gdb/configure.ac
===================================================================
--- gdb-7.4.50.20120120.orig/gdb/configure.ac 2012-05-14 14:18:01.000000000 +0200
+++ gdb-7.4.50.20120120/gdb/configure.ac 2012-05-14 14:21:01.597871716 +0200
@@ -339,16 +339,26 @@ extern rpmdbMatchIterator rpmtsInitItera
fi
fi
+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.])
Index: gdb-7.4.50.20120120/gdb/doc/gdb.texinfo
===================================================================
--- gdb-7.4.50.20120120.orig/gdb/doc/gdb.texinfo 2012-05-14 14:18:01.000000000 +0200
+++ gdb-7.4.50.20120120/gdb/doc/gdb.texinfo 2012-05-14 14:20:13.653966212 +0200
@@ -20804,6 +20804,8 @@ local-gdbinit: Auto-loading of .gdbinit
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}
@@ -20864,6 +20866,10 @@ These are @value{GDBN} control commands
@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}.
@@ -21040,15 +21046,13 @@ loading and execution of scripts. Multi
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}.
@@ -25135,7 +25139,7 @@ registering objfile-specific pretty-prin
@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
@@ -25143,14 +25147,42 @@ readable, @value{GDBN} will evaluate it
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}/python/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