public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Aaron Merey <amerey@redhat.com>
To: Mark Wielaard <mark@klomp.org>
Cc: elfutils-devel@sourceware.org
Subject: Re: [PATCH] Handle DW_AT_decl_file 0
Date: Mon, 12 Feb 2024 20:44:20 -0500	[thread overview]
Message-ID: <CAJDtP-T-fXHDLY_73qhSXLy1qwYKytHQ6ATA3ag5r0b7BmJgPw@mail.gmail.com> (raw)
In-Reply-To: <20240212211356.GI21691@gnu.wildebeest.org>

Hi Mark,

On Mon, Feb 12, 2024 at 4:14 PM Mark Wielaard <mark@klomp.org> wrote:
>
> On Mon, Feb 12, 2024 at 01:16:30PM -0500, Aaron Merey wrote:
> > On Mon, Feb 12, 2024 at 12:31 PM Mark Wielaard <mark@klomp.org> wrote:
> > > >        (void) INTUSE(dwarf_getsrclines) (&CUDIE (cu), &lines, &nlines);
> > > > -      assert (cu->lines != NULL);
> > > >      }
> > >
> > > I see why would like to get rid of asserts in the code base.
> > > But I believe the assert is valid. dwarf_getsrclines will check whether
> > > cu->lines is NULL, in which case it tries to load the line table. It
> > > then sets cu->lines to the newly parsed line table, or to -1 to
> > > indicate there was an error parsing (or no) line table.
> > > >
> > > > -  if (cu->lines == (void *) -1l)
> > > > +  if (cu->lines == NULL || cu->lines == (void *) -1l)
> > > >      {
> > > > -      /* If the file index is not zero, there must be file information
> > > > -      available.  */
> > > > -      __libdw_seterrno (DWARF_E_INVALID_DWARF);
> > > > +      /* Line table could not be found.  */
> > > >        return NULL;
> > > >      }
> > >
> > > Which means this is a change in behavior. Now if there was no line
> > > table, or a problem parsing it, then no error is set, but NULL is
> > > returned anyway. Which means using dwarf_errno or dwarf_errmsg after
> > > dwarf_decl_file returns NULL doesn't work reliably anymore. Are you
> > > sure libdw errno shouldn't be set to DWARF_E_INVALID_DWARF?
> >
> > My thinking was to rely on dwarf_getsrclines setting the libdw errno
> > if an error occurred.  If we always use DWARF_E_INVALID_DWARF then we
> > might overwrite an error code that describes the failure more specifically.
>
> Ah, yes. That makes sense. But because of caching dwarf_getsrclines
> only sets an error on first try.
>
> > If we want to ensure that the libdw errno is set whenever we reach this
> > condition, we could check if dwarf_getsrclines set the errno. If it did,
> > then just leave that errno set. If it didn't, then set errno to
> > DWARF_E_INVALID_DWARF.
>
> Good idea. Or we could (also) cache the error in the cu
> (files_libdwerr?), that is what e.g. dwfl_module_getdwarf does
> (see mod->dwerr). But I think either solution is more like a
> redesign/factoring. And you might consider doing it separate from this
> bug fix.
>
> If you have time, you could then also look into this
> (performance/caching) issue:
> https://sourceware.org/bugzilla/show_bug.cgi?id=27405
> "libdw_get_srcfiles should not imply srclines"

Ok I'll look at PR27405.  I've removed the error handling changes from
this patch.  I also recompiled the testfile without -O0. It didn't end up
improving the size of the testfile but the -O0 was unnecessary either way.

Pushed as commit add63e0317b6e.

Aaron


      reply	other threads:[~2024-02-13  1:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-10  2:52 Aaron Merey
2024-02-12 17:31 ` Mark Wielaard
2024-02-12 18:16   ` Aaron Merey
2024-02-12 21:13     ` Mark Wielaard
2024-02-13  1:44       ` 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-T-fXHDLY_73qhSXLy1qwYKytHQ6ATA3ag5r0b7BmJgPw@mail.gmail.com \
    --to=amerey@redhat.com \
    --cc=elfutils-devel@sourceware.org \
    --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).