OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/debugger.h" | 5 #include "vm/debugger.h" |
6 | 6 |
7 #include "vm/code_index_table.h" | 7 #include "vm/code_index_table.h" |
8 #include "vm/code_generator.h" | 8 #include "vm/code_generator.h" |
9 #include "vm/code_patcher.h" | 9 #include "vm/code_patcher.h" |
10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 line_number_(-1), | 301 line_number_(-1), |
302 is_enabled_(false), | 302 is_enabled_(false), |
303 src_bpt_(NULL), | 303 src_bpt_(NULL), |
304 next_(NULL) { | 304 next_(NULL) { |
305 ASSERT(!func.HasOptimizedCode()); | 305 ASSERT(!func.HasOptimizedCode()); |
306 Code& code = Code::Handle(func.unoptimized_code()); | 306 Code& code = Code::Handle(func.unoptimized_code()); |
307 ASSERT(!code.IsNull()); // Function must be compiled. | 307 ASSERT(!code.IsNull()); // Function must be compiled. |
308 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); | 308 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); |
309 ASSERT(pc_desc_index < desc.Length()); | 309 ASSERT(pc_desc_index < desc.Length()); |
310 token_index_ = desc.TokenIndex(pc_desc_index); | 310 token_index_ = desc.TokenIndex(pc_desc_index); |
311 ASSERT(token_index_ > 0); | 311 ASSERT(token_index_ >= 0); |
312 pc_ = desc.PC(pc_desc_index); | 312 pc_ = desc.PC(pc_desc_index); |
313 ASSERT(pc_ != 0); | 313 ASSERT(pc_ != 0); |
314 breakpoint_kind_ = desc.DescriptorKind(pc_desc_index); | 314 breakpoint_kind_ = desc.DescriptorKind(pc_desc_index); |
315 } | 315 } |
316 | 316 |
317 | 317 |
318 CodeBreakpoint::~CodeBreakpoint() { | 318 CodeBreakpoint::~CodeBreakpoint() { |
319 // Make sure we don't leave patched code behind. | 319 // Make sure we don't leave patched code behind. |
320 ASSERT(!IsEnabled()); | 320 ASSERT(!IsEnabled()); |
321 } | 321 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
408 ASSERT(!is_enabled_); | 408 ASSERT(!is_enabled_); |
409 } | 409 } |
410 | 410 |
411 | 411 |
412 Debugger::Debugger() | 412 Debugger::Debugger() |
413 : isolate_(NULL), | 413 : isolate_(NULL), |
414 initialized_(false), | 414 initialized_(false), |
415 bp_handler_(NULL), | 415 bp_handler_(NULL), |
416 src_breakpoints_(NULL), | 416 src_breakpoints_(NULL), |
417 code_breakpoints_(NULL), | 417 code_breakpoints_(NULL), |
418 resume_action_(kContinue) { | 418 resume_action_(kContinue), |
419 ignore_breakpoints_(false) { | |
419 } | 420 } |
420 | 421 |
421 | 422 |
422 Debugger::~Debugger() { | 423 Debugger::~Debugger() { |
423 ASSERT(src_breakpoints_ == NULL); | 424 ASSERT(src_breakpoints_ == NULL); |
424 ASSERT(code_breakpoints_ == NULL); | 425 ASSERT(code_breakpoints_ == NULL); |
425 } | 426 } |
426 | 427 |
427 | 428 |
428 void Debugger::Shutdown() { | 429 void Debugger::Shutdown() { |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
666 const String& field_name, | 667 const String& field_name, |
667 const Instance& object) { | 668 const Instance& object) { |
668 const Function& getter_func = | 669 const Function& getter_func = |
669 Function::Handle(cls.LookupGetterFunction(field_name)); | 670 Function::Handle(cls.LookupGetterFunction(field_name)); |
670 ASSERT(!getter_func.IsNull()); | 671 ASSERT(!getter_func.IsNull()); |
671 | 672 |
672 Object& result = Object::Handle(); | 673 Object& result = Object::Handle(); |
673 LongJump* base = isolate_->long_jump_base(); | 674 LongJump* base = isolate_->long_jump_base(); |
674 LongJump jump; | 675 LongJump jump; |
675 isolate_->set_long_jump_base(&jump); | 676 isolate_->set_long_jump_base(&jump); |
677 bool saved_ignore_flag = ignore_breakpoints_; | |
678 ignore_breakpoints_ = true; | |
676 if (setjmp(*jump.Set()) == 0) { | 679 if (setjmp(*jump.Set()) == 0) { |
677 GrowableArray<const Object*> noArguments; | 680 GrowableArray<const Object*> noArguments; |
678 const Array& noArgumentNames = Array::Handle(); | 681 const Array& noArgumentNames = Array::Handle(); |
679 result = DartEntry::InvokeDynamic(object, getter_func, | 682 result = DartEntry::InvokeDynamic(object, getter_func, |
680 noArguments, noArgumentNames); | 683 noArguments, noArgumentNames); |
681 } else { | 684 } else { |
682 result = isolate_->object_store()->sticky_error(); | 685 result = isolate_->object_store()->sticky_error(); |
683 } | 686 } |
687 ignore_breakpoints_ = saved_ignore_flag; | |
siva
2012/03/10 00:11:40
Why save and restore the flag instead of just sett
hausner
2012/03/10 00:41:56
I thought it's more future-proof to allow for recu
siva
2012/03/12 22:19:14
Sounds like premature optimization :-)
On 2012/03
| |
684 isolate_->set_long_jump_base(base); | 688 isolate_->set_long_jump_base(base); |
685 return result.raw(); | 689 return result.raw(); |
686 } | 690 } |
687 | 691 |
688 | 692 |
689 RawObject* Debugger::GetStaticField(const Class& cls, | 693 RawObject* Debugger::GetStaticField(const Class& cls, |
690 const String& field_name) { | 694 const String& field_name) { |
691 const Function& getter_func = | 695 const Function& getter_func = |
692 Function::Handle(cls.LookupGetterFunction(field_name)); | 696 Function::Handle(cls.LookupGetterFunction(field_name)); |
693 ASSERT(!getter_func.IsNull()); | 697 ASSERT(!getter_func.IsNull()); |
694 | 698 |
695 Object& result = Object::Handle(); | 699 Object& result = Object::Handle(); |
696 LongJump* base = isolate_->long_jump_base(); | 700 LongJump* base = isolate_->long_jump_base(); |
697 LongJump jump; | 701 LongJump jump; |
698 isolate_->set_long_jump_base(&jump); | 702 isolate_->set_long_jump_base(&jump); |
703 bool saved_ignore_flag = ignore_breakpoints_; | |
704 ignore_breakpoints_ = true; | |
699 if (setjmp(*jump.Set()) == 0) { | 705 if (setjmp(*jump.Set()) == 0) { |
700 GrowableArray<const Object*> noArguments; | 706 GrowableArray<const Object*> noArguments; |
701 const Array& noArgumentNames = Array::Handle(); | 707 const Array& noArgumentNames = Array::Handle(); |
702 result = DartEntry::InvokeStatic(getter_func, noArguments, noArgumentNames); | 708 result = DartEntry::InvokeStatic(getter_func, noArguments, noArgumentNames); |
703 } else { | 709 } else { |
704 result = isolate_->object_store()->sticky_error(); | 710 result = isolate_->object_store()->sticky_error(); |
705 } | 711 } |
712 ignore_breakpoints_ = saved_ignore_flag; | |
706 isolate_->set_long_jump_base(base); | 713 isolate_->set_long_jump_base(base); |
707 return result.raw(); | 714 return result.raw(); |
708 } | 715 } |
709 | 716 |
710 | 717 |
711 RawArray* Debugger::GetInstanceFields(const Instance& obj) { | 718 RawArray* Debugger::GetInstanceFields(const Instance& obj) { |
712 Class& cls = Class::Handle(obj.clazz()); | 719 Class& cls = Class::Handle(obj.clazz()); |
713 Array& fields = Array::Handle(); | 720 Array& fields = Array::Handle(); |
714 Field& field = Field::Handle(); | 721 Field& field = Field::Handle(); |
715 const GrowableObjectArray& field_list = | 722 const GrowableObjectArray& field_list = |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
791 void Debugger::SetBreakpointHandler(BreakpointHandler* handler) { | 798 void Debugger::SetBreakpointHandler(BreakpointHandler* handler) { |
792 bp_handler_ = handler; | 799 bp_handler_ = handler; |
793 if (bp_handler_ == NULL) { | 800 if (bp_handler_ == NULL) { |
794 bp_handler_ = &DefaultBreakpointHandler; | 801 bp_handler_ = &DefaultBreakpointHandler; |
795 } | 802 } |
796 } | 803 } |
797 | 804 |
798 | 805 |
799 void Debugger::BreakpointCallback() { | 806 void Debugger::BreakpointCallback() { |
800 ASSERT(initialized_); | 807 ASSERT(initialized_); |
808 | |
809 if (ignore_breakpoints_) { | |
810 return; | |
811 } | |
801 DartFrameIterator iterator; | 812 DartFrameIterator iterator; |
802 DartFrame* frame = iterator.NextFrame(); | 813 DartFrame* frame = iterator.NextFrame(); |
803 ASSERT(frame != NULL); | 814 ASSERT(frame != NULL); |
804 CodeBreakpoint* bpt = GetCodeBreakpoint(frame->pc()); | 815 CodeBreakpoint* bpt = GetCodeBreakpoint(frame->pc()); |
805 ASSERT(bpt != NULL); | 816 ASSERT(bpt != NULL); |
806 if (verbose) { | 817 if (verbose) { |
807 OS::Print(">>> %s breakpoint at %s:%d (Address %p)\n", | 818 OS::Print(">>> %s breakpoint at %s:%d (Address %p)\n", |
808 bpt->IsInternal() ? "hit internal" : "hit user", | 819 bpt->IsInternal() ? "hit internal" : "hit user", |
809 bpt ? String::Handle(bpt->SourceUrl()).ToCString() : "?", | 820 bpt ? String::Handle(bpt->SourceUrl()).ToCString() : "?", |
810 bpt ? bpt->LineNumber() : 0, | 821 bpt ? bpt->LineNumber() : 0, |
811 frame->pc()); | 822 frame->pc()); |
812 } | 823 } |
813 DebuggerStackTrace* stack_trace = new DebuggerStackTrace(8); | 824 DebuggerStackTrace* stack_trace = new DebuggerStackTrace(8); |
814 while (frame != NULL) { | 825 while (frame != NULL) { |
815 ASSERT(frame->IsValid()); | 826 ASSERT(frame->IsValid()); |
816 ASSERT(frame->IsDartFrame()); | 827 ASSERT(frame->IsDartFrame()); |
817 ActivationFrame* activation = | 828 ActivationFrame* activation = |
818 new ActivationFrame(frame->pc(), frame->fp(), frame->sp()); | 829 new ActivationFrame(frame->pc(), frame->fp(), frame->sp()); |
819 stack_trace->AddActivation(activation); | 830 stack_trace->AddActivation(activation); |
820 frame = iterator.NextFrame(); | 831 frame = iterator.NextFrame(); |
821 } | 832 } |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1010 } | 1021 } |
1011 | 1022 |
1012 | 1023 |
1013 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { | 1024 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { |
1014 ASSERT(bpt->next() == NULL); | 1025 ASSERT(bpt->next() == NULL); |
1015 bpt->set_next(code_breakpoints_); | 1026 bpt->set_next(code_breakpoints_); |
1016 code_breakpoints_ = bpt; | 1027 code_breakpoints_ = bpt; |
1017 } | 1028 } |
1018 | 1029 |
1019 } // namespace dart | 1030 } // namespace dart |
OLD | NEW |