[llvm] [symbolizer] Empty string is not an error (PR #92660)

Serge Pavlov via llvm-commits llvm-commits at lists.llvm.org
Mon May 20 02:01:07 PDT 2024


https://github.com/spavloff updated https://github.com/llvm/llvm-project/pull/92660

>From c180cd93f9d4b2d756060b0ebda89ee09e69e5f1 Mon Sep 17 00:00:00 2001
From: Serge Pavlov <sepavloff at gmail.com>
Date: Sat, 18 May 2024 22:35:26 +0700
Subject: [PATCH 1/3] [symbolizer] Empty string is not an error

After commit 1792852f86dc7 ([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
(https://github.com/llvm/llvm-project/commit/1792852f86dc75efa1f44d46b1a0daf386d64afa#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.
---
 llvm/test/tools/llvm-symbolizer/get-input-file.test | 6 ++----
 llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp      | 7 +++++++
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/llvm/test/tools/llvm-symbolizer/get-input-file.test b/llvm/test/tools/llvm-symbolizer/get-input-file.test
index 8c21816591c81..fcf31ac8ff306 100644
--- a/llvm/test/tools/llvm-symbolizer/get-input-file.test
+++ b/llvm/test/tools/llvm-symbolizer/get-input-file.test
@@ -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 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
@@ -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]]
diff --git a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
index b98bdbc388faf..4fe1f4505a1b9 100644
--- a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
+++ b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
@@ -337,6 +337,13 @@ static void symbolizeInput(const opt::InputArgList &Args,
   object::BuildID BuildID(IncomingBuildID.begin(), IncomingBuildID.end());
   uint64_t Offset = 0;
   StringRef Symbol;
+
+  // Empty input string may be used to check if the process is alive. 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)) {

>From 93b34782ba9bbc406a3b8dd11c496642d4b9edad Mon Sep 17 00:00:00 2001
From: Serge Pavlov <sepavloff at gmail.com>
Date: Mon, 20 May 2024 16:00:36 +0700
Subject: [PATCH 2/3] Commit suggestion to llvm-symbolizer.cpp

Co-authored-by: James Henderson <46713263+jh7370 at users.noreply.github.com>
---
 llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
index 4fe1f4505a1b9..beb70f2d7ae9b 100644
--- a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
+++ b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
@@ -338,7 +338,7 @@ static void symbolizeInput(const opt::InputArgList &Args,
   uint64_t Offset = 0;
   StringRef Symbol;
 
-  // Empty input string may be used to check if the process is alive. Do not
+  // 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);

>From 010d4dca6143c740616fc66a830978575f07abaf Mon Sep 17 00:00:00 2001
From: Serge Pavlov <sepavloff at gmail.com>
Date: Mon, 20 May 2024 16:00:59 +0700
Subject: [PATCH 3/3] Commit suggestion to
 llvm/test/tools/llvm-symbolizer/get-input-file.test

Co-authored-by: James Henderson <46713263+jh7370 at users.noreply.github.com>
---
 llvm/test/tools/llvm-symbolizer/get-input-file.test | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/test/tools/llvm-symbolizer/get-input-file.test b/llvm/test/tools/llvm-symbolizer/get-input-file.test
index fcf31ac8ff306..50eb051968718 100644
--- a/llvm/test/tools/llvm-symbolizer/get-input-file.test
+++ b/llvm/test/tools/llvm-symbolizer/get-input-file.test
@@ -1,7 +1,7 @@
 # If binary input file is not specified, llvm-symbolizer assumes it is the first
 # item in the command.
 
-# No input items at all. Report unknown line, but do not produce any output on stderr.
+# 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 --implicit-check-not={{.}} --allow-empty %s
 



More information about the llvm-commits mailing list