diff options
author | Tom Tromey <tom@tromey.com> | 2024-09-29 12:22:07 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2024-10-19 13:18:00 -0600 |
commit | 03ace3807c891427019686f4137ad0257d63e138 (patch) | |
tree | b8a21f4e659ab366269180f12e5fd84da9c91662 | |
parent | e686338105177046975bcff8fe6199536e80caf9 (diff) | |
download | binutils-03ace3807c891427019686f4137ad0257d63e138.zip binutils-03ace3807c891427019686f4137ad0257d63e138.tar.gz binutils-03ace3807c891427019686f4137ad0257d63e138.tar.bz2 |
Pass current directory to gdb_abspath
Currently, gdb_abspath uses the current_directory global. However,
background threads need to capture this global to avoid races with the
user using "cd".
This patch changes this function to accept a cwd parameter, in
prepration for this.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31716
-rw-r--r-- | gdbsupport/pathstuff.cc | 6 | ||||
-rw-r--r-- | gdbsupport/pathstuff.h | 18 |
2 files changed, 12 insertions, 12 deletions
diff --git a/gdbsupport/pathstuff.cc b/gdbsupport/pathstuff.cc index 029e3c9..faed79b 100644 --- a/gdbsupport/pathstuff.cc +++ b/gdbsupport/pathstuff.cc @@ -124,17 +124,17 @@ gdb_realpath_keepfile (const char *filename) /* See gdbsupport/pathstuff.h. */ std::string -gdb_abspath (const char *path) +gdb_abspath (const char *path, const char *cwd) { gdb_assert (path != NULL && path[0] != '\0'); if (path[0] == '~') return gdb_tilde_expand (path); - if (IS_ABSOLUTE_PATH (path) || current_directory == NULL) + if (IS_ABSOLUTE_PATH (path) || cwd == NULL) return path; - return path_join (current_directory, path); + return path_join (cwd, path); } /* See gdbsupport/pathstuff.h. */ diff --git a/gdbsupport/pathstuff.h b/gdbsupport/pathstuff.h index 22170bb..15c7872 100644 --- a/gdbsupport/pathstuff.h +++ b/gdbsupport/pathstuff.h @@ -30,6 +30,9 @@ /* Path utilities. */ +/* String containing the current directory (what getwd would return). */ +extern char *current_directory; + /* Return the real path of FILENAME, expanding all the symbolic links. Contrary to "gdb_abspath", this function does not use @@ -47,14 +50,14 @@ extern std::string gdb_realpath_keepfile (const char *filename); PATH cannot be NULL or the empty string. This does not resolve symlinks however, use gdb_realpath for that. - Contrary to "gdb_realpath", this function uses CURRENT_DIRECTORY - for the path expansion. This may lead to scenarios the current - working directory (CWD) is different than CURRENT_DIRECTORY. + Contrary to "gdb_realpath", this function uses CWD for the path + expansion. This may lead to scenarios the current working + directory is different than CWD. - If CURRENT_DIRECTORY is NULL, this function returns a copy of - PATH. */ + If CWD is NULL, this function returns a copy of PATH. */ -extern std::string gdb_abspath (const char *path); +extern std::string gdb_abspath (const char *path, + const char *cwd = current_directory); /* Overload of gdb_abspath which takes std::string. */ @@ -177,7 +180,4 @@ extern const char *get_shell (); extern gdb::char_vector make_temp_filename (const std::string &f); -/* String containing the current directory (what getwd would return). */ -extern char *current_directory; - #endif /* COMMON_PATHSTUFF_H */ |