aboutsummaryrefslogtreecommitdiff
path: root/tools/llvm-strings
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-01-02 19:17:04 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-01-02 19:17:04 +0000
commitb915e9e0fc85ba6f398b3fab0db6a81a8913af94 (patch)
tree98b8f811c7aff2547cab8642daf372d6c59502fb /tools/llvm-strings
parent6421cca32f69ac849537a3cff78c352195e99f1b (diff)
downloadsrc-b915e9e0fc85ba6f398b3fab0db6a81a8913af94.tar.gz
src-b915e9e0fc85ba6f398b3fab0db6a81a8913af94.zip
Vendor import of llvm trunk r290819:vendor/llvm/llvm-trunk-r290819
Notes
Notes: svn path=/vendor/llvm/dist/; revision=311116 svn path=/vendor/llvm/llvm-trunk-r290819/; revision=311117; tag=vendor/llvm/llvm-trunk-r290819
Diffstat (limited to 'tools/llvm-strings')
-rw-r--r--tools/llvm-strings/CMakeLists.txt10
-rw-r--r--tools/llvm-strings/LLVMBuild.txt22
-rw-r--r--tools/llvm-strings/llvm-strings.cpp90
3 files changed, 122 insertions, 0 deletions
diff --git a/tools/llvm-strings/CMakeLists.txt b/tools/llvm-strings/CMakeLists.txt
new file mode 100644
index 000000000000..9339892a4997
--- /dev/null
+++ b/tools/llvm-strings/CMakeLists.txt
@@ -0,0 +1,10 @@
+set(LLVM_LINK_COMPONENTS
+ Core
+ Object
+ Support
+ )
+
+add_llvm_tool(llvm-strings
+ llvm-strings.cpp
+ )
+
diff --git a/tools/llvm-strings/LLVMBuild.txt b/tools/llvm-strings/LLVMBuild.txt
new file mode 100644
index 000000000000..9cd41d0eebf5
--- /dev/null
+++ b/tools/llvm-strings/LLVMBuild.txt
@@ -0,0 +1,22 @@
+;===- ./tools/llvm-strings/LLVMBuild.txt -----------------------*- Conf -*--===;
+;
+; The LLVM Compiler Infrastructure
+;
+; This file is distributed under the University of Illinois Open Source
+; License. See LICENSE.TXT for details.
+;
+;===------------------------------------------------------------------------===;
+;
+; This is an LLVMBuild description file for the components in this subdirectory.
+;
+; For more information on the LLVMBuild system, please see:
+;
+; http://llvm.org/docs/LLVMBuild.html
+;
+;===------------------------------------------------------------------------===;
+
+[component_0]
+type = Tool
+name = llvm-strings
+parent = Tools
+required_libraries = Archive Object
diff --git a/tools/llvm-strings/llvm-strings.cpp b/tools/llvm-strings/llvm-strings.cpp
new file mode 100644
index 000000000000..e750995331e3
--- /dev/null
+++ b/tools/llvm-strings/llvm-strings.cpp
@@ -0,0 +1,90 @@
+//===-- llvm-strings.cpp - Printable String dumping utility ---------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This program is a utility that works like binutils "strings", that is, it
+// prints out printable strings in a binary, objdump, or archive file.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Object/Binary.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/Support/Program.h"
+#include "llvm/Support/Signals.h"
+#include <cctype>
+#include <string>
+
+using namespace llvm;
+using namespace llvm::object;
+
+static cl::list<std::string> InputFileNames(cl::Positional,
+ cl::desc("<input object files>"),
+ cl::ZeroOrMore);
+
+static cl::opt<bool>
+ PrintFileName("print-file-name",
+ cl::desc("Print the name of the file before each string"));
+static cl::alias PrintFileNameShort("f", cl::desc(""),
+ cl::aliasopt(PrintFileName));
+
+static cl::opt<int>
+ MinLength("bytes", cl::desc("Print sequences of the specified length"),
+ cl::init(4));
+static cl::alias MinLengthShort("n", cl::desc(""), cl::aliasopt(MinLength));
+
+static void strings(raw_ostream &OS, StringRef FileName, StringRef Contents) {
+ auto print = [&OS, FileName](StringRef L) {
+ if (L.size() < static_cast<size_t>(MinLength))
+ return;
+ if (PrintFileName)
+ OS << FileName << ": ";
+ OS << L << '\n';
+ };
+
+ const char *P = nullptr, *E = nullptr, *S = nullptr;
+ for (P = Contents.begin(), E = Contents.end(); P < E; ++P) {
+ if (std::isgraph(*P) || std::isblank(*P)) {
+ if (S == nullptr)
+ S = P;
+ } else if (S) {
+ print(StringRef(S, P - S));
+ S = nullptr;
+ }
+ }
+ if (S)
+ print(StringRef(S, E - S));
+}
+
+int main(int argc, char **argv) {
+ sys::PrintStackTraceOnErrorSignal(argv[0]);
+ PrettyStackTraceProgram X(argc, argv);
+
+ cl::ParseCommandLineOptions(argc, argv, "llvm string dumper\n");
+ if (MinLength == 0) {
+ errs() << "invalid minimum string length 0\n";
+ return EXIT_FAILURE;
+ }
+
+ if (InputFileNames.empty())
+ InputFileNames.push_back("-");
+
+ for (const auto &File : InputFileNames) {
+ ErrorOr<std::unique_ptr<MemoryBuffer>> Buffer =
+ MemoryBuffer::getFileOrSTDIN(File);
+ if (std::error_code EC = Buffer.getError())
+ errs() << File << ": " << EC.message() << '\n';
+ else
+ strings(llvm::outs(), File == "-" ? "{standard input}" : File,
+ Buffer.get()->getMemBufferRef().getBuffer());
+ }
+
+ return EXIT_SUCCESS;
+}