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 9239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9250 return compiled_module->GetPossibleBreakpoints(start, end, locations); | 9250 return compiled_module->GetPossibleBreakpoints(start, end, locations); |
9251 } | 9251 } |
9252 | 9252 |
9253 i::Script::InitLineEnds(script); | 9253 i::Script::InitLineEnds(script); |
9254 CHECK(script->line_ends()->IsFixedArray()); | 9254 CHECK(script->line_ends()->IsFixedArray()); |
9255 i::Isolate* isolate = script->GetIsolate(); | 9255 i::Isolate* isolate = script->GetIsolate(); |
9256 i::Handle<i::FixedArray> line_ends = | 9256 i::Handle<i::FixedArray> line_ends = |
9257 i::Handle<i::FixedArray>::cast(i::handle(script->line_ends(), isolate)); | 9257 i::Handle<i::FixedArray>::cast(i::handle(script->line_ends(), isolate)); |
9258 CHECK(line_ends->length()); | 9258 CHECK(line_ends->length()); |
9259 | 9259 |
9260 int start_offset = GetSourcePosition(start); | 9260 int start_offset = GetSourceOffset(start); |
9261 int end_offset; | 9261 int end_offset; |
9262 if (end.IsEmpty()) { | 9262 if (end.IsEmpty()) { |
alph
2017/02/27 22:01:29
nit: looks like a place for ternary op.
kozy
2017/02/27 23:16:35
Done.
| |
9263 end_offset = GetSmiValue(line_ends, line_ends->length() - 1) + 1; | 9263 end_offset = GetSmiValue(line_ends, line_ends->length() - 1) + 1; |
9264 } else { | 9264 } else { |
9265 end_offset = GetSourcePosition(end); | 9265 end_offset = GetSourceOffset(end); |
9266 } | 9266 } |
9267 if (start_offset >= end_offset) return true; | 9267 if (start_offset >= end_offset) return true; |
9268 | 9268 |
9269 std::set<int> offsets; | 9269 std::set<int> offsets; |
9270 if (!isolate->debug()->GetPossibleBreakpoints( | 9270 if (!isolate->debug()->GetPossibleBreakpoints( |
9271 script, start_offset, end_offset, restrict_to_function, &offsets)) { | 9271 script, start_offset, end_offset, restrict_to_function, &offsets)) { |
9272 return false; | 9272 return false; |
9273 } | 9273 } |
9274 | 9274 |
9275 int current_line_end_index = 0; | 9275 int current_line_end_index = 0; |
9276 for (const auto& it : offsets) { | 9276 for (const auto& it : offsets) { |
9277 int offset = it; | 9277 int offset = it; |
9278 while (offset > GetSmiValue(line_ends, current_line_end_index)) { | 9278 while (offset > GetSmiValue(line_ends, current_line_end_index)) { |
9279 ++current_line_end_index; | 9279 ++current_line_end_index; |
9280 CHECK(current_line_end_index < line_ends->length()); | 9280 CHECK(current_line_end_index < line_ends->length()); |
9281 } | 9281 } |
9282 int line_offset = 0; | 9282 int line_offset = 0; |
9283 | 9283 |
9284 if (current_line_end_index > 0) { | 9284 if (current_line_end_index > 0) { |
9285 line_offset = GetSmiValue(line_ends, current_line_end_index - 1) + 1; | 9285 line_offset = GetSmiValue(line_ends, current_line_end_index - 1) + 1; |
9286 } | 9286 } |
9287 locations->push_back(debug::Location( | 9287 locations->push_back(debug::Location( |
9288 current_line_end_index + script->line_offset(), | 9288 current_line_end_index + script->line_offset(), |
9289 offset - line_offset + | 9289 offset - line_offset + |
9290 (current_line_end_index == 0 ? script->column_offset() : 0))); | 9290 (current_line_end_index == 0 ? script->column_offset() : 0))); |
9291 } | 9291 } |
9292 return true; | 9292 return true; |
9293 } | 9293 } |
9294 | 9294 |
9295 int debug::Script::GetSourcePosition(const debug::Location& location) const { | 9295 int debug::Script::GetSourceOffset(const debug::Location& location) const { |
9296 i::Handle<i::Script> script = Utils::OpenHandle(this); | 9296 i::Handle<i::Script> script = Utils::OpenHandle(this); |
9297 if (script->type() == i::Script::TYPE_WASM) { | 9297 if (script->type() == i::Script::TYPE_WASM) { |
9298 // TODO(clemensh): Return the proper thing for wasm. | 9298 // TODO(clemensh): Return the proper thing for wasm. |
9299 return 0; | 9299 return 0; |
9300 } | 9300 } |
9301 | 9301 |
9302 int line = std::max(location.GetLineNumber() - script->line_offset(), 0); | 9302 int line = std::max(location.GetLineNumber() - script->line_offset(), 0); |
9303 int column = location.GetColumnNumber(); | 9303 int column = location.GetColumnNumber(); |
9304 if (line == 0) { | 9304 if (line == 0) { |
9305 column = std::max(0, column - script->column_offset()); | 9305 column = std::max(0, column - script->column_offset()); |
9306 } | 9306 } |
9307 | 9307 |
9308 i::Script::InitLineEnds(script); | 9308 i::Script::InitLineEnds(script); |
9309 CHECK(script->line_ends()->IsFixedArray()); | 9309 CHECK(script->line_ends()->IsFixedArray()); |
9310 i::Handle<i::FixedArray> line_ends = i::Handle<i::FixedArray>::cast( | 9310 i::Handle<i::FixedArray> line_ends = i::Handle<i::FixedArray>::cast( |
9311 i::handle(script->line_ends(), script->GetIsolate())); | 9311 i::handle(script->line_ends(), script->GetIsolate())); |
9312 CHECK(line_ends->length()); | 9312 CHECK(line_ends->length()); |
9313 if (line >= line_ends->length()) | 9313 if (line >= line_ends->length()) |
9314 return GetSmiValue(line_ends, line_ends->length() - 1); | 9314 return GetSmiValue(line_ends, line_ends->length() - 1); |
9315 int line_offset = GetSmiValue(line_ends, line); | 9315 int line_offset = GetSmiValue(line_ends, line); |
9316 if (line == 0) return std::min(column, line_offset); | 9316 if (line == 0) return std::min(column, line_offset); |
9317 int prev_line_offset = GetSmiValue(line_ends, line - 1); | 9317 int prev_line_offset = GetSmiValue(line_ends, line - 1); |
9318 return std::min(prev_line_offset + column + 1, line_offset); | 9318 return std::min(prev_line_offset + column + 1, line_offset); |
9319 } | 9319 } |
9320 | 9320 |
9321 v8::debug::Location debug::Script::GetSourceLocation(int offset) const { | |
9322 i::Handle<i::Script> script = Utils::OpenHandle(this); | |
9323 if (script->type() == i::Script::TYPE_WASM) { | |
9324 // TODO(clemensh): Return the proper thing for wasm. | |
9325 return v8::debug::Location(); | |
9326 } | |
9327 i::Script::PositionInfo info; | |
9328 i::Script::GetPositionInfo(script, offset, &info, i::Script::WITH_OFFSET); | |
9329 return debug::Location(info.line, info.column); | |
9330 } | |
9331 | |
9321 debug::WasmScript* debug::WasmScript::Cast(debug::Script* script) { | 9332 debug::WasmScript* debug::WasmScript::Cast(debug::Script* script) { |
9322 CHECK(script->IsWasm()); | 9333 CHECK(script->IsWasm()); |
9323 return static_cast<WasmScript*>(script); | 9334 return static_cast<WasmScript*>(script); |
9324 } | 9335 } |
9325 | 9336 |
9326 int debug::WasmScript::NumFunctions() const { | 9337 int debug::WasmScript::NumFunctions() const { |
9327 i::DisallowHeapAllocation no_gc; | 9338 i::DisallowHeapAllocation no_gc; |
9328 i::Handle<i::Script> script = Utils::OpenHandle(this); | 9339 i::Handle<i::Script> script = Utils::OpenHandle(this); |
9329 DCHECK_EQ(i::Script::TYPE_WASM, script->type()); | 9340 DCHECK_EQ(i::Script::TYPE_WASM, script->type()); |
9330 i::WasmCompiledModule* compiled_module = | 9341 i::WasmCompiledModule* compiled_module = |
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10272 Address callback_address = | 10283 Address callback_address = |
10273 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 10284 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
10274 VMState<EXTERNAL> state(isolate); | 10285 VMState<EXTERNAL> state(isolate); |
10275 ExternalCallbackScope call_scope(isolate, callback_address); | 10286 ExternalCallbackScope call_scope(isolate, callback_address); |
10276 callback(info); | 10287 callback(info); |
10277 } | 10288 } |
10278 | 10289 |
10279 | 10290 |
10280 } // namespace internal | 10291 } // namespace internal |
10281 } // namespace v8 | 10292 } // namespace v8 |
OLD | NEW |