| 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 9223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9234 } | 9234 } |
| 9235 | 9235 |
| 9236 namespace { | 9236 namespace { |
| 9237 int GetSmiValue(i::Handle<i::FixedArray> array, int index) { | 9237 int GetSmiValue(i::Handle<i::FixedArray> array, int index) { |
| 9238 return i::Smi::cast(array->get(index))->value(); | 9238 return i::Smi::cast(array->get(index))->value(); |
| 9239 } | 9239 } |
| 9240 } // namespace | 9240 } // namespace |
| 9241 | 9241 |
| 9242 bool debug::Script::GetPossibleBreakpoints( | 9242 bool debug::Script::GetPossibleBreakpoints( |
| 9243 const debug::Location& start, const debug::Location& end, | 9243 const debug::Location& start, const debug::Location& end, |
| 9244 bool restrict_to_function, std::vector<debug::Location>* locations) const { | 9244 bool restrict_to_function, |
| 9245 std::vector<debug::BreakLocation>* locations) const { |
| 9245 CHECK(!start.IsEmpty()); | 9246 CHECK(!start.IsEmpty()); |
| 9246 i::Handle<i::Script> script = Utils::OpenHandle(this); | 9247 i::Handle<i::Script> script = Utils::OpenHandle(this); |
| 9247 if (script->type() == i::Script::TYPE_WASM) { | 9248 if (script->type() == i::Script::TYPE_WASM) { |
| 9248 i::Handle<i::WasmCompiledModule> compiled_module( | 9249 i::Handle<i::WasmCompiledModule> compiled_module( |
| 9249 i::WasmCompiledModule::cast(script->wasm_compiled_module())); | 9250 i::WasmCompiledModule::cast(script->wasm_compiled_module())); |
| 9250 return compiled_module->GetPossibleBreakpoints(start, end, locations); | 9251 return compiled_module->GetPossibleBreakpoints(start, end, locations); |
| 9251 } | 9252 } |
| 9252 | 9253 |
| 9253 i::Script::InitLineEnds(script); | 9254 i::Script::InitLineEnds(script); |
| 9254 CHECK(script->line_ends()->IsFixedArray()); | 9255 CHECK(script->line_ends()->IsFixedArray()); |
| 9255 i::Isolate* isolate = script->GetIsolate(); | 9256 i::Isolate* isolate = script->GetIsolate(); |
| 9256 i::Handle<i::FixedArray> line_ends = | 9257 i::Handle<i::FixedArray> line_ends = |
| 9257 i::Handle<i::FixedArray>::cast(i::handle(script->line_ends(), isolate)); | 9258 i::Handle<i::FixedArray>::cast(i::handle(script->line_ends(), isolate)); |
| 9258 CHECK(line_ends->length()); | 9259 CHECK(line_ends->length()); |
| 9259 | 9260 |
| 9260 int start_offset = GetSourceOffset(start); | 9261 int start_offset = GetSourceOffset(start); |
| 9261 int end_offset = end.IsEmpty() | 9262 int end_offset = end.IsEmpty() |
| 9262 ? GetSmiValue(line_ends, line_ends->length() - 1) + 1 | 9263 ? GetSmiValue(line_ends, line_ends->length() - 1) + 1 |
| 9263 : GetSourceOffset(end); | 9264 : GetSourceOffset(end); |
| 9264 if (start_offset >= end_offset) return true; | 9265 if (start_offset >= end_offset) return true; |
| 9265 | 9266 |
| 9266 std::set<int> offsets; | 9267 std::vector<i::BreakLocation> v8_locations; |
| 9267 if (!isolate->debug()->GetPossibleBreakpoints( | 9268 if (!isolate->debug()->GetPossibleBreakpoints( |
| 9268 script, start_offset, end_offset, restrict_to_function, &offsets)) { | 9269 script, start_offset, end_offset, restrict_to_function, |
| 9270 &v8_locations)) { |
| 9269 return false; | 9271 return false; |
| 9270 } | 9272 } |
| 9271 | 9273 |
| 9274 std::map<int, i::BreakLocation> unique_locations; |
| 9275 for (const auto& location : v8_locations) { |
| 9276 auto it = unique_locations.find(location.position()); |
| 9277 if (it != unique_locations.end() && |
| 9278 (it->second.IsCall() || it->second.IsDebuggerStatement() || |
| 9279 it->second.IsReturn())) { |
| 9280 continue; |
| 9281 } |
| 9282 if (it == unique_locations.end()) { |
| 9283 unique_locations.insert(std::make_pair(location.position(), location)); |
| 9284 } else { |
| 9285 it->second = location; |
| 9286 } |
| 9287 } |
| 9272 int current_line_end_index = 0; | 9288 int current_line_end_index = 0; |
| 9273 for (const auto& it : offsets) { | 9289 for (const auto& it : unique_locations) { |
| 9274 int offset = it; | 9290 int offset = it.first; |
| 9275 while (offset > GetSmiValue(line_ends, current_line_end_index)) { | 9291 while (offset > GetSmiValue(line_ends, current_line_end_index)) { |
| 9276 ++current_line_end_index; | 9292 ++current_line_end_index; |
| 9277 CHECK(current_line_end_index < line_ends->length()); | 9293 CHECK(current_line_end_index < line_ends->length()); |
| 9278 } | 9294 } |
| 9279 int line_offset = 0; | 9295 int line_offset = 0; |
| 9280 | 9296 |
| 9281 if (current_line_end_index > 0) { | 9297 if (current_line_end_index > 0) { |
| 9282 line_offset = GetSmiValue(line_ends, current_line_end_index - 1) + 1; | 9298 line_offset = GetSmiValue(line_ends, current_line_end_index - 1) + 1; |
| 9283 } | 9299 } |
| 9284 locations->push_back(debug::Location( | 9300 debug::Location location( |
| 9285 current_line_end_index + script->line_offset(), | 9301 current_line_end_index + script->line_offset(), |
| 9286 offset - line_offset + | 9302 offset - line_offset + |
| 9287 (current_line_end_index == 0 ? script->column_offset() : 0))); | 9303 (current_line_end_index == 0 ? script->column_offset() : 0)); |
| 9304 locations->emplace_back(location, it.second.IsCall(), it.second.IsReturn(), |
| 9305 it.second.IsDebuggerStatement()); |
| 9288 } | 9306 } |
| 9289 return true; | 9307 return true; |
| 9290 } | 9308 } |
| 9291 | 9309 |
| 9292 int debug::Script::GetSourceOffset(const debug::Location& location) const { | 9310 int debug::Script::GetSourceOffset(const debug::Location& location) const { |
| 9293 i::Handle<i::Script> script = Utils::OpenHandle(this); | 9311 i::Handle<i::Script> script = Utils::OpenHandle(this); |
| 9294 if (script->type() == i::Script::TYPE_WASM) { | 9312 if (script->type() == i::Script::TYPE_WASM) { |
| 9295 // TODO(clemensh): Return the proper thing for wasm. | 9313 // TODO(clemensh): Return the proper thing for wasm. |
| 9296 return 0; | 9314 return 0; |
| 9297 } | 9315 } |
| (...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10280 Address callback_address = | 10298 Address callback_address = |
| 10281 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 10299 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 10282 VMState<EXTERNAL> state(isolate); | 10300 VMState<EXTERNAL> state(isolate); |
| 10283 ExternalCallbackScope call_scope(isolate, callback_address); | 10301 ExternalCallbackScope call_scope(isolate, callback_address); |
| 10284 callback(info); | 10302 callback(info); |
| 10285 } | 10303 } |
| 10286 | 10304 |
| 10287 | 10305 |
| 10288 } // namespace internal | 10306 } // namespace internal |
| 10289 } // namespace v8 | 10307 } // namespace v8 |
| OLD | NEW |