public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Aaron Merey <amerey@redhat.com>
To: Mark Wielaard <mark@klomp.org>
Cc: Frank Eigler <fche@redhat.com>, elfutils-devel@sourceware.org
Subject: Re: [PATCH] readelf: Support .gdb_index version 9
Date: Thu, 2 Nov 2023 12:30:50 -0400	[thread overview]
Message-ID: <CAJDtP-SkFK84iL=FC-jAEVJBXpTin7kGyqU8+K3UG6yrFEOwZw@mail.gmail.com> (raw)
In-Reply-To: <9a13a2cee1bff48ae7121515ccef4bcd5b047601.camel@klomp.org>

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


      parent reply	other threads:[~2023-11-02 16:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-31 20:33 Aaron Merey
2023-11-02 12:53 ` Mark Wielaard
2023-11-02 14:20   ` Frank Ch. Eigler
2023-11-02 16:30   ` Aaron Merey [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAJDtP-SkFK84iL=FC-jAEVJBXpTin7kGyqU8+K3UG6yrFEOwZw@mail.gmail.com' \
    --to=amerey@redhat.com \
    --cc=elfutils-devel@sourceware.org \
    --cc=fche@redhat.com \
    --cc=mark@klomp.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).