debug-coverage.h 1.42 KB
Newer Older
1 2 3 4 5 6 7 8 9
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_DEBUG_DEBUG_COVERAGE_H_
#define V8_DEBUG_DEBUG_COVERAGE_H_

#include <vector>

10 11
#include "src/debug/debug-interface.h"
#include "src/objects.h"
12 13 14 15 16 17 18

namespace v8 {
namespace internal {

// Forward declaration.
class Isolate;

19 20
struct CoverageFunction {
  CoverageFunction(int s, int e, uint32_t c, Handle<String> n)
21 22 23 24 25 26 27 28 29
      : start(s), end(e), count(c), name(n) {}
  int start;
  int end;
  uint32_t count;
  Handle<String> name;
};

struct CoverageScript {
  // Initialize top-level function in case it has been garbage-collected.
30
  CoverageScript(Isolate* isolate, Handle<Script> s) : script(s) {}
31
  Handle<Script> script;
32 33
  // Functions are sorted by start position, from outer to inner function.
  std::vector<CoverageFunction> functions;
34 35 36
};

class Coverage : public std::vector<CoverageScript> {
37
 public:
38 39
  // Allocate a new Coverage object and populate with result.
  // The ownership is transferred to the caller.
40
  static Coverage* Collect(Isolate* isolate, bool reset_count);
41 42 43

  // Enable precise code coverage. This disables optimization and makes sure
  // invocation count is not affected by GC.
44 45 46 47
  static void TogglePrecise(Isolate* isolate, bool enable);

 private:
  Coverage() {}
48 49 50 51 52 53
};

}  // namespace internal
}  // namespace v8

#endif  // V8_DEBUG_DEBUG_COVERAGE_H_