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 "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 | 8 |
9 #include "vm/code_generator.h" | 9 #include "vm/code_generator.h" |
10 #include "vm/code_patcher.h" | 10 #include "vm/code_patcher.h" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 location.AddProperty("type", "Location"); | 149 location.AddProperty("type", "Location"); |
150 | 150 |
151 const String& url = String::Handle(script.url()); | 151 const String& url = String::Handle(script.url()); |
152 location.AddProperty("script", url.ToCString()); | 152 location.AddProperty("script", url.ToCString()); |
153 location.AddProperty("tokenPos", token_pos); | 153 location.AddProperty("tokenPos", token_pos); |
154 } | 154 } |
155 } | 155 } |
156 | 156 |
157 | 157 |
158 void CodeBreakpoint::VisitObjectPointers(ObjectPointerVisitor* visitor) { | 158 void CodeBreakpoint::VisitObjectPointers(ObjectPointerVisitor* visitor) { |
159 visitor->VisitPointer(reinterpret_cast<RawObject**>(&function_)); | 159 visitor->VisitPointer(reinterpret_cast<RawObject**>(&code_)); |
160 } | 160 } |
161 | 161 |
162 | 162 |
163 ActivationFrame::ActivationFrame( | 163 ActivationFrame::ActivationFrame( |
164 uword pc, | 164 uword pc, |
165 uword fp, | 165 uword fp, |
166 uword sp, | 166 uword sp, |
167 const Code& code, | 167 const Code& code, |
168 const Array& deopt_frame, | 168 const Array& deopt_frame, |
169 intptr_t deopt_frame_offset) | 169 intptr_t deopt_frame_offset) |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
699 (kind == PcDescriptors::kRuntimeCall)); | 699 (kind == PcDescriptors::kRuntimeCall)); |
700 } | 700 } |
701 | 701 |
702 | 702 |
703 static bool IsSafePoint(const PcDescriptors& desc, intptr_t i) { | 703 static bool IsSafePoint(const PcDescriptors& desc, intptr_t i) { |
704 return IsSafeDescKind(desc.DescriptorKind(i)) && | 704 return IsSafeDescKind(desc.DescriptorKind(i)) && |
705 (desc.TokenPos(i) != Scanner::kNoSourcePos); | 705 (desc.TokenPos(i) != Scanner::kNoSourcePos); |
706 } | 706 } |
707 | 707 |
708 | 708 |
709 CodeBreakpoint::CodeBreakpoint(const Function& func, intptr_t pc_desc_index) | 709 CodeBreakpoint::CodeBreakpoint(const Code& code, intptr_t pc_desc_index) |
710 : function_(func.raw()), | 710 : code_(code.raw()), |
711 pc_desc_index_(pc_desc_index), | 711 pc_desc_index_(pc_desc_index), |
712 pc_(0), | 712 pc_(0), |
713 line_number_(-1), | 713 line_number_(-1), |
714 is_enabled_(false), | 714 is_enabled_(false), |
715 src_bpt_(NULL), | 715 src_bpt_(NULL), |
716 next_(NULL) { | 716 next_(NULL) { |
717 saved_value_ = 0; | 717 saved_value_ = 0; |
718 ASSERT(!func.HasOptimizedCode()); | 718 ASSERT(!code.IsNull()); |
719 Code& code = Code::Handle(func.unoptimized_code()); | |
720 ASSERT(!code.IsNull()); // Function must be compiled. | |
721 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); | 719 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); |
722 ASSERT(pc_desc_index < desc.Length()); | 720 ASSERT(pc_desc_index < desc.Length()); |
723 token_pos_ = desc.TokenPos(pc_desc_index); | 721 token_pos_ = desc.TokenPos(pc_desc_index); |
724 ASSERT(token_pos_ > 0); | 722 ASSERT(token_pos_ > 0); |
725 pc_ = desc.PC(pc_desc_index); | 723 pc_ = desc.PC(pc_desc_index); |
726 ASSERT(pc_ != 0); | 724 ASSERT(pc_ != 0); |
727 breakpoint_kind_ = desc.DescriptorKind(pc_desc_index); | 725 breakpoint_kind_ = desc.DescriptorKind(pc_desc_index); |
728 ASSERT(IsSafeDescKind(breakpoint_kind_)); | 726 ASSERT(IsSafeDescKind(breakpoint_kind_)); |
729 } | 727 } |
730 | 728 |
731 | 729 |
732 CodeBreakpoint::~CodeBreakpoint() { | 730 CodeBreakpoint::~CodeBreakpoint() { |
733 // Make sure we don't leave patched code behind. | 731 // Make sure we don't leave patched code behind. |
734 ASSERT(!IsEnabled()); | 732 ASSERT(!IsEnabled()); |
735 // Poison the data so we catch use after free errors. | 733 // Poison the data so we catch use after free errors. |
736 #ifdef DEBUG | 734 #ifdef DEBUG |
737 function_ = Function::null(); | 735 code_ = Code::null(); |
738 pc_ = 0ul; | 736 pc_ = 0ul; |
739 src_bpt_ = NULL; | 737 src_bpt_ = NULL; |
740 next_ = NULL; | 738 next_ = NULL; |
741 breakpoint_kind_ = PcDescriptors::kOther; | 739 breakpoint_kind_ = PcDescriptors::kOther; |
742 #endif | 740 #endif |
743 } | 741 } |
744 | 742 |
745 | 743 |
744 RawFunction* CodeBreakpoint::function() const { | |
745 return Code::Handle(code_).function(); | |
746 } | |
747 | |
748 | |
746 RawScript* CodeBreakpoint::SourceCode() { | 749 RawScript* CodeBreakpoint::SourceCode() { |
747 const Function& func = Function::Handle(function_); | 750 const Function& func = Function::Handle(this->function()); |
748 return func.script(); | 751 return func.script(); |
749 } | 752 } |
750 | 753 |
751 | 754 |
752 RawString* CodeBreakpoint::SourceUrl() { | 755 RawString* CodeBreakpoint::SourceUrl() { |
753 const Script& script = Script::Handle(SourceCode()); | 756 const Script& script = Script::Handle(SourceCode()); |
754 return script.url(); | 757 return script.url(); |
755 } | 758 } |
756 | 759 |
757 | 760 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
959 if (!target_function.HasCode()) { | 962 if (!target_function.HasCode()) { |
960 Compiler::CompileFunction(target_function); | 963 Compiler::CompileFunction(target_function); |
961 // If there were any errors, ignore them silently and return without | 964 // If there were any errors, ignore them silently and return without |
962 // adding breakpoints to target. | 965 // adding breakpoints to target. |
963 if (!target_function.HasCode()) { | 966 if (!target_function.HasCode()) { |
964 return; | 967 return; |
965 } | 968 } |
966 } | 969 } |
967 DeoptimizeWorld(); | 970 DeoptimizeWorld(); |
968 ASSERT(!target_function.HasOptimizedCode()); | 971 ASSERT(!target_function.HasOptimizedCode()); |
969 Code& code = Code::Handle(target_function.unoptimized_code()); | 972 Code& code = Code::Handle(target_function.unoptimized_code()); |
zra
2014/01/24 23:04:14
If there might be a GC during DeoptimizeWorld, the
hausner
2014/01/24 23:54:30
Done.
| |
970 ASSERT(!code.IsNull()); | 973 ASSERT(!code.IsNull()); |
971 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); | 974 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); |
972 for (intptr_t i = 0; i < desc.Length(); i++) { | 975 for (intptr_t i = 0; i < desc.Length(); i++) { |
973 if (IsSafePoint(desc, i)) { | 976 if (IsSafePoint(desc, i)) { |
974 CodeBreakpoint* bpt = GetCodeBreakpoint(desc.PC(i)); | 977 CodeBreakpoint* bpt = GetCodeBreakpoint(desc.PC(i)); |
975 if (bpt != NULL) { | 978 if (bpt != NULL) { |
976 // There is already a breakpoint for this address. Make sure | 979 // There is already a breakpoint for this address. Make sure |
977 // it is enabled. | 980 // it is enabled. |
978 bpt->Enable(); | 981 bpt->Enable(); |
979 continue; | 982 continue; |
980 } | 983 } |
981 bpt = new CodeBreakpoint(target_function, i); | 984 bpt = new CodeBreakpoint(code, i); |
982 RegisterCodeBreakpoint(bpt); | 985 RegisterCodeBreakpoint(bpt); |
983 bpt->Enable(); | 986 bpt->Enable(); |
984 } | 987 } |
985 } | 988 } |
986 } | 989 } |
987 | 990 |
988 | 991 |
989 void Debugger::SignalBpResolved(SourceBreakpoint* bpt) { | 992 void Debugger::SignalBpResolved(SourceBreakpoint* bpt) { |
990 if (event_handler_ != NULL) { | 993 if (event_handler_ != NULL) { |
991 DebuggerEvent event(kBreakpointResolved); | 994 DebuggerEvent event(kBreakpointResolved); |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1299 ASSERT(!func.HasOptimizedCode()); | 1302 ASSERT(!func.HasOptimizedCode()); |
1300 Code& code = Code::Handle(func.unoptimized_code()); | 1303 Code& code = Code::Handle(func.unoptimized_code()); |
1301 ASSERT(!code.IsNull()); | 1304 ASSERT(!code.IsNull()); |
1302 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); | 1305 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); |
1303 for (intptr_t i = 0; i < desc.Length(); i++) { | 1306 for (intptr_t i = 0; i < desc.Length(); i++) { |
1304 intptr_t desc_token_pos = desc.TokenPos(i); | 1307 intptr_t desc_token_pos = desc.TokenPos(i); |
1305 if ((desc_token_pos == bpt->token_pos_) && IsSafePoint(desc, i)) { | 1308 if ((desc_token_pos == bpt->token_pos_) && IsSafePoint(desc, i)) { |
1306 CodeBreakpoint* code_bpt = GetCodeBreakpoint(desc.PC(i)); | 1309 CodeBreakpoint* code_bpt = GetCodeBreakpoint(desc.PC(i)); |
1307 if (code_bpt == NULL) { | 1310 if (code_bpt == NULL) { |
1308 // No code breakpoint for this code exists; create one. | 1311 // No code breakpoint for this code exists; create one. |
1309 code_bpt = new CodeBreakpoint(func, i); | 1312 code_bpt = new CodeBreakpoint(code, i); |
1310 RegisterCodeBreakpoint(code_bpt); | 1313 RegisterCodeBreakpoint(code_bpt); |
1311 } | 1314 } |
1312 code_bpt->set_src_bpt(bpt); | 1315 code_bpt->set_src_bpt(bpt); |
1313 if (bpt->IsEnabled()) { | 1316 if (bpt->IsEnabled()) { |
1314 code_bpt->Enable(); | 1317 code_bpt->Enable(); |
1315 } | 1318 } |
1316 } | 1319 } |
1317 } | 1320 } |
1318 } | 1321 } |
1319 | 1322 |
(...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2240 } | 2243 } |
2241 | 2244 |
2242 | 2245 |
2243 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { | 2246 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { |
2244 ASSERT(bpt->next() == NULL); | 2247 ASSERT(bpt->next() == NULL); |
2245 bpt->set_next(code_breakpoints_); | 2248 bpt->set_next(code_breakpoints_); |
2246 code_breakpoints_ = bpt; | 2249 code_breakpoints_ = bpt; |
2247 } | 2250 } |
2248 | 2251 |
2249 } // namespace dart | 2252 } // namespace dart |
OLD | NEW |