[PATCH] readelf: Support .gdb_index version 9
Aaron Merey
amerey@redhat.com
Thu Nov 2 16:30:50 GMT 2023
On Thu, Nov 2, 2023 at 10:20 AM Frank Ch. Eigler <fche@redhat.com> wrote:
>
> > BTW the description of the gdb_index at the top
> > https://sourceware.org/gdb/current/onlinedocs/gdb/Index-Section-Format.html
> > doesn't resolve anymore. It is now
> > https://sourceware.org/gdb/current/onlinedocs/gdb.html/Index-Section-Format.html
>
> Added another httpd redirect to make the first link work too.
Thanks Frank.
On Thu, Nov 2, 2023 at 8:54 AM Mark Wielaard <mark@klomp.org> wrote:
>
> > + printf (_("\nShortcut table at offset %#" PRIx32 " contains %zu slots:\n"),
> > + shortcut_off, shortcut_nr);
>
> That is a fancy way to print "contains 2 slots" :)
My intention was to require fewer changes to the code if the shortcut
table was extended in a future version. But yes at the moment this is
slightly excessive!
>
> > + uint32_t lang = read_4ubyte_unaligned (dbg, readp);
> > + readp += 4;
> > +
> > + printf (_("Language of main: %s\n"), dwarf_lang_name (lang));
>
> Note that dwarf_lang_name calls string_or_unknown with false for
> print_unknown_num so it might make sense to either flip that to true
> (but there is probably a reason it doesn't print the hex num) or to
> always add the hex num after the name so the user doesn't just get ???
> on an unknown DWARF_LANG constant.
Binutils readelf includes the language hex number for unknown languages
and we should too. I will add the hex number to the output when the
language is unknown.
>
> > + printf (_("Name of main: "));
> > +
> > + if (lang != 0)
> > + {
> > + uint32_t name = read_4ubyte_unaligned (dbg, readp);
> > + readp += 4;
> > + const unsigned char *sym = const_start + name;
> > +
> > + if (unlikely ((size_t) (dataend - const_start) < name
> > + || memchr (sym, '\0', dataend - sym) == NULL))
> > + goto invalid_data;
>
> Good end of string check.
> BTW. DW_LANG constants are going away with DWARF6:
> https://dwarfstd.org/languages-v6.html
Interesting. If gdb continues to support .gdb_index then we may end up
extending the shortcut table to include the new DW_AT_language_version.
> > +Shortcut table at offset 0x207c contains 2 slots:
> > +Language of main: ???
> > +Name of main: <unknown>
> > +EOF
>
> This seems an unfortunate example. Why is the language unknown?
> But maybe it is a nice example to show why you should at least print
> the hex num of the language?
Currently gdb only populates the shortcut table when it can find
DW_AT_main_subprogram or DW_AT_calling_convention with value
DW_CC_program. gcc doesn't emit this for C/C++ programs so their
shortcut tables all have language and name set to 0.
See https://sourceware.org/bugzilla/show_bug.cgi?id=30996
I will change this testcase to include the hex number of the language.
Aaron
More information about the Elfutils-devel
mailing list