<div dir="ltr">On Thu, Nov 10, 2016 at 8:02 PM, Rui Ueyama <span dir="ltr"><<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5">On Thu, Nov 10, 2016 at 7:59 PM, Rui Ueyama <span dir="ltr"><<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>I got this warning message. I was trying to add (void) there, but probably we should handle errors instead of ignore them. Could you fix it?</div><div><br></div><div>[1/2] Building CXX object tools/llvm-strings/CMakeFiles/<wbr>llvm-strings.dir/llvm-strings.<wbr>cpp.o</div><div>/ssd/llvm/tools/llvm-strings/l<wbr>lvm-strings.cpp:77:5: warning: expression result unused [-Wunused-value]</div><div>    static_cast<bool>(E);</div><div>    ^~~~~~~~~~~~~~~~~~~~</div></div><div class="gmail_extra"><br><div class="gmail_quote"><span class="m_-8216162247072393285gmail-">On Thu, Nov 10, 2016 at 7:44 PM, Saleem Abdulrasool via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br></span><div><div class="m_-8216162247072393285gmail-h5"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Author: compnerd<br>
Date: Thu Nov 10 21:44:12 2016<br>
New Revision: 286556<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=286556&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject?rev=286556&view=rev</a><br>
Log:<br>
llvm-strings: introduce basic strings tool<br>
<br>
This is a replacement to binutils' string tool.  It prints strings found in a<br>
binary (object file, executable, or archive library).  It is rather bare and<br>
not functionally equivalent, however, it lays the groundwork necessary for the<br>
strings tool, enabling iterative development of features to reach feature<br>
parity.<br>
<br>
Added:<br>
    llvm/trunk/tools/llvm-strings/<br>
    llvm/trunk/tools/llvm-strings/<wbr>CMakeLists.txt<br>
    llvm/trunk/tools/llvm-strings/<wbr>LLVMBuild.txt<br>
    llvm/trunk/tools/llvm-strings/<wbr>llvm-strings.cpp<br>
<br>
Added: llvm/trunk/tools/llvm-strings/<wbr>CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-strings/CMakeLists.txt?rev=286556&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/tools/llvm-st<wbr>rings/CMakeLists.txt?rev=28655<wbr>6&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/tools/llvm-strings/<wbr>CMakeLists.txt (added)<br>
+++ llvm/trunk/tools/llvm-strings/<wbr>CMakeLists.txt Thu Nov 10 21:44:12 2016<br>
@@ -0,0 +1,8 @@<br>
+set(LLVM_LINK_COMPONENTS<br>
+  Object<br>
+  )<br>
+<br>
+add_llvm_tool(llvm-strings<br>
+  llvm-strings.cpp<br>
+  )<br>
+<br>
<br>
Added: llvm/trunk/tools/llvm-strings/<wbr>LLVMBuild.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-strings/LLVMBuild.txt?rev=286556&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/tools/llvm-st<wbr>rings/LLVMBuild.txt?rev=286556<wbr>&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/tools/llvm-strings/<wbr>LLVMBuild.txt (added)<br>
+++ llvm/trunk/tools/llvm-strings/<wbr>LLVMBuild.txt Thu Nov 10 21:44:12 2016<br>
@@ -0,0 +1,22 @@<br>
+;===- ./tools/llvm-strings/LLVMBuild<wbr>.txt -----------------------*- Conf -*--===;<br>
+;<br>
+;                     The LLVM Compiler Infrastructure<br>
+;<br>
+; This file is distributed under the University of Illinois Open Source<br>
+; License. See LICENSE.TXT for details.<br>
+;<br>
+;===-------------------------<wbr>------------------------------<wbr>-----------------===;<br>
+;<br>
+; This is an LLVMBuild description file for the components in this subdirectory.<br>
+;<br>
+; For more information on the LLVMBuild system, please see:<br>
+;<br>
+;   <a href="http://llvm.org/docs/LLVMBuild.html" rel="noreferrer" target="_blank">http://llvm.org/docs/LLVMBuil<wbr>d.html</a><br>
+;<br>
+;===-------------------------<wbr>------------------------------<wbr>-----------------===;<br>
+<br>
+[component_0]<br>
+type = Tool<br>
+name = llvm-strings<br>
+parent = Tools<br>
+required_libraries = Archive Object<br>
<br>
Added: llvm/trunk/tools/llvm-strings/<wbr>llvm-strings.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-strings/llvm-strings.cpp?rev=286556&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/llvm/trunk/tools/llvm-st<wbr>rings/llvm-strings.cpp?rev=286<wbr>556&view=auto</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/tools/llvm-strings/<wbr>llvm-strings.cpp (added)<br>
+++ llvm/trunk/tools/llvm-strings/<wbr>llvm-strings.cpp Thu Nov 10 21:44:12 2016<br>
@@ -0,0 +1,120 @@<br>
+//===-- llvm-strings.cpp - Printable String dumping utility ---------------===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===------------------------<wbr>------------------------------<wbr>----------------===//<br>
+//<br>
+// This program is a utility that works like binutils "strings", that is, it<br>
+// prints out printable strings in a binary, objdump, or archive file.<br>
+//<br>
+//===------------------------<wbr>------------------------------<wbr>----------------===//<br>
+<br>
+#include "llvm/IR/LLVMContext.h"<br>
+#include "llvm/Object/Archive.h"<br>
+#include "llvm/Object/Binary.h"<br>
+#include "llvm/Object/ObjectFile.h"<br>
+#include "llvm/Support/CommandLine.h"<br>
+#include "llvm/Support/Error.h"<br>
+#include "llvm/Support/MemoryBuffer.h"<br>
+#include "llvm/Support/PrettyStackTrace<wbr>.h"<br>
+#include "llvm/Support/Program.h"<br>
+#include "llvm/Support/Signals.h"<br>
+#include <string><br>
+<br>
+using namespace llvm;<br>
+using namespace llvm::object;<br>
+<br>
+static cl::list<std::string> InputFileNames(cl::Positional,<br>
+                                            cl::desc("<input object files>"),<br>
+                                            cl::ZeroOrMore);<br>
+<br>
+static void dump(raw_ostream &OS, StringRef Contents) {<br>
+  const char *S = nullptr;<br>
+  for (const char *P = Contents.begin(), *E = Contents.end(); P < E; ++P) {<br>
+    if (std::isgraph(*P) || std::isblank(*P)) {<br>
+      if (S == nullptr)<br>
+        S = P;<br>
+    } else if (S) {<br>
+      if (P - S > 3)<br>
+        OS << StringRef(S, P - S) << '\n';<br>
+      S = nullptr;<br>
+    }<br>
+  }<br>
+}<br>
</blockquote></div></div></div></div></blockquote><div><br></div></div></div><div>There's a bug here.</div><div><br></div><div>  $ echo -n abcdefg > foo</div><div>  $ bin/llvm-strings foo</div><div>  $ [nothing printed out]</div></div></div></div></blockquote><div><br></div><div>Nice find!  Ill fix this and add a test.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail_extra"><div class="gmail_quote"><div><div class="m_-8216162247072393285gmail-h5"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+namespace {<br>
+class Strings {<br>
+  LLVMContext Context;<br>
+  raw_ostream &OS;<br>
+<br>
+  void dump(const ObjectFile *O) {<br>
+    for (const auto &S : O->sections()) {<br>
+      StringRef Contents;<br>
+      if (!S.getContents(Contents))<br>
+        ::dump(OS, Contents);<br>
+    }<br>
+  }<br>
+<br>
+  void dump(const Archive *A) {<br>
+    Error E;<br>
+    for (auto &Element : A->children(E)) {<br>
+      if (Expected<std::unique_ptr<Bina<wbr>ry>> Child =<br>
+              Element.getAsBinary(&Context)) {<br>
+        dump(dyn_cast<ObjectFile>(&**C<wbr>hild));<br>
+      } else {<br>
+        if (auto E = isNotObjectErrorInvalidFileTyp<wbr>e(Child.takeError())) {<br>
+          errs() << A->getFileName();<br>
+          if (Expected<StringRef> Name = Element.getName())<br>
+            errs() << '(' << *Name << ')';<br>
+          logAllUnhandledErrors(std::mov<wbr>e(E), errs(), "");<br>
+          errs() << '\n';<br>
+        }<br>
+      }<br>
+    }<br>
+    static_cast<bool>(E);<br>
+  }<br>
+<br>
+public:<br>
+  Strings(raw_ostream &S) : OS(S) {}<br>
+<br>
+  void scan(StringRef File) {<br>
+    ErrorOr<std::unique_ptr<Memory<wbr>Buffer>> Buffer =<br>
+        MemoryBuffer::getFileOrSTDIN(F<wbr>ile);<br>
+    if (std::error_code EC = Buffer.getError()) {<br>
+      errs() << File << ": " << EC.message() << '\n';<br>
+      return;<br>
+    }<br>
+<br>
+    if (Expected<std::unique_ptr<Bina<wbr>ry>> B =<br>
+            createBinary(Buffer.get()->get<wbr>MemBufferRef(), &Context)) {<br>
+      if (auto *A = dyn_cast<Archive>(&**B))<br>
+        return dump(A);<br>
+      if (auto *O = dyn_cast<ObjectFile>(&**B))<br>
+        return dump(O);<br>
+      ::dump(OS, Buffer.get()->getMemBufferRef(<wbr>).getBuffer());<br>
+    } else {<br>
+      consumeError(B.takeError());<br>
+      ::dump(OS, Buffer.get()->getMemBufferRef(<wbr>).getBuffer());<br>
+    }<br>
+  }<br>
+};<br>
+}<br>
+<br>
+int main(int argc, char **argv) {<br>
+  sys::PrintStackTraceOnErrorSig<wbr>nal(argv[0]);<br>
+  PrettyStackTraceProgram X(argc, argv);<br>
+<br>
+  cl::ParseCommandLineOptions(ar<wbr>gc, argv, "llvm string dumper\n");<br>
+<br>
+  if (InputFileNames.empty())<br>
+    InputFileNames.push_back("-");<br>
+<br>
+  Strings S(llvm::outs());<br>
+  std::for_each(InputFileNames.b<wbr>egin(), InputFileNames.end(),<br>
+                [&S](StringRef F) { S.scan(F); });<br>
+  return EXIT_SUCCESS;<br>
+}<br>
+<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div></div><br></div>
</blockquote></div></div></div><br></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Saleem Abdulrasool<br>compnerd (at) compnerd (dot) org</div>
</div></div>