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 8960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8971 return Utils::OpenHandle(this)->type() == i::Script::TYPE_WASM; | 8971 return Utils::OpenHandle(this)->type() == i::Script::TYPE_WASM; |
8972 } | 8972 } |
8973 | 8973 |
8974 namespace { | 8974 namespace { |
8975 int GetSmiValue(i::Handle<i::FixedArray> array, int index) { | 8975 int GetSmiValue(i::Handle<i::FixedArray> array, int index) { |
8976 return i::Smi::cast(array->get(index))->value(); | 8976 return i::Smi::cast(array->get(index))->value(); |
8977 } | 8977 } |
8978 } // namespace | 8978 } // namespace |
8979 | 8979 |
8980 bool DebugInterface::Script::GetPossibleBreakpoints( | 8980 bool DebugInterface::Script::GetPossibleBreakpoints( |
8981 const Location& start, const Location& end, | 8981 const debug::Location& start, const debug::Location& end, |
8982 std::vector<Location>* locations) const { | 8982 std::vector<debug::Location>* locations) const { |
8983 CHECK(!start.IsEmpty()); | 8983 CHECK(!start.IsEmpty()); |
8984 i::Handle<i::Script> script = Utils::OpenHandle(this); | 8984 i::Handle<i::Script> script = Utils::OpenHandle(this); |
8985 if (script->type() == i::Script::TYPE_WASM) { | 8985 if (script->type() == i::Script::TYPE_WASM) { |
8986 // TODO(clemensh): Return the proper thing once we support wasm breakpoints. | 8986 // TODO(clemensh): Return the proper thing once we support wasm breakpoints. |
8987 return false; | 8987 return false; |
8988 } | 8988 } |
8989 | 8989 |
8990 i::Script::InitLineEnds(script); | 8990 i::Script::InitLineEnds(script); |
8991 CHECK(script->line_ends()->IsFixedArray()); | 8991 CHECK(script->line_ends()->IsFixedArray()); |
8992 i::Isolate* isolate = script->GetIsolate(); | 8992 i::Isolate* isolate = script->GetIsolate(); |
(...skipping 21 matching lines...) Expand all Loading... |
9014 int offset = it; | 9014 int offset = it; |
9015 while (offset > GetSmiValue(line_ends, current_line_end_index)) { | 9015 while (offset > GetSmiValue(line_ends, current_line_end_index)) { |
9016 ++current_line_end_index; | 9016 ++current_line_end_index; |
9017 CHECK(current_line_end_index < line_ends->length()); | 9017 CHECK(current_line_end_index < line_ends->length()); |
9018 } | 9018 } |
9019 int line_offset = 0; | 9019 int line_offset = 0; |
9020 | 9020 |
9021 if (current_line_end_index > 0) { | 9021 if (current_line_end_index > 0) { |
9022 line_offset = GetSmiValue(line_ends, current_line_end_index - 1) + 1; | 9022 line_offset = GetSmiValue(line_ends, current_line_end_index - 1) + 1; |
9023 } | 9023 } |
9024 locations->push_back(Location( | 9024 locations->push_back(debug::Location( |
9025 current_line_end_index + script->line_offset(), | 9025 current_line_end_index + script->line_offset(), |
9026 offset - line_offset + | 9026 offset - line_offset + |
9027 (current_line_end_index == 0 ? script->column_offset() : 0))); | 9027 (current_line_end_index == 0 ? script->column_offset() : 0))); |
9028 } | 9028 } |
9029 return true; | 9029 return true; |
9030 } | 9030 } |
9031 | 9031 |
9032 int DebugInterface::Script::GetSourcePosition(const Location& location) const { | 9032 int DebugInterface::Script::GetSourcePosition( |
| 9033 const debug::Location& location) const { |
9033 i::Handle<i::Script> script = Utils::OpenHandle(this); | 9034 i::Handle<i::Script> script = Utils::OpenHandle(this); |
9034 if (script->type() == i::Script::TYPE_WASM) { | 9035 if (script->type() == i::Script::TYPE_WASM) { |
9035 // TODO(clemensh): Return the proper thing for wasm. | 9036 // TODO(clemensh): Return the proper thing for wasm. |
9036 return 0; | 9037 return 0; |
9037 } | 9038 } |
9038 | 9039 |
9039 int line = std::max(location.GetLineNumber() - script->line_offset(), 0); | 9040 int line = std::max(location.GetLineNumber() - script->line_offset(), 0); |
9040 int column = location.GetColumnNumber(); | 9041 int column = location.GetColumnNumber(); |
9041 if (line == 0) { | 9042 if (line == 0) { |
9042 column = std::max(0, column - script->column_offset()); | 9043 column = std::max(0, column - script->column_offset()); |
(...skipping 26 matching lines...) Expand all Loading... |
9069 } | 9070 } |
9070 i::Handle<i::Script> script_obj = i::Handle<i::Script>::cast(script_value); | 9071 i::Handle<i::Script> script_obj = i::Handle<i::Script>::cast(script_value); |
9071 if (script_obj->type() != i::Script::TYPE_NORMAL && | 9072 if (script_obj->type() != i::Script::TYPE_NORMAL && |
9072 script_obj->type() != i::Script::TYPE_WASM) { | 9073 script_obj->type() != i::Script::TYPE_WASM) { |
9073 return MaybeLocal<Script>(); | 9074 return MaybeLocal<Script>(); |
9074 } | 9075 } |
9075 return ToApiHandle<DebugInterface::Script>( | 9076 return ToApiHandle<DebugInterface::Script>( |
9076 handle_scope.CloseAndEscape(script_obj)); | 9077 handle_scope.CloseAndEscape(script_obj)); |
9077 } | 9078 } |
9078 | 9079 |
9079 DebugInterface::Location::Location(int lineNumber, int columnNumber) | 9080 debug::Location::Location(int line_number, int column_number) |
9080 : lineNumber_(lineNumber), columnNumber_(columnNumber) { | 9081 : line_number_(line_number), column_number_(column_number) { |
9081 CHECK(lineNumber >= 0); | 9082 CHECK(line_number >= 0); |
9082 CHECK(columnNumber >= 0); | 9083 CHECK(column_number >= 0); |
9083 } | 9084 } |
9084 | 9085 |
9085 DebugInterface::Location::Location() : lineNumber_(-1), columnNumber_(-1) {} | 9086 debug::Location::Location() : line_number_(-1), column_number_(-1) {} |
9086 | 9087 |
9087 int DebugInterface::Location::GetLineNumber() const { | 9088 int debug::Location::GetLineNumber() const { |
9088 CHECK(lineNumber_ >= 0); | 9089 CHECK(line_number_ >= 0); |
9089 return lineNumber_; | 9090 return line_number_; |
9090 } | 9091 } |
9091 | 9092 |
9092 int DebugInterface::Location::GetColumnNumber() const { | 9093 int debug::Location::GetColumnNumber() const { |
9093 CHECK(columnNumber_ >= 0); | 9094 CHECK(column_number_ >= 0); |
9094 return columnNumber_; | 9095 return column_number_; |
9095 } | 9096 } |
9096 | 9097 |
9097 bool DebugInterface::Location::IsEmpty() const { | 9098 bool debug::Location::IsEmpty() const { |
9098 return lineNumber_ == -1 && columnNumber_ == -1; | 9099 return line_number_ == -1 && column_number_ == -1; |
9099 } | 9100 } |
9100 | 9101 |
9101 void DebugInterface::GetLoadedScripts( | 9102 void DebugInterface::GetLoadedScripts( |
9102 v8::Isolate* v8_isolate, | 9103 v8::Isolate* v8_isolate, |
9103 PersistentValueVector<DebugInterface::Script>& scripts) { | 9104 PersistentValueVector<DebugInterface::Script>& scripts) { |
9104 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 9105 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
9105 ENTER_V8(isolate); | 9106 ENTER_V8(isolate); |
9106 // TODO(kozyatinskiy): remove this GC once tests are dealt with. | 9107 // TODO(kozyatinskiy): remove this GC once tests are dealt with. |
9107 isolate->heap()->CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask, | 9108 isolate->heap()->CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask, |
9108 i::GarbageCollectionReason::kDebugger); | 9109 i::GarbageCollectionReason::kDebugger); |
9109 { | 9110 { |
9110 i::DisallowHeapAllocation no_gc; | 9111 i::DisallowHeapAllocation no_gc; |
9111 i::Script::Iterator iterator(isolate); | 9112 i::Script::Iterator iterator(isolate); |
9112 i::Script* script; | 9113 i::Script* script; |
9113 while ((script = iterator.Next())) { | 9114 while ((script = iterator.Next())) { |
9114 if (script->type() != i::Script::TYPE_NORMAL) continue; | 9115 if (script->type() != i::Script::TYPE_NORMAL) continue; |
9115 if (script->HasValidSource()) { | 9116 if (script->HasValidSource()) { |
9116 i::HandleScope handle_scope(isolate); | 9117 i::HandleScope handle_scope(isolate); |
9117 i::Handle<i::Script> script_handle(script, isolate); | 9118 i::Handle<i::Script> script_handle(script, isolate); |
9118 scripts.Append(ToApiHandle<Script>(script_handle)); | 9119 scripts.Append(ToApiHandle<Script>(script_handle)); |
9119 } | 9120 } |
9120 } | 9121 } |
9121 } | 9122 } |
9122 } | 9123 } |
9123 | 9124 |
9124 std::pair<std::string, std::vector<std::tuple<uint32_t, int, int>>> | 9125 debug::WasmDisassembly DebugInterface::DisassembleWasmFunction( |
9125 DebugInterface::DisassembleWasmFunction(Isolate* v8_isolate, | 9126 Isolate* v8_isolate, Local<Object> v8_script, int function_index) { |
9126 Local<Object> v8_script, | |
9127 int function_index) { | |
9128 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 9127 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
9129 if (v8_script.IsEmpty()) return {}; | 9128 if (v8_script.IsEmpty()) return {}; |
9130 i::Handle<i::Object> script_wrapper = Utils::OpenHandle(*v8_script); | 9129 i::Handle<i::Object> script_wrapper = Utils::OpenHandle(*v8_script); |
9131 if (!script_wrapper->IsJSValue()) return {}; | 9130 if (!script_wrapper->IsJSValue()) return {}; |
9132 i::Handle<i::Object> script_obj( | 9131 i::Handle<i::Object> script_obj( |
9133 i::Handle<i::JSValue>::cast(script_wrapper)->value(), isolate); | 9132 i::Handle<i::JSValue>::cast(script_wrapper)->value(), isolate); |
9134 if (!script_obj->IsScript()) return {}; | 9133 if (!script_obj->IsScript()) return {}; |
9135 i::Handle<i::Script> script = i::Handle<i::Script>::cast(script_obj); | 9134 i::Handle<i::Script> script = i::Handle<i::Script>::cast(script_obj); |
9136 if (script->type() != i::Script::TYPE_WASM) return {}; | 9135 if (script->type() != i::Script::TYPE_WASM) return {}; |
9137 i::Handle<i::WasmCompiledModule> compiled_module( | 9136 i::Handle<i::WasmCompiledModule> compiled_module( |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9839 Address callback_address = | 9838 Address callback_address = |
9840 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9839 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
9841 VMState<EXTERNAL> state(isolate); | 9840 VMState<EXTERNAL> state(isolate); |
9842 ExternalCallbackScope call_scope(isolate, callback_address); | 9841 ExternalCallbackScope call_scope(isolate, callback_address); |
9843 callback(info); | 9842 callback(info); |
9844 } | 9843 } |
9845 | 9844 |
9846 | 9845 |
9847 } // namespace internal | 9846 } // namespace internal |
9848 } // namespace v8 | 9847 } // namespace v8 |
OLD | NEW |