diff options
author | Mark Wielaard <mark@klomp.org> | 2018-01-19 23:59:21 +0100 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2018-01-25 16:30:47 +0100 |
commit | 240a068fcf3eb6bbcda525f80c8778de62621d9e (patch) | |
tree | e6ed4947e17dc97c77e99ddc1d649231c92c49e8 /libdw/dwarf_setalt.c | |
parent | 4407903a7433327dbeda74519d036fc82ef64de3 (diff) | |
download | elfutils-240a068fcf3eb6bbcda525f80c8778de62621d9e.tar.gz |
libdw: Resolve alt file on first use.
Add a new alt_fd field to the Dwarf struct. This tracks whether we tried
to open the alt file ourselves. This is used in dwarf_getalt to see if
we should try to find and open the alt file ourselves (if the user hasn't
called dwarf_setalt yet). dwarf_formref_die and dwarf_formstring now call
dwarf_getalt instead of accessing the alt_dwarf Dwarf field directly.
For applications using libdwfl nothing changes (dwfl will find, set and
clean up the alt file). For programs that set the alt file themselves
already through other means, nothing changes. But for applications that
don't create the Dwarf through libdwfl and don't set the alt file already
libdw will now try to find and set it on first access. If found the
application will now not get errors for missing alt files.
Add a simple testcase based on the existing allfcts test which already
tries to set the alt file, but is too simplistic to find it in some
subdir (relative to the main debug file).
Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'libdw/dwarf_setalt.c')
-rw-r--r-- | libdw/dwarf_setalt.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/libdw/dwarf_setalt.c b/libdw/dwarf_setalt.c index 9bd566ff..9051b8e0 100644 --- a/libdw/dwarf_setalt.c +++ b/libdw/dwarf_setalt.c @@ -1,5 +1,5 @@ /* Provides the data referenced by the .gnu_debugaltlink section. - Copyright (C) 2014 Red Hat, Inc. + Copyright (C) 2014, 2018 Red Hat, Inc. This file is part of elfutils. This file is free software; you can redistribute it and/or modify @@ -32,9 +32,18 @@ #include "libdwP.h" +#include <unistd.h> + void dwarf_setalt (Dwarf *main, Dwarf *alt) { + if (main->alt_fd != -1) + { + INTUSE(dwarf_end) (main->alt_dwarf); + close (main->alt_fd); + main->alt_fd = -1; + } + main->alt_dwarf = alt; } INTDEF (dwarf_setalt) |