Skip to content

Commit 22a7f7c

Browse files
spavloffjh7370
andauthored
[symbolizer] Empty string is not an error (#92660)
After commit 1792852 ([symbolizer] Change reaction on invalid input) llvm-symbolizer issues an error on malformed command instead of echoing it to the standard output, as in previous versions. It turns out this behavior broke a use case when echoing was used to check if llvm-symbolizer is working (1792852#commitcomment-142161925). With this change an empty line as input is not considered as an error anymore and does not produce any output on stderr. llvm-symbolizer still respond on empty line with line not found, this is consistent with GNU addr2line. --------- Co-authored-by: James Henderson <46713263+jh7370@users.noreply.github.com>
1 parent 6b30180 commit 22a7f7c

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

llvm/test/tools/llvm-symbolizer/get-input-file.test

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# If binary input file is not specified, llvm-symbolizer assumes it is the first
22
# item in the command.
33

4-
# No input items at all, complain about missing input file.
4+
# No input items at all. Report an unknown line, but do not produce any output on stderr.
55
RUN: echo | llvm-symbolizer 2>%t.1.err | FileCheck %s --check-prefix=NOSOURCE
6-
RUN: FileCheck --input-file=%t.1.err --check-prefix=NOFILE %s
6+
RUN: FileCheck --input-file=%t.1.err --implicit-check-not={{.}} --allow-empty %s
77

88
# Only one input item, complain about missing addresses.
99
RUN: llvm-symbolizer "foo" 2>%t.2.err | FileCheck %s --check-prefix=NOSOURCE
@@ -32,8 +32,6 @@ RUN: FileCheck --input-file=%t.7.err --check-prefix=BAD-QUOTE %s
3232
NOSOURCE: ??
3333
NOSOURCE-NEXT: ??:0:0
3434

35-
NOFILE: error: no input filename has been specified
36-
3735
NOADDR: error: 'foo': no module offset has been specified
3836

3937
NOTFOUND: error: 'foo': [[MSG]]

llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,14 @@ static void symbolizeInput(const opt::InputArgList &Args,
337337
object::BuildID BuildID(IncomingBuildID.begin(), IncomingBuildID.end());
338338
uint64_t Offset = 0;
339339
StringRef Symbol;
340+
341+
// An empty input string may be used to check if the process is alive and
342+
// responding to input. Do not emit a message on stderr in this case but
343+
// respond on stdout.
344+
if (InputString.empty()) {
345+
printUnknownLineInfo(ModuleName, Printer);
346+
return;
347+
}
340348
if (Error E = parseCommand(Args.getLastArgValue(OPT_obj_EQ), IsAddr2Line,
341349
StringRef(InputString), Cmd, ModuleName, BuildID,
342350
Symbol, Offset)) {

0 commit comments

Comments
 (0)