[PATCH] D95609: [llvm-symbolizer] - Fix the crash in GNU output style with --no-inlines and missing input file.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 28 05:47:09 PST 2021
grimar created this revision.
grimar added reviewers: jhenderson, MaskRay.
Herald added a subscriber: rupprecht.
grimar requested review of this revision.
Herald added a project: LLVM.
Fixes https://bugs.llvm.org/show_bug.cgi?id=48882.
When an input file is missing, the following cpde will crash on the second run
auto ResOrErr = Symbolizer.symbolizeInlinedCode(
ModuleName, {Offset, object::SectionedAddress::UndefSection});
Printer << (error(ResOrErr) ? DILineInfo() : ResOrErr.get().getFrame(0));
It happens, because `symbolizeInlinedCode` returns an error on the first call,
but on the second call it returns no error (but an empty result), and this is expected:
// A null module means an error has already been reported. Return an empty
// result.
if (!Info)
return DIInliningInfo();
https://reviews.llvm.org/D95609
Files:
llvm/test/tools/llvm-symbolizer/output-style-inlined.test
llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
Index: llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
===================================================================
--- llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
+++ llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
@@ -181,7 +181,12 @@
// the topmost function, which suits our needs better.
auto ResOrErr = Symbolizer.symbolizeInlinedCode(
ModuleName, {Offset, object::SectionedAddress::UndefSection});
- Printer << (error(ResOrErr) ? DILineInfo() : ResOrErr.get().getFrame(0));
+ if (!ResOrErr || ResOrErr->getNumberOfFrames() == 0) {
+ error(ResOrErr);
+ Printer << DILineInfo();
+ } else {
+ Printer << ResOrErr->getFrame(0);
+ }
} else {
auto ResOrErr = Symbolizer.symbolizeCode(
ModuleName, {Offset, object::SectionedAddress::UndefSection});
Index: llvm/test/tools/llvm-symbolizer/output-style-inlined.test
===================================================================
--- llvm/test/tools/llvm-symbolizer/output-style-inlined.test
+++ llvm/test/tools/llvm-symbolizer/output-style-inlined.test
@@ -28,3 +28,23 @@
LLVM: main
GNU: inctwo
+
+## Check the output in the case when a file doesn't exist.
+
+RUN: llvm-symbolizer --output-style=GNU --obj=%p/Inputs/not.exist 0x1 0x2 --no-inlines 2>&1 \
+RUN: | FileCheck %s --check-prefix=NOT-EXIST-GNU
+RUN: llvm-symbolizer --output-style=LLVM --obj=%p/Inputs/not.exist 0x1 0x2 --no-inlines 2>&1 \
+RUN: | FileCheck %s --check-prefix=NOT-EXIST-LLVM
+
+# NOT-EXIST-GNU: LLVMSymbolizer: error reading file: {{N|n}}o such file or directory
+# NOT-EXIST-GNU-NEXT: ??
+# NOT-EXIST-GNU-NEXT: ??:0
+# NOT-EXIST-GNU-NEXT: ??
+# NOT-EXIST-GNU-NEXT: ??:0
+
+# NOT-EXIST-LLVM: LLVMSymbolizer: error reading file: {{N|n}}o such file or directory
+# NOT-EXIST-LLVM-NEXT: ??
+# NOT-EXIST-LLVM-NEXT: ??:0:0
+# NOT-EXIST-LLVM-EMPTY:
+# NOT-EXIST-LLVM-NEXT: ??
+# NOT-EXIST-LLVM-NEXT: ??:0:0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95609.319843.patch
Type: text/x-patch
Size: 1923 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210128/ca91860b/attachment.bin>
More information about the llvm-commits
mailing list