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.
This commit is contained in:
parent
b09aca3aa7
commit
6dea1fbd79
12 changed files with 162 additions and 26 deletions
|
@ -1,3 +1,27 @@
|
|||
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.
|
||||
* 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 <jan.kratochvil@redhat.com>
|
||||
|
||||
Make auto-load handle multiple components of DEBUG_FILE_DIRECTORY.
|
||||
|
|
11
gdb/NEWS
11
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
|
||||
|
|
|
@ -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;
|
||||
|
||||
/* Ensure the current entry is at least tilde_expand-ed. */
|
||||
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 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,
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
14
gdb/configure
vendored
14
gdb/configure
vendored
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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])
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,3 +1,12 @@
|
|||
2012-05-11 Jan Kratochvil <jan.kratochvil@redhat.com>
|
||||
|
||||
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 <jan.kratochvil@redhat.com>
|
||||
|
||||
* gdb.texinfo (Auto-loading): Wrap too long lines in @smallexample.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
12
gdb/top.c
12
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);
|
||||
}
|
||||
|
|
42
gdb/utils.c
42
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
|
||||
|
|
Loading…
Reference in a new issue