<div dir="ltr">No worries. I'll fix it as well.</div><br><div class="gmail_quote"><div dir="ltr">On Fri, Mar 18, 2016 at 4:03 PM Chandler Carruth <<a href="mailto:chandlerc@google.com">chandlerc@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Terribly sorry, I picked the wrong commit. It is the *pass* that appears to have the wrong clang format.</div><br><div class="gmail_quote"><div dir="ltr">On Fri, Mar 18, 2016 at 11:54 PM Mike Aizatsky <<a href="mailto:aizatsky@chromium.org" target="_blank">aizatsky@chromium.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Here's how I run it:<div><br></div><div><div>$ ~/out/llvm/default/bin/clang-format -style=file -i -sort-includes tools/sancov/sancov.cc</div></div><div><br></div><div><div>$ cat .clang-format</div><div>BasedOnStyle: LLVM</div></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Mar 18, 2016 at 3:52 PM Chandler Carruth <<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I think your clang-format might not be using the LLVM style.</div><br><div class="gmail_quote"><div dir="ltr">On Fri, Mar 18, 2016 at 11:47 PM Mike Aizatsky <<a href="mailto:aizatsky@chromium.org" target="_blank">aizatsky@chromium.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Here it is:<div><br></div><div><a href="http://reviews.llvm.org/rL263846" target="_blank">http://reviews.llvm.org/rL263846</a><br></div><div><br></div><div>If you see something that is not following LLVM conventions - let me know. I'll try to fix our clang-tidy / clang-format configurations.</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Mar 18, 2016 at 3:42 PM Mike Aizatsky <<a href="mailto:aizatsky@chromium.org" target="_blank">aizatsky@chromium.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">It is actually formatted with clang-format. There are couple of lines wrong (not sure how they crept in), but for 99% it is correctly formatted now. Clang-tidy also finds one issue (include sort order).<div><br></div><div>I'll submit these nits right now..</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Mar 18, 2016 at 3:34 PM Kostya Serebryany <<a href="mailto:kcc@google.com" target="_blank">kcc@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Yep, Mike, please do that. </div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 18, 2016 at 3:30 PM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hey Mike and Kostya,<div><br></div><div>This entire pass, and all the code that has been added on top of it, is not *at all* following LLVM's coding conventions. It doesn't look like it has been formatted with clang-format, and the formatting it does have isn't the LLVM convention at all.</div><div><br></div><div>As a start, please run clang-format over this following the LLVM conventions. Also, you might try some of the LLVM clang-tidy checks to pull in more of the coding conventions.<div><div><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Nov 11, 2015 at 10:00 PM Mike Aizatsky via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: aizatsky<br>
Date: Wed Nov 11 14:58:20 2015<br>
New Revision: 252801<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=252801&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=252801&view=rev</a><br>
Log:<br>
sancov tool in c++<br>
<br>
First batch of sancov.py rewrite in c++.<br>
Supports "-print" and "-coveredfns" commands.<br>
<br>
Followup to <a href="http://reviews.llvm.org/D14356" rel="noreferrer" target="_blank">http://reviews.llvm.org/D14356</a> in a better location.<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D14579" rel="noreferrer" target="_blank">http://reviews.llvm.org/D14579</a><br>
<br>
Added:<br>
    llvm/trunk/tools/sancov/<br>
    llvm/trunk/tools/sancov/CMakeLists.txt<br>
    llvm/trunk/tools/sancov/Makefile<br>
    llvm/trunk/tools/sancov/sancov.cc<br>
<br>
Added: llvm/trunk/tools/sancov/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/sancov/CMakeLists.txt?rev=252801&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/sancov/CMakeLists.txt?rev=252801&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/tools/sancov/CMakeLists.txt (added)<br>
+++ llvm/trunk/tools/sancov/CMakeLists.txt Wed Nov 11 14:58:20 2015<br>
@@ -0,0 +1,11 @@<br>
+set(LLVM_LINK_COMPONENTS<br>
+  DebugInfoDWARF<br>
+  DebugInfoPDB<br>
+  Object<br>
+  Support<br>
+  Symbolize<br>
+  )<br>
+<br>
+add_llvm_tool(sancov<br>
+  sancov.cc<br>
+  )<br>
<br>
Added: llvm/trunk/tools/sancov/Makefile<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/sancov/Makefile?rev=252801&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/sancov/Makefile?rev=252801&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/tools/sancov/Makefile (added)<br>
+++ llvm/trunk/tools/sancov/Makefile Wed Nov 11 14:58:20 2015<br>
@@ -0,0 +1,17 @@<br>
+##===- tools/sancov/Makefile ----------------------*- Makefile -*-===##<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>
+##===----------------------------------------------------------------------===##<br>
+<br>
+LEVEL := ../..<br>
+TOOLNAME := sancov<br>
+LINK_COMPONENTS := DebugInfoDWARF DebugInfoPDB Object Support Symbolize<br>
+<br>
+# This tool has no plugins, optimize startup time.<br>
+TOOL_NO_EXPORTS := 1<br>
+<br>
+include $(LEVEL)/Makefile.common<br>
<br>
Added: llvm/trunk/tools/sancov/sancov.cc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/sancov/sancov.cc?rev=252801&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/sancov/sancov.cc?rev=252801&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/tools/sancov/sancov.cc (added)<br>
+++ llvm/trunk/tools/sancov/sancov.cc Wed Nov 11 14:58:20 2015<br>
@@ -0,0 +1,264 @@<br>
+//===-- sancov.cc --------------------------------------------===//<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>
+//===----------------------------------------------------------------------===//<br>
+//<br>
+// This file is a command-line tool for reading and analyzing sanitizer<br>
+// coverage.<br>
+//===----------------------------------------------------------------------===//<br>
+#include "llvm/ADT/STLExtras.h"<br>
+#include "llvm/DebugInfo/Symbolize/Symbolize.h"<br>
+#include "llvm/Support/CommandLine.h"<br>
+#include "llvm/Support/Errc.h"<br>
+#include "llvm/Support/ErrorOr.h"<br>
+#include "llvm/Support/FileSystem.h"<br>
+#include "llvm/Support/LineIterator.h"<br>
+#include "llvm/Support/ManagedStatic.h"<br>
+#include "llvm/Support/MemoryBuffer.h"<br>
+#include "llvm/Support/Path.h"<br>
+#include "llvm/Support/PrettyStackTrace.h"<br>
+#include "llvm/Support/Signals.h"<br>
+#include "llvm/Support/ToolOutputFile.h"<br>
+#include "llvm/Support/raw_ostream.h"<br>
+<br>
+#include <set><br>
+#include <stdio.h><br>
+#include <vector><br>
+<br>
+using namespace llvm;<br>
+<br>
+namespace {<br>
+<br>
+// --------- COMMAND LINE FLAGS ---------<br>
+<br>
+enum ActionType { PrintAction, CoveredFunctionsAction };<br>
+<br>
+cl::opt<ActionType> Action(<br>
+    cl::desc("Action (required)"), cl::Required,<br>
+    cl::values(clEnumValN(PrintAction, "print", "Print coverage addresses"),<br>
+               clEnumValN(CoveredFunctionsAction, "covered_functions",<br>
+                          "Print all covered funcions."),<br>
+               clEnumValEnd));<br>
+<br>
+static cl::list<std::string> ClInputFiles(cl::Positional, cl::OneOrMore,<br>
+                                          cl::desc("<filenames...>"));<br>
+<br>
+static cl::opt<std::string><br>
+    ClBinaryName("obj", cl::Required,<br>
+                 cl::desc("Path to object file to be symbolized"));<br>
+<br>
+static cl::opt<bool><br>
+    ClDemangle("demangle", cl::init(true),<br>
+        cl::desc("Print demangled function name."));<br>
+<br>
+// --------- FORMAT SPECIFICATION ---------<br>
+<br>
+struct FileHeader {<br>
+  uint32_t Bitness;<br>
+  uint32_t Magic;<br>
+};<br>
+<br>
+static const uint32_t BinCoverageMagic = 0xC0BFFFFF;<br>
+static const uint32_t Bitness32 = 0xFFFFFF32;<br>
+static const uint32_t Bitness64 = 0xFFFFFF64;<br>
+<br>
+// ---------<br>
+<br>
+template <typename T> static void FailIfError(const ErrorOr<T> &E) {<br>
+  if (E)<br>
+    return;<br>
+<br>
+  auto Error = E.getError();<br>
+  errs() << "Error: " << Error.message() << "(" << Error.value() << ")\n";<br>
+  exit(-2);<br>
+}<br>
+<br>
+template <typename T><br>
+static void readInts(const char *Start, const char *End,<br>
+                     std::vector<uint64_t> *V) {<br>
+  const T *S = reinterpret_cast<const T *>(Start);<br>
+  const T *E = reinterpret_cast<const T *>(End);<br>
+  V->reserve(E - S);<br>
+  std::copy(S, E, std::back_inserter(*V));<br>
+}<br>
+<br>
+static std::string CommonPrefix(std::string A, std::string B) {<br>
+  if (A.size() > B.size())<br>
+    return std::string(B.begin(),<br>
+                       std::mismatch(B.begin(), B.end(), A.begin()).first);<br>
+  else<br>
+    return std::string(A.begin(),<br>
+                       std::mismatch(A.begin(), A.end(), B.begin()).first);<br>
+}<br>
+<br>
+class CoverageData {<br>
+ public:<br>
+  // Read single file coverage data.<br>
+  static ErrorOr<std::unique_ptr<CoverageData>> read(std::string FileName) {<br>
+    ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrErr =<br>
+        MemoryBuffer::getFile(FileName);<br>
+    if (!BufOrErr)<br>
+      return BufOrErr.getError();<br>
+    std::unique_ptr<MemoryBuffer> Buf = std::move(BufOrErr.get());<br>
+    if (Buf->getBufferSize() < 8) {<br>
+      errs() << "File too small (<8): " << Buf->getBufferSize();<br>
+      return make_error_code(errc::illegal_byte_sequence);<br>
+    }<br>
+    const FileHeader *Header =<br>
+        reinterpret_cast<const FileHeader *>(Buf->getBufferStart());<br>
+<br>
+    if (Header->Magic != BinCoverageMagic) {<br>
+      errs() << "Wrong magic: " << Header->Magic;<br>
+      return make_error_code(errc::illegal_byte_sequence);<br>
+    }<br>
+<br>
+    auto Addrs = make_unique<std::vector<uint64_t>>();<br>
+<br>
+    switch (Header->Bitness) {<br>
+    case Bitness64:<br>
+      readInts<uint64_t>(Buf->getBufferStart() + 8, Buf->getBufferEnd(),<br>
+                         Addrs.get());<br>
+      break;<br>
+    case Bitness32:<br>
+      readInts<uint32_t>(Buf->getBufferStart() + 8, Buf->getBufferEnd(),<br>
+                         Addrs.get());<br>
+      break;<br>
+    default:<br>
+      errs() << "Unsupported bitness: " << Header->Bitness;<br>
+      return make_error_code(errc::illegal_byte_sequence);<br>
+    }<br>
+<br>
+    return std::unique_ptr<CoverageData>(new CoverageData(std::move(Addrs)));<br>
+  }<br>
+<br>
+  // Merge multiple coverage data together.<br>
+  static std::unique_ptr<CoverageData><br>
+  merge(const std::vector<std::unique_ptr<CoverageData>> &Covs) {<br>
+    std::set<uint64_t> Addrs;<br>
+<br>
+    for (const auto &Cov : Covs)<br>
+      Addrs.insert(Cov->Addrs->begin(), Cov->Addrs->end());<br>
+<br>
+    auto AddrsVector = make_unique<std::vector<uint64_t>>(<br>
+        Addrs.begin(), Addrs.end());<br>
+    return std::unique_ptr<CoverageData>(<br>
+        new CoverageData(std::move(AddrsVector)));<br>
+  }<br>
+<br>
+  // Read list of files and merges their coverage info.<br>
+  static ErrorOr<std::unique_ptr<CoverageData>><br>
+  readAndMerge(const std::vector<std::string> &FileNames) {<br>
+    std::vector<std::unique_ptr<CoverageData>> Covs;<br>
+    for (const auto &FileName : FileNames) {<br>
+      auto Cov = read(FileName);<br>
+      if (!Cov)<br>
+        return Cov.getError();<br>
+      Covs.push_back(std::move(Cov.get()));<br>
+    }<br>
+    return merge(Covs);<br>
+  }<br>
+<br>
+  // Print coverage addresses.<br>
+  void printAddrs(raw_ostream &out) {<br>
+    for (auto Addr : *Addrs) {<br>
+      out << "0x";<br>
+      out.write_hex(Addr);<br>
+      out << "\n";<br>
+    }<br>
+  }<br>
+<br>
+  // Print list of covered functions.<br>
+  // Line format: <file_name>:<line> <function_name><br>
+  void printCoveredFunctions(raw_ostream &out) {<br>
+    if (Addrs->empty())<br>
+      return;<br>
+    symbolize::LLVMSymbolizer::Options SymbolizerOptions;<br>
+    SymbolizerOptions.Demangle = ClDemangle;<br>
+    symbolize::LLVMSymbolizer Symbolizer;<br>
+<br>
+    struct FileLoc {<br>
+      std::string FileName;<br>
+      uint32_t Line;<br>
+      bool operator<(const FileLoc &Rhs) const {<br>
+        return std::tie(FileName, Line) < std::tie(Rhs.FileName, Rhs.Line);<br>
+      }<br>
+    };<br>
+<br>
+    // FileLoc -> FunctionName<br>
+    std::map<FileLoc, std::string> Fns;<br>
+<br>
+    // Fill in Fns map.<br>
+    for (auto Addr : *Addrs) {<br>
+      auto InliningInfo = Symbolizer.symbolizeInlinedCode(ClBinaryName, Addr);<br>
+      FailIfError(InliningInfo);<br>
+      for (uint32_t i = 0; i < InliningInfo->getNumberOfFrames(); ++i) {<br>
+        auto FrameInfo = InliningInfo->getFrame(i);<br>
+        SmallString<256> FileName(FrameInfo.FileName);<br>
+        sys::path::remove_dots(FileName, /* remove_dot_dot */ true);<br>
+        FileLoc Loc = { FileName.str(), FrameInfo.Line };<br>
+        Fns[Loc] = FrameInfo.FunctionName;<br>
+      }<br>
+    }<br>
+<br>
+    // Compute file names common prefix.<br>
+    std::string FilePrefix = Fns.begin()->first.FileName;<br>
+    for (const auto &P : Fns)<br>
+      FilePrefix = CommonPrefix(FilePrefix, P.first.FileName);<br>
+<br>
+    // Print first function occurence in a file.<br>
+    {<br>
+      std::string LastFileName;<br>
+      std::set<std::string> ProcessedFunctions;<br>
+<br>
+      for (const auto &P : Fns) {<br>
+        std::string FileName = P.first.FileName;<br>
+        std::string FunctionName = P.second;<br>
+        uint32_t Line = P.first.Line;<br>
+<br>
+        if (LastFileName != FileName)<br>
+          ProcessedFunctions.clear();<br>
+        LastFileName = FileName;<br>
+<br>
+        if (!ProcessedFunctions.insert(FunctionName).second)<br>
+          continue;<br>
+<br>
+        out << FileName.substr(FilePrefix.size()) << ":" << Line << " "<br>
+            << FunctionName << "\n";<br>
+      }<br>
+    }<br>
+  }<br>
+<br>
+ private:<br>
+  explicit CoverageData(std::unique_ptr<std::vector<uint64_t>> Addrs)<br>
+      : Addrs(std::move(Addrs)) {}<br>
+<br>
+  std::unique_ptr<std::vector<uint64_t>> Addrs;<br>
+};<br>
+} // namespace<br>
+<br>
+int main(int argc, char **argv) {<br>
+  // Print stack trace if we signal out.<br>
+  sys::PrintStackTraceOnErrorSignal();<br>
+  PrettyStackTraceProgram X(argc, argv);<br>
+  llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.<br>
+<br>
+  cl::ParseCommandLineOptions(argc, argv, "Sanitizer Coverage Processing Tool");<br>
+<br>
+  auto CovData = CoverageData::readAndMerge(ClInputFiles);<br>
+  FailIfError(CovData);<br>
+<br>
+  switch (Action) {<br>
+  case PrintAction: {<br>
+    CovData.get()->printAddrs(outs());<br>
+    return 0;<br>
+  }<br>
+  case CoveredFunctionsAction: {<br>
+    CovData.get()->printCoveredFunctions(outs());<br>
+    return 0;<br>
+  }<br>
+  }<br>
+}<br>
<br>
<br>
_______________________________________________<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/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div></div></div></div>
</blockquote></div><br></div>
</blockquote></div></blockquote></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>
</blockquote></div>