summaryrefslogtreecommitdiff
path: root/gdb/utils.c
diff options
context:
space:
mode:
authorJan Kratochvil <jan.kratochvil@redhat.com>2012-05-11 18:13:22 +0000
committerJan Kratochvil <jan.kratochvil@redhat.com>2012-05-11 18:13:22 +0000
commite7dce50ad0b3c0437d3d4541bc4197cd2452baab (patch)
tree2f064034e40ee9572fc1f59a57df2c7ee130d9cc /gdb/utils.c
parent27e670ef3c91ca1f6146ef0da19df2e8fd5fb938 (diff)
downloadgdb-e7dce50ad0b3c0437d3d4541bc4197cd2452baab.tar.gz
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.
Diffstat (limited to 'gdb/utils.c')
-rw-r--r--gdb/utils.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/gdb/utils.c b/gdb/utils.c
index b70edd8988b..15956b7670c 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