[PATCH] D64290: [tools] [llvm-nm] Default to reading from stdin not a.out
Alex Brachet via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 6 13:17:38 PDT 2019
abrachet created this revision.
abrachet added reviewers: jhenderson, rupprecht.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
abrachet added reviewers: MaskRay, chrisjackson.
This moves away from defaulting to a.out and uses stdin only if stdin has a file redirected to it. This has been discussed on the llvm-dev mailing list here <https://lists.llvm.org/pipermail/llvm-dev/2019-July/133642.html>.
https://reviews.llvm.org/D64290
Files:
llvm/test/tools/llvm-nm/warn-invalid-stdin.test
llvm/tools/llvm-nm/llvm-nm.cpp
Index: llvm/tools/llvm-nm/llvm-nm.cpp
===================================================================
--- llvm/tools/llvm-nm/llvm-nm.cpp
+++ llvm/tools/llvm-nm/llvm-nm.cpp
@@ -34,6 +34,7 @@
#include "llvm/Support/Format.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Process.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/TargetSelect.h"
@@ -1751,6 +1752,12 @@
}
static void dumpSymbolNamesFromFile(std::string &Filename) {
+ if (sys::Process::StandardInIsUserInput()) {
+ WithColor::warning(outs(), ToolName) << "can't read from keyboard input.\n";
+ cl::PrintHelpMessage();
+ HadError = true;
+ return;
+ }
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
MemoryBuffer::getFileOrSTDIN(Filename);
if (error(BufferOrErr.getError(), Filename))
@@ -2082,7 +2089,7 @@
if (OutputFormat == sysv || SizeSort)
PrintSize = true;
if (InputFilenames.empty())
- InputFilenames.push_back("a.out");
+ InputFilenames.push_back("-");
if (InputFilenames.size() > 1)
MultipleFiles = true;
Index: llvm/test/tools/llvm-nm/warn-invalid-stdin.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-nm/warn-invalid-stdin.test
@@ -0,0 +1,7 @@
+## Tests that when no input file is specified stdin is
+## read but only when not reading from keyoard input.
+
+# RUN: not llvm-nm 2>&1 | FileCheck %s
+
+# CHECK: llvm-nm: warning: can't read from keyboard input.
+# CHECK-NEXT: OVERVIEW: llvm symbol table dumper
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64290.208279.patch
Type: text/x-patch
Size: 1615 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190706/890dc0dd/attachment.bin>
More information about the llvm-commits
mailing list