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 9193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9204 } | 9204 } |
9205 | 9205 |
9206 bool debug::Script::IsModule() const { | 9206 bool debug::Script::IsModule() const { |
9207 return Utils::OpenHandle(this)->origin_options().IsModule(); | 9207 return Utils::OpenHandle(this)->origin_options().IsModule(); |
9208 } | 9208 } |
9209 | 9209 |
9210 namespace { | 9210 namespace { |
9211 int GetSmiValue(i::Handle<i::FixedArray> array, int index) { | 9211 int GetSmiValue(i::Handle<i::FixedArray> array, int index) { |
9212 return i::Smi::cast(array->get(index))->value(); | 9212 return i::Smi::cast(array->get(index))->value(); |
9213 } | 9213 } |
| 9214 |
| 9215 bool CompareBreakLocation(const i::BreakLocation& loc1, |
| 9216 const i::BreakLocation& loc2) { |
| 9217 return loc1.position() < loc2.position(); |
| 9218 } |
9214 } // namespace | 9219 } // namespace |
9215 | 9220 |
9216 bool debug::Script::GetPossibleBreakpoints( | 9221 bool debug::Script::GetPossibleBreakpoints( |
9217 const debug::Location& start, const debug::Location& end, | 9222 const debug::Location& start, const debug::Location& end, |
9218 bool restrict_to_function, std::vector<debug::Location>* locations) const { | 9223 bool restrict_to_function, |
| 9224 std::vector<debug::BreakLocation>* locations) const { |
9219 CHECK(!start.IsEmpty()); | 9225 CHECK(!start.IsEmpty()); |
9220 i::Handle<i::Script> script = Utils::OpenHandle(this); | 9226 i::Handle<i::Script> script = Utils::OpenHandle(this); |
9221 if (script->type() == i::Script::TYPE_WASM) { | 9227 if (script->type() == i::Script::TYPE_WASM) { |
9222 i::Handle<i::WasmCompiledModule> compiled_module( | 9228 i::Handle<i::WasmCompiledModule> compiled_module( |
9223 i::WasmCompiledModule::cast(script->wasm_compiled_module())); | 9229 i::WasmCompiledModule::cast(script->wasm_compiled_module())); |
9224 return compiled_module->GetPossibleBreakpoints(start, end, locations); | 9230 return compiled_module->GetPossibleBreakpoints(start, end, locations); |
9225 } | 9231 } |
9226 | 9232 |
9227 i::Script::InitLineEnds(script); | 9233 i::Script::InitLineEnds(script); |
9228 CHECK(script->line_ends()->IsFixedArray()); | 9234 CHECK(script->line_ends()->IsFixedArray()); |
9229 i::Isolate* isolate = script->GetIsolate(); | 9235 i::Isolate* isolate = script->GetIsolate(); |
9230 i::Handle<i::FixedArray> line_ends = | 9236 i::Handle<i::FixedArray> line_ends = |
9231 i::Handle<i::FixedArray>::cast(i::handle(script->line_ends(), isolate)); | 9237 i::Handle<i::FixedArray>::cast(i::handle(script->line_ends(), isolate)); |
9232 CHECK(line_ends->length()); | 9238 CHECK(line_ends->length()); |
9233 | 9239 |
9234 int start_offset = GetSourceOffset(start); | 9240 int start_offset = GetSourceOffset(start); |
9235 int end_offset = end.IsEmpty() | 9241 int end_offset = end.IsEmpty() |
9236 ? GetSmiValue(line_ends, line_ends->length() - 1) + 1 | 9242 ? GetSmiValue(line_ends, line_ends->length() - 1) + 1 |
9237 : GetSourceOffset(end); | 9243 : GetSourceOffset(end); |
9238 if (start_offset >= end_offset) return true; | 9244 if (start_offset >= end_offset) return true; |
9239 | 9245 |
9240 std::set<int> offsets; | 9246 std::vector<i::BreakLocation> v8_locations; |
9241 if (!isolate->debug()->GetPossibleBreakpoints( | 9247 if (!isolate->debug()->GetPossibleBreakpoints( |
9242 script, start_offset, end_offset, restrict_to_function, &offsets)) { | 9248 script, start_offset, end_offset, restrict_to_function, |
| 9249 &v8_locations)) { |
9243 return false; | 9250 return false; |
9244 } | 9251 } |
9245 | 9252 |
| 9253 std::sort(v8_locations.begin(), v8_locations.end(), CompareBreakLocation); |
9246 int current_line_end_index = 0; | 9254 int current_line_end_index = 0; |
9247 for (const auto& it : offsets) { | 9255 for (const auto& v8_location : v8_locations) { |
9248 int offset = it; | 9256 int offset = v8_location.position(); |
9249 while (offset > GetSmiValue(line_ends, current_line_end_index)) { | 9257 while (offset > GetSmiValue(line_ends, current_line_end_index)) { |
9250 ++current_line_end_index; | 9258 ++current_line_end_index; |
9251 CHECK(current_line_end_index < line_ends->length()); | 9259 CHECK(current_line_end_index < line_ends->length()); |
9252 } | 9260 } |
9253 int line_offset = 0; | 9261 int line_offset = 0; |
9254 | 9262 |
9255 if (current_line_end_index > 0) { | 9263 if (current_line_end_index > 0) { |
9256 line_offset = GetSmiValue(line_ends, current_line_end_index - 1) + 1; | 9264 line_offset = GetSmiValue(line_ends, current_line_end_index - 1) + 1; |
9257 } | 9265 } |
9258 locations->push_back(debug::Location( | 9266 locations->emplace_back( |
9259 current_line_end_index + script->line_offset(), | 9267 current_line_end_index + script->line_offset(), |
9260 offset - line_offset + | 9268 offset - line_offset + |
9261 (current_line_end_index == 0 ? script->column_offset() : 0))); | 9269 (current_line_end_index == 0 ? script->column_offset() : 0), |
| 9270 v8_location.type()); |
9262 } | 9271 } |
9263 return true; | 9272 return true; |
9264 } | 9273 } |
9265 | 9274 |
9266 int debug::Script::GetSourceOffset(const debug::Location& location) const { | 9275 int debug::Script::GetSourceOffset(const debug::Location& location) const { |
9267 i::Handle<i::Script> script = Utils::OpenHandle(this); | 9276 i::Handle<i::Script> script = Utils::OpenHandle(this); |
9268 if (script->type() == i::Script::TYPE_WASM) { | 9277 if (script->type() == i::Script::TYPE_WASM) { |
9269 // TODO(clemensh): Return the proper thing for wasm. | 9278 // TODO(clemensh): Return the proper thing for wasm. |
9270 return 0; | 9279 return 0; |
9271 } | 9280 } |
(...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10247 Address callback_address = | 10256 Address callback_address = |
10248 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 10257 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
10249 VMState<EXTERNAL> state(isolate); | 10258 VMState<EXTERNAL> state(isolate); |
10250 ExternalCallbackScope call_scope(isolate, callback_address); | 10259 ExternalCallbackScope call_scope(isolate, callback_address); |
10251 callback(info); | 10260 callback(info); |
10252 } | 10261 } |
10253 | 10262 |
10254 | 10263 |
10255 } // namespace internal | 10264 } // namespace internal |
10256 } // namespace v8 | 10265 } // namespace v8 |
OLD | NEW |