aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2024-08-24 08:37:15 -0600
committerTom Tromey <tom@tromey.com>2024-10-19 13:18:00 -0600
commit3fbf1a34f10aa6a67d9f96c437e8f9dc57832d22 (patch)
tree88c78b02b574a3a6070036b850ccf4d314528795 /gdb
parentf4ab1188c055d65c99663902317eb5ec4cfc7271 (diff)
downloadbinutils-3fbf1a34f10aa6a67d9f96c437e8f9dc57832d22.zip
binutils-3fbf1a34f10aa6a67d9f96c437e8f9dc57832d22.tar.gz
binutils-3fbf1a34f10aa6a67d9f96c437e8f9dc57832d22.tar.bz2
Capture the current directory and debug directory in DWARF reader
This changes the DWARF reader to capture the current working directory and the current debug directory. This avoids races when the DWARF reader is working in the background. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31716
Diffstat (limited to 'gdb')
-rw-r--r--gdb/dwarf2/read.c19
-rw-r--r--gdb/dwarf2/read.h6
2 files changed, 18 insertions, 7 deletions
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 95498bf..bd2de02 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1252,7 +1252,9 @@ line_header_eq_voidp (const void *item_lhs, const void *item_rhs)
dwarf2_per_bfd::dwarf2_per_bfd (bfd *obfd, const dwarf2_debug_sections *names,
bool can_copy_)
: obfd (obfd),
- can_copy (can_copy_)
+ can_copy (can_copy_),
+ captured_cwd (current_directory),
+ captured_debug_dir (debug_file_directory)
{
if (names == NULL)
names = &dwarf2_elf_names;
@@ -9046,10 +9048,12 @@ try_open_dwop_file (dwarf2_per_objfile *per_objfile,
gdb::unique_xmalloc_ptr<char> search_path_holder;
if (search_cwd)
{
- if (!debug_file_directory.empty ())
+ const std::string &debug_dir = per_objfile->per_bfd->captured_debug_dir;
+
+ if (!debug_dir.empty ())
{
search_path_holder.reset (concat (".", dirname_separator_string,
- debug_file_directory.c_str (),
+ debug_dir.c_str (),
(char *) NULL));
search_path = search_path_holder.get ();
}
@@ -9057,7 +9061,7 @@ try_open_dwop_file (dwarf2_per_objfile *per_objfile,
search_path = ".";
}
else
- search_path = debug_file_directory.c_str ();
+ search_path = per_objfile->per_bfd->captured_debug_dir.c_str ();
/* Add the path for the executable binary to the list of search paths. */
std::string objfile_dir = ldirname (objfile_name (per_objfile->objfile));
@@ -9072,7 +9076,8 @@ try_open_dwop_file (dwarf2_per_objfile *per_objfile,
gdb::unique_xmalloc_ptr<char> absolute_name;
desc = openp (search_path, flags, file_name,
- O_RDONLY | O_BINARY, &absolute_name);
+ O_RDONLY | O_BINARY, &absolute_name,
+ per_objfile->per_bfd->captured_cwd.c_str ());
if (desc < 0)
return NULL;
@@ -9126,7 +9131,7 @@ open_dwo_file (dwarf2_per_objfile *per_objfile,
/* That didn't work, try debug-file-directory, which, despite its name,
is a list of paths. */
- if (debug_file_directory.empty ())
+ if (per_objfile->per_bfd->captured_debug_dir.empty ())
return NULL;
return try_open_dwop_file (per_objfile, file_name,
@@ -9407,7 +9412,7 @@ open_dwp_file (dwarf2_per_objfile *per_objfile, const char *file_name)
[IWBN if the dwp file name was recorded in the executable, akin to
.gnu_debuglink, but that doesn't exist yet.]
Strip the directory from FILE_NAME and search again. */
- if (!debug_file_directory.empty ())
+ if (!per_objfile->per_bfd->captured_debug_dir.empty ())
{
/* Don't implicitly search the current directory here.
If the user wants to search "." to handle this case,
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 7c42017..728f2b5 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -558,6 +558,12 @@ public:
std::unordered_map<sect_offset, std::vector<sect_offset>,
gdb::hash_enum<sect_offset>>
abstract_to_concrete;
+
+ /* Current directory, captured at the moment that object this was
+ created. */
+ std::string captured_cwd;
+ /* Captured copy of debug_file_directory. */
+ std::string captured_debug_dir;
};
/* An iterator for all_units that is based on index. This