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