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]

[commit] [patch+doc 2/2] auto-load: Fix default /usr/lib/debug/ loading


On Sun, 20 May 2012 17:45:27 +0200, Eli Zaretskii wrote:
> OK with those changes.

Thanks for the review.  Checked it in.


Jan


http://sourceware.org/ml/gdb-cvs/2012-05/msg00152.html

--- src/gdb/ChangeLog	2012/05/20 17:15:26	1.14272
+++ src/gdb/ChangeLog	2012/05/20 20:35:16	1.14273
@@ -1,3 +1,19 @@
+2012-05-20  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+	* NEWS (--with-auto-load-dir): Prepend $debugdir to the default path.
+	Describe it.
+	* auto-load.c (auto_load_expand_dir_vars): New function.
+	(auto_load_safe_path_vec_update): Use it, remove the
+	substitute_path_component call thanks to it.
+	(auto_load_objfile_script): Remove the debug_file_directory processing.
+	Use auto_load_expand_dir_vars, remove the substitute_path_component
+	call thanks to it.
+	* configure: Regenerate.
+	* configure.ac (--with-auto-load-dir): Prepend $debugdir to the default
+	path.  Escape $ also for $debugdir.
+	(--with_auto_load_safe_path): Escape $ also for $debugdir.
+	* utils.c (substitute_path_component): Accept also DIRNAME_SEPARATOR.
+
 2012-05-20  Doug Evans  <dje@google.com>
 
 	* dwarf2read.c (recursively_find_pc_sect_symtab): Initialize "s"
--- src/gdb/doc/ChangeLog	2012/05/19 08:50:59	1.1324
+++ src/gdb/doc/ChangeLog	2012/05/20 20:35:19	1.1325
@@ -1,3 +1,13 @@
+2012-05-20  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+	* gdb.texinfo (Separate Debug Files): New anchor debug-file-directory.
+	Mention also --with-separate-debug-dir.
+	(Auto-loading): Prepend $debugdir in the sample output.
+	(Auto-loading safe path): Likewise.  Mention also $debugdir for the
+	auto-load safe-path variable.
+	(objfile-gdb.py file): Remove the extra debug-file-directory paragraph.
+	Mention also $debugdir for 'set auto-load scripts-directory'.
+
 2012-05-19  Eli Zaretskii  <eliz@gnu.org>
 
 	* gdb.texinfo (Continuing and Stepping, Selection, Byte Order)
--- src/gdb/NEWS	2012/05/18 23:46:40	1.523
+++ src/gdb/NEWS	2012/05/20 20:35:18	1.524
@@ -239,8 +239,10 @@
 
 --with-auto-load-dir
   Configure default value for the 'set auto-load scripts-directory'
-  setting above.  It defaults to '$datadir/auto-load', $datadir
-  representing GDB's data directory (available via show data-directory).
+  setting above.  It defaults to '$debugdir:$datadir/auto-load',
+  $debugdir representing global debugging info directories (available
+  via 'show debug-file-directory') and $datadir 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
--- src/gdb/auto-load.c	2012/05/18 17:47:28	1.11
+++ src/gdb/auto-load.c	2012/05/20 20:35:18	1.12
@@ -147,6 +147,30 @@
    counterpart.  */
 static VEC (char_ptr) *auto_load_safe_path_vec;
 
+/* Expand $datadir and $debugdir in STRING according to the rules of
+   substitute_path_component.  Return vector from dirnames_to_char_ptr_vec,
+   this vector must be freed by free_char_ptr_vec by the caller.  */
+
+static VEC (char_ptr) *
+auto_load_expand_dir_vars (const char *string)
+{
+  VEC (char_ptr) *dir_vec;
+  char *s;
+
+  s = xstrdup (string);
+  substitute_path_component (&s, "$datadir", gdb_datadir);
+  substitute_path_component (&s, "$debugdir", debug_file_directory);
+
+  if (debug_auto_load && strcmp (s, string) != 0)
+    fprintf_unfiltered (gdb_stdlog,
+			_("auto-load: Expanded $-variables to \"%s\".\n"), s);
+
+  dir_vec = dirnames_to_char_ptr_vec (s);
+  xfree(s);
+
+  return dir_vec;
+}
+
 /* Update auto_load_safe_path_vec from current AUTO_LOAD_SAFE_PATH.  */
 
 static void
@@ -163,7 +187,7 @@
 
   free_char_ptr_vec (auto_load_safe_path_vec);
 
-  auto_load_safe_path_vec = dirnames_to_char_ptr_vec (auto_load_safe_path);
+  auto_load_safe_path_vec = auto_load_expand_dir_vars (auto_load_safe_path);
   len = VEC_length (char_ptr, auto_load_safe_path_vec);
 
   /* Apply tilde_expand and gdb_realpath to each AUTO_LOAD_SAFE_PATH_VEC
@@ -171,16 +195,10 @@
   for (ix = 0; ix < len; ix++)
     {
       char *dir = VEC_index (char_ptr, auto_load_safe_path_vec, ix);
-      char *ddir_subst, *expanded, *real_path;
-
-      ddir_subst = xstrdup (dir);
-      substitute_path_component (&ddir_subst, "$datadir", gdb_datadir);
-      expanded = tilde_expand (ddir_subst);
-      xfree (ddir_subst);
-      real_path = gdb_realpath (expanded);
+      char *expanded = tilde_expand (dir);
+      char *real_path = gdb_realpath (expanded);
 
-      /* Ensure the current entry is at least a valid path (therefore
-	 $datadir-expanded and tilde-expanded).  */
+      /* Ensure the current entry is at least tilde_expand-ed.  */
       VEC_replace (char_ptr, auto_load_safe_path_vec, ix, expanded);
 
       if (debug_auto_load)
@@ -645,42 +663,6 @@
 
   if (!input)
     {
-      char *debugdir;
-      VEC (char_ptr) *debugdir_vec;
-      int ix;
-
-      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.  */
-	  debugfile = xmalloc (strlen (debugdir) + strlen (filename) + 1);
-	  strcpy (debugfile, debugdir);
-
-	  /* 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)
-    {
       VEC (char_ptr) *vec;
       int ix;
       char *dir;
@@ -688,7 +670,7 @@
       /* Also try the same file in a subdirectory of gdb's data
 	 directory.  */
 
-      vec = dirnames_to_char_ptr_vec (auto_load_dir);
+      vec = auto_load_expand_dir_vars (auto_load_dir);
       make_cleanup_free_char_ptr_vec (vec);
 
       if (debug_auto_load)
@@ -698,10 +680,8 @@
 
       for (ix = 0; VEC_iterate (char_ptr, vec, ix, dir); ++ix)
 	{
-	  debugfile = xstrdup (dir);
-	  substitute_path_component (&debugfile, "$datadir", gdb_datadir);
-	  debugfile = xrealloc (debugfile, (strlen (debugfile)
-					    + strlen (filename) + 1));
+	  debugfile = xmalloc (strlen (dir) + strlen (filename) + 1);
+	  strcpy (debugfile, dir);
 
 	  /* FILENAME is absolute, so we don't need a "/" here.  */
 	  strcat (debugfile, filename);
--- src/gdb/configure	2012/05/18 17:47:28	1.364
+++ src/gdb/configure	2012/05/20 20:35:18	1.365
@@ -1488,7 +1488,7 @@
                           automatically relocate this path for source files
   --with-auto-load-dir=PATH
                           directories from which to load auto-loaded scripts
-                          [$datadir/auto-load]
+                          [$debugdir:$datadir/auto-load]
   --with-auto-load-safe-path=PATH
                           directories safe to hold auto-loaded files
                           [--with-auto-load-dir]
@@ -4970,10 +4970,10 @@
 if test "${with_auto_load_dir+set}" = set; then :
   withval=$with_auto_load_dir;
 else
-  with_auto_load_dir='$datadir/auto-load'
+  with_auto_load_dir='$debugdir:$datadir/auto-load'
 fi
 
-escape_dir=`echo $with_auto_load_dir | sed 's/[$]datadir\>/\\\\\\\\\\\\&/g'`
+escape_dir=`echo $with_auto_load_dir | sed 's/[$]\(datadir\|debugdir\)\>/\\\\\\\\\\\\&/g'`
 
   test "x$prefix" = xNONE && prefix="$ac_default_prefix"
   test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
@@ -5000,7 +5000,7 @@
   with_auto_load_safe_path="$with_auto_load_dir"
 fi
 
-escape_dir=`echo $with_auto_load_safe_path | sed 's/[$]datadir\>/\\\\\\\\\\\\&/g'`
+escape_dir=`echo $with_auto_load_safe_path | sed 's/[$]\(datadir\|debugdir\)\>/\\\\\\\\\\\\&/g'`
 
   test "x$prefix" = xNONE && prefix="$ac_default_prefix"
   test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
--- src/gdb/configure.ac	2012/05/18 17:47:30	1.175
+++ src/gdb/configure.ac	2012/05/20 20:35:19	1.176
@@ -139,9 +139,9 @@
 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 @<:@$datadir/auto-load@:>@]),,
-  [with_auto_load_dir='$datadir/auto-load'])
-escape_dir=`echo $with_auto_load_dir | sed 's/[[$]]datadir\>/\\\\\\\\\\\\&/g'`
+  [directories from which to load auto-loaded scripts @<:@$debugdir:$datadir/auto-load@:>@]),,
+  [with_auto_load_dir='$debugdir:$datadir/auto-load'])
+escape_dir=`echo $with_auto_load_dir | sed 's/[[$]]\(datadir\|debugdir\)\>/\\\\\\\\\\\\&/g'`
 AC_DEFINE_DIR(AUTO_LOAD_DIR, escape_dir,
 	      [Directories from which to load auto-loaded scripts.])
 AC_MSG_RESULT([$with_auto_load_dir])
@@ -156,7 +156,7 @@
      with_auto_load_safe_path="/"
      fi],
 [with_auto_load_safe_path="$with_auto_load_dir"])
-escape_dir=`echo $with_auto_load_safe_path | sed 's/[[$]]datadir\>/\\\\\\\\\\\\&/g'`
+escape_dir=`echo $with_auto_load_safe_path | sed 's/[[$]]\(datadir\|debugdir\)\>/\\\\\\\\\\\\&/g'`
 AC_DEFINE_DIR(AUTO_LOAD_SAFE_PATH, escape_dir,
 	      [Directories safe to hold auto-loaded files.])
 AC_MSG_RESULT([$with_auto_load_safe_path])
--- src/gdb/utils.c	2012/05/11 18:13:24	1.278
+++ src/gdb/utils.c	2012/05/20 20:35:19	1.279
@@ -3726,8 +3726,8 @@
 
 /* Substitute all occurences of string FROM by string TO in *STRINGP.  *STRINGP
    must come from xrealloc-compatible allocator and it may be updated.  FROM
-   needs to be delimited by IS_DIR_SEPARATOR (or be located at the start or
-   end of *STRINGP.  */
+   needs to be delimited by IS_DIR_SEPARATOR or DIRNAME_SEPARATOR (or be
+   located at the start or end of *STRINGP.  */
 
 void
 substitute_path_component (char **stringp, const char *from, const char *to)
@@ -3742,8 +3742,10 @@
       if (s == NULL)
 	break;
 
-      if ((s == string || IS_DIR_SEPARATOR (s[-1]))
-          && (s[from_len] == '\0' || IS_DIR_SEPARATOR (s[from_len])))
+      if ((s == string || IS_DIR_SEPARATOR (s[-1])
+	   || s[-1] == DIRNAME_SEPARATOR)
+          && (s[from_len] == '\0' || IS_DIR_SEPARATOR (s[from_len])
+	      || s[from_len] == DIRNAME_SEPARATOR))
 	{
 	  char *string_new;
 
--- src/gdb/doc/gdb.texinfo	2012/05/19 08:50:59	1.969
+++ src/gdb/doc/gdb.texinfo	2012/05/20 20:35:19	1.970
@@ -16465,8 +16465,11 @@
 @file{/usr/lib/debug/usr/bin/ls.debug}.
 @end itemize
 
-You can set the global debugging info directories, and view the
-list @value{GDBN} is currently using.
+@anchor{debug-file-directory}
+Global debugging info directories default to what is set by @value{GDBN}
+configure option @option{--with-separate-debug-dir}.  During @value{GDBN} run
+you can also set the global debugging info directories, and view the list
+@value{GDBN} is currently using.
 
 @table @code
 
@@ -21232,9 +21235,9 @@
                 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 $datadir/auto-load.
+            is $debugdir:$datadir/auto-load.
 scripts-directory:  List of directories from which to load auto-loaded scripts
-                    is $datadir/auto-load.
+                    is $debugdir:$datadir/auto-load.
 @end smallexample
 
 @anchor{info auto-load}
@@ -21450,9 +21453,11 @@
 $ ./gdb -q ./gdb
 Reading symbols from /home/user/gdb/gdb...done.
 warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
-         declined by your `auto-load safe-path' set to "$datadir/auto-load".
+         declined by your `auto-load safe-path' set
+         to "$debugdir:$datadir/auto-load".
 warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
-         declined by your `auto-load safe-path' set to "$datadir/auto-load".
+         declined by your `auto-load safe-path' set
+         to "$debugdir:$datadir/auto-load".
 @end smallexample
 
 The list of trusted directories is controlled by the following commands:
@@ -21485,11 +21490,10 @@
 @end table
 
 This variable defaults to what @code{--with-auto-load-dir} has been configured
-to (@pxref{with-auto-load-dir}).  @file{$datadir} 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}.
+to (@pxref{with-auto-load-dir}).  @file{$debugdir} and @file{$datadir}
+substitution applies the same as for @ref{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}.
 
 Setting this variable to @file{/} disables this security protection,
 corresponding @value{GDBN} configuration option is
@@ -25701,12 +25705,7 @@
 @code{.} and @code{..} components.  If this file exists and is
 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{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
+If this file does not exist, then @value{GDBN} will look for
 @var{script-name} file in all of the directories as specified below.
 
 Note that loading of this script file also requires accordingly configured
@@ -25724,14 +25723,17 @@
 @code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
 
 @anchor{with-auto-load-dir}
-This variable defaults to @file{$datadir/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{$datadir} will get replaced by @var{data-directory} which
-is determined at @value{GDBN} startup (@pxref{Data Files}).  @file{$datadir}
-must be placed as a directory component --- either alone or delimited by
-@file{/} or @file{\} directory separators, depending on the host platform.
+This variable defaults to @file{$debugdir:$datadir/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 reference to @file{$debugdir} will get replaced by
+@var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
+reference to @file{$datadir} will get replaced by @var{data-directory} which is
+determined at @value{GDBN} startup (@pxref{Data Files}).  @file{$debugdir} and
+@file{$datadir} must 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


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