• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_INSPECTOR_WASMTRANSLATION_H_
6 #define V8_INSPECTOR_WASMTRANSLATION_H_
7 
8 #include <unordered_map>
9 
10 #include "include/v8.h"
11 #include "src/base/macros.h"
12 #include "src/debug/debug-interface.h"
13 #include "src/inspector/string-16.h"
14 
15 namespace v8_inspector {
16 
17 // Forward declarations.
18 class V8DebuggerAgentImpl;
19 
20 class WasmTranslation {
21  public:
22   enum Mode { Raw, Disassemble };
23 
24   explicit WasmTranslation(v8::Isolate* isolate);
25   ~WasmTranslation();
26 
27   // Set translation mode.
SetMode(Mode mode)28   void SetMode(Mode mode) { mode_ = mode; }
29 
30   // Make a wasm script known to the translation. This will trigger a number of
31   // didParseScript calls to the given debugger agent.
32   // Only locations referencing a registered script will be translated by the
33   // Translate functions below.
34   void AddScript(v8::Local<v8::debug::WasmScript> script,
35                  V8DebuggerAgentImpl* agent);
36 
37   // Clear all registered scripts.
38   void Clear();
39 
40   // Translate a location as generated by V8 to a location that should be sent
41   // over protocol.
42   // Does nothing for locations referencing a script which was not registered
43   // before via AddScript.
44   // Line and column are 0-based.
45   // Returns true if the location was translated, false otherwise.
46   bool TranslateWasmScriptLocationToProtocolLocation(String16* script_id,
47                                                      int* line_number,
48                                                      int* column_number);
49 
50   // Translate back from protocol locations (potentially referencing artificial
51   // scripts for individual wasm functions) to locations that make sense to V8.
52   // Does nothing if the location was not generated by the translate method
53   // above.
54   // Returns true if the location was translated, false otherwise.
55   bool TranslateProtocolLocationToWasmScriptLocation(String16* script_id,
56                                                      int* line_number,
57                                                      int* column_number);
58 
59  private:
60   class TranslatorImpl;
61   friend class TranslatorImpl;
62 
63   void AddFakeScript(const String16& scriptId, TranslatorImpl* translator);
64 
65   v8::Isolate* isolate_;
66   std::unordered_map<int, std::unique_ptr<TranslatorImpl>> wasm_translators_;
67   std::unordered_map<String16, TranslatorImpl*> fake_scripts_;
68   Mode mode_;
69 
70   DISALLOW_COPY_AND_ASSIGN(WasmTranslation);
71 };
72 
73 }  // namespace v8_inspector
74 
75 #endif  // V8_INSPECTOR_WASMTRANSLATION_H_
76