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 8892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8903 int DebugInterface::Script::LineOffset() const { | 8903 int DebugInterface::Script::LineOffset() const { |
8904 return Utils::OpenHandle(this)->line_offset(); | 8904 return Utils::OpenHandle(this)->line_offset(); |
8905 } | 8905 } |
8906 | 8906 |
8907 int DebugInterface::Script::ColumnOffset() const { | 8907 int DebugInterface::Script::ColumnOffset() const { |
8908 return Utils::OpenHandle(this)->column_offset(); | 8908 return Utils::OpenHandle(this)->column_offset(); |
8909 } | 8909 } |
8910 | 8910 |
8911 std::vector<int> DebugInterface::Script::LineEnds() const { | 8911 std::vector<int> DebugInterface::Script::LineEnds() const { |
8912 i::Handle<i::Script> script = Utils::OpenHandle(this); | 8912 i::Handle<i::Script> script = Utils::OpenHandle(this); |
| 8913 if (script->type() == i::Script::TYPE_WASM) return std::vector<int>(); |
8913 i::Isolate* isolate = script->GetIsolate(); | 8914 i::Isolate* isolate = script->GetIsolate(); |
8914 i::HandleScope scope(isolate); | 8915 i::HandleScope scope(isolate); |
8915 i::Script::InitLineEnds(script); | 8916 i::Script::InitLineEnds(script); |
8916 CHECK(script->line_ends()->IsFixedArray()); | 8917 CHECK(script->line_ends()->IsFixedArray()); |
8917 i::Handle<i::FixedArray> line_ends(i::FixedArray::cast(script->line_ends())); | 8918 i::Handle<i::FixedArray> line_ends(i::FixedArray::cast(script->line_ends())); |
8918 std::vector<int> result(line_ends->length()); | 8919 std::vector<int> result(line_ends->length()); |
8919 for (int i = 0; i < line_ends->length(); ++i) { | 8920 for (int i = 0; i < line_ends->length(); ++i) { |
8920 i::Smi* line_end = i::Smi::cast(line_ends->get(i)); | 8921 i::Smi* line_end = i::Smi::cast(line_ends->get(i)); |
8921 result[i] = line_end->value(); | 8922 result[i] = line_end->value(); |
8922 } | 8923 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8966 MaybeLocal<String> DebugInterface::Script::Source() const { | 8967 MaybeLocal<String> DebugInterface::Script::Source() const { |
8967 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 8968 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
8968 i::HandleScope handle_scope(isolate); | 8969 i::HandleScope handle_scope(isolate); |
8969 i::Handle<i::Script> script = Utils::OpenHandle(this); | 8970 i::Handle<i::Script> script = Utils::OpenHandle(this); |
8970 i::Handle<i::Object> value(script->source(), isolate); | 8971 i::Handle<i::Object> value(script->source(), isolate); |
8971 if (!value->IsString()) return MaybeLocal<String>(); | 8972 if (!value->IsString()) return MaybeLocal<String>(); |
8972 return Utils::ToLocal( | 8973 return Utils::ToLocal( |
8973 handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value))); | 8974 handle_scope.CloseAndEscape(i::Handle<i::String>::cast(value))); |
8974 } | 8975 } |
8975 | 8976 |
| 8977 bool DebugInterface::Script::IsWasm() const { |
| 8978 return Utils::OpenHandle(this)->type() == i::Script::TYPE_WASM; |
| 8979 } |
| 8980 |
8976 namespace { | 8981 namespace { |
8977 int GetSmiValue(i::Handle<i::FixedArray> array, int index) { | 8982 int GetSmiValue(i::Handle<i::FixedArray> array, int index) { |
8978 return i::Smi::cast(array->get(index))->value(); | 8983 return i::Smi::cast(array->get(index))->value(); |
8979 } | 8984 } |
8980 } // namespace | 8985 } // namespace |
8981 | 8986 |
8982 bool DebugInterface::Script::GetPossibleBreakpoints( | 8987 bool DebugInterface::Script::GetPossibleBreakpoints( |
8983 const Location& start, const Location& end, | 8988 const Location& start, const Location& end, |
8984 std::vector<Location>* locations) const { | 8989 std::vector<Location>* locations) const { |
8985 CHECK(!start.IsEmpty()); | 8990 CHECK(!start.IsEmpty()); |
8986 i::Handle<i::Script> script = Utils::OpenHandle(this); | 8991 i::Handle<i::Script> script = Utils::OpenHandle(this); |
| 8992 if (script->type() == i::Script::TYPE_WASM) { |
| 8993 // TODO(clemensh): Return the proper thing once we support wasm breakpoints. |
| 8994 return false; |
| 8995 } |
8987 | 8996 |
8988 i::Script::InitLineEnds(script); | 8997 i::Script::InitLineEnds(script); |
8989 CHECK(script->line_ends()->IsFixedArray()); | 8998 CHECK(script->line_ends()->IsFixedArray()); |
8990 i::Isolate* isolate = script->GetIsolate(); | 8999 i::Isolate* isolate = script->GetIsolate(); |
8991 i::Handle<i::FixedArray> line_ends = | 9000 i::Handle<i::FixedArray> line_ends = |
8992 i::Handle<i::FixedArray>::cast(i::handle(script->line_ends(), isolate)); | 9001 i::Handle<i::FixedArray>::cast(i::handle(script->line_ends(), isolate)); |
8993 CHECK(line_ends->length()); | 9002 CHECK(line_ends->length()); |
8994 | 9003 |
8995 int start_offset = GetSourcePosition(start); | 9004 int start_offset = GetSourcePosition(start); |
8996 int end_offset; | 9005 int end_offset; |
(...skipping 25 matching lines...) Expand all Loading... |
9022 locations->push_back(Location( | 9031 locations->push_back(Location( |
9023 current_line_end_index + script->line_offset(), | 9032 current_line_end_index + script->line_offset(), |
9024 offset - line_offset + | 9033 offset - line_offset + |
9025 (current_line_end_index == 0 ? script->column_offset() : 0))); | 9034 (current_line_end_index == 0 ? script->column_offset() : 0))); |
9026 } | 9035 } |
9027 return true; | 9036 return true; |
9028 } | 9037 } |
9029 | 9038 |
9030 int DebugInterface::Script::GetSourcePosition(const Location& location) const { | 9039 int DebugInterface::Script::GetSourcePosition(const Location& location) const { |
9031 i::Handle<i::Script> script = Utils::OpenHandle(this); | 9040 i::Handle<i::Script> script = Utils::OpenHandle(this); |
| 9041 if (script->type() == i::Script::TYPE_WASM) { |
| 9042 // TODO(clemensh): Return the proper thing for wasm. |
| 9043 return 0; |
| 9044 } |
9032 | 9045 |
9033 int line = std::max(location.GetLineNumber() - script->line_offset(), 0); | 9046 int line = std::max(location.GetLineNumber() - script->line_offset(), 0); |
9034 int column = location.GetColumnNumber(); | 9047 int column = location.GetColumnNumber(); |
9035 if (line == 0) { | 9048 if (line == 0) { |
9036 column = std::max(0, column - script->column_offset()); | 9049 column = std::max(0, column - script->column_offset()); |
9037 } | 9050 } |
9038 | 9051 |
9039 i::Script::InitLineEnds(script); | 9052 i::Script::InitLineEnds(script); |
9040 CHECK(script->line_ends()->IsFixedArray()); | 9053 CHECK(script->line_ends()->IsFixedArray()); |
9041 i::Handle<i::FixedArray> line_ends = i::Handle<i::FixedArray>::cast( | 9054 i::Handle<i::FixedArray> line_ends = i::Handle<i::FixedArray>::cast( |
(...skipping 13 matching lines...) Expand all Loading... |
9055 ENTER_V8(isolate); | 9068 ENTER_V8(isolate); |
9056 i::HandleScope handle_scope(isolate); | 9069 i::HandleScope handle_scope(isolate); |
9057 i::Handle<i::JSReceiver> script_receiver(Utils::OpenHandle(*script)); | 9070 i::Handle<i::JSReceiver> script_receiver(Utils::OpenHandle(*script)); |
9058 if (!script_receiver->IsJSValue()) return MaybeLocal<Script>(); | 9071 if (!script_receiver->IsJSValue()) return MaybeLocal<Script>(); |
9059 i::Handle<i::Object> script_value( | 9072 i::Handle<i::Object> script_value( |
9060 i::Handle<i::JSValue>::cast(script_receiver)->value(), isolate); | 9073 i::Handle<i::JSValue>::cast(script_receiver)->value(), isolate); |
9061 if (!script_value->IsScript()) { | 9074 if (!script_value->IsScript()) { |
9062 return MaybeLocal<Script>(); | 9075 return MaybeLocal<Script>(); |
9063 } | 9076 } |
9064 i::Handle<i::Script> script_obj = i::Handle<i::Script>::cast(script_value); | 9077 i::Handle<i::Script> script_obj = i::Handle<i::Script>::cast(script_value); |
9065 if (script_obj->type() != i::Script::TYPE_NORMAL) return MaybeLocal<Script>(); | 9078 if (script_obj->type() != i::Script::TYPE_NORMAL && |
| 9079 script_obj->type() != i::Script::TYPE_WASM) { |
| 9080 return MaybeLocal<Script>(); |
| 9081 } |
9066 return ToApiHandle<DebugInterface::Script>( | 9082 return ToApiHandle<DebugInterface::Script>( |
9067 handle_scope.CloseAndEscape(script_obj)); | 9083 handle_scope.CloseAndEscape(script_obj)); |
9068 } | 9084 } |
9069 | 9085 |
9070 DebugInterface::Location::Location(int lineNumber, int columnNumber) | 9086 DebugInterface::Location::Location(int lineNumber, int columnNumber) |
9071 : lineNumber_(lineNumber), columnNumber_(columnNumber) { | 9087 : lineNumber_(lineNumber), columnNumber_(columnNumber) { |
9072 CHECK(lineNumber >= 0); | 9088 CHECK(lineNumber >= 0); |
9073 CHECK(columnNumber >= 0); | 9089 CHECK(columnNumber >= 0); |
9074 } | 9090 } |
9075 | 9091 |
(...skipping 29 matching lines...) Expand all Loading... |
9105 if (script->type() != i::Script::TYPE_NORMAL) continue; | 9121 if (script->type() != i::Script::TYPE_NORMAL) continue; |
9106 if (script->HasValidSource()) { | 9122 if (script->HasValidSource()) { |
9107 i::HandleScope handle_scope(isolate); | 9123 i::HandleScope handle_scope(isolate); |
9108 i::Handle<i::Script> script_handle(script, isolate); | 9124 i::Handle<i::Script> script_handle(script, isolate); |
9109 scripts.Append(ToApiHandle<Script>(script_handle)); | 9125 scripts.Append(ToApiHandle<Script>(script_handle)); |
9110 } | 9126 } |
9111 } | 9127 } |
9112 } | 9128 } |
9113 } | 9129 } |
9114 | 9130 |
| 9131 std::pair<std::string, std::vector<std::tuple<uint32_t, int, int>>> |
| 9132 DebugInterface::DisassembleWasmFunction(Isolate* v8_isolate, |
| 9133 Local<Object> v8_script, |
| 9134 int function_index) { |
| 9135 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 9136 if (v8_script.IsEmpty()) return {}; |
| 9137 i::Handle<i::Object> script_wrapper = Utils::OpenHandle(*v8_script); |
| 9138 if (!script_wrapper->IsJSValue()) return {}; |
| 9139 i::Handle<i::Object> script_obj( |
| 9140 i::Handle<i::JSValue>::cast(script_wrapper)->value(), isolate); |
| 9141 if (!script_obj->IsScript()) return {}; |
| 9142 i::Handle<i::Script> script = i::Handle<i::Script>::cast(script_obj); |
| 9143 if (script->type() != i::Script::TYPE_WASM) return {}; |
| 9144 i::Handle<i::WasmCompiledModule> compiled_module( |
| 9145 i::WasmCompiledModule::cast(script->wasm_compiled_module()), isolate); |
| 9146 return i::wasm::DisassembleFunction(compiled_module, function_index); |
| 9147 } |
| 9148 |
9115 Local<String> CpuProfileNode::GetFunctionName() const { | 9149 Local<String> CpuProfileNode::GetFunctionName() const { |
9116 const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); | 9150 const i::ProfileNode* node = reinterpret_cast<const i::ProfileNode*>(this); |
9117 i::Isolate* isolate = node->isolate(); | 9151 i::Isolate* isolate = node->isolate(); |
9118 const i::CodeEntry* entry = node->entry(); | 9152 const i::CodeEntry* entry = node->entry(); |
9119 i::Handle<i::String> name = | 9153 i::Handle<i::String> name = |
9120 isolate->factory()->InternalizeUtf8String(entry->name()); | 9154 isolate->factory()->InternalizeUtf8String(entry->name()); |
9121 if (!entry->has_name_prefix()) { | 9155 if (!entry->has_name_prefix()) { |
9122 return ToApiHandle<String>(name); | 9156 return ToApiHandle<String>(name); |
9123 } else { | 9157 } else { |
9124 // We do not expect this to fail. Change this if it does. | 9158 // We do not expect this to fail. Change this if it does. |
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9793 Address callback_address = | 9827 Address callback_address = |
9794 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9828 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
9795 VMState<EXTERNAL> state(isolate); | 9829 VMState<EXTERNAL> state(isolate); |
9796 ExternalCallbackScope call_scope(isolate, callback_address); | 9830 ExternalCallbackScope call_scope(isolate, callback_address); |
9797 callback(info); | 9831 callback(info); |
9798 } | 9832 } |
9799 | 9833 |
9800 | 9834 |
9801 } // namespace internal | 9835 } // namespace internal |
9802 } // namespace v8 | 9836 } // namespace v8 |
OLD | NEW |