From 1564a2618d1766c3ea3a27dfa2ae77fe4ef51ef3 Mon Sep 17 00:00:00 2001 From: Jan Kratochvil Date: Sun, 20 May 2012 20:35:19 +0000 Subject: [PATCH] gdb/ * 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. gdb/doc/ * 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'. --- gdb/ChangeLog | 16 +++++++++ gdb/NEWS | 6 ++-- gdb/auto-load.c | 82 +++++++++++++++++---------------------------- gdb/configure | 8 ++--- gdb/configure.ac | 8 ++--- gdb/doc/ChangeLog | 10 ++++++ gdb/doc/gdb.texinfo | 52 ++++++++++++++-------------- gdb/utils.c | 10 +++--- 8 files changed, 102 insertions(+), 90 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e686fb5aa91..d8442e56b81 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,19 @@ +2012-05-20 Jan Kratochvil + + * 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 * dwarf2read.c (recursively_find_pc_sect_symtab): Initialize "s" diff --git a/gdb/NEWS b/gdb/NEWS index d85fe0d88b9..1b05bfeb403 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -239,8 +239,10 @@ show dprintf-channel --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 diff --git a/gdb/auto-load.c b/gdb/auto-load.c index 07c00610e0c..cfcab7b09cc 100644 --- a/gdb/auto-load.c +++ b/gdb/auto-load.c @@ -147,6 +147,30 @@ static char *auto_load_safe_path; 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 @@ auto_load_safe_path_vec_update (void) 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 @@ auto_load_safe_path_vec_update (void) 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) @@ -643,42 +661,6 @@ auto_load_objfile_script (struct objfile *objfile, fprintf_unfiltered (gdb_stdlog, _("auto-load: Attempted file \"%s\" %s.\n"), debugfile, input ? _("exists") : _("does not exist")); - 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; @@ -688,7 +670,7 @@ auto_load_objfile_script (struct objfile *objfile, /* 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 @@ auto_load_objfile_script (struct objfile *objfile, 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); diff --git a/gdb/configure b/gdb/configure index de746e834cc..f638268c2be 100755 --- a/gdb/configure +++ b/gdb/configure @@ -1488,7 +1488,7 @@ Optional Packages: 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 @@ $as_echo_n "checking for default auto-load directory... " >&6; } 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 @@ else 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}' diff --git a/gdb/configure.ac b/gdb/configure.ac index 6433bf954a6..d7409d0d6ef 100644 --- a/gdb/configure.ac +++ b/gdb/configure.ac @@ -139,9 +139,9 @@ AS_HELP_STRING([--with-relocated-sources=PATH], [automatically relocate this pat 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 @@ AS_HELP_STRING([--without-auto-load-safe-path], 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]) diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 360d95b3e19..70e4e41267d 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,13 @@ +2012-05-20 Jan Kratochvil + + * 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 * gdb.texinfo (Continuing and Stepping, Selection, Byte Order) diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 790eea113aa..c12f9765d3e 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -16465,8 +16465,11 @@ debug information files, in the indicated order: @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 @@ 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 $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 @@ get loaded: $ ./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 @@ host platform path separator in use. @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 @@ that the file name is absolute, following all symlinks, and resolving @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 @@ 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{$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 diff --git a/gdb/utils.c b/gdb/utils.c index 15956b7670c..2d607efd7a6 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -3726,8 +3726,8 @@ dirnames_to_char_ptr_vec (const char *dirnames) /* 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 @@ substitute_path_component (char **stringp, const char *from, const char *to) 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; -- 2.30.2