From: Jan Kratochvil Date: Fri, 11 May 2012 18:13:26 +0000 (+0000) Subject: gdb/ X-Git-Tag: sid-snapshot-20120601~243 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6dea1fbd79e621463ba1eba5b4b417ecdf16b3eb;p=external%2Fbinutils.git gdb/ Provide $ddir substitution for --with-auto-load-safe-path. * NEWS (--with-auto-load-safe-path, --without-auto-load-safe-path): New entries. * auto-load.c: Include observer.h. (auto_load_safe_path_vec_update): Call substitute_path_component for each component. New variable ddir_subst. (auto_load_gdb_datadir_changed): New function. (set_auto_load_safe_path): Rename DEFAULT_AUTO_LOAD_SAFE_PATH to AUTO_LOAD_SAFE_PATH. New comment. (_initialize_auto_load): Rename DEFAULT_AUTO_LOAD_SAFE_PATH to AUTO_LOAD_SAFE_PATH. Install auto_load_gdb_datadir_changed. * config.in: Regenerate. * configure: Regenerate. * configure.ac (--auto-load-safe-path): Rename DEFAULT_AUTO_LOAD_SAFE_PATH to AUTO_LOAD_SAFE_PATH. Default to GDB_DATADIR/auto-load. * defs.h (substitute_path_component): New declaration. * top.c: Include observer.h. (set_gdb_datadir): New function. (init_main): Install it for "set data-directory". * utils.c (substitute_path_component): New function. gdb/doc/ Provide $ddir substitution for --with-auto-load-safe-path. * gdb.texinfo (Auto-loading): Replace /usr/local by $ddir/auto-load. (Auto-loading safe path): Likewise. Mention the default value, $ddir substitution, --with-auto-load-safe-path and --without-auto-load-safe-path. * observer.texi (gdb_datadir_changed): New. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e6179bb..fec1f8a 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,29 @@ 2012-05-11 Jan Kratochvil + Provide $ddir substitution for --with-auto-load-safe-path. + * NEWS (--with-auto-load-safe-path, --without-auto-load-safe-path): New + entries. + * auto-load.c: Include observer.h. + (auto_load_safe_path_vec_update): Call substitute_path_component for + each component. New variable ddir_subst. + (auto_load_gdb_datadir_changed): New function. + (set_auto_load_safe_path): Rename DEFAULT_AUTO_LOAD_SAFE_PATH to + AUTO_LOAD_SAFE_PATH. New comment. + (_initialize_auto_load): Rename DEFAULT_AUTO_LOAD_SAFE_PATH to + AUTO_LOAD_SAFE_PATH. Install auto_load_gdb_datadir_changed. + * config.in: Regenerate. + * configure: Regenerate. + * configure.ac (--auto-load-safe-path): Rename + DEFAULT_AUTO_LOAD_SAFE_PATH to AUTO_LOAD_SAFE_PATH. Default to + GDB_DATADIR/auto-load. + * defs.h (substitute_path_component): New declaration. + * top.c: Include observer.h. + (set_gdb_datadir): New function. + (init_main): Install it for "set data-directory". + * utils.c (substitute_path_component): New function. + +2012-05-11 Jan Kratochvil + Make auto-load handle multiple components of DEBUG_FILE_DIRECTORY. * auto-load.c (auto_load_objfile_script): Remove check for NULL DEBUG_FILE_DIRECTORY. Handle multiple components of diff --git a/gdb/NEWS b/gdb/NEWS index 8b620c1..c7f9824 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -181,6 +181,17 @@ set debug auto-load on|off show debug auto-load Control display of debugging info for auto-loading the files above. +* New configure options + +--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). + +--without-auto-load-safe-path + Set 'set auto-load safe-path' to '/', effectively disabling this + security feature. + * New remote packets z0/z1 conditional breakpoints extension diff --git a/gdb/auto-load.c b/gdb/auto-load.c index 254de3b..171c9b1 100644 --- a/gdb/auto-load.c +++ b/gdb/auto-load.c @@ -35,6 +35,7 @@ #include "gdb_vecs.h" #include "readline/tilde.h" #include "completer.h" +#include "observer.h" /* The suffix of per-objfile scripts to auto-load as non-Python command files. E.g. When the program loads libfoo.so, look for libfoo-gdb.gdb. */ @@ -141,10 +142,16 @@ 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 *expanded = tilde_expand (dir); - char *real_path = gdb_realpath (expanded); + char *ddir_subst, *expanded, *real_path; + + ddir_subst = xstrdup (dir); + substitute_path_component (&ddir_subst, "$ddir", gdb_datadir); + expanded = tilde_expand (ddir_subst); + xfree (ddir_subst); + real_path = gdb_realpath (expanded); - /* Ensure the current entry is at least tilde_expand-ed. */ + /* Ensure the current entry is at least a valid path (therefore + $ddir-expanded and tilde-expanded). */ VEC_replace (char_ptr, auto_load_safe_path_vec, ix, expanded); if (debug_auto_load) @@ -176,15 +183,24 @@ auto_load_safe_path_vec_update (void) } } +/* Variable gdb_datadir has been set. Update content depending on $ddir. */ + +static void +auto_load_gdb_datadir_changed (void) +{ + auto_load_safe_path_vec_update (); +} + /* "set" command for the auto_load_safe_path configuration variable. */ static void set_auto_load_safe_path (char *args, int from_tty, struct cmd_list_element *c) { + /* Setting the variable to "" resets it to the compile time defaults. */ if (auto_load_safe_path[0] == '\0') { xfree (auto_load_safe_path); - auto_load_safe_path = xstrdup (DEFAULT_AUTO_LOAD_SAFE_PATH); + auto_load_safe_path = xstrdup (AUTO_LOAD_SAFE_PATH); } auto_load_safe_path_vec_update (); @@ -1040,7 +1056,7 @@ This options has security implications for untrusted inferiors."), Usage: info auto-load local-gdbinit"), auto_load_info_cmdlist_get ()); - auto_load_safe_path = xstrdup (DEFAULT_AUTO_LOAD_SAFE_PATH); + auto_load_safe_path = xstrdup (AUTO_LOAD_SAFE_PATH); auto_load_safe_path_vec_update (); add_setshow_optional_filename_cmd ("safe-path", class_support, &auto_load_safe_path, _("\ @@ -1058,6 +1074,7 @@ This options has security implications for untrusted inferiors."), show_auto_load_safe_path, auto_load_set_cmdlist_get (), auto_load_show_cmdlist_get ()); + observer_attach_gdb_datadir_changed (auto_load_gdb_datadir_changed); cmd = add_cmd ("add-auto-load-safe-path", class_support, add_auto_load_safe_path, diff --git a/gdb/config.in b/gdb/config.in index e54c1ea..f98ea42 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 safe to hold auto-loaded files. */ +#undef AUTO_LOAD_SAFE_PATH + /* Directory of programs. */ #undef BINDIR @@ -24,9 +27,6 @@ moved. */ #undef DEBUGDIR_RELOCATABLE -/* Directories safe to hold auto-loaded files. */ -#undef DEFAULT_AUTO_LOAD_SAFE_PATH - /* Define to BFD's default architecture. */ #undef DEFAULT_BFD_ARCH diff --git a/gdb/configure b/gdb/configure index c1775b7..934f5c1 100755 --- a/gdb/configure +++ b/gdb/configure @@ -1486,7 +1486,8 @@ Optional Packages: --with-relocated-sources=PATH automatically relocate this path for source files --with-auto-load-safe-path=PATH - directories safe to hold auto-loaded files + directories safe to hold auto-loaded files, use + $ddir for --with-gdb-datadir path [$ddir/auto-load] --without-auto-load-safe-path do not restrict auto-loaded files locations --with-libunwind-ia64 use libunwind frame unwinding for ia64 targets @@ -4964,20 +4965,21 @@ $as_echo_n "checking for default auto-load safe-path... " >&6; } # Check whether --with-auto-load-safe-path was given. if test "${with_auto_load_safe_path+set}" = set; then : withval=$with_auto_load_safe_path; if test "$with_auto_load_safe_path" = "no"; then - with_auto_load_safe_path="/" - fi + with_auto_load_safe_path="/" + fi else - with_auto_load_safe_path="$prefix" + with_auto_load_safe_path='$ddir/auto-load' fi +escape_dir=`echo $with_auto_load_safe_path | 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 $with_auto_load_safe_path` + ac_define_dir=`eval echo $escape_dir` ac_define_dir=`eval echo $ac_define_dir` cat >>confdefs.h <<_ACEOF -#define DEFAULT_AUTO_LOAD_SAFE_PATH "$ac_define_dir" +#define AUTO_LOAD_SAFE_PATH "$ac_define_dir" _ACEOF diff --git a/gdb/configure.ac b/gdb/configure.ac index ce7515b..1a889d9 100644 --- a/gdb/configure.ac +++ b/gdb/configure.ac @@ -138,13 +138,16 @@ AS_HELP_STRING([--with-relocated-sources=PATH], [automatically relocate this pat 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]) -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="$prefix"]) -AC_DEFINE_DIR(DEFAULT_AUTO_LOAD_SAFE_PATH, 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@:>@]) +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']) +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.]) AC_MSG_RESULT([$with_auto_load_safe_path]) diff --git a/gdb/defs.h b/gdb/defs.h index 4d2d2a8..004f335 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -381,6 +381,9 @@ extern struct cleanup *make_bpstat_clear_actions_cleanup (void); extern int producer_is_gcc_ge_4 (const char *producer); +extern void substitute_path_component (char **stringp, const char *from, + const char *to); + #ifdef HAVE_WAITPID extern pid_t wait_to_die_with_timeout (pid_t pid, int *status, int timeout); #endif diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 502a9e5..9cdc2ba 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,12 @@ +2012-05-11 Jan Kratochvil + + Provide $ddir substitution for --with-auto-load-safe-path. + * gdb.texinfo (Auto-loading): Replace /usr/local by $ddir/auto-load. + (Auto-loading safe path): Likewise. Mention the default value, + $ddir substitution, --with-auto-load-safe-path and + --without-auto-load-safe-path. + * observer.texi (gdb_datadir_changed): New. + 2012-05-09 Jan Kratochvil * gdb.texinfo (Auto-loading): Wrap too long lines in @smallexample. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 5d8444c..eab9774 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -21008,7 +21008,7 @@ 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 /usr/local. + is $ddir/auto-load. @end smallexample @anchor{info auto-load} @@ -21211,9 +21211,9 @@ 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 "/usr/local". + declined by your `auto-load safe-path' set to "$ddir/auto-load". warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been - declined by your `auto-load safe-path' set to "/usr/local". + declined by your `auto-load safe-path' set to "$ddir/auto-load". @end smallexample The list of trusted directories is controlled by the following commands: @@ -21245,7 +21245,18 @@ loading and execution of scripts. Multiple entries may be delimited by the host platform path separator in use. @end table -Setting this variable to @file{/} disables this security protection. +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-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}. This variable is supposed to be set to the system directories writable by the system superuser only. Users can add their source directories in init files in their home directories (@pxref{Home Directory Init File}). See also deprecated diff --git a/gdb/doc/observer.texi b/gdb/doc/observer.texi index 24233cb..6827ed8 100644 --- a/gdb/doc/observer.texi +++ b/gdb/doc/observer.texi @@ -226,6 +226,10 @@ Called before a top-level prompt is displayed. @var{current_prompt} is the current top-level prompt. @end deftypefun +@deftypefun void gdb_datadir_changed (void) +Variable gdb_datadir has been set. The value may not necessarily change. +@end deftypefun + @deftypefun void test_notification (int @var{somearg}) This observer is used for internal testing. Do not use. See testsuite/gdb.gdb/observer.exp. diff --git a/gdb/top.c b/gdb/top.c index a138480..061ad48 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -47,6 +47,7 @@ #include "gdbthread.h" #include "python/python.h" #include "interps.h" +#include "observer.h" /* readline include files. */ #include "readline/readline.h" @@ -1559,6 +1560,15 @@ show_exec_done_display_p (struct ui_file *file, int from_tty, "asynchronous execution commands is %s.\n"), value); } + +/* "set" command for the gdb_datadir configuration variable. */ + +static void +set_gdb_datadir (char *args, int from_tty, struct cmd_list_element *c) +{ + observer_notify_gdb_datadir_changed (); +} + static void init_main (void) { @@ -1666,7 +1676,7 @@ Use \"on\" to enable the notification, and \"off\" to disable it."), _("Show GDB's data directory."), _("\ When set, GDB uses the specified path to search for data files."), - NULL, NULL, + set_gdb_datadir, NULL, &setlist, &showlist); } diff --git a/gdb/utils.c b/gdb/utils.c index b70edd8..15956b7 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -3724,6 +3724,48 @@ dirnames_to_char_ptr_vec (const char *dirnames) return retval; } +/* 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. */ + +void +substitute_path_component (char **stringp, const char *from, const char *to) +{ + char *string = *stringp, *s; + const size_t from_len = strlen (from); + const size_t to_len = strlen (to); + + for (s = string;;) + { + s = strstr (s, from); + if (s == NULL) + break; + + if ((s == string || IS_DIR_SEPARATOR (s[-1])) + && (s[from_len] == '\0' || IS_DIR_SEPARATOR (s[from_len]))) + { + char *string_new; + + string_new = xrealloc (string, (strlen (string) + to_len + 1)); + + /* Relocate the current S pointer. */ + s = s - string + string_new; + string = string_new; + + /* Replace from by to. */ + memmove (&s[to_len], &s[from_len], strlen (&s[from_len]) + 1); + memcpy (s, to, to_len); + + s += to_len; + } + else + s++; + } + + *stringp = string; +} + #ifdef HAVE_WAITPID #ifdef SIGALRM