Coverage for /Syzygy/refinery/run_refinery_main.cc

CoverageLines executed / instrumented / missingexe / inst / missLanguageGroup
0.0%0074.C++source

Line-by-line coverage:

   1    :  // Copyright 2015 Google Inc. All Rights Reserved.
   2    :  //
   3    :  // Licensed under the Apache License, Version 2.0 (the "License");
   4    :  // you may not use this file except in compliance with the License.
   5    :  // You may obtain a copy of the License at
   6    :  //
   7    :  //     http://www.apache.org/licenses/LICENSE-2.0
   8    :  //
   9    :  // Unless required by applicable law or agreed to in writing, software
  10    :  // distributed under the License is distributed on an "AS IS" BASIS,
  11    :  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12    :  // See the License for the specific language governing permissions and
  13    :  // limitations under the License.
  14    :  
  15    :  // Runs the refinery over a minidump and outputs the validation report.
  16    :  
  17    :  #include <iostream>
  18    :  #include <memory>
  19    :  
  20    :  #include "base/command_line.h"
  21    :  #include "base/logging.h"
  22    :  #include "base/files/file_path.h"
  23    :  #include "base/strings/stringprintf.h"
  24    :  #include "syzygy/minidump/minidump.h"
  25    :  #include "syzygy/refinery/analyzers/analysis_runner.h"
  26    :  #include "syzygy/refinery/analyzers/analyzer_util.h"
  27    :  #include "syzygy/refinery/analyzers/exception_analyzer.h"
  28    :  #include "syzygy/refinery/analyzers/heap_analyzer.h"
  29    :  #include "syzygy/refinery/analyzers/memory_analyzer.h"
  30    :  #include "syzygy/refinery/analyzers/module_analyzer.h"
  31    :  #include "syzygy/refinery/analyzers/stack_analyzer.h"
  32    :  #include "syzygy/refinery/analyzers/thread_analyzer.h"
  33    :  #include "syzygy/refinery/process_state/process_state.h"
  34    :  #include "syzygy/refinery/process_state/process_state_util.h"
  35    :  #include "syzygy/refinery/process_state/refinery.pb.h"
  36    :  #include "syzygy/refinery/symbols/dia_symbol_provider.h"
  37    :  #include "syzygy/refinery/symbols/symbol_provider.h"
  38    :  #include "syzygy/refinery/validators/exception_handler_validator.h"
  39    :  
  40  m :  namespace {
  41    :  
  42  m :  using minidump::Minidump;
  43  m :  using refinery::AnalysisRunner;
  44  m :  using refinery::Analyzer;
  45  m :  using refinery::ProcessState;
  46  m :  using refinery::ValidationReport;
  47  m :  using refinery::Validator;
  48    :  
  49  m :  const char kUsage[] =
  50  m :    "Usage: %ls --dump=<dump file>\n"
  51  m :    "\n"
  52  m :    "  Runs the refinery analysis and validation, then prints the validation \n"
  53  m :    "  report.\n";
  54    :  
  55  m :  bool ParseCommandLine(const base::CommandLine* cmd,
  56  m :                        base::FilePath* dump_path) {
  57  m :    *dump_path = cmd->GetSwitchValuePath("dump");
  58  m :    if (dump_path->empty()) {
  59  m :      LOG(ERROR) << "Missing dump file.";
  60  m :      LOG(ERROR) << base::StringPrintf(kUsage, cmd->GetProgram().value().c_str());
  61  m :      return false;
  62  m :    }
  63    :  
  64  m :    return true;
  65  m :  }
  66    :  
  67  m :  bool Analyze(const Minidump& minidump, ProcessState* process_state) {
  68  m :    AnalysisRunner runner;
  69    :  
  70  m :    std::unique_ptr<Analyzer> analyzer(new refinery::MemoryAnalyzer());
  71  m :    runner.AddAnalyzer(std::move(analyzer));
  72  m :    analyzer.reset(new refinery::ThreadAnalyzer());
  73  m :    runner.AddAnalyzer(std::move(analyzer));
  74  m :    analyzer.reset(new refinery::ExceptionAnalyzer());
  75  m :    runner.AddAnalyzer(std::move(analyzer));
  76  m :    analyzer.reset(new refinery::ModuleAnalyzer());
  77  m :    runner.AddAnalyzer(std::move(analyzer));
  78  m :    analyzer.reset(new refinery::HeapAnalyzer());
  79  m :    runner.AddAnalyzer(std::move(analyzer));
  80  m :    analyzer.reset(new refinery::StackAnalyzer());
  81  m :    runner.AddAnalyzer(std::move(analyzer));
  82    :  
  83  m :    scoped_refptr<refinery::SymbolProvider> symbol_provider(
  84  m :        new refinery::SymbolProvider());
  85  m :    scoped_refptr<refinery::DiaSymbolProvider> dia_symbol_provider(
  86  m :        new refinery::DiaSymbolProvider());
  87    :  
  88  m :    refinery::SimpleProcessAnalysis analysis(process_state, dia_symbol_provider,
  89  m :                                             symbol_provider);
  90    :  
  91  m :    return runner.Analyze(minidump, analysis) == Analyzer::ANALYSIS_COMPLETE;
  92  m :  }
  93    :  
  94  m :  bool Validate(ProcessState* process_state, ValidationReport* report) {
  95  m :    refinery::ExceptionHandlerValidator validator;
  96  m :    if (validator.Validate(process_state, report) !=
  97  m :        Validator::VALIDATION_COMPLETE) {
  98  m :      LOG(ERROR) << "Exception handler chain validation failed";
  99  m :      return false;
 100  m :    }
 101    :  
 102  m :    return true;
 103  m :  }
 104    :  
 105  m :  }  // namespace
 106    :  
 107  m :  int main(int argc, const char* const* argv) {
 108  m :    base::CommandLine::Init(argc, argv);
 109    :  
 110    :    // Get the dump.
 111  m :    base::FilePath dump_path;
 112  m :    if (!ParseCommandLine(base::CommandLine::ForCurrentProcess(), &dump_path))
 113  m :      return 1;
 114    :  
 115  m :    minidump::FileMinidump minidump;
 116  m :    if (!minidump.Open(dump_path)) {
 117  m :      LOG(ERROR) << "Unable to open dump file.";
 118  m :      return 1;
 119  m :    }
 120    :  
 121    :    // Analyze.
 122  m :    ProcessState process_state;
 123  m :    if (!Analyze(minidump, &process_state))
 124  m :      return 1;
 125    :  
 126    :    // Validate and output.
 127  m :    ValidationReport report;
 128  m :    if (!Validate(&process_state, &report))
 129  m :      return 1;
 130    :  
 131  m :    std::cout << "Validation report:";
 132  m :    std::cout << report.DebugString();
 133    :  
 134  m :    return 0;
 135  m :  }

Coverage information generated Fri Jul 29 11:00:21 2016.