diff options
-rw-r--r-- | gdb/symfile.c | 41 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/sysroot-debug-lookup.exp | 6 | ||||
-rw-r--r-- | gdbsupport/pathstuff.cc | 16 | ||||
-rw-r--r-- | gdbsupport/pathstuff.h | 6 |
4 files changed, 32 insertions, 37 deletions
diff --git a/gdb/symfile.c b/gdb/symfile.c index 49b9845..11313c8 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1371,17 +1371,13 @@ find_separate_debug_file (const char *dir, objfile_name (objfile)); /* First try in the same directory as the original file. */ - std::string debugfile = dir; - debugfile += debuglink; + std::string debugfile = path_join (dir, debuglink); if (separate_debug_file_exists (debugfile, crc32, objfile, warnings)) return debugfile; /* Then try in the subdirectory named DEBUG_SUBDIRECTORY. */ - debugfile = dir; - debugfile += DEBUG_SUBDIRECTORY; - debugfile += "/"; - debugfile += debuglink; + debugfile = path_join (dir, DEBUG_SUBDIRECTORY, debuglink); if (separate_debug_file_exists (debugfile, crc32, objfile, warnings)) return debugfile; @@ -1394,6 +1390,7 @@ find_separate_debug_file (const char *dir, bool target_prefix = is_target_filename (dir); const char *dir_notarget = target_prefix ? dir + strlen (TARGET_SYSROOT_PREFIX) : dir; + const char *target_prefix_str = target_prefix ? TARGET_SYSROOT_PREFIX : ""; std::vector<gdb::unique_xmalloc_ptr<char>> debugdir_vec = dirnames_to_char_ptr_vec (debug_file_directory.c_str ()); gdb::unique_xmalloc_ptr<char> canon_sysroot @@ -1422,12 +1419,8 @@ find_separate_debug_file (const char *dir, for (const gdb::unique_xmalloc_ptr<char> &debugdir : debugdir_vec) { - debugfile = target_prefix ? TARGET_SYSROOT_PREFIX : ""; - debugfile += debugdir; - debugfile += "/"; - debugfile += drive; - debugfile += dir_notarget; - debugfile += debuglink; + debugfile = path_join (target_prefix_str, debugdir.get (), + drive.c_str (), dir_notarget, debuglink); if (separate_debug_file_exists (debugfile, crc32, objfile, warnings)) return debugfile; @@ -1444,12 +1437,8 @@ find_separate_debug_file (const char *dir, { /* If the file is in the sysroot, try using its base path in the global debugfile directory. */ - debugfile = target_prefix ? TARGET_SYSROOT_PREFIX : ""; - debugfile += debugdir; - debugfile += "/"; - debugfile += base_path; - debugfile += "/"; - debugfile += debuglink; + debugfile = path_join (target_prefix_str, debugdir.get (), + base_path, debuglink); if (separate_debug_file_exists (debugfile, crc32, objfile, warnings)) return debugfile; @@ -1462,21 +1451,17 @@ find_separate_debug_file (const char *dir, same result as above. */ if (gdb_sysroot != TARGET_SYSROOT_PREFIX) { - debugfile = target_prefix ? TARGET_SYSROOT_PREFIX : ""; + std::string root; if (is_target_filename (gdb_sysroot)) { - std::string root - = gdb_sysroot.substr (strlen (TARGET_SYSROOT_PREFIX)); + root = gdb_sysroot.substr (strlen (TARGET_SYSROOT_PREFIX)); gdb_assert (!root.empty ()); - debugfile += root; } else - debugfile += gdb_sysroot; - debugfile += debugdir; - debugfile += "/"; - debugfile += base_path; - debugfile += "/"; - debugfile += debuglink; + root = gdb_sysroot; + + debugfile = path_join (target_prefix_str, root.c_str (), + debugdir.get (), base_path, debuglink); if (separate_debug_file_exists (debugfile, crc32, objfile, warnings)) diff --git a/gdb/testsuite/gdb.base/sysroot-debug-lookup.exp b/gdb/testsuite/gdb.base/sysroot-debug-lookup.exp index 36f6519..88be6ff 100644 --- a/gdb/testsuite/gdb.base/sysroot-debug-lookup.exp +++ b/gdb/testsuite/gdb.base/sysroot-debug-lookup.exp @@ -180,13 +180,15 @@ proc_with_prefix lookup_via_debuglink {} { # # Bug PR gdb/30866 seems to be the (or a) relevant bug for # this problem. - if { $sysroot_prefix ne "" } { + if { $sysroot_prefix ne "" + && [target_info gdb_protocol] ne "extended-remote" } { setup_kfail "*-*-*" 31804 } gdb_assert { $::gdb_file_cmd_debug_info eq "debug" } \ "ensure debug information was found" - if { $sysroot_prefix ne "" } { + if { $sysroot_prefix ne "" + && [target_info gdb_protocol] ne "extended-remote" } { setup_kfail "*-*-*" 31804 } set re [string_to_regexp "Reading symbols from ${sysroot_prefix}$debug_symlink..."] diff --git a/gdbsupport/pathstuff.cc b/gdbsupport/pathstuff.cc index 9c3816c..029e3c9 100644 --- a/gdbsupport/pathstuff.cc +++ b/gdbsupport/pathstuff.cc @@ -198,11 +198,17 @@ path_join (gdb::array_view<const char *> paths) { const char *path = paths[i]; - if (i > 0) - gdb_assert (strlen (path) == 0 || !IS_ABSOLUTE_PATH (path)); - - if (!ret.empty () && !IS_DIR_SEPARATOR (ret.back ())) - ret += '/'; + if (!ret.empty ()) + { + /* If RET doesn't already end with a separator then add one. */ + if (!IS_DIR_SEPARATOR (ret.back ())) + ret += '/'; + + /* Now that RET ends with a separator, ignore any at the start of + PATH. */ + while (IS_DIR_SEPARATOR (path[0])) + ++path; + } ret.append (path); } diff --git a/gdbsupport/pathstuff.h b/gdbsupport/pathstuff.h index a61ce23..22170bb 100644 --- a/gdbsupport/pathstuff.h +++ b/gdbsupport/pathstuff.h @@ -80,8 +80,10 @@ extern const char *child_path (const char *parent, const char *child); /* Join elements in PATHS into a single path. - The first element can be absolute or relative. All the others must be - relative. */ + The first element can be absolute or relative. Only a single directory + separator will be placed between elements of PATHS, if one element ends + with a directory separator, or an element starts with a directory + separator, then these will be collapsed into a single separator. */ extern std::string path_join (gdb::array_view<const char *> paths); |