wasm-translation.h 2.98 KB
Newer Older
1 2 3 4
// Copyright 2016 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.

5 6
#ifndef V8_INSPECTOR_WASM_TRANSLATION_H_
#define V8_INSPECTOR_WASM_TRANSLATION_H_
7

8
#include <memory>
9 10 11 12
#include <unordered_map>

#include "include/v8.h"
#include "src/base/macros.h"
13
#include "src/debug/debug-interface.h"
14 15 16 17 18
#include "src/inspector/string-16.h"

namespace v8_inspector {

// Forward declarations.
19
class V8DebuggerAgentImpl;
20 21 22

class WasmTranslation {
 public:
23
  explicit WasmTranslation(v8::Isolate* isolate);
24 25
  ~WasmTranslation();

26 27 28 29 30 31
  // Make a wasm script known to the translation. This will trigger a number of
  // didParseScript calls to the given debugger agent.
  // Only locations referencing a registered script will be translated by the
  // Translate functions below.
  void AddScript(v8::Local<v8::debug::WasmScript> script,
                 V8DebuggerAgentImpl* agent);
32 33 34 35

  // Clear all registered scripts.
  void Clear();

36 37 38
  // Clear all registered scripts for context group.
  void Clear(v8::Isolate* isolate, const std::vector<int>& contextIdsToClear);

39 40 41 42 43 44 45 46
  // Translate a location as generated by V8 to a location that should be sent
  // over protocol.
  // Does nothing for locations referencing a script which was not registered
  // before via AddScript.
  // Line and column are 0-based.
  // Returns true if the location was translated, false otherwise.
  bool TranslateWasmScriptLocationToProtocolLocation(String16* script_id,
                                                     int* line_number,
47
                                                     int* column_number);
48 49 50 51 52 53 54 55 56 57

  // Translate back from protocol locations (potentially referencing artificial
  // scripts for individual wasm functions) to locations that make sense to V8.
  // Does nothing if the location was not generated by the translate method
  // above.
  // Returns true if the location was translated, false otherwise.
  bool TranslateProtocolLocationToWasmScriptLocation(String16* script_id,
                                                     int* line_number,
                                                     int* column_number);

58 59 60 61 62 63 64
  const String16& GetSource(const String16& script_id, int func_index);
  int GetStartLine(const String16& script_id, int func_index) { return 0; }
  int GetStartColumn(const String16& script_id, int func_index) { return 0; }
  int GetEndLine(const String16& script_id, int func_index);
  int GetEndColumn(const String16& script_id, int func_index);
  String16 GetHash(const String16& script_id, int func_index);

65 66 67 68
 private:
  class TranslatorImpl;
  friend class TranslatorImpl;

69
  void AddFakeScript(const String16& scriptId, TranslatorImpl* translator);
70 71 72 73 74 75 76 77 78 79

  v8::Isolate* isolate_;
  std::unordered_map<int, std::unique_ptr<TranslatorImpl>> wasm_translators_;
  std::unordered_map<String16, TranslatorImpl*> fake_scripts_;

  DISALLOW_COPY_AND_ASSIGN(WasmTranslation);
};

}  // namespace v8_inspector

80
#endif  // V8_INSPECTOR_WASM_TRANSLATION_H_