From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1879) id A000F384B433; Sat, 30 Jul 2022 00:55:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A000F384B433 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Simon Marchi To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/dwarf: pass a file_entry to line_header::file_file_name X-Act-Checkin: binutils-gdb X-Git-Author: Simon Marchi X-Git-Refname: refs/heads/master X-Git-Oldrev: ddc01737d34f16074b2c9a92c5a808be5c91340f X-Git-Newrev: 0aa306fed318f679c1db21974b64e29d236d51e5 Message-Id: <20220730005524.A000F384B433@sourceware.org> Date: Sat, 30 Jul 2022 00:55:24 +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: Sat, 30 Jul 2022 00:55:24 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D0aa306fed318= f679c1db21974b64e29d236d51e5 commit 0aa306fed318f679c1db21974b64e29d236d51e5 Author: Simon Marchi Date: Tue Apr 26 22:50:22 2022 -0400 gdb/dwarf: pass a file_entry to line_header::file_file_name =20 In the following patch, there will be some callers of file_file_name that will already have access to the file_entry object for which they want the file name. It would be inefficient to have them pass an index, only for line_header::file_file_name to re-lookup the same file_entry object. Change line_header::file_file_name to accept a file_entry object reference, instead of an index to look up. =20 I think this change makes sense in any case. Callers that have an index can first obtain a file_entry using line_header::file_name_at or line_header::file_names. =20 When passing a file_entry object, we can assume that the file_entry's index is valid, unlike when passing an index. So, push the special case about an invalid index to the sole current caller of file_file_name, macro_start_file. I think that error belongs there anyway, since it specifically talks about "bad file number in macro information". =20 This requires recording the file index in the file_entry structure, so add that. =20 Change-Id: Ic6e44c407539d92b7863d7ba82405ade17f384ad Diff: --- gdb/dwarf2/line-header.c | 47 ++++++++++++++------------------------------= --- gdb/dwarf2/line-header.h | 10 +++++++--- gdb/dwarf2/macro.c | 16 +++++++++++++++- 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/gdb/dwarf2/line-header.c b/gdb/dwarf2/line-header.c index 13379851b9b..a1bd39df7ed 100644 --- a/gdb/dwarf2/line-header.c +++ b/gdb/dwarf2/line-header.c @@ -48,47 +48,28 @@ line_header::add_file_name (const char *name, unsigned int mod_time, unsigned int length) { + file_name_index index + =3D version >=3D 5 ? file_names_size (): file_names_size () + 1; + if (dwarf_line_debug >=3D 2) - { - size_t new_size; - if (version >=3D 5) - new_size =3D file_names_size (); - else - new_size =3D file_names_size () + 1; - gdb_printf (gdb_stdlog, "Adding file %zu: %s\n", - new_size, name); - } - m_file_names.emplace_back (name, d_index, mod_time, length); + gdb_printf (gdb_stdlog, "Adding file %d: %s\n", index, name); + + m_file_names.emplace_back (name, index, d_index, mod_time, length); } =20 std::string -line_header::file_file_name (int file) const +line_header::file_file_name (const file_entry &fe) const { - /* Is the file number a valid index into the line header's file name - table? Remember that file numbers start with one, not zero. */ - if (is_valid_file_index (file)) - { - const file_entry *fe =3D file_name_at (file); + gdb_assert (is_valid_file_index (fe.index)); =20 - if (!IS_ABSOLUTE_PATH (fe->name)) - { - const char *dir =3D fe->include_dir (this); - if (dir !=3D NULL) - return path_join (dir, fe->name); - } + if (IS_ABSOLUTE_PATH (fe.name)) + return fe.name; =20 - return fe->name; - } - else - { - /* The compiler produced a bogus file number. We can at least - record the macro definitions made in the file, even if we - won't be able to find the file by name. */ - complaint (_("bad file number in macro information (%d)"), - file); + const char *dir =3D fe.include_dir (this); + if (dir =3D=3D nullptr) + return fe.name; =20 - return string_printf ("", file); - } + return path_join (dir, fe.name); } =20 static void diff --git a/gdb/dwarf2/line-header.h b/gdb/dwarf2/line-header.h index 32f52c4a647..e6b52f7520e 100644 --- a/gdb/dwarf2/line-header.h +++ b/gdb/dwarf2/line-header.h @@ -36,9 +36,10 @@ struct file_entry { file_entry () =3D default; =20 - file_entry (const char *name_, dir_index d_index_, + file_entry (const char *name_, file_name_index index_, dir_index d_index= _, unsigned int mod_time_, unsigned int length_) : name (name_), + index (index_), d_index (d_index_), mod_time (mod_time_), length (length_) @@ -52,6 +53,9 @@ struct file_entry owned by debug_line_buffer. */ const char *name {}; =20 + /* The index of this file in the file table. */ + file_name_index index {}; + /* The directory index (1-based). */ dir_index d_index {}; =20 @@ -168,8 +172,8 @@ struct line_header const gdb_byte *statement_program_start {}, *statement_program_end {}; =20 /* Return file name relative to the compilation directory of file - number FILE in this object's file name table. */ - std::string file_file_name (int file) const; + FE in this object's file name table. */ + std::string file_file_name (const file_entry &fe) const; =20 /* Return the compilation directory of the compilation unit in the conte= xt of which this line header is read. Return nullptr if non applicable. */ diff --git a/gdb/dwarf2/macro.c b/gdb/dwarf2/macro.c index 99c3653a2c3..38c0fdfec73 100644 --- a/gdb/dwarf2/macro.c +++ b/gdb/dwarf2/macro.c @@ -52,7 +52,21 @@ macro_start_file (buildsym_compunit *builder, const struct line_header *lh) { /* File name relative to the compilation directory of this source file. = */ - std::string file_name =3D lh->file_file_name (file); + const file_entry *fe =3D lh->file_name_at (file); + std::string file_name; + + if (fe !=3D nullptr) + file_name =3D lh->file_file_name (*fe); + else + { + /* The compiler produced a bogus file number. We can at least + record the macro definitions made in the file, even if we + won't be able to find the file by name. */ + complaint (_("bad file number in macro information (%d)"), + file); + + file_name =3D string_printf ("", file); + } =20 if (! current_file) {