This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch 2/2] Implement multi-component --with-auto-load-dir


Hi,

currently GDB has hard-coded GDB_DATADIR/auto-load for the auto-loaded
scripts.  The problem is one may need more of such directories as you may have
multiple package sets / packages on the same system in different
subdirectories overriding each other in some order.

Therefore created 'set auto-load scripts-directory' for it.  There are some
discrepancies that --with-auto-load-dir is "auto-load" in general while
'set auto-load scripts-directory' looks scripts-specific.  GDB currently
already uses "auto-load" directory name so the general form looks more logical
but I found 'set auto-load directory' not clear enough in the list

(gdb) show auto-load 
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.
safe-path:  List of directories from which it is safe to auto-load files is $ddir/auto-load:/tmp/foo.
scripts-directory:  List of directories with auto-loaded scripts is $ddir/auto-load.

that it really applies just to gdb-scripts and python-scripts there.
Maybe 'set libthread-db-search-path' could be renamed
to 'set auto-load libthread-db-directory' etc., I did not go so far.

I am sorry I have made a bit "kitchen sink" even this patch, such as the
debug_auto_load output and some docs fixes.  I find it all just to be fix ups
of the already checked-in auto-load patchset.

No regressions on {x86_64,x86_64-m32,i686}-fedora17-linux-gnu.


Thanks,
Jan


gdb/
2012-05-09  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.

gdb/doc/
2012-05-09  Jan Kratochvil  <jan.kratochvil@redhat.com>

	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'.

--- 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 <dir1>[:<dir2>...]
+  Set a list of directories with 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.
@@ -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
+  the value of configure option --with-gdb-datadir.
+
 --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 the value
-  of configure option --with-gdb-datadir.
+  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
--- 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 with 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 with 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 with auto-loaded scripts."), _("\
+Show the list of directories with 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,
--- 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 with auto-loaded scripts. */
+#undef AUTO_LOAD_DIR
+
 /* Directories safe to hold auto-loaded files. */
 #undef AUTO_LOAD_SAFE_PATH
 
--- 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 with 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'`
--- 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 with 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 with 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.])
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -21008,6 +21008,8 @@ local-gdbinit:  Auto-loading of .gdbinit script from current directory is on.
 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 with auto-loaded scripts
+                    is $ddir/auto-load.
 @end smallexample
 
 @anchor{info auto-load}
@@ -21067,6 +21069,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}.
@@ -21243,15 +21249,13 @@ loading and execution of scripts.  Multiple entries may be delimited by the
 host platform directory 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}.
@@ -25447,7 +25451,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
@@ -25455,14 +25459,41 @@ 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 directory separator in use.
+
+Each entry here needs to be covered also by the security setting
+@xref{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 directory 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]