OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/api.h" | 5 #include "src/api.h" |
6 | 6 |
7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
(...skipping 9058 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9069 } | 9069 } |
9070 i::Handle<i::Script> script_obj = i::Handle<i::Script>::cast(script_value); | 9070 i::Handle<i::Script> script_obj = i::Handle<i::Script>::cast(script_value); |
9071 if (script_obj->type() != i::Script::TYPE_NORMAL && | 9071 if (script_obj->type() != i::Script::TYPE_NORMAL && |
9072 script_obj->type() != i::Script::TYPE_WASM) { | 9072 script_obj->type() != i::Script::TYPE_WASM) { |
9073 return MaybeLocal<Script>(); | 9073 return MaybeLocal<Script>(); |
9074 } | 9074 } |
9075 return ToApiHandle<DebugInterface::Script>( | 9075 return ToApiHandle<DebugInterface::Script>( |
9076 handle_scope.CloseAndEscape(script_obj)); | 9076 handle_scope.CloseAndEscape(script_obj)); |
9077 } | 9077 } |
9078 | 9078 |
| 9079 DebugInterface::WasmScript* DebugInterface::WasmScript::Cast( |
| 9080 DebugInterface::Script* script) { |
| 9081 CHECK(script->IsWasm()); |
| 9082 return static_cast<WasmScript*>(script); |
| 9083 } |
| 9084 |
| 9085 int DebugInterface::WasmScript::NumFunction() const { |
| 9086 i::DisallowHeapAllocation no_gc; |
| 9087 i::Handle<i::Script> script = Utils::OpenHandle(this); |
| 9088 DCHECK_EQ(i::Script::TYPE_WASM, script->type()); |
| 9089 i::WasmCompiledModule* compiled_module = |
| 9090 i::WasmCompiledModule::cast(script->wasm_compiled_module()); |
| 9091 DCHECK_GE(i::kMaxInt, compiled_module->module()->functions.size()); |
| 9092 return static_cast<int>(compiled_module->module()->functions.size()); |
| 9093 } |
| 9094 |
| 9095 int DebugInterface::WasmScript::NumImportedFunction() const { |
| 9096 i::DisallowHeapAllocation no_gc; |
| 9097 i::Handle<i::Script> script = Utils::OpenHandle(this); |
| 9098 DCHECK_EQ(i::Script::TYPE_WASM, script->type()); |
| 9099 i::WasmCompiledModule* compiled_module = |
| 9100 i::WasmCompiledModule::cast(script->wasm_compiled_module()); |
| 9101 DCHECK_GE(i::kMaxInt, compiled_module->module()->num_imported_functions); |
| 9102 return static_cast<int>(compiled_module->module()->num_imported_functions); |
| 9103 } |
| 9104 |
| 9105 std::pair<std::string, std::vector<std::tuple<uint32_t, int, int>>> |
| 9106 DebugInterface::WasmScript::DisassembleFunction(int function_index) { |
| 9107 i::DisallowHeapAllocation no_gc; |
| 9108 i::Handle<i::Script> script = Utils::OpenHandle(this); |
| 9109 DCHECK_EQ(i::Script::TYPE_WASM, script->type()); |
| 9110 i::WasmCompiledModule* compiled_module = |
| 9111 i::WasmCompiledModule::cast(script->wasm_compiled_module()); |
| 9112 return compiled_module->DisassembleFunction(function_index); |
| 9113 } |
| 9114 |
9079 DebugInterface::Location::Location(int lineNumber, int columnNumber) | 9115 DebugInterface::Location::Location(int lineNumber, int columnNumber) |
9080 : lineNumber_(lineNumber), columnNumber_(columnNumber) { | 9116 : lineNumber_(lineNumber), columnNumber_(columnNumber) { |
9081 CHECK(lineNumber >= 0); | 9117 CHECK(lineNumber >= 0); |
9082 CHECK(columnNumber >= 0); | 9118 CHECK(columnNumber >= 0); |
9083 } | 9119 } |
9084 | 9120 |
9085 DebugInterface::Location::Location() : lineNumber_(-1), columnNumber_(-1) {} | 9121 DebugInterface::Location::Location() : lineNumber_(-1), columnNumber_(-1) {} |
9086 | 9122 |
9087 int DebugInterface::Location::GetLineNumber() const { | 9123 int DebugInterface::Location::GetLineNumber() const { |
9088 CHECK(lineNumber_ >= 0); | 9124 CHECK(lineNumber_ >= 0); |
(...skipping 25 matching lines...) Expand all Loading... |
9114 if (script->type() != i::Script::TYPE_NORMAL) continue; | 9150 if (script->type() != i::Script::TYPE_NORMAL) continue; |
9115 if (script->HasValidSource()) { | 9151 if (script->HasValidSource()) { |
9116 i::HandleScope handle_scope(isolate); | 9152 i::HandleScope handle_scope(isolate); |
9117 i::Handle<i::Script> script_handle(script, isolate); | 9153 i::Handle<i::Script> script_handle(script, isolate); |
9118 scripts.Append(ToApiHandle<Script>(script_handle)); | 9154 scripts.Append(ToApiHandle<Script>(script_handle)); |
9119 } | 9155 } |
9120 } | 9156 } |
9121 } | 9157 } |
9122 } | 9158 } |
9123 | 9159 |
9124 std::pair<std::string, std::vector<std::tuple<uint32_t, int, int>>> | |
9125 DebugInterface::DisassembleWasmFunction(Isolate* v8_isolate, | |
9126 Local<Object> v8_script, | |
9127 int function_index) { | |
9128 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | |
9129 if (v8_script.IsEmpty()) return {}; | |
9130 i::Handle<i::Object> script_wrapper = Utils::OpenHandle(*v8_script); | |
9131 if (!script_wrapper->IsJSValue()) return {}; | |
9132 i::Handle<i::Object> script_obj( | |
9133 i::Handle<i::JSValue>::cast(script_wrapper)->value(), isolate); | |
9134 if (!script_obj->IsScript()) return {}; | |
9135 i::Handle<i::Script> script = i::Handle<i::Script>::cast(script_obj); | |
9136 if (script->type() != i::Script::TYPE_WASM) return {}; | |
9137 i::Handle<i::WasmCompiledModule> compiled_module( | |
9138 i::WasmCompiledModule::cast(script->wasm_compiled_module()), isolate); | |
9139 return compiled_module->DisassembleFunction(function_index); | |
9140 } | |
9141 | |
9142 MaybeLocal<UnboundScript> DebugInterface::CompileInspectorScript( | 9160 MaybeLocal<UnboundScript> DebugInterface::CompileInspectorScript( |
9143 Isolate* v8_isolate, Local<String> source) { | 9161 Isolate* v8_isolate, Local<String> source) { |
9144 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 9162 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
9145 PREPARE_FOR_DEBUG_INTERFACE_EXECUTION_WITH_ISOLATE(isolate, UnboundScript); | 9163 PREPARE_FOR_DEBUG_INTERFACE_EXECUTION_WITH_ISOLATE(isolate, UnboundScript); |
9146 i::ScriptData* script_data = NULL; | 9164 i::ScriptData* script_data = NULL; |
9147 i::Handle<i::String> str = Utils::OpenHandle(*source); | 9165 i::Handle<i::String> str = Utils::OpenHandle(*source); |
9148 i::Handle<i::SharedFunctionInfo> result; | 9166 i::Handle<i::SharedFunctionInfo> result; |
9149 { | 9167 { |
9150 ScriptOriginOptions origin_options; | 9168 ScriptOriginOptions origin_options; |
9151 result = i::Compiler::GetSharedFunctionInfoForScript( | 9169 result = i::Compiler::GetSharedFunctionInfoForScript( |
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9839 Address callback_address = | 9857 Address callback_address = |
9840 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9858 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
9841 VMState<EXTERNAL> state(isolate); | 9859 VMState<EXTERNAL> state(isolate); |
9842 ExternalCallbackScope call_scope(isolate, callback_address); | 9860 ExternalCallbackScope call_scope(isolate, callback_address); |
9843 callback(info); | 9861 callback(info); |
9844 } | 9862 } |
9845 | 9863 |
9846 | 9864 |
9847 } // namespace internal | 9865 } // namespace internal |
9848 } // namespace v8 | 9866 } // namespace v8 |
OLD | NEW |