aboutsummaryrefslogtreecommitdiff
path: root/gdb/auto-load.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2023-04-04 12:50:03 -0600
committerTom Tromey <tom@tromey.com>2023-05-05 07:49:43 -0600
commit02601231fdd91a7bd4837ce202906ea2ce661489 (patch)
treec9745539b4869c0f70b698b8ac0e4366618154c1 /gdb/auto-load.c
parent4891c459927d9a9c0f516c35e2d9d4ce212dd06e (diff)
downloadgdb-02601231fdd91a7bd4837ce202906ea2ce661489.zip
gdb-02601231fdd91a7bd4837ce202906ea2ce661489.tar.gz
gdb-02601231fdd91a7bd4837ce202906ea2ce661489.tar.bz2
Simplify auto_load_expand_dir_vars and remove substitute_path_component
This simplifies auto_load_expand_dir_vars to first split the string, then do any needed substitutions. This was suggested by Simon, and is much simpler than the current approach. Then this patch also removes substitute_path_component, as it is no longer called. This is nice because it helps with the long term goal of removing utils.h. Regression tested on x86-64 Fedora 36.
Diffstat (limited to 'gdb/auto-load.c')
-rw-r--r--gdb/auto-load.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index 5267cb4..9d6fabe 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -173,24 +173,33 @@ static std::string auto_load_safe_path = AUTO_LOAD_SAFE_PATH;
counterpart. */
static std::vector<gdb::unique_xmalloc_ptr<char>> auto_load_safe_path_vec;
-/* Expand $datadir and $debugdir in STRING according to the rules of
- substitute_path_component. */
+/* Expand $datadir and $debugdir in STRING. */
static std::vector<gdb::unique_xmalloc_ptr<char>>
auto_load_expand_dir_vars (const char *string)
{
- char *s = xstrdup (string);
- substitute_path_component (&s, "$datadir", gdb_datadir.c_str ());
- substitute_path_component (&s, "$debugdir", debug_file_directory.c_str ());
+ std::vector<gdb::unique_xmalloc_ptr<char>> result
+ = dirnames_to_char_ptr_vec (string);
- if (debug_auto_load && strcmp (s, string) != 0)
- auto_load_debug_printf ("Expanded $-variables to \"%s\".", s);
-
- std::vector<gdb::unique_xmalloc_ptr<char>> dir_vec
- = dirnames_to_char_ptr_vec (s);
- xfree(s);
+ for (auto &elt : result)
+ {
+ if (strcmp (elt.get (), "$datadir") == 0)
+ {
+ elt = make_unique_xstrdup (gdb_datadir.c_str ());
+ if (debug_auto_load)
+ auto_load_debug_printf ("Expanded $datadir to \"%s\".",
+ gdb_datadir.c_str ());
+ }
+ else if (strcmp (elt.get (), "$debugdir") == 0)
+ {
+ elt = make_unique_xstrdup (debug_file_directory.c_str ());
+ if (debug_auto_load)
+ auto_load_debug_printf ("Expanded $debugdir to \"%s\".",
+ debug_file_directory.c_str ());
+ }
+ }
- return dir_vec;
+ return result;
}
/* Update auto_load_safe_path_vec from current AUTO_LOAD_SAFE_PATH. */