[llvm] 27c4777 - [symbolizer] Treat invalid address as addr2line does

Serge Pavlov via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 29 08:29:37 PDT 2023


Author: Serge Pavlov
Date: 2023-03-29T22:28:48+07:00
New Revision: 27c4777f41d2ab204c1cf84ff1cccd5ba41354da

URL: https://github.com/llvm/llvm-project/commit/27c4777f41d2ab204c1cf84ff1cccd5ba41354da
DIFF: https://github.com/llvm/llvm-project/commit/27c4777f41d2ab204c1cf84ff1cccd5ba41354da.diff

LOG: [symbolizer] Treat invalid address as addr2line does

llvm-symbolizer echoed input if it was not recognized as a valid address.
This behavior was extended to llvm-addr2line as well. GNU addr2line in
this case optputs "??:0". This difference prevents implementation of
symbol+offset lookup available in the recent versions of GNU binutils.
In that case a string that is not an address may be a symbol.

This change make reaction of llvm-addr2line on unrecognized input closer
to GNU addr2line.

Added: 
    

Modified: 
    llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h
    llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
    llvm/test/tools/llvm-symbolizer/flush-output.s
    llvm/test/tools/llvm-symbolizer/input-base.test
    llvm/test/tools/llvm-symbolizer/invalid-input-address.test
    llvm/test/tools/llvm-symbolizer/options-from-env.test
    llvm/test/tools/llvm-symbolizer/output-style-empty-line.test
    llvm/test/tools/llvm-symbolizer/sym.test

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h b/llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h
index f799b0a4cde0a..04028203be342 100644
--- a/llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h
+++ b/llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h
@@ -121,6 +121,8 @@ class GNUPrinter : public PlainPrinterBase {
 public:
   GNUPrinter(raw_ostream &OS, raw_ostream &ES, PrinterConfig &Config)
       : PlainPrinterBase(OS, ES, Config) {}
+
+  void printInvalidCommand(const Request &Request, StringRef Command) override;
 };
 
 class JSONPrinter : public DIPrinter {

diff  --git a/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp b/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
index bfd6f7c02ca3b..2d3b144c9f6f1 100644
--- a/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
@@ -146,6 +146,11 @@ void GNUPrinter::printSimpleLocation(StringRef Filename,
       SourceCode(Filename, Info.Line, Config.SourceContextLines, Info.Source));
 }
 
+void GNUPrinter::printInvalidCommand(const Request &Request,
+                                     StringRef Command) {
+  OS << "??:0\n";
+}
+
 void PlainPrinterBase::printVerbose(StringRef Filename,
                                     const DILineInfo &Info) {
   OS << "  Filename: " << Filename << '\n';

diff  --git a/llvm/test/tools/llvm-symbolizer/flush-output.s b/llvm/test/tools/llvm-symbolizer/flush-output.s
index 840f430feaf81..070bf3fa3c86e 100644
--- a/llvm/test/tools/llvm-symbolizer/flush-output.s
+++ b/llvm/test/tools/llvm-symbolizer/flush-output.s
@@ -14,4 +14,4 @@ foo:
 # RUN:   | FileCheck %s
 
 # CHECK: flush-output.s:10
-# CHECK: bad
+# CHECK: ??:0

diff  --git a/llvm/test/tools/llvm-symbolizer/input-base.test b/llvm/test/tools/llvm-symbolizer/input-base.test
index 66244a7203c08..cb8061998c513 100644
--- a/llvm/test/tools/llvm-symbolizer/input-base.test
+++ b/llvm/test/tools/llvm-symbolizer/input-base.test
@@ -17,8 +17,8 @@ RUN: llvm-addr2line -e /dev/null -a 1234 | FileCheck %s
 RUN: llvm-addr2line -e /dev/null -a 01234 | FileCheck %s
 RUN: llvm-addr2line -e /dev/null -a 0b1010 | FileCheck %s --check-prefix=HEXADECIMAL-NOT-BINARY
 RUN: llvm-addr2line -e /dev/null -a 0B1010 | FileCheck %s --check-prefix=HEXADECIMAL-NOT-BINARY
-RUN: llvm-addr2line -e /dev/null -a 0o1234 | FileCheck %s --check-prefix=INVALID-NOT-OCTAL-LOWER
-RUN: llvm-addr2line -e /dev/null -a 0O1234 | FileCheck %s --check-prefix=INVALID-NOT-OCTAL-UPPER
+RUN: llvm-addr2line -e /dev/null -a 0o1234 | FileCheck %s --check-prefix=INVALID-NOT-OCTAL
+RUN: llvm-addr2line -e /dev/null -a 0O1234 | FileCheck %s --check-prefix=INVALID-NOT-OCTAL
 
 CHECK: 0x1234
 CHECK-NEXT: ??
@@ -26,8 +26,7 @@ CHECK-NEXT: ??
 HEXADECIMAL-NOT-BINARY: 0xb1010
 HEXADECIMAL-NOT-BINARY: ??
 
-INVALID-NOT-OCTAL-LOWER: 0o1234
-INVALID-NOT-OCTAL-LOWER-NOT: ??
-
 INVALID-NOT-OCTAL-UPPER: 0O1234
 INVALID-NOT-OCTAL-UPPER-NOT: ??
+
+INVALID-NOT-OCTAL: ??:0

diff  --git a/llvm/test/tools/llvm-symbolizer/invalid-input-address.test b/llvm/test/tools/llvm-symbolizer/invalid-input-address.test
index 559aeeec0cd2c..1479ba80c1e42 100644
--- a/llvm/test/tools/llvm-symbolizer/invalid-input-address.test
+++ b/llvm/test/tools/llvm-symbolizer/invalid-input-address.test
@@ -14,10 +14,13 @@ RUN: llvm-symbolizer --obj=%p/Inputs/addr.exe < %t.inp | FileCheck --check-prefi
 RUN: llvm-symbolizer --obj=%p/Inputs/addr.exe "some text" "some text2" | FileCheck --check-prefix=BAD-INPUT %s
 RUN: llvm-symbolizer --obj=%p/Inputs/addr.exe @%t.rsp | FileCheck --check-prefix=BAD-INPUT %s
 
-# Test bad input address values for the GNU-compatible version.
-RUN: llvm-addr2line --obj=%p/Inputs/addr.exe < %t.inp | FileCheck --check-prefix=BAD-INPUT %s
-RUN: llvm-addr2line --obj=%p/Inputs/addr.exe "some text" "some text2" | FileCheck --check-prefix=BAD-INPUT %s
-RUN: llvm-addr2line --obj=%p/Inputs/addr.exe @%t.rsp | FileCheck --check-prefix=BAD-INPUT %s
-
 BAD-INPUT:      some text
 BAD-INPUT-NEXT: some text2
+
+# Test bad input address values for the GNU-compatible version.
+RUN: llvm-addr2line --obj=%p/Inputs/addr.exe < %t.inp | FileCheck --check-prefix=GNU-BAD-INPUT %s
+RUN: llvm-addr2line --obj=%p/Inputs/addr.exe "some text" "some text2" | FileCheck --check-prefix=GNU-BAD-INPUT %s
+RUN: llvm-addr2line --obj=%p/Inputs/addr.exe @%t.rsp | FileCheck --check-prefix=GNU-BAD-INPUT %s
+
+GNU-BAD-INPUT:      ??:0
+GNU-BAD-INPUT-NEXT: ??:0

diff  --git a/llvm/test/tools/llvm-symbolizer/options-from-env.test b/llvm/test/tools/llvm-symbolizer/options-from-env.test
index 5fb566f56a025..c2204593da8d3 100644
--- a/llvm/test/tools/llvm-symbolizer/options-from-env.test
+++ b/llvm/test/tools/llvm-symbolizer/options-from-env.test
@@ -1,6 +1,20 @@
-# RUN: env LLVM_SYMBOLIZER_OPTS='0 1 --verbose' llvm-symbolizer 2 | FileCheck %s
-# RUN: env LLVM_ADDR2LINE_OPTS='0 1 --verbose' llvm-addr2line 2 | FileCheck %s
+# RUN: env LLVM_SYMBOLIZER_OPTS='0x400540 0x40054d --verbose' llvm-symbolizer -e %p/Inputs/addr.exe --no-inlines 0x40055e | FileCheck %s
+# RUN: env LLVM_ADDR2LINE_OPTS='400540 40054d --verbose' llvm-addr2line -e %p/Inputs/addr.exe 40055e | FileCheck %s
 
-# CHECK:      0
-# CHECK-NEXT: 1
-# CHECK-NEXT: 2
+# CHECK:       Filename: /tmp{{[\\/]}}x.c
+# CHECK-NEXT:  Function start filename: /tmp{{[\\/]}}x.c
+# CHECK-NEXT:  Function start line: 2
+# CHECK:       Line: 3
+# CHECK-NEXT:  Column: 3
+
+# CHECK:       Filename: /tmp{{[\\/]}}x.c
+# CHECK-NEXT:  Function start filename: /tmp{{[\\/]}}x.c
+# CHECK-NEXT:  Function start line: 2
+# CHECK:       Line: 3
+# CHECK-NEXT:  Column: 3
+
+# CHECK:       Filename: /tmp{{[\\/]}}x.c
+# CHECK-NEXT:  Function start filename: /tmp{{[\\/]}}x.c
+# CHECK-NEXT:  Function start line: 6
+# CHECK:       Line: 7
+# CHECK-NEXT:  Column: 3

diff  --git a/llvm/test/tools/llvm-symbolizer/output-style-empty-line.test b/llvm/test/tools/llvm-symbolizer/output-style-empty-line.test
index 213d86f3b8150..5709d07c2e5fd 100644
--- a/llvm/test/tools/llvm-symbolizer/output-style-empty-line.test
+++ b/llvm/test/tools/llvm-symbolizer/output-style-empty-line.test
@@ -25,4 +25,4 @@ LLVM-EMPTY:
 LLVM-NEXT: some text2
 
 GNU: x.c:14
-GNU-NEXT: some text2
+GNU-NEXT: ??:0

diff  --git a/llvm/test/tools/llvm-symbolizer/sym.test b/llvm/test/tools/llvm-symbolizer/sym.test
index 4bb3eb0aaf5be..d687b7af10b0b 100644
--- a/llvm/test/tools/llvm-symbolizer/sym.test
+++ b/llvm/test/tools/llvm-symbolizer/sym.test
@@ -66,7 +66,7 @@ RUN: llvm-addr2line -pafi --obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCh
 #ZERO: ??
 #ZERO: ??:0:0
 #
-#A2L:         some text
+#A2L:         ??:0
 #A2L_A-NEXT:  0x40054d
 #A2L_F-NEXT:  inctwo
 #A2L-NEXT:    {{[/\]+}}tmp{{[/\]+}}x.c:3{{$}}
@@ -74,9 +74,9 @@ RUN: llvm-addr2line -pafi --obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCh
 #A2L_I-NEXT:  {{[/\]+}}tmp{{[/\]+}}x.c:7{{$}}
 #A2L_FI-NEXT: main
 #A2L_I-NEXT:  {{[/\]+}}tmp{{[/\]+}}x.c:14{{$}}
-#A2L-NEXT:    some text2
+#A2L-NEXT:    ??:0
 
-#A2LP:          some text
+#A2LP:          ??:0
 #A2LP_A-NEXT:   0x40054d: {{[/\]+}}tmp{{[/\]+}}x.c:3{{$}}
 #A2LP_F-NEXT:   inctwo at {{[/\]+}}tmp{{[/\]+}}x.c:3{{$}}
 #A2LP_AF-NEXT:  0x40054d: inctwo at {{[/\]+}}tmp{{[/\]+}}x.c:3{{$}}
@@ -84,4 +84,4 @@ RUN: llvm-addr2line -pafi --obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCh
 #A2LP_I-NEXT:   {{[/\]+}}tmp{{[/\]+}}x.c:14{{$}}
 #A2LP_FI-NEXT:   (inlined by) inc at {{[/\]+}}tmp{{[/\]+}}x.c:7{{$}}
 #A2LP_FI-NEXT:   (inlined by) main at {{[/\]+}}tmp{{[/\]+}}x.c:14{{$}}
-#A2LP-NEXT:     some text2
+#A2LP-NEXT:     ??:0


        


More information about the llvm-commits mailing list