Correct bounds check when working around GAS DWARF 5 directory table bug
Recent Go toolchains are causing GDB to crash on a relatively recent
workaround for a GAS bug:
commit
a833790a626d9620319d0ca6aee23daa584d445c
Date: Wed Nov 1 00:33:12 2023 +0100
[gdb/symtab] Work around gas PR28629
In the original GAS bug, the first directory table entry did not contain
the current directory of the compilation. So the above commit added a
workaround fix to prepend the second directory table entry.
However recent Go toolchain compilations (specifically on aarch64)
only output a single directory table entry. Looking at the workaround:
if (lh->version == 5 && lh->is_valid_file_index (1))
{
std::string dir = lh->include_dir_at (1);
fnd.set_comp_dir (std::move (dir));
}
`lh->is_valid_file_index (1)' is true, but since the directory table only
has one entry, `include_dir_at (1)' returns nullptr. Consequently the
std::string ctor will segfault. Since there are no guarantees that the file
and directory tables are the same size, a better bounds check is to simply
rely on `include_dir_at' to ensure a valid directory table entry.
I have updated the workaround commit's test, gdb.dwarf2/dw2-gas-workaround.exp
and tested on x86_64 and aarch64 RHEL 9 and Fedora 41.
Approved-By: Andrew Burgess <aburgess@redhat.com>