Skip to content

Commit 6f0e356

Browse files
GHFjeremy-rifkin
andauthored
Make dwarf_init_path_a error non-fatal (#251)
I ran into an exception in the case of a "corrupted" ELF section (just unreadable by libdwarf, not corrupted). It turned out to be percolated from `dwarf_init_path_a` returning an error. libdwarf failing to parse an object should not inhibit falling back to parsing the ELF symtab, so I make this particular path less fatal. I repeated `ok = false;` for consistency and readability but I do realize all of the appearances in the function of this line seem redundant. --------- Co-authored-by: Jeremy Rifkin <51220084+jeremy-rifkin@users.noreply.github.com>
1 parent a88f87f commit 6f0e356

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/symbols/dwarf/dwarf_resolver.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "utils/lru_cache.hpp"
1414
#include "platform/path.hpp"
1515
#include "platform/program_name.hpp" // For CPPTRACE_MAX_PATH
16+
#include "logging.hpp"
1617

1718
#if IS_APPLE
1819
#include "binary/mach-o.hpp"
@@ -147,22 +148,28 @@ namespace libdwarf {
147148
buffer = std::unique_ptr<char[]>(new char[CPPTRACE_MAX_PATH]);
148149
}
149150
dwarf_set_de_alloc_flag(0);
150-
auto ret = wrap(
151-
dwarf_init_path_a,
151+
Dwarf_Error error = nullptr;
152+
auto ret = dwarf_init_path_a(
152153
object_path.c_str(),
153154
buffer.get(),
154155
CPPTRACE_MAX_PATH,
155156
DW_GROUPNUMBER_ANY,
156157
universal_number,
157158
nullptr,
158159
nullptr,
159-
&dbg.get()
160+
&dbg.get(),
161+
&error
160162
);
161163
if(ret == DW_DLV_OK) {
162164
ok = true;
163165
} else if(ret == DW_DLV_NO_ENTRY) {
164166
// fail, no debug info
165167
ok = false;
168+
} else if(ret == DW_DLV_ERROR) {
169+
// fail, parsing error
170+
ok = false;
171+
auto msg = raii_wrap(dwarf_errmsg(error), [this, error] (char*) { dwarf_dealloc_error(dbg.get(), error); });
172+
log::error("dwarf error: dwarf_init_path_a failed with {}", msg.get());
166173
} else {
167174
ok = false;
168175
PANIC("Unknown return code from dwarf_init_path");

0 commit comments

Comments
 (0)