<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/llvm-strings.dir/llvm-strings.cpp.o</div><div>/ssd/llvm/tools/llvm-strings/llvm-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">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><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;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-<wbr>project?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-<wbr>project/llvm/trunk/tools/llvm-<wbr>strings/CMakeLists.txt?rev=<wbr>286556&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-<wbr>project/llvm/trunk/tools/llvm-<wbr>strings/LLVMBuild.txt?rev=<wbr>286556&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/<wbr>LLVMBuild.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/<wbr>LLVMBuild.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-<wbr>project/llvm/trunk/tools/llvm-<wbr>strings/llvm-strings.cpp?rev=<wbr>286556&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/<wbr>PrettyStackTrace.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>
+<br>
+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<<wbr>Binary>> Child =<br>
+ Element.getAsBinary(&Context)) {<br>
+ dump(dyn_cast<ObjectFile>(&**<wbr>Child));<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::<wbr>move(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<<wbr>MemoryBuffer>> Buffer =<br>
+ MemoryBuffer::getFileOrSTDIN(<wbr>File);<br>
+ if (std::error_code EC = Buffer.getError()) {<br>
+ errs() << File << ": " << EC.message() << '\n';<br>
+ return;<br>
+ }<br>
+<br>
+ if (Expected<std::unique_ptr<<wbr>Binary>> B =<br>
+ createBinary(Buffer.get()-><wbr>getMemBufferRef(), &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::<wbr>PrintStackTraceOnErrorSignal(<wbr>argv[0]);<br>
+ PrettyStackTraceProgram X(argc, argv);<br>
+<br>
+ cl::ParseCommandLineOptions(<wbr>argc, 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.<wbr>begin(), 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">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><br></div>