| 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 1675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1686 if (stack_trace->Length() > 0) { | 1686 if (stack_trace->Length() > 0) { |
| 1687 event.set_top_frame(stack_trace->FrameAt(0)); | 1687 event.set_top_frame(stack_trace->FrameAt(0)); |
| 1688 } | 1688 } |
| 1689 ASSERT(stack_trace_ == NULL); | 1689 ASSERT(stack_trace_ == NULL); |
| 1690 stack_trace_ = stack_trace; | 1690 stack_trace_ = stack_trace; |
| 1691 Pause(&event); | 1691 Pause(&event); |
| 1692 stack_trace_ = NULL; | 1692 stack_trace_ = NULL; |
| 1693 } | 1693 } |
| 1694 | 1694 |
| 1695 | 1695 |
| 1696 static TokenPosition LastTokenOnLine(const TokenStream& tokens, | 1696 static TokenPosition LastTokenOnLine(Zone* zone, |
| 1697 const TokenStream& tokens, |
| 1697 TokenPosition pos) { | 1698 TokenPosition pos) { |
| 1698 TokenStream::Iterator iter(tokens, | 1699 TokenStream::Iterator iter(zone, |
| 1700 tokens, |
| 1699 pos, | 1701 pos, |
| 1700 TokenStream::Iterator::kAllTokens); | 1702 TokenStream::Iterator::kAllTokens); |
| 1701 ASSERT(iter.IsValid()); | 1703 ASSERT(iter.IsValid()); |
| 1702 TokenPosition last_pos = pos; | 1704 TokenPosition last_pos = pos; |
| 1703 while ((iter.CurrentTokenKind() != Token::kNEWLINE) && | 1705 while ((iter.CurrentTokenKind() != Token::kNEWLINE) && |
| 1704 (iter.CurrentTokenKind() != Token::kEOS)) { | 1706 (iter.CurrentTokenKind() != Token::kEOS)) { |
| 1705 last_pos = iter.CurrentPosition(); | 1707 last_pos = iter.CurrentPosition(); |
| 1706 iter.Advance(); | 1708 iter.Advance(); |
| 1707 } | 1709 } |
| 1708 return last_pos; | 1710 return last_pos; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1773 ASSERT(func.HasCode()); | 1775 ASSERT(func.HasCode()); |
| 1774 ASSERT(!func.HasOptimizedCode()); | 1776 ASSERT(!func.HasOptimizedCode()); |
| 1775 | 1777 |
| 1776 if (requested_token_pos < func.token_pos()) { | 1778 if (requested_token_pos < func.token_pos()) { |
| 1777 requested_token_pos = func.token_pos(); | 1779 requested_token_pos = func.token_pos(); |
| 1778 } | 1780 } |
| 1779 if (last_token_pos > func.end_token_pos()) { | 1781 if (last_token_pos > func.end_token_pos()) { |
| 1780 last_token_pos = func.end_token_pos(); | 1782 last_token_pos = func.end_token_pos(); |
| 1781 } | 1783 } |
| 1782 | 1784 |
| 1783 Script& script = Script::Handle(func.script()); | 1785 Zone* zone = Thread::Current()->zone(); |
| 1784 Code& code = Code::Handle(func.unoptimized_code()); | 1786 Script& script = Script::Handle(zone, func.script()); |
| 1787 Code& code = Code::Handle(zone, func.unoptimized_code()); |
| 1785 ASSERT(!code.IsNull()); | 1788 ASSERT(!code.IsNull()); |
| 1786 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); | 1789 PcDescriptors& desc = PcDescriptors::Handle(zone, code.pc_descriptors()); |
| 1787 | 1790 |
| 1788 // First pass: find the safe point which is closest to the beginning | 1791 // First pass: find the safe point which is closest to the beginning |
| 1789 // of the given token range. | 1792 // of the given token range. |
| 1790 TokenPosition best_fit_pos = TokenPosition::kMaxSource; | 1793 TokenPosition best_fit_pos = TokenPosition::kMaxSource; |
| 1791 intptr_t best_column = INT_MAX; | 1794 intptr_t best_column = INT_MAX; |
| 1792 PcDescriptors::Iterator iter(desc, kSafepointKind); | 1795 PcDescriptors::Iterator iter(desc, kSafepointKind); |
| 1793 while (iter.MoveNext()) { | 1796 while (iter.MoveNext()) { |
| 1794 const TokenPosition pos = iter.TokenPos(); | 1797 const TokenPosition pos = iter.TokenPos(); |
| 1795 if ((!pos.IsReal()) || | 1798 if ((!pos.IsReal()) || |
| 1796 (pos < requested_token_pos) || | 1799 (pos < requested_token_pos) || |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1823 if (pos < best_fit_pos) { | 1826 if (pos < best_fit_pos) { |
| 1824 best_fit_pos = pos; | 1827 best_fit_pos = pos; |
| 1825 best_column = token_start_column; | 1828 best_column = token_start_column; |
| 1826 } | 1829 } |
| 1827 } | 1830 } |
| 1828 | 1831 |
| 1829 // Second pass (if we found a safe point in the first pass). Find | 1832 // Second pass (if we found a safe point in the first pass). Find |
| 1830 // the token on the line which is at the best fit column (if column | 1833 // the token on the line which is at the best fit column (if column |
| 1831 // was specified) and has the lowest code address. | 1834 // was specified) and has the lowest code address. |
| 1832 if (best_fit_pos != TokenPosition::kMaxSource) { | 1835 if (best_fit_pos != TokenPosition::kMaxSource) { |
| 1833 const Script& script = Script::Handle(func.script()); | 1836 const Script& script = Script::Handle(zone, func.script()); |
| 1834 const TokenStream& tokens = TokenStream::Handle(script.tokens()); | 1837 const TokenStream& tokens = TokenStream::Handle(zone, script.tokens()); |
| 1835 const TokenPosition begin_pos = best_fit_pos; | 1838 const TokenPosition begin_pos = best_fit_pos; |
| 1836 const TokenPosition end_of_line_pos = LastTokenOnLine(tokens, begin_pos); | 1839 const TokenPosition end_of_line_pos = |
| 1840 LastTokenOnLine(zone, tokens, begin_pos); |
| 1837 uword lowest_pc_offset = kUwordMax; | 1841 uword lowest_pc_offset = kUwordMax; |
| 1838 PcDescriptors::Iterator iter(desc, kSafepointKind); | 1842 PcDescriptors::Iterator iter(desc, kSafepointKind); |
| 1839 while (iter.MoveNext()) { | 1843 while (iter.MoveNext()) { |
| 1840 const TokenPosition pos = iter.TokenPos(); | 1844 const TokenPosition pos = iter.TokenPos(); |
| 1841 if (!pos.IsReal() || | 1845 if (!pos.IsReal() || |
| 1842 (pos < begin_pos) || | 1846 (pos < begin_pos) || |
| 1843 (pos > end_of_line_pos)) { | 1847 (pos > end_of_line_pos)) { |
| 1844 // Token is not on same line as best fit. | 1848 // Token is not on same line as best fit. |
| 1845 continue; | 1849 continue; |
| 1846 } | 1850 } |
| (...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2655 | 2659 |
| 2656 DebuggerEvent event(isolate_, DebuggerEvent::kBreakpointReached); | 2660 DebuggerEvent event(isolate_, DebuggerEvent::kBreakpointReached); |
| 2657 event.set_top_frame(top_frame); | 2661 event.set_top_frame(top_frame); |
| 2658 event.set_breakpoint(bpt); | 2662 event.set_breakpoint(bpt); |
| 2659 event.set_at_async_jump(IsAtAsyncJump(top_frame)); | 2663 event.set_at_async_jump(IsAtAsyncJump(top_frame)); |
| 2660 Pause(&event); | 2664 Pause(&event); |
| 2661 } | 2665 } |
| 2662 | 2666 |
| 2663 | 2667 |
| 2664 bool Debugger::IsAtAsyncJump(ActivationFrame* top_frame) { | 2668 bool Debugger::IsAtAsyncJump(ActivationFrame* top_frame) { |
| 2665 Object& closure_or_null = Object::Handle(top_frame->GetAsyncOperation()); | 2669 Zone* zone = Thread::Current()->zone(); |
| 2670 Object& closure_or_null = |
| 2671 Object::Handle(zone, top_frame->GetAsyncOperation()); |
| 2666 if (!closure_or_null.IsNull()) { | 2672 if (!closure_or_null.IsNull()) { |
| 2667 ASSERT(closure_or_null.IsInstance()); | 2673 ASSERT(closure_or_null.IsInstance()); |
| 2668 ASSERT(Instance::Cast(closure_or_null).IsClosure()); | 2674 ASSERT(Instance::Cast(closure_or_null).IsClosure()); |
| 2669 const Script& script = Script::Handle(top_frame->SourceScript()); | 2675 const Script& script = Script::Handle(zone, top_frame->SourceScript()); |
| 2670 const TokenStream& tokens = TokenStream::Handle(script.tokens()); | 2676 const TokenStream& tokens = TokenStream::Handle(zone, script.tokens()); |
| 2671 TokenStream::Iterator iter(tokens, top_frame->TokenPos()); | 2677 TokenStream::Iterator iter(zone, tokens, top_frame->TokenPos()); |
| 2672 if ((iter.CurrentTokenKind() == Token::kIDENT) && | 2678 if ((iter.CurrentTokenKind() == Token::kIDENT) && |
| 2673 ((iter.CurrentLiteral() == Symbols::Await().raw()) || | 2679 ((iter.CurrentLiteral() == Symbols::Await().raw()) || |
| 2674 (iter.CurrentLiteral() == Symbols::YieldKw().raw()))) { | 2680 (iter.CurrentLiteral() == Symbols::YieldKw().raw()))) { |
| 2675 return true; | 2681 return true; |
| 2676 } | 2682 } |
| 2677 } | 2683 } |
| 2678 return false; | 2684 return false; |
| 2679 } | 2685 } |
| 2680 | 2686 |
| 2681 RawError* Debugger::DebuggerStepCallback() { | 2687 RawError* Debugger::DebuggerStepCallback() { |
| (...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3354 | 3360 |
| 3355 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { | 3361 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { |
| 3356 ASSERT(bpt->next() == NULL); | 3362 ASSERT(bpt->next() == NULL); |
| 3357 bpt->set_next(code_breakpoints_); | 3363 bpt->set_next(code_breakpoints_); |
| 3358 code_breakpoints_ = bpt; | 3364 code_breakpoints_ = bpt; |
| 3359 } | 3365 } |
| 3360 | 3366 |
| 3361 #endif // !PRODUCT | 3367 #endif // !PRODUCT |
| 3362 | 3368 |
| 3363 } // namespace dart | 3369 } // namespace dart |
| OLD | NEW |