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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 var_descriptors_(LocalVarDescriptors::ZoneHandle()), | 148 var_descriptors_(LocalVarDescriptors::ZoneHandle()), |
149 desc_indices_(8), | 149 desc_indices_(8), |
150 pc_desc_(PcDescriptors::ZoneHandle()) { | 150 pc_desc_(PcDescriptors::ZoneHandle()) { |
151 } | 151 } |
152 | 152 |
153 | 153 |
154 void Debugger::SignalIsolateEvent(EventType type) { | 154 void Debugger::SignalIsolateEvent(EventType type) { |
155 if (event_handler_ != NULL) { | 155 if (event_handler_ != NULL) { |
156 Debugger* debugger = Isolate::Current()->debugger(); | 156 Debugger* debugger = Isolate::Current()->debugger(); |
157 ASSERT(debugger != NULL); | 157 ASSERT(debugger != NULL); |
158 DebuggerEvent event; | 158 DebuggerEvent event(type); |
159 event.type = type; | |
160 event.isolate_id = debugger->GetIsolateId(); | 159 event.isolate_id = debugger->GetIsolateId(); |
161 ASSERT(event.isolate_id != ILLEGAL_ISOLATE_ID); | 160 ASSERT(event.isolate_id != ILLEGAL_ISOLATE_ID); |
162 if (type == kIsolateInterrupted) { | 161 if (type == kIsolateInterrupted) { |
163 DebuggerStackTrace* stack_trace = debugger->CollectStackTrace(); | 162 DebuggerStackTrace* stack_trace = debugger->CollectStackTrace(); |
164 ASSERT(stack_trace->Length() > 0); | 163 ASSERT(stack_trace->Length() > 0); |
165 ASSERT(debugger->stack_trace_ == NULL); | 164 ASSERT(debugger->stack_trace_ == NULL); |
166 ASSERT(debugger->obj_cache_ == NULL); | 165 ASSERT(debugger->obj_cache_ == NULL); |
167 debugger->obj_cache_ = new RemoteObjectCache(64); | 166 debugger->obj_cache_ = new RemoteObjectCache(64); |
168 debugger->stack_trace_ = stack_trace; | 167 debugger->stack_trace_ = stack_trace; |
169 (*event_handler_)(&event); | 168 (*event_handler_)(&event); |
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 bpt = new CodeBreakpoint(target_function, i); | 1036 bpt = new CodeBreakpoint(target_function, i); |
1038 RegisterCodeBreakpoint(bpt); | 1037 RegisterCodeBreakpoint(bpt); |
1039 bpt->Enable(); | 1038 bpt->Enable(); |
1040 } | 1039 } |
1041 } | 1040 } |
1042 } | 1041 } |
1043 | 1042 |
1044 | 1043 |
1045 void Debugger::SignalBpResolved(SourceBreakpoint* bpt) { | 1044 void Debugger::SignalBpResolved(SourceBreakpoint* bpt) { |
1046 if (event_handler_ != NULL) { | 1045 if (event_handler_ != NULL) { |
1047 DebuggerEvent event; | 1046 DebuggerEvent event(kBreakpointResolved); |
1048 event.type = kBreakpointResolved; | |
1049 event.breakpoint = bpt; | 1047 event.breakpoint = bpt; |
1050 (*event_handler_)(&event); | 1048 (*event_handler_)(&event); |
1051 } | 1049 } |
1052 } | 1050 } |
1053 | 1051 |
1054 | 1052 |
1055 static void PrintStackTraceError(const char* message, | 1053 static void PrintStackTraceError(const char* message, |
1056 ActivationFrame* current_activation, | 1054 ActivationFrame* current_activation, |
1057 ActivationFrame* callee_activation) { | 1055 ActivationFrame* callee_activation) { |
1058 const Function& current = current_activation->function(); | 1056 const Function& current = current_activation->function(); |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1383 } | 1381 } |
1384 DebuggerStackTrace* stack_trace = CollectStackTrace(); | 1382 DebuggerStackTrace* stack_trace = CollectStackTrace(); |
1385 if (!ShouldPauseOnException(stack_trace, exc)) { | 1383 if (!ShouldPauseOnException(stack_trace, exc)) { |
1386 return; | 1384 return; |
1387 } | 1385 } |
1388 ASSERT(stack_trace_ == NULL); | 1386 ASSERT(stack_trace_ == NULL); |
1389 stack_trace_ = stack_trace; | 1387 stack_trace_ = stack_trace; |
1390 ASSERT(obj_cache_ == NULL); | 1388 ASSERT(obj_cache_ == NULL); |
1391 in_event_notification_ = true; | 1389 in_event_notification_ = true; |
1392 obj_cache_ = new RemoteObjectCache(64); | 1390 obj_cache_ = new RemoteObjectCache(64); |
1393 DebuggerEvent event; | 1391 DebuggerEvent event(kExceptionThrown); |
1394 event.type = kExceptionThrown; | |
1395 event.exception = &exc; | 1392 event.exception = &exc; |
1396 (*event_handler_)(&event); | 1393 (*event_handler_)(&event); |
1397 in_event_notification_ = false; | 1394 in_event_notification_ = false; |
1398 stack_trace_ = NULL; | 1395 stack_trace_ = NULL; |
1399 obj_cache_ = NULL; // Remote object cache is zone allocated. | 1396 obj_cache_ = NULL; // Remote object cache is zone allocated. |
1400 } | 1397 } |
1401 | 1398 |
1402 | 1399 |
1403 // Given a function and a token position range, return the best fit | 1400 // Given a function and a token position range, return the best fit |
1404 // token position to set a breakpoint. | 1401 // token position to set a breakpoint. |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1876 (fkind == RawFunction::kNoSuchMethodDispatcher) || | 1873 (fkind == RawFunction::kNoSuchMethodDispatcher) || |
1877 (fkind == RawFunction::kInvokeFieldDispatcher)) { | 1874 (fkind == RawFunction::kInvokeFieldDispatcher)) { |
1878 return false; | 1875 return false; |
1879 } | 1876 } |
1880 const Class& cls = Class::Handle(func.Owner()); | 1877 const Class& cls = Class::Handle(func.Owner()); |
1881 const Library& lib = Library::Handle(cls.library()); | 1878 const Library& lib = Library::Handle(cls.library()); |
1882 return lib.IsDebuggable(); | 1879 return lib.IsDebuggable(); |
1883 } | 1880 } |
1884 | 1881 |
1885 | 1882 |
1886 void Debugger::SignalPausedEvent(ActivationFrame* top_frame) { | 1883 void Debugger::SignalPausedEvent(ActivationFrame* top_frame, |
| 1884 SourceBreakpoint* bpt) { |
1887 resume_action_ = kContinue; | 1885 resume_action_ = kContinue; |
1888 isolate_->set_single_step(false); | 1886 isolate_->set_single_step(false); |
1889 ASSERT(!in_event_notification_); | 1887 ASSERT(!in_event_notification_); |
1890 ASSERT(obj_cache_ == NULL); | 1888 ASSERT(obj_cache_ == NULL); |
1891 in_event_notification_ = true; | 1889 in_event_notification_ = true; |
1892 obj_cache_ = new RemoteObjectCache(64); | 1890 obj_cache_ = new RemoteObjectCache(64); |
1893 DebuggerEvent event; | 1891 DebuggerEvent event(kBreakpointReached); |
1894 event.type = kBreakpointReached; | |
1895 event.top_frame = top_frame; | 1892 event.top_frame = top_frame; |
| 1893 event.breakpoint = bpt; |
1896 (*event_handler_)(&event); | 1894 (*event_handler_)(&event); |
1897 in_event_notification_ = false; | 1895 in_event_notification_ = false; |
1898 obj_cache_ = NULL; // Remote object cache is zone allocated. | 1896 obj_cache_ = NULL; // Remote object cache is zone allocated. |
1899 } | 1897 } |
1900 | 1898 |
1901 | 1899 |
1902 void Debugger::SingleStepCallback() { | 1900 void Debugger::SingleStepCallback() { |
1903 ASSERT(resume_action_ == kSingleStep); | 1901 ASSERT(resume_action_ == kSingleStep); |
1904 ASSERT(isolate_->single_step()); | 1902 ASSERT(isolate_->single_step()); |
1905 // We can't get here unless the debugger event handler enabled | 1903 // We can't get here unless the debugger event handler enabled |
(...skipping 16 matching lines...) Expand all Loading... |
1922 | 1920 |
1923 if (FLAG_verbose_debug) { | 1921 if (FLAG_verbose_debug) { |
1924 OS::Print(">>> single step break at %s:%" Pd " (func %s token %" Pd ")\n", | 1922 OS::Print(">>> single step break at %s:%" Pd " (func %s token %" Pd ")\n", |
1925 String::Handle(frame->SourceUrl()).ToCString(), | 1923 String::Handle(frame->SourceUrl()).ToCString(), |
1926 frame->LineNumber(), | 1924 frame->LineNumber(), |
1927 String::Handle(frame->QualifiedFunctionName()).ToCString(), | 1925 String::Handle(frame->QualifiedFunctionName()).ToCString(), |
1928 frame->TokenPos()); | 1926 frame->TokenPos()); |
1929 } | 1927 } |
1930 | 1928 |
1931 stack_trace_ = CollectStackTrace(); | 1929 stack_trace_ = CollectStackTrace(); |
1932 SignalPausedEvent(frame); | 1930 SignalPausedEvent(frame, NULL); |
1933 | 1931 |
1934 RemoveInternalBreakpoints(); | 1932 RemoveInternalBreakpoints(); |
1935 if (resume_action_ == kStepOver) { | 1933 if (resume_action_ == kStepOver) { |
1936 InstrumentForStepping(func); | 1934 InstrumentForStepping(func); |
1937 } else if (resume_action_ == kStepOut) { | 1935 } else if (resume_action_ == kStepOut) { |
1938 if (stack_trace_->Length() > 1) { | 1936 if (stack_trace_->Length() > 1) { |
1939 ActivationFrame* caller_frame = stack_trace_->FrameAt(1); | 1937 ActivationFrame* caller_frame = stack_trace_->FrameAt(1); |
1940 InstrumentForStepping(caller_frame->function()); | 1938 InstrumentForStepping(caller_frame->function()); |
1941 } | 1939 } |
1942 } | 1940 } |
(...skipping 25 matching lines...) Expand all Loading... |
1968 report_bp ? "hit" : "ignore", | 1966 report_bp ? "hit" : "ignore", |
1969 bpt->IsInternal() ? "internal" : "user", | 1967 bpt->IsInternal() ? "internal" : "user", |
1970 String::Handle(bpt->SourceUrl()).ToCString(), | 1968 String::Handle(bpt->SourceUrl()).ToCString(), |
1971 bpt->LineNumber(), | 1969 bpt->LineNumber(), |
1972 bpt->token_pos(), | 1970 bpt->token_pos(), |
1973 top_frame->pc()); | 1971 top_frame->pc()); |
1974 } | 1972 } |
1975 | 1973 |
1976 if (report_bp && (event_handler_ != NULL)) { | 1974 if (report_bp && (event_handler_ != NULL)) { |
1977 stack_trace_ = stack_trace; | 1975 stack_trace_ = stack_trace; |
1978 SignalPausedEvent(top_frame); | 1976 SignalPausedEvent(top_frame, bpt->src_bpt_); |
1979 stack_trace_ = NULL; | 1977 stack_trace_ = NULL; |
1980 } | 1978 } |
1981 | 1979 |
1982 Function& func_to_instrument = Function::Handle(); | 1980 Function& func_to_instrument = Function::Handle(); |
1983 if (resume_action_ == kStepOver) { | 1981 if (resume_action_ == kStepOver) { |
1984 if (bpt->breakpoint_kind_ == PcDescriptors::kReturn) { | 1982 if (bpt->breakpoint_kind_ == PcDescriptors::kReturn) { |
1985 // Step over return is converted into a single step so we break at | 1983 // Step over return is converted into a single step so we break at |
1986 // the caller. | 1984 // the caller. |
1987 SetSingleStep(); | 1985 SetSingleStep(); |
1988 } else { | 1986 } else { |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2240 } | 2238 } |
2241 | 2239 |
2242 | 2240 |
2243 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { | 2241 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { |
2244 ASSERT(bpt->next() == NULL); | 2242 ASSERT(bpt->next() == NULL); |
2245 bpt->set_next(code_breakpoints_); | 2243 bpt->set_next(code_breakpoints_); |
2246 code_breakpoints_ = bpt; | 2244 code_breakpoints_ = bpt; |
2247 } | 2245 } |
2248 | 2246 |
2249 } // namespace dart | 2247 } // namespace dart |
OLD | NEW |