diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2022-04-20 17:03:25 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@efficios.com> | 2022-04-21 11:11:21 -0400 |
commit | ffaebc199ed7b1f7e539c938e8b234d2a4ad9df9 (patch) | |
tree | f08456fdf016edb0a24c821f7cba7f2dc21e09b0 /gdb/buildsym.c | |
parent | 78088b89602ad5c2b68142d6a56481fb792725aa (diff) | |
download | binutils-ffaebc199ed7b1f7e539c938e8b234d2a4ad9df9.zip binutils-ffaebc199ed7b1f7e539c938e8b234d2a4ad9df9.tar.gz binutils-ffaebc199ed7b1f7e539c938e8b234d2a4ad9df9.tar.bz2 |
gdbsupport: add path_join function
In this review [1], Eli pointed out that we should be careful when
concatenating file names to avoid duplicated slashes. On Windows, a
double slash at the beginning of a file path has a special meaning. So
naively concatenating "/" and "foo/bar" would give "//foo/bar", which
would not give the desired results. We already have a few spots doing:
if (first_path ends with a slash)
path = first_path + second_path
else
path = first_path + slash + second_path
In general, I think it's nice to avoid superfluous slashes in file
paths, since they might end up visible to the user and look a bit
unprofessional.
Introduce the path_join function that can be used to join multiple path
components together (along with unit tests).
I initially wanted to make it possible to join two absolute paths, to
support the use case of prepending a sysroot path to a target file path,
or the prepending the debug-file-directory to a target file path. But
the code in solib_find_1 shows that it is more complex than this anyway
(for example, when the right hand side is a Windows path with a drive
letter). So I don't think we need to support that case in path_join.
That also keeps the implementation simpler.
Change a few spots to use path_join to show how it can be used. I
believe that all the spots I changed are guarded by some checks that
ensure the right hand side operand is not an absolute path.
Regression-tested on Ubuntu 18.04. Built-tested on Windows, and I also
ran the new unit-test there.
[1] https://sourceware.org/pipermail/gdb-patches/2022-April/187559.html
Change-Id: I0df889f7e3f644e045f42ff429277b732eb6c752
Diffstat (limited to 'gdb/buildsym.c')
-rw-r--r-- | gdb/buildsym.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/gdb/buildsym.c b/gdb/buildsym.c index 927074b..586c092 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -20,6 +20,7 @@ #include "buildsym-legacy.h" #include "bfd.h" #include "gdbsupport/gdb_obstack.h" +#include "gdbsupport/pathstuff.h" #include "symtab.h" #include "symfile.h" #include "objfiles.h" @@ -507,8 +508,8 @@ buildsym_compunit::start_subfile (const char *name) && !IS_ABSOLUTE_PATH (subfile->name) && !m_comp_dir.empty ()) { - subfile_name_holder = string_printf ("%s/%s", m_comp_dir.c_str (), - subfile->name.c_str ()); + subfile_name_holder = path_join (m_comp_dir.c_str (), + subfile->name.c_str ()); subfile_name = subfile_name_holder.c_str (); } else |