[PATCH] D72313: [llvm-symbolizer]Fix printing of malformed address values not passed via stdin
Xuanda Yang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 8 02:56:58 PST 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdfeb8730e24c: [llvm-symbolizer]Fix printing of malformed address values not passed via stdin (authored by TH3CHARLie).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D72313/new/
https://reviews.llvm.org/D72313
Files:
llvm/test/tools/llvm-symbolizer/invalid-input-address.test
llvm/test/tools/llvm-symbolizer/sym.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
@@ -24,6 +24,7 @@
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
+#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
@@ -228,7 +229,7 @@
std::string ModuleName;
uint64_t Offset = 0;
if (!parseCommand(StringRef(InputString), Cmd, ModuleName, Offset)) {
- outs() << InputString;
+ outs() << InputString << "\n";
return;
}
@@ -328,7 +329,13 @@
char InputString[kMaxInputStringLength];
while (fgets(InputString, sizeof(InputString), stdin)) {
- symbolizeInput(InputString, Symbolizer, Printer);
+ // Strip newline characters.
+ std::string StrippedInputString(InputString);
+ StrippedInputString.erase(
+ std::remove_if(StrippedInputString.begin(), StrippedInputString.end(),
+ [](char c) { return c == '\r' || c == '\n'; }),
+ StrippedInputString.end());
+ symbolizeInput(StrippedInputString, Symbolizer, Printer);
outs().flush();
}
} else {
Index: llvm/test/tools/llvm-symbolizer/sym.test
===================================================================
--- llvm/test/tools/llvm-symbolizer/sym.test
+++ llvm/test/tools/llvm-symbolizer/sym.test
@@ -42,11 +42,16 @@
RUN: llvm-addr2line -pfi -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck -check-prefixes=A2LP,A2LP_F,A2LP_FI %s
RUN: llvm-addr2line -pafi -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck -check-prefixes=A2LP,A2LP_AF,A2LP_FI %s
-#CHECK: some text
-#CHECK: 0x40054d
-#CHECK: main
-#CHECK: {{[/\]+}}tmp{{[/\]+}}x.c:14:0
-#CHECK: some text2
+# CHECK: some text
+# CHECK-NEXT: 0x40054d
+# CHECK-NEXT: inctwo
+# CHECK-NEXT: {{[/\]+}}tmp{{[/\]+}}x.c:3:3
+# CHECK-NEXT: inc
+# CHECK-NEXT: {{[/\]+}}tmp{{[/\]+}}x.c:7:0
+# CHECK-NEXT: main
+# CHECK-NEXT: {{[/\]+}}tmp{{[/\]+}}x.c:14:0
+# CHECK-EMPTY:
+# CHECK-NEXT: some text2
#
#PRETTY: some text
#PRETTY: {{[0x]+}}40054d: inctwo at {{[/\]+}}tmp{{[/\]+}}x.c:3:3
Index: llvm/test/tools/llvm-symbolizer/invalid-input-address.test
===================================================================
--- llvm/test/tools/llvm-symbolizer/invalid-input-address.test
+++ llvm/test/tools/llvm-symbolizer/invalid-input-address.test
@@ -1,7 +1,23 @@
# Use address that can't fit in a 64-bit number. Show that llvm-symbolizer
# simply echoes it as per other malformed input addresses.
-RUN: llvm-symbolizer --obj=addr.exe 0x10000000000000000 | FileCheck %s
+RUN: llvm-symbolizer --obj=addr.exe 0x10000000000000000 | FileCheck --check-prefix=LARGE-ADDR %s
-CHECK-NOT: {{.}}
-CHECK: 0x10000000000000000
-CHECK-NOT: {{.}}
+LARGE-ADDR-NOT: {{.}}
+LARGE-ADDR: 0x10000000000000000
+LARGE-ADDR-NOT: {{.}}
+
+RUN: echo '"some text"' '"some text2"' > %t.rsp
+RUN: echo -e 'some text\nsome text2\n' > %t.inp
+
+# Test bad input address values, via stdin, command line and response file.
+RUN: llvm-symbolizer --obj=%p/Inputs/addr.exe < %t.inp | FileCheck --check-prefix=BAD-INPUT %s
+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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72313.236785.patch
Type: text/x-patch
Size: 3865 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200108/a2705661/attachment.bin>
More information about the llvm-commits
mailing list