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/debug/debug.h" | 5 #include "src/debug/debug.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 command_queue_(isolate->logger(), kQueueInitialSize), | 36 command_queue_(isolate->logger(), kQueueInitialSize), |
37 is_active_(false), | 37 is_active_(false), |
38 is_suppressed_(false), | 38 is_suppressed_(false), |
39 live_edit_enabled_(true), // TODO(yangguo): set to false by default. | 39 live_edit_enabled_(true), // TODO(yangguo): set to false by default. |
40 break_disabled_(false), | 40 break_disabled_(false), |
41 break_points_active_(true), | 41 break_points_active_(true), |
42 in_debug_event_listener_(false), | 42 in_debug_event_listener_(false), |
43 break_on_exception_(false), | 43 break_on_exception_(false), |
44 break_on_uncaught_exception_(false), | 44 break_on_uncaught_exception_(false), |
45 debug_info_list_(NULL), | 45 debug_info_list_(NULL), |
| 46 feature_tracker_(isolate), |
46 isolate_(isolate) { | 47 isolate_(isolate) { |
47 ThreadInit(); | 48 ThreadInit(); |
48 } | 49 } |
49 | 50 |
50 | 51 |
51 static v8::Local<v8::Context> GetDebugEventContext(Isolate* isolate) { | 52 static v8::Local<v8::Context> GetDebugEventContext(Isolate* isolate) { |
52 Handle<Context> context = isolate->debug()->debugger_entry()->GetContext(); | 53 Handle<Context> context = isolate->debug()->debugger_entry()->GetContext(); |
53 // Isolate::context() may have been NULL when "script collected" event | 54 // Isolate::context() may have been NULL when "script collected" event |
54 // occured. | 55 // occured. |
55 if (context.is_null()) return v8::Local<v8::Context>(); | 56 if (context.is_null()) return v8::Local<v8::Context>(); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 } | 310 } |
310 return false; | 311 return false; |
311 } | 312 } |
312 | 313 |
313 | 314 |
314 Handle<Object> BreakLocation::BreakPointObjects() const { | 315 Handle<Object> BreakLocation::BreakPointObjects() const { |
315 return debug_info_->GetBreakPointObjects(pc_offset_); | 316 return debug_info_->GetBreakPointObjects(pc_offset_); |
316 } | 317 } |
317 | 318 |
318 | 319 |
| 320 void DebugFeatureTracker::Track(DebugFeatureTracker::Feature feature) { |
| 321 uint32_t mask = 1 << feature; |
| 322 // Only count one sample per feature and isolate. |
| 323 if (bitfield_ & mask) return; |
| 324 isolate_->counters()->debug_feature_usage()->AddSample(feature); |
| 325 bitfield_ |= mask; |
| 326 } |
| 327 |
| 328 |
319 // Threading support. | 329 // Threading support. |
320 void Debug::ThreadInit() { | 330 void Debug::ThreadInit() { |
321 thread_local_.break_count_ = 0; | 331 thread_local_.break_count_ = 0; |
322 thread_local_.break_id_ = 0; | 332 thread_local_.break_id_ = 0; |
323 thread_local_.break_frame_id_ = StackFrame::NO_ID; | 333 thread_local_.break_frame_id_ = StackFrame::NO_ID; |
324 thread_local_.last_step_action_ = StepNone; | 334 thread_local_.last_step_action_ = StepNone; |
325 thread_local_.last_statement_position_ = RelocInfo::kNoPosition; | 335 thread_local_.last_statement_position_ = RelocInfo::kNoPosition; |
326 thread_local_.step_count_ = 0; | 336 thread_local_.step_count_ = 0; |
327 thread_local_.last_fp_ = 0; | 337 thread_local_.last_fp_ = 0; |
328 thread_local_.queued_step_count_ = 0; | 338 thread_local_.queued_step_count_ = 0; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 ExtensionConfiguration no_extensions; | 399 ExtensionConfiguration no_extensions; |
390 Handle<Context> context = isolate_->bootstrapper()->CreateEnvironment( | 400 Handle<Context> context = isolate_->bootstrapper()->CreateEnvironment( |
391 MaybeHandle<JSGlobalProxy>(), v8::Local<ObjectTemplate>(), &no_extensions, | 401 MaybeHandle<JSGlobalProxy>(), v8::Local<ObjectTemplate>(), &no_extensions, |
392 DEBUG_CONTEXT); | 402 DEBUG_CONTEXT); |
393 | 403 |
394 // Fail if no context could be created. | 404 // Fail if no context could be created. |
395 if (context.is_null()) return false; | 405 if (context.is_null()) return false; |
396 | 406 |
397 debug_context_ = Handle<Context>::cast( | 407 debug_context_ = Handle<Context>::cast( |
398 isolate_->global_handles()->Create(*context)); | 408 isolate_->global_handles()->Create(*context)); |
| 409 |
| 410 feature_tracker()->Track(DebugFeatureTracker::kActive); |
| 411 |
399 return true; | 412 return true; |
400 } | 413 } |
401 | 414 |
402 | 415 |
403 void Debug::Unload() { | 416 void Debug::Unload() { |
404 ClearAllBreakPoints(); | 417 ClearAllBreakPoints(); |
405 ClearStepping(); | 418 ClearStepping(); |
406 | 419 |
407 // Return debugger is not loaded. | 420 // Return debugger is not loaded. |
408 if (!is_loaded()) return; | 421 if (!is_loaded()) return; |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 Handle<DebugInfo> debug_info(shared->GetDebugInfo()); | 631 Handle<DebugInfo> debug_info(shared->GetDebugInfo()); |
619 // Source positions starts with zero. | 632 // Source positions starts with zero. |
620 DCHECK(*source_position >= 0); | 633 DCHECK(*source_position >= 0); |
621 | 634 |
622 // Find the break point and change it. | 635 // Find the break point and change it. |
623 BreakLocation location = BreakLocation::FromPosition( | 636 BreakLocation location = BreakLocation::FromPosition( |
624 debug_info, ALL_BREAK_LOCATIONS, *source_position, STATEMENT_ALIGNED); | 637 debug_info, ALL_BREAK_LOCATIONS, *source_position, STATEMENT_ALIGNED); |
625 *source_position = location.statement_position(); | 638 *source_position = location.statement_position(); |
626 location.SetBreakPoint(break_point_object); | 639 location.SetBreakPoint(break_point_object); |
627 | 640 |
| 641 feature_tracker()->Track(DebugFeatureTracker::kBreakPoint); |
| 642 |
628 // At least one active break point now. | 643 // At least one active break point now. |
629 return debug_info->GetBreakPointCount() > 0; | 644 return debug_info->GetBreakPointCount() > 0; |
630 } | 645 } |
631 | 646 |
632 | 647 |
633 bool Debug::SetBreakPointForScript(Handle<Script> script, | 648 bool Debug::SetBreakPointForScript(Handle<Script> script, |
634 Handle<Object> break_point_object, | 649 Handle<Object> break_point_object, |
635 int* source_position, | 650 int* source_position, |
636 BreakPositionAlignment alignment) { | 651 BreakPositionAlignment alignment) { |
637 HandleScope scope(isolate_); | 652 HandleScope scope(isolate_); |
(...skipping 21 matching lines...) Expand all Loading... |
659 | 674 |
660 Handle<DebugInfo> debug_info(shared->GetDebugInfo()); | 675 Handle<DebugInfo> debug_info(shared->GetDebugInfo()); |
661 // Source positions starts with zero. | 676 // Source positions starts with zero. |
662 DCHECK(position >= 0); | 677 DCHECK(position >= 0); |
663 | 678 |
664 // Find the break point and change it. | 679 // Find the break point and change it. |
665 BreakLocation location = BreakLocation::FromPosition( | 680 BreakLocation location = BreakLocation::FromPosition( |
666 debug_info, ALL_BREAK_LOCATIONS, position, alignment); | 681 debug_info, ALL_BREAK_LOCATIONS, position, alignment); |
667 location.SetBreakPoint(break_point_object); | 682 location.SetBreakPoint(break_point_object); |
668 | 683 |
| 684 feature_tracker()->Track(DebugFeatureTracker::kBreakPoint); |
| 685 |
669 position = (alignment == STATEMENT_ALIGNED) ? location.statement_position() | 686 position = (alignment == STATEMENT_ALIGNED) ? location.statement_position() |
670 : location.position(); | 687 : location.position(); |
671 | 688 |
672 *source_position = position + shared->start_position(); | 689 *source_position = position + shared->start_position(); |
673 | 690 |
674 // At least one active break point now. | 691 // At least one active break point now. |
675 DCHECK(debug_info->GetBreakPointCount() > 0); | 692 DCHECK(debug_info->GetBreakPointCount() > 0); |
676 return true; | 693 return true; |
677 } | 694 } |
678 | 695 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 if (id == StackFrame::NO_ID) { | 884 if (id == StackFrame::NO_ID) { |
868 // If there is no JavaScript stack don't do anything. | 885 // If there is no JavaScript stack don't do anything. |
869 return; | 886 return; |
870 } | 887 } |
871 if (frame_id != StackFrame::NO_ID) { | 888 if (frame_id != StackFrame::NO_ID) { |
872 id = frame_id; | 889 id = frame_id; |
873 } | 890 } |
874 JavaScriptFrameIterator frames_it(isolate_, id); | 891 JavaScriptFrameIterator frames_it(isolate_, id); |
875 JavaScriptFrame* frame = frames_it.frame(); | 892 JavaScriptFrame* frame = frames_it.frame(); |
876 | 893 |
| 894 feature_tracker()->Track(DebugFeatureTracker::kStepping); |
| 895 |
877 // First of all ensure there is one-shot break points in the top handler | 896 // First of all ensure there is one-shot break points in the top handler |
878 // if any. | 897 // if any. |
879 FloodHandlerWithOneShot(); | 898 FloodHandlerWithOneShot(); |
880 | 899 |
881 // If the function on the top frame is unresolved perform step out. This will | 900 // If the function on the top frame is unresolved perform step out. This will |
882 // be the case when calling unknown function and having the debugger stopped | 901 // be the case when calling unknown function and having the debugger stopped |
883 // in an unhandled exception. | 902 // in an unhandled exception. |
884 if (!frame->function()->IsJSFunction()) { | 903 if (!frame->function()->IsJSFunction()) { |
885 // Step out: Find the calling JavaScript frame and flood it with | 904 // Step out: Find the calling JavaScript frame and flood it with |
886 // breakpoints. | 905 // breakpoints. |
(...skipping 1715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2602 } | 2621 } |
2603 | 2622 |
2604 | 2623 |
2605 void LockingCommandMessageQueue::Clear() { | 2624 void LockingCommandMessageQueue::Clear() { |
2606 base::LockGuard<base::Mutex> lock_guard(&mutex_); | 2625 base::LockGuard<base::Mutex> lock_guard(&mutex_); |
2607 queue_.Clear(); | 2626 queue_.Clear(); |
2608 } | 2627 } |
2609 | 2628 |
2610 } // namespace internal | 2629 } // namespace internal |
2611 } // namespace v8 | 2630 } // namespace v8 |
OLD | NEW |