aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-11-29 11:34:17 -0700
committerTom Tromey <tom@tromey.com>2021-12-04 11:16:22 -0700
commit63538d8e16bca32e8d03c3d1309c5ed8894a59b4 (patch)
tree4606fa4a9c376cc5351c241dd522e19306986ed2
parentbb3f8ae2902a9878a25fad21efd23fe0f888c232 (diff)
downloadbinutils-63538d8e16bca32e8d03c3d1309c5ed8894a59b4.zip
binutils-63538d8e16bca32e8d03c3d1309c5ed8894a59b4.tar.gz
binutils-63538d8e16bca32e8d03c3d1309c5ed8894a59b4.tar.bz2
Cache the result of find_file_and_directory
This changes the DWARF reader to cache the result of find_file_and_directory. This is not especially important now, but it will help the new DWARF indexer.
-rw-r--r--gdb/dwarf2/read.c19
-rw-r--r--gdb/dwarf2/read.h7
2 files changed, 18 insertions, 8 deletions
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index a2ed2cd..ff5758e 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -34,7 +34,6 @@
#include "dwarf2/attribute.h"
#include "dwarf2/comp-unit-head.h"
#include "dwarf2/cu.h"
-#include "dwarf2/file-and-dir.h"
#include "dwarf2/index-cache.h"
#include "dwarf2/index-common.h"
#include "dwarf2/leb.h"
@@ -1538,8 +1537,8 @@ dwarf2_per_cu_data_deleter::operator() (dwarf2_per_cu_data *data)
delete data;
}
-static file_and_directory find_file_and_directory (struct die_info *die,
- struct dwarf2_cu *cu);
+static file_and_directory &find_file_and_directory
+ (struct die_info *die, struct dwarf2_cu *cu);
static const char *compute_include_file_name
(const struct line_header *lh,
@@ -3006,7 +3005,7 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader,
lh = dwarf_decode_line_header (line_offset, cu);
}
- file_and_directory fnd = find_file_and_directory (comp_unit_die, cu);
+ file_and_directory &fnd = find_file_and_directory (comp_unit_die, cu);
int offset = 0;
if (fnd.is_unknown ())
@@ -6989,7 +6988,7 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
/* Allocate a new partial symbol table structure. */
gdb::unique_xmalloc_ptr<char> debug_filename;
static const char artificial[] = "<artificial>";
- file_and_directory fnd = find_file_and_directory (comp_unit_die, cu);
+ file_and_directory &fnd = find_file_and_directory (comp_unit_die, cu);
if (strcmp (fnd.get_name (), artificial) == 0)
{
debug_filename.reset (concat (artificial, "@",
@@ -10475,9 +10474,12 @@ producer_is_gcc_lt_4_3 (struct dwarf2_cu *cu)
return cu->producer_is_gcc_lt_4_3;
}
-static file_and_directory
+static file_and_directory &
find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu)
{
+ if (cu->per_cu->fnd != nullptr)
+ return *cu->per_cu->fnd;
+
/* Find the filename. Do not use dwarf2_name here, since the filename
is not a source language identifier. */
file_and_directory res (dwarf2_string_attr (die, DW_AT_name, cu),
@@ -10489,7 +10491,8 @@ find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu)
&& IS_ABSOLUTE_PATH (res.get_name ()))
res.set_comp_dir (ldirname (res.get_name ()));
- return res;
+ cu->per_cu->fnd.reset (new file_and_directory (std::move (res)));
+ return *cu->per_cu->fnd;
}
/* Handle DW_AT_stmt_list for a compilation unit.
@@ -10617,7 +10620,7 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
lowpc = highpc;
lowpc = gdbarch_adjust_dwarf2_addr (gdbarch, lowpc + baseaddr);
- file_and_directory fnd = find_file_and_directory (die, cu);
+ file_and_directory &fnd = find_file_and_directory (die, cu);
cu->start_symtab (fnd.get_name (), fnd.intern_comp_dir (objfile), lowpc);
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index fe34e3f..2f849d5 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -23,6 +23,7 @@
#include <queue>
#include <unordered_map>
#include "dwarf2/comp-unit-head.h"
+#include "dwarf2/file-and-dir.h"
#include "dwarf2/index-cache.h"
#include "dwarf2/section.h"
#include "filename-seen-cache.h"
@@ -179,6 +180,12 @@ struct dwarf2_per_cu_data
should be private, but we can't make it private at the moment. */
mutable comp_unit_head m_header {};
+ /* The file and directory for this CU. This is cached so that we
+ don't need to re-examine the DWO in some situations. This may be
+ nullptr, depending on the CU; for example a partial unit won't
+ have one. */
+ std::unique_ptr<file_and_directory> fnd;
+
/* When dwarf2_per_bfd::using_index is true, the 'quick' field
is active. Otherwise, the 'psymtab' field is active. */
union