[llvm] [llvm-symbolizer] Improve error messages for filter symbolization failure (PR #114649)
Roland McGrath via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 2 01:41:58 PDT 2024
https://github.com/frobtech updated https://github.com/llvm/llvm-project/pull/114649
>From 01a57357ece71d77a8eb96c4d0343fd618dbd7ed Mon Sep 17 00:00:00 2001
From: Roland McGrath <mcgrathr at google.com>
Date: Sat, 2 Nov 2024 01:32:48 -0700
Subject: [PATCH] [llvm-symbolizer] Improve error messages for filter
symbolization failure
Consolidate some duplicated code in the symbolizer markup filter
into a subroutine for handling a failure from the symbolizer.
The common kind of such failure is a file not findable from the
build ID, for which including the module info for what was
missing is very much more helpful than the previous behavior.
Unlike other error cases, highlighting the input markup line that
couldn't be symbolized is less informative since it requires
manual correlation of the address with the module maps to
understand which module's debug file was inaccessible.
This also firms up an existing test case that shares some of the
same error-producing code path. Previously that test case would
not have caught changes to the error text that are probably not
appropriate for all cases.
---
.../llvm/DebugInfo/Symbolize/MarkupFilter.h | 3 +++
llvm/lib/DebugInfo/Symbolize/MarkupFilter.cpp | 27 ++++++++++++++-----
...lize-filter-markup-build-id-not-found.test | 10 +++++++
.../debuginfod-missing-build-id.test | 16 +++++------
4 files changed, 42 insertions(+), 14 deletions(-)
create mode 100644 llvm/test/DebugInfo/symbolize-filter-markup-build-id-not-found.test
diff --git a/llvm/include/llvm/DebugInfo/Symbolize/MarkupFilter.h b/llvm/include/llvm/DebugInfo/Symbolize/MarkupFilter.h
index 10613ec57586df..9f764e0409b313 100644
--- a/llvm/include/llvm/DebugInfo/Symbolize/MarkupFilter.h
+++ b/llvm/include/llvm/DebugInfo/Symbolize/MarkupFilter.h
@@ -109,6 +109,9 @@ class MarkupFilter {
void printRawElement(const MarkupNode &Element);
void printValue(Twine Value);
+ void symbolizeFailure(const MarkupNode &Node, const Module *Mod,
+ Error SymbolizeError);
+
std::optional<Module> parseModule(const MarkupNode &Element) const;
std::optional<MMap> parseMMap(const MarkupNode &Element) const;
diff --git a/llvm/lib/DebugInfo/Symbolize/MarkupFilter.cpp b/llvm/lib/DebugInfo/Symbolize/MarkupFilter.cpp
index 3528da42b12bca..607caae1f3b7a3 100644
--- a/llvm/lib/DebugInfo/Symbolize/MarkupFilter.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/MarkupFilter.cpp
@@ -266,8 +266,7 @@ bool MarkupFilter::tryPC(const MarkupNode &Node) {
Expected<DILineInfo> LI = Symbolizer.symbolizeCode(
MMap->Mod->BuildID, {MMap->getModuleRelativeAddr(*Addr)});
if (!LI) {
- WithColor::defaultErrorHandler(LI.takeError());
- printRawElement(Node);
+ symbolizeFailure(Node, MMap->Mod, LI.takeError());
return true;
}
if (!*LI) {
@@ -323,8 +322,7 @@ bool MarkupFilter::tryBackTrace(const MarkupNode &Node) {
Expected<DIInliningInfo> II =
Symbolizer.symbolizeInlinedCode(MMap->Mod->BuildID, {MRA});
if (!II) {
- WithColor::defaultErrorHandler(II.takeError());
- printRawElement(Node);
+ symbolizeFailure(Node, MMap->Mod, II.takeError());
return true;
}
@@ -386,8 +384,7 @@ bool MarkupFilter::tryData(const MarkupNode &Node) {
Expected<DIGlobal> Symbol = Symbolizer.symbolizeData(
MMap->Mod->BuildID, {MMap->getModuleRelativeAddr(*Addr)});
if (!Symbol) {
- WithColor::defaultErrorHandler(Symbol.takeError());
- printRawElement(Node);
+ symbolizeFailure(Node, MMap->Mod, Symbol.takeError());
return true;
}
@@ -698,6 +695,24 @@ void MarkupFilter::reportLocation(StringRef::iterator Loc) const {
errs() << '\n';
}
+void MarkupFilter::symbolizeFailure(const MarkupNode &Node, const Module *Mod,
+ Error SymbolizeError) {
+ if (Mod) {
+ auto add_module_info = [Mod](std::unique_ptr<StringError> SE) -> Error {
+ return createStringError(
+ SE->getMessage() +
+ formatv(" for ELF module #{0:x} \"{1}\"; BuildID=", Mod->ID,
+ Mod->Name)
+ .str() +
+ toHex(Mod->BuildID, /*LowerCase=*/true),
+ SE->convertToErrorCode());
+ };
+ SymbolizeError = handleErrors(std::move(SymbolizeError), add_module_info);
+ }
+ WithColor::defaultErrorHandler(std::move(SymbolizeError));
+ printRawElement(Node);
+}
+
// Checks for an existing mmap that overlaps the given one and returns a
// pointer to one of them.
const MarkupFilter::MMap *
diff --git a/llvm/test/DebugInfo/symbolize-filter-markup-build-id-not-found.test b/llvm/test/DebugInfo/symbolize-filter-markup-build-id-not-found.test
new file mode 100644
index 00000000000000..c4e8928e377b5a
--- /dev/null
+++ b/llvm/test/DebugInfo/symbolize-filter-markup-build-id-not-found.test
@@ -0,0 +1,10 @@
+RUN: split-file %s %t
+RUN: llvm-symbolizer --filter-markup < %t/log > /dev/null 2> %t.err
+RUN: FileCheck %s -input-file=%t.err --match-full-lines --strict-whitespace
+
+CHECK:error: could not find build ID for ELF module #0x0 "notfound"; BuildID=abad1d
+
+;--- log
+{{{module:0:notfound:elf:abad1d}}}
+{{{mmap:0x1000:0x1000:load:0:rx:0}}}
+{{{pc:0x1234}}}
diff --git a/llvm/test/tools/llvm-symbolizer/debuginfod-missing-build-id.test b/llvm/test/tools/llvm-symbolizer/debuginfod-missing-build-id.test
index 76772e3417e4f6..37b5d01a3e5de6 100644
--- a/llvm/test/tools/llvm-symbolizer/debuginfod-missing-build-id.test
+++ b/llvm/test/tools/llvm-symbolizer/debuginfod-missing-build-id.test
@@ -1,10 +1,10 @@
-RUN: llvm-symbolizer --build-id=abad 0x1234 0x5678 > %t.stdout 2> %t.stderr
-RUN: FileCheck %s --check-prefix=STDOUT < %t.stdout
-RUN: FileCheck %s --check-prefix=STDERR < %t.stderr
+RUN: llvm-symbolizer --build-id=abad 0x1234 0x5678 > %t.out 2> %t.err
+RUN: FileCheck %s --check-prefix=STDOUT -input-file=%t.out --match-full-lines --strict-whitespace
+RUN: FileCheck %s --check-prefix=STDERR -input-file=%t.err --match-full-lines --strict-whitespace
-STDOUT: ??
-STDOUT: ??:0:0
-STDOUT: ??
-STDOUT: ??:0:0
+STDOUT:??
+STDOUT:??:0:0
+STDOUT:??
+STDOUT:??:0:0
-STDERR-COUNT-2: llvm-symbolizer{{.*}}: error: 'ABAD': could not find build ID
+STDERR-COUNT-2:{{.*}}llvm-symbolizer: error: 'ABAD': could not find build ID
More information about the llvm-commits
mailing list