From: Igor Kudrin Date: Fri, 19 Apr 2019 10:12:56 +0000 (+0000) Subject: [llvm-symbolizer] Make the output with -output-style=GNU closer to addr2line's X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4bc29cbf6b393f8e4219043ba0fb901d734e0bcd;p=platform%2Fupstream%2Fllvm.git [llvm-symbolizer] Make the output with -output-style=GNU closer to addr2line's This patch addresses two differences in the output of llvm-symbolizer and GNU's addr2line: * llvm-symbolizer prints an empty line after the report for an address. * With "-f -i=0", llvm-symbolizer replaces the name of an inlined function with the name from the symbol table, i. e., the top caller function in the inlining chain. addr2line preserves the name of the inlined function. Differential Revision: https://reviews.llvm.org/D60770 llvm-svn: 358747 --- diff --git a/llvm/test/tools/llvm-symbolizer/output-style.test b/llvm/test/tools/llvm-symbolizer/output-style-column.test similarity index 100% rename from llvm/test/tools/llvm-symbolizer/output-style.test rename to llvm/test/tools/llvm-symbolizer/output-style-column.test diff --git a/llvm/test/tools/llvm-symbolizer/output-style-empty-line.test b/llvm/test/tools/llvm-symbolizer/output-style-empty-line.test new file mode 100644 index 0000000..8b14b4c --- /dev/null +++ b/llvm/test/tools/llvm-symbolizer/output-style-empty-line.test @@ -0,0 +1,19 @@ +This test checks that with --output-style=GNU the tool does not print an empty +line after the report for an address. The current behavior is preserved for +--output-style=LLVM or if the option is omitted. + +RUN: llvm-symbolizer -e %p/Inputs/addr.exe < %p/Inputs/addr.inp \ +RUN: | FileCheck %s --check-prefix=LLVM + +RUN: llvm-symbolizer --output-style=LLVM -e %p/Inputs/addr.exe < %p/Inputs/addr.inp \ +RUN: | FileCheck %s --check-prefix=LLVM + +RUN: llvm-symbolizer --output-style=GNU -e %p/Inputs/addr.exe < %p/Inputs/addr.inp \ +RUN: | FileCheck %s --check-prefix=GNU + +LLVM: x.c:14:0 +LLVM-EMPTY: +LLVM-NEXT: some text2 + +GNU: x.c:14 +GNU-NEXT: some text2 diff --git a/llvm/test/tools/llvm-symbolizer/output-style-inlined.test b/llvm/test/tools/llvm-symbolizer/output-style-inlined.test new file mode 100644 index 0000000..e970753 --- /dev/null +++ b/llvm/test/tools/llvm-symbolizer/output-style-inlined.test @@ -0,0 +1,17 @@ +This test checks that when inlined frames are not shown (-i=0) and the output +style is set to GNU (--output-style=GNU) the name of an inlined function is not +replaced with the name of the top caller function. At the same time, the current +behavior of llvm-symbolizer is preserved with --output-style=LLVM or when +the option is not specified. + +RUN: llvm-symbolizer -i=0 -e %p/Inputs/addr.exe 0x40054d \ +RUN: | FileCheck %s --check-prefix=LLVM --implicit-check-not=inctwo + +RUN: llvm-symbolizer --output-style=LLVM -i=0 -e %p/Inputs/addr.exe 0x40054d \ +RUN: | FileCheck %s --check-prefix=LLVM --implicit-check-not=inctwo + +RUN: llvm-symbolizer --output-style=GNU -i=0 -e %p/Inputs/addr.exe 0x40054d \ +RUN: | FileCheck %s --check-prefix=GNU --implicit-check-not=main + +LLVM: main +GNU: inctwo diff --git a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp index 359c64b..c57f5f8 100644 --- a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp +++ b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp @@ -227,13 +227,25 @@ static void symbolizeInput(StringRef InputString, LLVMSymbolizer &Symbolizer, ModuleName, {Offset, object::SectionedAddress::UndefSection}, ClDwpName); Printer << (error(ResOrErr) ? DIInliningInfo() : ResOrErr.get()); + } else if (ClOutputStyle == DIPrinter::OutputStyle::GNU) { + // With ClPrintFunctions == FunctionNameKind::LinkageName (default) + // and ClUseSymbolTable == true (also default), Symbolizer.symbolizeCode() + // may override the name of an inlined function with the name of the topmost + // caller function in the inlining chain. This contradicts the existing + // behavior of addr2line. Symbolizer.symbolizeInlinedCode() overrides only + // the topmost function, which suits our needs better. + auto ResOrErr = Symbolizer.symbolizeInlinedCode( + ModuleName, {Offset, object::SectionedAddress::UndefSection}, + ClDwpName); + Printer << (error(ResOrErr) ? DILineInfo() : ResOrErr.get().getFrame(0)); } else { auto ResOrErr = Symbolizer.symbolizeCode( ModuleName, {Offset, object::SectionedAddress::UndefSection}, ClDwpName); Printer << (error(ResOrErr) ? DILineInfo() : ResOrErr.get()); } - outs() << "\n"; + if (ClOutputStyle == DIPrinter::OutputStyle::LLVM) + outs() << "\n"; outs().flush(); }