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 9067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9078 i::HandleScope scope(isolate); | 9078 i::HandleScope scope(isolate); |
9079 for (i::StackTraceFrameIterator it(isolate); !it.done(); it.Advance()) { | 9079 for (i::StackTraceFrameIterator it(isolate); !it.done(); it.Advance()) { |
9080 if (!it.is_javascript()) continue; | 9080 if (!it.is_javascript()) continue; |
9081 if (!isolate->debug()->IsFrameBlackboxed(it.javascript_frame())) { | 9081 if (!isolate->debug()->IsFrameBlackboxed(it.javascript_frame())) { |
9082 return true; | 9082 return true; |
9083 } | 9083 } |
9084 } | 9084 } |
9085 return false; | 9085 return false; |
9086 } | 9086 } |
9087 | 9087 |
9088 Local<debug::BreakPoint> debug::BreakPoint::New(Isolate* v8_isolate, | |
9089 Local<Value> condition, | |
9090 Local<Value> data) { | |
9091 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | |
9092 ENTER_V8(isolate); | |
9093 i::HandleScope handle_scope(isolate); | |
9094 i::Handle<i::Object> condition_obj = Utils::OpenHandle(*condition); | |
Yang
2017/02/15 13:21:10
Can we limit the condition to strings only? empty
kozy
2017/02/15 16:21:33
Done.
| |
9095 i::Handle<i::Object> data_obj = Utils::OpenHandle(*data); | |
9096 i::Handle<i::BreakPoint> break_point = | |
9097 isolate->factory()->NewBreakPoint(condition_obj, data_obj); | |
9098 return ToApiHandle<debug::BreakPoint>( | |
9099 handle_scope.CloseAndEscape(break_point)); | |
9100 } | |
9101 | |
9102 MaybeLocal<debug::BreakPoint> debug::BreakPoint::Cast( | |
9103 Isolate* v8_isolate, v8::Local<v8::Value> value) { | |
9104 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | |
9105 ENTER_V8(isolate); | |
9106 i::HandleScope handle_scope(isolate); | |
9107 i::Handle<i::Object> break_point_obj = Utils::OpenHandle(*value); | |
9108 if (!break_point_obj->IsBreakPoint()) return MaybeLocal<debug::BreakPoint>(); | |
9109 i::Handle<i::BreakPoint> break_point(i::BreakPoint::cast(*break_point_obj), | |
9110 isolate); | |
9111 return ToApiHandle<debug::BreakPoint>( | |
9112 handle_scope.CloseAndEscape(break_point)); | |
9113 } | |
9114 | |
9115 v8::Local<v8::Value> debug::BreakPoint::Data() const { | |
9116 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | |
9117 i::HandleScope handle_scope(isolate); | |
9118 i::Handle<i::BreakPoint> break_point = Utils::OpenHandle(this); | |
9119 i::Handle<i::Object> data_obj(break_point->data(), isolate); | |
9120 return Utils::ToLocal(handle_scope.CloseAndEscape(data_obj)); | |
9121 } | |
9122 | |
9088 v8::Isolate* debug::Script::GetIsolate() const { | 9123 v8::Isolate* debug::Script::GetIsolate() const { |
9089 return reinterpret_cast<v8::Isolate*>(Utils::OpenHandle(this)->GetIsolate()); | 9124 return reinterpret_cast<v8::Isolate*>(Utils::OpenHandle(this)->GetIsolate()); |
9090 } | 9125 } |
9091 | 9126 |
9092 ScriptOriginOptions debug::Script::OriginOptions() const { | 9127 ScriptOriginOptions debug::Script::OriginOptions() const { |
9093 return Utils::OpenHandle(this)->origin_options(); | 9128 return Utils::OpenHandle(this)->origin_options(); |
9094 } | 9129 } |
9095 | 9130 |
9096 bool debug::Script::WasCompiled() const { | 9131 bool debug::Script::WasCompiled() const { |
9097 return Utils::OpenHandle(this)->compilation_state() == | 9132 return Utils::OpenHandle(this)->compilation_state() == |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9232 line_offset = GetSmiValue(line_ends, current_line_end_index - 1) + 1; | 9267 line_offset = GetSmiValue(line_ends, current_line_end_index - 1) + 1; |
9233 } | 9268 } |
9234 locations->push_back(debug::Location( | 9269 locations->push_back(debug::Location( |
9235 current_line_end_index + script->line_offset(), | 9270 current_line_end_index + script->line_offset(), |
9236 offset - line_offset + | 9271 offset - line_offset + |
9237 (current_line_end_index == 0 ? script->column_offset() : 0))); | 9272 (current_line_end_index == 0 ? script->column_offset() : 0))); |
9238 } | 9273 } |
9239 return true; | 9274 return true; |
9240 } | 9275 } |
9241 | 9276 |
9277 debug::Location debug::Script::SetBreakPoint( | |
9278 const debug::Location& position, | |
9279 Local<debug::BreakPoint> break_point) const { | |
9280 i::Handle<i::Script> script = Utils::OpenHandle(this); | |
9281 i::Isolate* isolate = script->GetIsolate(); | |
9282 int offset = GetSourcePosition(position); | |
9283 i::Handle<i::BreakPoint> break_point_obj = Utils::OpenHandle(*break_point); | |
9284 int result_offset = offset; | |
9285 if (!isolate->debug()->SetBreakPointForScript( | |
9286 script, break_point_obj, &result_offset, i::BREAK_POSITION_ALIGNED)) { | |
9287 return debug::Location(); | |
9288 } | |
9289 i::Script::PositionInfo info; | |
9290 i::Script::GetPositionInfo(script, result_offset, &info, | |
9291 i::Script::WITH_OFFSET); | |
9292 return debug::Location(info.line, info.column); | |
9293 } | |
9294 | |
9242 int debug::Script::GetSourcePosition(const debug::Location& location) const { | 9295 int debug::Script::GetSourcePosition(const debug::Location& location) const { |
9243 i::Handle<i::Script> script = Utils::OpenHandle(this); | 9296 i::Handle<i::Script> script = Utils::OpenHandle(this); |
9244 if (script->type() == i::Script::TYPE_WASM) { | 9297 if (script->type() == i::Script::TYPE_WASM) { |
9245 // TODO(clemensh): Return the proper thing for wasm. | 9298 return i::WasmCompiledModule::cast(script->wasm_compiled_module()) |
9246 return 0; | 9299 ->GetFunctionOffset(location.GetLineNumber()) + |
9300 location.GetColumnNumber(); | |
9247 } | 9301 } |
9248 | 9302 |
9249 int line = std::max(location.GetLineNumber() - script->line_offset(), 0); | 9303 int line = std::max(location.GetLineNumber() - script->line_offset(), 0); |
9250 int column = location.GetColumnNumber(); | 9304 int column = location.GetColumnNumber(); |
9251 if (line == 0) { | 9305 if (line == 0) { |
9252 column = std::max(0, column - script->column_offset()); | 9306 column = std::max(0, column - script->column_offset()); |
9253 } | 9307 } |
9254 | 9308 |
9255 i::Script::InitLineEnds(script); | 9309 i::Script::InitLineEnds(script); |
9256 CHECK(script->line_ends()->IsFixedArray()); | 9310 CHECK(script->line_ends()->IsFixedArray()); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9310 debug::WasmDisassembly debug::WasmScript::DisassembleFunction( | 9364 debug::WasmDisassembly debug::WasmScript::DisassembleFunction( |
9311 int function_index) const { | 9365 int function_index) const { |
9312 i::DisallowHeapAllocation no_gc; | 9366 i::DisallowHeapAllocation no_gc; |
9313 i::Handle<i::Script> script = Utils::OpenHandle(this); | 9367 i::Handle<i::Script> script = Utils::OpenHandle(this); |
9314 DCHECK_EQ(i::Script::TYPE_WASM, script->type()); | 9368 DCHECK_EQ(i::Script::TYPE_WASM, script->type()); |
9315 i::WasmCompiledModule* compiled_module = | 9369 i::WasmCompiledModule* compiled_module = |
9316 i::WasmCompiledModule::cast(script->wasm_compiled_module()); | 9370 i::WasmCompiledModule::cast(script->wasm_compiled_module()); |
9317 return compiled_module->DisassembleFunction(function_index); | 9371 return compiled_module->DisassembleFunction(function_index); |
9318 } | 9372 } |
9319 | 9373 |
9374 void debug::ClearBreakPoint(v8::Isolate* v8_isolate, | |
9375 Local<BreakPoint> break_point) { | |
9376 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | |
9377 ENTER_V8(isolate); | |
9378 i::Handle<i::Object> break_point_obj = Utils::OpenHandle(*break_point); | |
9379 isolate->debug()->ClearBreakPoint(break_point_obj); | |
9380 } | |
9381 | |
9320 debug::Location::Location(int line_number, int column_number) | 9382 debug::Location::Location(int line_number, int column_number) |
9321 : line_number_(line_number), column_number_(column_number) { | 9383 : line_number_(line_number), column_number_(column_number) { |
9322 CHECK(line_number >= 0); | 9384 CHECK(line_number >= 0); |
9323 CHECK(column_number >= 0); | 9385 CHECK(column_number >= 0); |
9324 } | 9386 } |
9325 | 9387 |
9326 debug::Location::Location() | 9388 debug::Location::Location() |
9327 : line_number_(v8::Function::kLineOffsetNotFound), | 9389 : line_number_(v8::Function::kLineOffsetNotFound), |
9328 column_number_(v8::Function::kLineOffsetNotFound) {} | 9390 column_number_(v8::Function::kLineOffsetNotFound) {} |
9329 | 9391 |
9330 int debug::Location::GetLineNumber() const { | 9392 int debug::Location::GetLineNumber() const { |
9331 CHECK(line_number_ >= 0); | 9393 CHECK(line_number_ >= 0); |
9332 return line_number_; | 9394 return line_number_; |
9333 } | 9395 } |
9334 | 9396 |
9335 int debug::Location::GetColumnNumber() const { | 9397 int debug::Location::GetColumnNumber() const { |
9336 CHECK(column_number_ >= 0); | 9398 CHECK(column_number_ >= 0); |
9337 return column_number_; | 9399 return column_number_; |
9338 } | 9400 } |
9339 | 9401 |
9340 bool debug::Location::IsEmpty() const { | 9402 bool debug::Location::IsEmpty() const { |
9341 return line_number_ == -1 && column_number_ == -1; | 9403 return line_number_ == v8::Function::kLineOffsetNotFound && |
9404 column_number_ == v8::Function::kLineOffsetNotFound; | |
9342 } | 9405 } |
9343 | 9406 |
9344 void debug::GetLoadedScripts(v8::Isolate* v8_isolate, | 9407 void debug::GetLoadedScripts(v8::Isolate* v8_isolate, |
9345 PersistentValueVector<debug::Script>& scripts) { | 9408 PersistentValueVector<debug::Script>& scripts) { |
9346 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 9409 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
9347 ENTER_V8(isolate); | 9410 ENTER_V8(isolate); |
9348 // TODO(kozyatinskiy): remove this GC once tests are dealt with. | 9411 // TODO(kozyatinskiy): remove this GC once tests are dealt with. |
9349 isolate->heap()->CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask, | 9412 isolate->heap()->CollectAllGarbage(i::Heap::kFinalizeIncrementalMarkingMask, |
9350 i::GarbageCollectionReason::kDebugger); | 9413 i::GarbageCollectionReason::kDebugger); |
9351 { | 9414 { |
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10169 Address callback_address = | 10232 Address callback_address = |
10170 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 10233 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
10171 VMState<EXTERNAL> state(isolate); | 10234 VMState<EXTERNAL> state(isolate); |
10172 ExternalCallbackScope call_scope(isolate, callback_address); | 10235 ExternalCallbackScope call_scope(isolate, callback_address); |
10173 callback(info); | 10236 callback(info); |
10174 } | 10237 } |
10175 | 10238 |
10176 | 10239 |
10177 } // namespace internal | 10240 } // namespace internal |
10178 } // namespace v8 | 10241 } // namespace v8 |
OLD | NEW |