| 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 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 } | 893 } |
| 894 | 894 |
| 895 | 895 |
| 896 DebuggerStackTrace* Debugger::CollectStackTrace() { | 896 DebuggerStackTrace* Debugger::CollectStackTrace() { |
| 897 Isolate* isolate = Isolate::Current(); | 897 Isolate* isolate = Isolate::Current(); |
| 898 DebuggerStackTrace* stack_trace = new DebuggerStackTrace(8); | 898 DebuggerStackTrace* stack_trace = new DebuggerStackTrace(8); |
| 899 Context& ctx = Context::Handle(isolate->top_context()); | 899 Context& ctx = Context::Handle(isolate->top_context()); |
| 900 Code& code = Code::Handle(isolate); | 900 Code& code = Code::Handle(isolate); |
| 901 StackFrameIterator iterator(false); | 901 StackFrameIterator iterator(false); |
| 902 StackFrame* frame = iterator.NextFrame(); | 902 StackFrame* frame = iterator.NextFrame(); |
| 903 ActivationFrame* callee_activation = NULL; |
| 903 bool optimized_frame_found = false; | 904 bool optimized_frame_found = false; |
| 904 while (frame != NULL) { | 905 while (frame != NULL) { |
| 905 ASSERT(frame->IsValid()); | 906 ASSERT(frame->IsValid()); |
| 906 if (frame->IsDartFrame()) { | 907 if (frame->IsDartFrame()) { |
| 907 code = frame->LookupDartCode(); | 908 code = frame->LookupDartCode(); |
| 908 ActivationFrame* activation = new ActivationFrame(frame->pc(), | 909 ActivationFrame* activation = |
| 909 frame->fp(), | 910 new ActivationFrame(frame->pc(), frame->fp(), frame->sp(), code); |
| 910 frame->sp(), | |
| 911 code); | |
| 912 // If this activation frame called a closure, the function has | 911 // If this activation frame called a closure, the function has |
| 913 // saved its context before the call. | 912 // saved its context before the call. |
| 914 if (stack_trace->Length() > 0) { | 913 if ((callee_activation != NULL) && |
| 915 ActivationFrame* callee_frame = | 914 (callee_activation->function().IsClosureFunction())) { |
| 916 stack_trace->ActivationFrameAt(stack_trace->Length() - 1); | 915 ctx = activation->GetSavedCurrentContext(); |
| 917 if (callee_frame->function().IsClosureFunction()) { | 916 if (FLAG_verbose_debug && ctx.IsNull()) { |
| 918 ctx = activation->GetSavedCurrentContext(); | 917 const Function& caller = activation->function(); |
| 919 if (FLAG_verbose_debug && ctx.IsNull()) { | 918 const Function& callee = callee_activation->function(); |
| 920 const Function& caller = activation->function(); | 919 const Script& script = |
| 921 const Function& callee = callee_frame->function(); | 920 Script::Handle(Class::Handle(caller.Owner()).script()); |
| 922 const Script& script = | 921 intptr_t line, col; |
| 923 Script::Handle(Class::Handle(caller.Owner()).script()); | 922 script.GetTokenLocation(activation->TokenPos(), &line, &col); |
| 924 intptr_t line, col; | 923 OS::Print("CollectStackTrace error: no saved context in function " |
| 925 script.GetTokenLocation(activation->TokenPos(), &line, &col); | 924 "'%s' which calls closure '%s' " |
| 926 printf("CollectStackTrace error: no saved context in function " | 925 " in line %"Pd" column %"Pd"\n", |
| 927 "'%s' which calls closure '%s' " | 926 caller.ToFullyQualifiedCString(), |
| 928 " in line %"Pd" column %"Pd"\n", | 927 callee.ToFullyQualifiedCString(), |
| 929 caller.ToFullyQualifiedCString(), | 928 line, col); |
| 930 callee.ToFullyQualifiedCString(), | |
| 931 line, col); | |
| 932 } | |
| 933 ASSERT(!ctx.IsNull()); | |
| 934 } | 929 } |
| 930 ASSERT(!ctx.IsNull()); |
| 935 } | 931 } |
| 936 if (optimized_frame_found || code.is_optimized()) { | 932 if (optimized_frame_found || code.is_optimized()) { |
| 937 // Set context to null, to avoid returning bad context variable values. | 933 // Set context to null, to avoid returning bad context variable values. |
| 938 activation->SetContext(Context::Handle()); | 934 activation->SetContext(Context::Handle()); |
| 939 optimized_frame_found = true; | 935 optimized_frame_found = true; |
| 940 } else { | 936 } else { |
| 941 activation->SetContext(ctx); | 937 activation->SetContext(ctx); |
| 942 } | 938 } |
| 943 stack_trace->AddActivation(activation); | 939 stack_trace->AddActivation(activation); |
| 940 callee_activation = activation; |
| 944 // Get caller's context if this function saved it on entry. | 941 // Get caller's context if this function saved it on entry. |
| 945 ctx = activation->GetSavedEntryContext(ctx); | 942 ctx = activation->GetSavedEntryContext(ctx); |
| 946 } else if (frame->IsEntryFrame()) { | 943 } else if (frame->IsEntryFrame()) { |
| 947 ctx = reinterpret_cast<EntryFrame*>(frame)->SavedContext(); | 944 ctx = reinterpret_cast<EntryFrame*>(frame)->SavedContext(); |
| 945 callee_activation = NULL; |
| 948 } | 946 } |
| 949 frame = iterator.NextFrame(); | 947 frame = iterator.NextFrame(); |
| 950 } | 948 } |
| 951 return stack_trace; | 949 return stack_trace; |
| 952 } | 950 } |
| 953 | 951 |
| 954 | 952 |
| 955 void Debugger::SetExceptionPauseInfo(Dart_ExceptionPauseInfo pause_info) { | 953 void Debugger::SetExceptionPauseInfo(Dart_ExceptionPauseInfo pause_info) { |
| 956 ASSERT((pause_info == kNoPauseOnExceptions) || | 954 ASSERT((pause_info == kNoPauseOnExceptions) || |
| 957 (pause_info == kPauseOnUnhandledExceptions) || | 955 (pause_info == kPauseOnUnhandledExceptions) || |
| (...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1781 } | 1779 } |
| 1782 | 1780 |
| 1783 | 1781 |
| 1784 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { | 1782 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { |
| 1785 ASSERT(bpt->next() == NULL); | 1783 ASSERT(bpt->next() == NULL); |
| 1786 bpt->set_next(code_breakpoints_); | 1784 bpt->set_next(code_breakpoints_); |
| 1787 code_breakpoints_ = bpt; | 1785 code_breakpoints_ = bpt; |
| 1788 } | 1786 } |
| 1789 | 1787 |
| 1790 } // namespace dart | 1788 } // namespace dart |
| OLD | NEW |