From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 353F23858C27; Tue, 12 Apr 2022 15:40:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 353F23858C27 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Add "fullname" handling to file_and_directory X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 85098eeb4c47debd67c793477bd04d33ab1a5645 X-Git-Newrev: c600d77cb77d6eafc15ff6b1bb34c765e3b21bcc Message-Id: <20220412154016.353F23858C27@sourceware.org> Date: Tue, 12 Apr 2022 15:40:16 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Apr 2022 15:40:16 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dc600d77cb77d= 6eafc15ff6b1bb34c765e3b21bcc commit c600d77cb77d6eafc15ff6b1bb34c765e3b21bcc Author: Tom Tromey Date: Mon Nov 29 17:56:56 2021 -0700 Add "fullname" handling to file_and_directory =20 This changes the file_and_directory object to be able to compute and cache the "fullname" in the same way that is done by other code, like the psymtab reader. Diff: --- gdb/dwarf2/file-and-dir.h | 18 ++++++++++++++++++ gdb/dwarf2/read.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/gdb/dwarf2/file-and-dir.h b/gdb/dwarf2/file-and-dir.h index a392636830d..1113fe09623 100644 --- a/gdb/dwarf2/file-and-dir.h +++ b/gdb/dwarf2/file-and-dir.h @@ -28,6 +28,7 @@ #define GDB_DWARF2_FILE_AND_DIR_H =20 #include "objfiles.h" +#include "source.h" #include =20 /* The return type of find_file_and_directory. Note, the enclosed @@ -90,6 +91,20 @@ struct file_and_directory m_name =3D m_name_storage.get (); } =20 + /* Return the full name, computing it if necessary. */ + const char *get_fullname () + { + if (m_fullname =3D=3D nullptr) + m_fullname =3D find_source_or_rewrite (get_name (), get_comp_dir ()); + return m_fullname.get (); + } + + /* Forget the full name. */ + void forget_fullname () + { + m_fullname.reset (); + } + private: =20 /* The filename. */ @@ -106,6 +121,9 @@ private: =20 /* The compilation directory, if it needed to be allocated. */ std::string m_comp_dir_storage; + + /* The full name. */ + gdb::unique_xmalloc_ptr m_fullname; }; =20 #endif /* GDB_DWARF2_FILE_AND_DIR_H */ diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index a986d9a2ab2..29e1f098d27 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -3139,6 +3139,9 @@ dwarf2_base_index_functions::find_last_source_symtab = (struct objfile *objfile) void dwarf2_per_cu_data::free_cached_file_names () { + if (fnd !=3D nullptr) + fnd->forget_fullname (); + if (per_bfd =3D=3D nullptr || !per_bfd->using_index || v.quick =3D=3D nu= llptr) return; =20 @@ -4362,6 +4365,27 @@ dw_expand_symtabs_matching_file_matcher if (per_objfile->symtab_set_p (per_cu.get ())) continue; =20 + if (per_cu->fnd !=3D nullptr) + { + file_and_directory *fnd =3D per_cu->fnd.get (); + + if (file_matcher (fnd->get_name (), false)) + { + per_cu->v.quick->mark =3D 1; + continue; + } + + /* Before we invoke realpath, which can get expensive when many + files are involved, do a quick comparison of the basenames. */ + if ((basenames_may_differ + || file_matcher (lbasename (fnd->get_name ()), true)) + && file_matcher (fnd->get_fullname (), false)) + { + per_cu->v.quick->mark =3D 1; + continue; + } + } + quick_file_names *file_data =3D dw2_get_file_names (per_cu.get (), per_objfile); if (file_data =3D=3D NULL) @@ -4556,6 +4580,24 @@ dwarf2_base_index_functions::map_symbol_filenames if (per_cu->is_debug_types || per_objfile->symtab_set_p (per_cu)) continue; =20 + if (per_cu->fnd !=3D nullptr) + { + file_and_directory *fnd =3D per_cu->fnd.get (); + + const char *filename =3D fnd->get_name (); + const char *key =3D filename; + const char *fullname =3D nullptr; + + if (need_fullname) + { + fullname =3D fnd->get_fullname (); + key =3D fullname; + } + + if (!filenames_cache.seen (key)) + fun (filename, fullname); + } + quick_file_names *file_data =3D dw2_get_file_names (per_cu, per_objf= ile); if (file_data =3D=3D nullptr || qfn_cache.find (file_data) !=3D qfn_cache.end ())