diff options
author | Simon Marchi <simon.marchi@polymtl.ca> | 2022-04-26 22:50:22 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2022-07-29 20:54:49 -0400 |
commit | 0aa306fed318f679c1db21974b64e29d236d51e5 (patch) | |
tree | ade6684b512c4e5dfa3f00b9a79ce0642c2a12e9 /gdb/dwarf2/macro.c | |
parent | ddc01737d34f16074b2c9a92c5a808be5c91340f (diff) | |
download | binutils-0aa306fed318f679c1db21974b64e29d236d51e5.zip binutils-0aa306fed318f679c1db21974b64e29d236d51e5.tar.gz binutils-0aa306fed318f679c1db21974b64e29d236d51e5.tar.bz2 |
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
Diffstat (limited to 'gdb/dwarf2/macro.c')
-rw-r--r-- | gdb/dwarf2/macro.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/gdb/dwarf2/macro.c b/gdb/dwarf2/macro.c index 99c3653..38c0fdf 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 = lh->file_file_name (file); + const file_entry *fe = lh->file_name_at (file); + std::string file_name; + + if (fe != nullptr) + file_name = 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 = string_printf ("<bad macro file number %d>", file); + } if (! current_file) { |