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_WASM_TRANSLATION_H_ 6 #define V8_INSPECTOR_WASM_TRANSLATION_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 const String16& GetSource(const String16& script_id, int func_index); GetStartLine(const String16 & script_id,int func_index)60 int GetStartLine(const String16& script_id, int func_index) { return 0; } GetStartColumn(const String16 & script_id,int func_index)61 int GetStartColumn(const String16& script_id, int func_index) { return 0; } 62 int GetEndLine(const String16& script_id, int func_index); 63 int GetEndColumn(const String16& script_id, int func_index); 64 String16 GetHash(const String16& script_id, int func_index); 65 66 private: 67 class TranslatorImpl; 68 friend class TranslatorImpl; 69 70 void AddFakeScript(const String16& scriptId, TranslatorImpl* translator); 71 72 v8::Isolate* isolate_; 73 std::unordered_map<int, std::unique_ptr<TranslatorImpl>> wasm_translators_; 74 std::unordered_map<String16, TranslatorImpl*> fake_scripts_; 75 Mode mode_; 76 77 DISALLOW_COPY_AND_ASSIGN(WasmTranslation); 78 }; 79 80 } // namespace v8_inspector 81 82 #endif // V8_INSPECTOR_WASM_TRANSLATION_H_ 83