[PATCH] Handle DW_AT_decl_file 0
Mark Wielaard
mark@klomp.org
Mon Feb 12 21:13:56 GMT 2024
Hi Aaron,
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"
Cheers,
Mark
More information about the Elfutils-devel
mailing list