binutils-gdb/gdb/unittests
Simon Marchi ffaebc199e 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
2022-04-21 11:11:21 -04:00
..
basic_string_view Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
optional Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
array-view-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
child-path-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
cli-utils-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
command-def-selftests.c Unify gdb printf functions 2022-03-29 12:46:24 -06:00
common-utils-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
copy_bitwise-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
enum-flags-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
environ-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
filtered_iterator-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
format_pieces-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
function-view-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
gdb_tilde_expand-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
gmp-utils-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
intrusive_list-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
lookup_name_info-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
main-thread-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
memory-map-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
memrange-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
mkdir-recursive-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
observable-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
offset-type-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
optional-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
parallel-for-selftests.c Add batching parameter to parallel_for_each 2022-04-12 09:31:16 -06:00
parse-connection-spec-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
path-join-selftests.c gdbsupport: add path_join function 2022-04-21 11:11:21 -04:00
ptid-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
rsp-low-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
scoped_fd-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
scoped_ignore_signal-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
scoped_mmap-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
scoped_restore-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
search-memory-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
string_view-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
style-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
tracepoint-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
tui-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
ui-file-selftests.c Implement putstr and putstrn in ui_file 2022-01-05 11:01:02 -07:00
unique_xmalloc_ptr_char.c gdb: add operator+= and operator+ overload for std::string 2022-02-25 17:50:22 +00:00
unpack-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
utils-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
vec-utils-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00
xml-utils-selftests.c Automatic Copyright Year update after running gdb/copyright.py 2022-01-01 19:13:23 +04:00