From 0aa306fed318f679c1db21974b64e29d236d51e5 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 26 Apr 2022 22:50:22 -0400 Subject: gdb/dwarf: pass a file_entry to line_header::file_file_name 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. 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. 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". This requires recording the file index in the file_entry structure, so add that. Change-Id: Ic6e44c407539d92b7863d7ba82405ade17f384ad --- gdb/dwarf2/line-header.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'gdb/dwarf2/line-header.h') diff --git a/gdb/dwarf2/line-header.h b/gdb/dwarf2/line-header.h index 32f52c4..e6b52f7 100644 --- a/gdb/dwarf2/line-header.h +++ b/gdb/dwarf2/line-header.h @@ -36,9 +36,10 @@ struct file_entry { file_entry () = default; - 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 {}; + /* The index of this file in the file table. */ + file_name_index index {}; + /* The directory index (1-based). */ dir_index d_index {}; @@ -168,8 +172,8 @@ struct line_header const gdb_byte *statement_program_start {}, *statement_program_end {}; /* 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; /* Return the compilation directory of the compilation unit in the context of which this line header is read. Return nullptr if non applicable. */ -- cgit v1.1