Skip to content

Commit

Permalink
[symbolizer] Empty string is not an error (llvm#97781)
Browse files Browse the repository at this point in the history
This is recommit of llvm#92660, reverted in
llvm#94424.
Original commit message is below.

After commit
llvm@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
(llvm@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.
  • Loading branch information
spavloff authored and kbluck committed Jul 6, 2024
1 parent a2fe82e commit 4350d6a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 2 additions & 4 deletions llvm/test/tools/llvm-symbolizer/get-input-file.test
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# If binary input file is not specified, llvm-symbolizer assumes it is the first
# item in the command.

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

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

NOFILE: error: no input filename has been specified

NOADDR: error: 'foo': no module offset has been specified

NOTFOUND: error: 'foo': [[MSG]]
Expand Down
8 changes: 8 additions & 0 deletions llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,14 @@ static void symbolizeInput(const opt::InputArgList &Args,
object::BuildID BuildID(IncomingBuildID.begin(), IncomingBuildID.end());
uint64_t Offset = 0;
StringRef Symbol;

// An empty input string may be used to check if the process is alive and
// responding to input. Do not emit a message on stderr in this case but
// respond on stdout.
if (InputString.empty()) {
printUnknownLineInfo(ModuleName, Printer);
return;
}
if (Error E = parseCommand(Args.getLastArgValue(OPT_obj_EQ), IsAddr2Line,
StringRef(InputString), Cmd, ModuleName, BuildID,
Symbol, Offset)) {
Expand Down

0 comments on commit 4350d6a

Please sign in to comment.