Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: src/api.cc

Issue 2728563002: [inspector] added type of break location into getPossibleBreakpoints output (Closed)
Patch Set: addressed comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/debug/debug.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 9197 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 } // namespace 9214 } // namespace
9215 9215
9216 bool debug::Script::GetPossibleBreakpoints( 9216 bool debug::Script::GetPossibleBreakpoints(
9217 const debug::Location& start, const debug::Location& end, 9217 const debug::Location& start, const debug::Location& end,
9218 bool restrict_to_function, std::vector<debug::Location>* locations) const { 9218 bool restrict_to_function,
9219 std::vector<debug::BreakLocation>* locations) const {
9219 CHECK(!start.IsEmpty()); 9220 CHECK(!start.IsEmpty());
9220 i::Handle<i::Script> script = Utils::OpenHandle(this); 9221 i::Handle<i::Script> script = Utils::OpenHandle(this);
9221 if (script->type() == i::Script::TYPE_WASM) { 9222 if (script->type() == i::Script::TYPE_WASM) {
9222 i::Handle<i::WasmCompiledModule> compiled_module( 9223 i::Handle<i::WasmCompiledModule> compiled_module(
9223 i::WasmCompiledModule::cast(script->wasm_compiled_module())); 9224 i::WasmCompiledModule::cast(script->wasm_compiled_module()));
9224 return compiled_module->GetPossibleBreakpoints(start, end, locations); 9225 return compiled_module->GetPossibleBreakpoints(start, end, locations);
9225 } 9226 }
9226 9227
9227 i::Script::InitLineEnds(script); 9228 i::Script::InitLineEnds(script);
9228 CHECK(script->line_ends()->IsFixedArray()); 9229 CHECK(script->line_ends()->IsFixedArray());
9229 i::Isolate* isolate = script->GetIsolate(); 9230 i::Isolate* isolate = script->GetIsolate();
9230 i::Handle<i::FixedArray> line_ends = 9231 i::Handle<i::FixedArray> line_ends =
9231 i::Handle<i::FixedArray>::cast(i::handle(script->line_ends(), isolate)); 9232 i::Handle<i::FixedArray>::cast(i::handle(script->line_ends(), isolate));
9232 CHECK(line_ends->length()); 9233 CHECK(line_ends->length());
9233 9234
9234 int start_offset = GetSourceOffset(start); 9235 int start_offset = GetSourceOffset(start);
9235 int end_offset = end.IsEmpty() 9236 int end_offset = end.IsEmpty()
9236 ? GetSmiValue(line_ends, line_ends->length() - 1) + 1 9237 ? GetSmiValue(line_ends, line_ends->length() - 1) + 1
9237 : GetSourceOffset(end); 9238 : GetSourceOffset(end);
9238 if (start_offset >= end_offset) return true; 9239 if (start_offset >= end_offset) return true;
9239 9240
9240 std::set<int> offsets; 9241 std::vector<i::BreakLocation> v8_locations;
9241 if (!isolate->debug()->GetPossibleBreakpoints( 9242 if (!isolate->debug()->GetPossibleBreakpoints(
9242 script, start_offset, end_offset, restrict_to_function, &offsets)) { 9243 script, start_offset, end_offset, restrict_to_function,
9244 &v8_locations)) {
9243 return false; 9245 return false;
9244 } 9246 }
9245 9247
9248 std::map<int, i::BreakLocation> unique_locations;
9249 for (const auto& location : v8_locations) {
dgozman 2017/03/03 18:55:56 I agree with Yang that we should move this to insp
kozy 2017/03/03 22:44:14 Done.
9250 auto it = unique_locations.find(location.position());
9251 if (it == unique_locations.end()) {
9252 unique_locations.insert(std::make_pair(location.position(), location));
9253 } else if (it->second.type() == debug::kCommonBreakLocation &&
9254 location.type() != debug::kCommonBreakLocation) {
9255 // debugger can returns more then one break location at the same source
9256 // location, e.g. foo() - in this case there are two break locations
9257 // before foo: for statement and for function call, we can merge them for
9258 // inspector and report only one with call type.
9259 DCHECK(location.IsCall());
9260 it->second = location;
9261 }
9262 }
9246 int current_line_end_index = 0; 9263 int current_line_end_index = 0;
9247 for (const auto& it : offsets) { 9264 for (const auto& it : unique_locations) {
9248 int offset = it; 9265 int offset = it.first;
9249 while (offset > GetSmiValue(line_ends, current_line_end_index)) { 9266 while (offset > GetSmiValue(line_ends, current_line_end_index)) {
9250 ++current_line_end_index; 9267 ++current_line_end_index;
9251 CHECK(current_line_end_index < line_ends->length()); 9268 CHECK(current_line_end_index < line_ends->length());
9252 } 9269 }
9253 int line_offset = 0; 9270 int line_offset = 0;
9254 9271
9255 if (current_line_end_index > 0) { 9272 if (current_line_end_index > 0) {
9256 line_offset = GetSmiValue(line_ends, current_line_end_index - 1) + 1; 9273 line_offset = GetSmiValue(line_ends, current_line_end_index - 1) + 1;
9257 } 9274 }
9258 locations->push_back(debug::Location( 9275 locations->emplace_back(
9259 current_line_end_index + script->line_offset(), 9276 current_line_end_index + script->line_offset(),
9260 offset - line_offset + 9277 offset - line_offset +
9261 (current_line_end_index == 0 ? script->column_offset() : 0))); 9278 (current_line_end_index == 0 ? script->column_offset() : 0),
9279 it.second.type());
9262 } 9280 }
9263 return true; 9281 return true;
9264 } 9282 }
9265 9283
9266 int debug::Script::GetSourceOffset(const debug::Location& location) const { 9284 int debug::Script::GetSourceOffset(const debug::Location& location) const {
9267 i::Handle<i::Script> script = Utils::OpenHandle(this); 9285 i::Handle<i::Script> script = Utils::OpenHandle(this);
9268 if (script->type() == i::Script::TYPE_WASM) { 9286 if (script->type() == i::Script::TYPE_WASM) {
9269 // TODO(clemensh): Return the proper thing for wasm. 9287 // TODO(clemensh): Return the proper thing for wasm.
9270 return 0; 9288 return 0;
9271 } 9289 }
(...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after
10247 Address callback_address = 10265 Address callback_address =
10248 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 10266 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
10249 VMState<EXTERNAL> state(isolate); 10267 VMState<EXTERNAL> state(isolate);
10250 ExternalCallbackScope call_scope(isolate, callback_address); 10268 ExternalCallbackScope call_scope(isolate, callback_address);
10251 callback(info); 10269 callback(info);
10252 } 10270 }
10253 10271
10254 10272
10255 } // namespace internal 10273 } // namespace internal
10256 } // namespace v8 10274 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/debug/debug.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698