Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: vm/debugger.cc

Issue 12225031: Minor cleanup of activation frame creation code. Get the code object while iterating the frames as … (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « vm/debugger.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 128 }
129 129
130 130
131 131
132 void CodeBreakpoint::VisitObjectPointers(ObjectPointerVisitor* visitor) { 132 void CodeBreakpoint::VisitObjectPointers(ObjectPointerVisitor* visitor) {
133 visitor->VisitPointer(reinterpret_cast<RawObject**>(&function_)); 133 visitor->VisitPointer(reinterpret_cast<RawObject**>(&function_));
134 } 134 }
135 135
136 136
137 ActivationFrame::ActivationFrame(uword pc, uword fp, uword sp, 137 ActivationFrame::ActivationFrame(uword pc, uword fp, uword sp,
138 const Code& code,
138 const Context& ctx) 139 const Context& ctx)
139 : pc_(pc), fp_(fp), sp_(sp), 140 : pc_(pc), fp_(fp), sp_(sp),
140 ctx_(Context::ZoneHandle(ctx.raw())), 141 ctx_(Context::ZoneHandle(ctx.raw())),
141 function_(Function::ZoneHandle()), 142 code_(Code::ZoneHandle(code.raw())),
142 code_(Code::ZoneHandle()), 143 function_(Function::ZoneHandle(code.function())),
143 token_pos_(-1), 144 token_pos_(-1),
144 pc_desc_index_(-1), 145 pc_desc_index_(-1),
145 line_number_(-1), 146 line_number_(-1),
146 context_level_(-1), 147 context_level_(-1),
147 vars_initialized_(false), 148 vars_initialized_(false),
148 var_descriptors_(LocalVarDescriptors::ZoneHandle()), 149 var_descriptors_(LocalVarDescriptors::ZoneHandle()),
149 desc_indices_(8), 150 desc_indices_(8),
150 pc_desc_(PcDescriptors::ZoneHandle()) { 151 pc_desc_(PcDescriptors::ZoneHandle()) {
151 } 152 }
152 153
153 154
154 const Code& ActivationFrame::DartCode() {
155 if (code_.IsNull()) {
156 Isolate* isolate = Isolate::Current();
157 ASSERT(isolate != NULL);
158 code_ = Code::LookupCode(pc_);
159 }
160 return code_;
161 }
162
163
164 const Function& ActivationFrame::DartFunction() {
165 if (function_.IsNull()) {
166 function_ = DartCode().function();
167 }
168 return function_;
169 }
170
171
172 void Debugger::SignalIsolateEvent(EventType type) { 155 void Debugger::SignalIsolateEvent(EventType type) {
173 if (event_handler_ != NULL) { 156 if (event_handler_ != NULL) {
174 Debugger* debugger = Isolate::Current()->debugger(); 157 Debugger* debugger = Isolate::Current()->debugger();
175 ASSERT(debugger != NULL); 158 ASSERT(debugger != NULL);
176 DebuggerEvent event; 159 DebuggerEvent event;
177 event.type = type; 160 event.type = type;
178 event.isolate_id = debugger->GetIsolateId(); 161 event.isolate_id = debugger->GetIsolateId();
179 ASSERT(event.isolate_id != ILLEGAL_ISOLATE_ID); 162 ASSERT(event.isolate_id != ILLEGAL_ISOLATE_ID);
180 if (type == kIsolateInterrupted) { 163 if (type == kIsolateInterrupted) {
181 DebuggerStackTrace* stack_trace = debugger->CollectStackTrace(); 164 DebuggerStackTrace* stack_trace = debugger->CollectStackTrace();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 if (func.raw() == cbpt->function()) { 217 if (func.raw() == cbpt->function()) {
235 return true; 218 return true;
236 } 219 }
237 cbpt = cbpt->next_; 220 cbpt = cbpt->next_;
238 } 221 }
239 return false; 222 return false;
240 } 223 }
241 224
242 225
243 RawString* ActivationFrame::QualifiedFunctionName() { 226 RawString* ActivationFrame::QualifiedFunctionName() {
244 const Function& func = DartFunction(); 227 return String::New(Debugger::QualifiedFunctionName(function()));
245 return String::New(Debugger::QualifiedFunctionName(func));
246 } 228 }
247 229
248 230
249 RawString* ActivationFrame::SourceUrl() { 231 RawString* ActivationFrame::SourceUrl() {
250 const Script& script = Script::Handle(SourceScript()); 232 const Script& script = Script::Handle(SourceScript());
251 return script.url(); 233 return script.url();
252 } 234 }
253 235
254 236
255 RawScript* ActivationFrame::SourceScript() { 237 RawScript* ActivationFrame::SourceScript() {
256 const Function& func = DartFunction(); 238 return function().script();
257 return func.script();
258 } 239 }
259 240
260 241
261 RawLibrary* ActivationFrame::Library() { 242 RawLibrary* ActivationFrame::Library() {
262 const Function& func = DartFunction(); 243 const Class& cls = Class::Handle(function().Owner());
263 const Class& cls = Class::Handle(func.Owner());
264 return cls.library(); 244 return cls.library();
265 } 245 }
266 246
267 247
268 void ActivationFrame::GetPcDescriptors() { 248 void ActivationFrame::GetPcDescriptors() {
269 if (pc_desc_.IsNull()) { 249 if (pc_desc_.IsNull()) {
270 const Code& code = DartCode(); 250 pc_desc_ = code().pc_descriptors();
271 ASSERT(!code.IsNull());
272 pc_desc_ = code.pc_descriptors();
273 ASSERT(!pc_desc_.IsNull()); 251 ASSERT(!pc_desc_.IsNull());
274 } 252 }
275 } 253 }
276 254
277 255
278 // Compute token_pos_ and pc_desc_index_. 256 // Compute token_pos_ and pc_desc_index_.
279 intptr_t ActivationFrame::TokenPos() { 257 intptr_t ActivationFrame::TokenPos() {
280 if (token_pos_ < 0) { 258 if (token_pos_ < 0) {
281 GetPcDescriptors(); 259 GetPcDescriptors();
282 for (int i = 0; i < pc_desc_.Length(); i++) { 260 for (int i = 0; i < pc_desc_.Length(); i++) {
(...skipping 30 matching lines...) Expand all
313 const Script& script = Script::Handle(SourceScript()); 291 const Script& script = Script::Handle(SourceScript());
314 intptr_t ignore_column; 292 intptr_t ignore_column;
315 script.GetTokenLocation(TokenPos(), &line_number_, &ignore_column); 293 script.GetTokenLocation(TokenPos(), &line_number_, &ignore_column);
316 } 294 }
317 return line_number_; 295 return line_number_;
318 } 296 }
319 297
320 298
321 void ActivationFrame::GetVarDescriptors() { 299 void ActivationFrame::GetVarDescriptors() {
322 if (var_descriptors_.IsNull()) { 300 if (var_descriptors_.IsNull()) {
323 const Code& code = DartCode(); 301 var_descriptors_ = code().var_descriptors();
324 var_descriptors_ = code.var_descriptors();
325 ASSERT(!var_descriptors_.IsNull()); 302 ASSERT(!var_descriptors_.IsNull());
326 } 303 }
327 } 304 }
328 305
329 306
330 // Calculate the context level at the current token index of the frame. 307 // Calculate the context level at the current token index of the frame.
331 intptr_t ActivationFrame::ContextLevel() { 308 intptr_t ActivationFrame::ContextLevel() {
332 if (context_level_ < 0) { 309 if (context_level_ < 0) {
333 context_level_ = 0; 310 context_level_ = 0;
334 intptr_t pc_desc_idx = PcDescIndex(); 311 intptr_t pc_desc_idx = PcDescIndex();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 ActivationFrame* DebuggerStackTrace::GetHandlerFrame( 358 ActivationFrame* DebuggerStackTrace::GetHandlerFrame(
382 const Instance& exc_obj) const { 359 const Instance& exc_obj) const {
383 ExceptionHandlers& handlers = ExceptionHandlers::Handle(); 360 ExceptionHandlers& handlers = ExceptionHandlers::Handle();
384 Array& handled_types = Array::Handle(); 361 Array& handled_types = Array::Handle();
385 AbstractType& type = Type::Handle(); 362 AbstractType& type = Type::Handle();
386 const TypeArguments& no_instantiator = TypeArguments::Handle(); 363 const TypeArguments& no_instantiator = TypeArguments::Handle();
387 for (int frame_index = 0; frame_index < Length(); frame_index++) { 364 for (int frame_index = 0; frame_index < Length(); frame_index++) {
388 ActivationFrame* frame = trace_[frame_index]; 365 ActivationFrame* frame = trace_[frame_index];
389 intptr_t try_index = frame->TryIndex(); 366 intptr_t try_index = frame->TryIndex();
390 if (try_index < 0) continue; 367 if (try_index < 0) continue;
391 const Code& code = frame->DartCode(); 368 handlers = frame->code().exception_handlers();
392 handlers = code.exception_handlers();
393 ASSERT(!handlers.IsNull()); 369 ASSERT(!handlers.IsNull());
394 intptr_t num_handlers_checked = 0; 370 intptr_t num_handlers_checked = 0;
395 while (try_index >= 0) { 371 while (try_index >= 0) {
396 // Detect circles in the exception handler data. 372 // Detect circles in the exception handler data.
397 num_handlers_checked++; 373 num_handlers_checked++;
398 ASSERT(num_handlers_checked <= handlers.Length()); 374 ASSERT(num_handlers_checked <= handlers.Length());
399 handled_types = handlers.GetHandledTypes(try_index); 375 handled_types = handlers.GetHandledTypes(try_index);
400 const intptr_t num_types = handled_types.Length(); 376 const intptr_t num_types = handled_types.Length();
401 for (int k = 0; k < num_types; k++) { 377 for (int k = 0; k < num_types; k++) {
402 type ^= handled_types.At(k); 378 type ^= handled_types.At(k);
(...skipping 16 matching lines...) Expand all
419 void ActivationFrame::GetDescIndices() { 395 void ActivationFrame::GetDescIndices() {
420 if (vars_initialized_) { 396 if (vars_initialized_) {
421 return; 397 return;
422 } 398 }
423 GetVarDescriptors(); 399 GetVarDescriptors();
424 400
425 // We don't trust variable descriptors in optimized code. 401 // We don't trust variable descriptors in optimized code.
426 // Rather than potentially displaying incorrect values, we 402 // Rather than potentially displaying incorrect values, we
427 // pretend that there are no variables in the frame. 403 // pretend that there are no variables in the frame.
428 // We should be more clever about this in the future. 404 // We should be more clever about this in the future.
429 if (DartCode().is_optimized()) { 405 if (code().is_optimized()) {
430 vars_initialized_ = true; 406 vars_initialized_ = true;
431 return; 407 return;
432 } 408 }
433 409
434 GrowableArray<String*> var_names(8); 410 GrowableArray<String*> var_names(8);
435 intptr_t activation_token_pos = TokenPos(); 411 intptr_t activation_token_pos = TokenPos();
436 intptr_t var_desc_len = var_descriptors_.Length(); 412 intptr_t var_desc_len = var_descriptors_.Length();
437 for (int cur_idx = 0; cur_idx < var_desc_len; cur_idx++) { 413 for (int cur_idx = 0; cur_idx < var_desc_len; cur_idx++) {
438 ASSERT(var_names.length() == desc_indices_.length()); 414 ASSERT(var_names.length() == desc_indices_.length());
439 RawLocalVarDescriptors::VarInfo var_info; 415 RawLocalVarDescriptors::VarInfo var_info;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 list.SetAt(2 * i, var_name); 532 list.SetAt(2 * i, var_name);
557 list.SetAt((2 * i) + 1, value); 533 list.SetAt((2 * i) + 1, value);
558 } 534 }
559 return list.raw(); 535 return list.raw();
560 } 536 }
561 537
562 538
563 const char* ActivationFrame::ToCString() { 539 const char* ActivationFrame::ToCString() {
564 const char* kFormat = "Function: '%s' url: '%s' line: %d"; 540 const char* kFormat = "Function: '%s' url: '%s' line: %d";
565 541
566 const Function& func = DartFunction();
567 const String& url = String::Handle(SourceUrl()); 542 const String& url = String::Handle(SourceUrl());
568 intptr_t line = LineNumber(); 543 intptr_t line = LineNumber();
569 const char* func_name = Debugger::QualifiedFunctionName(func); 544 const char* func_name = Debugger::QualifiedFunctionName(function());
570 545
571 intptr_t len = 546 intptr_t len =
572 OS::SNPrint(NULL, 0, kFormat, func_name, url.ToCString(), line); 547 OS::SNPrint(NULL, 0, kFormat, func_name, url.ToCString(), line);
573 len++; // String terminator. 548 len++; // String terminator.
574 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 549 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
575 OS::SNPrint(chars, len, kFormat, func_name, url.ToCString(), line); 550 OS::SNPrint(chars, len, kFormat, func_name, url.ToCString(), line);
576 return chars; 551 return chars;
577 } 552 }
578 553
579 554
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 if (event_handler_ != NULL) { 848 if (event_handler_ != NULL) {
874 DebuggerEvent event; 849 DebuggerEvent event;
875 event.type = kBreakpointResolved; 850 event.type = kBreakpointResolved;
876 event.breakpoint = bpt; 851 event.breakpoint = bpt;
877 (*event_handler_)(&event); 852 (*event_handler_)(&event);
878 } 853 }
879 } 854 }
880 855
881 856
882 DebuggerStackTrace* Debugger::CollectStackTrace() { 857 DebuggerStackTrace* Debugger::CollectStackTrace() {
858 Isolate* isolate = Isolate::Current();
883 DebuggerStackTrace* stack_trace = new DebuggerStackTrace(8); 859 DebuggerStackTrace* stack_trace = new DebuggerStackTrace(8);
884 Context& ctx = Context::Handle(Isolate::Current()->top_context()); 860 Context& ctx = Context::Handle(isolate->top_context());
861 Code& code = Code::Handle(isolate);
885 DartFrameIterator iterator; 862 DartFrameIterator iterator;
886 StackFrame* frame = iterator.NextFrame(); 863 StackFrame* frame = iterator.NextFrame();
887 while (frame != NULL) { 864 while (frame != NULL) {
888 ASSERT(frame->IsValid()); 865 ASSERT(frame->IsValid());
889 ASSERT(frame->IsDartFrame()); 866 ASSERT(frame->IsDartFrame());
867 code = frame->LookupDartCode();
890 ActivationFrame* activation = 868 ActivationFrame* activation =
891 new ActivationFrame(frame->pc(), frame->fp(), frame->sp(), ctx); 869 new ActivationFrame(frame->pc(), frame->fp(), frame->sp(), code, ctx);
892 ctx = activation->CallerContext(); 870 ctx = activation->CallerContext();
893 stack_trace->AddActivation(activation); 871 stack_trace->AddActivation(activation);
894 frame = iterator.NextFrame(); 872 frame = iterator.NextFrame();
895 } 873 }
896 return stack_trace; 874 return stack_trace;
897 } 875 }
898 876
899 877
900 void Debugger::SetExceptionPauseInfo(Dart_ExceptionPauseInfo pause_info) { 878 void Debugger::SetExceptionPauseInfo(Dart_ExceptionPauseInfo pause_info) {
901 ASSERT((pause_info == kNoPauseOnExceptions) || 879 ASSERT((pause_info == kNoPauseOnExceptions) ||
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 Function& func_to_instrument = Function::Handle(); 1457 Function& func_to_instrument = Function::Handle();
1480 if (resume_action_ == kContinue) { 1458 if (resume_action_ == kContinue) {
1481 // Nothing to do here, any potential instrumentation will be removed 1459 // Nothing to do here, any potential instrumentation will be removed
1482 // below. 1460 // below.
1483 } else if (resume_action_ == kStepOver) { 1461 } else if (resume_action_ == kStepOver) {
1484 func_to_instrument = bpt->function(); 1462 func_to_instrument = bpt->function();
1485 if (bpt->breakpoint_kind_ == PcDescriptors::kReturn) { 1463 if (bpt->breakpoint_kind_ == PcDescriptors::kReturn) {
1486 // If we are at the function return, do a StepOut action. 1464 // If we are at the function return, do a StepOut action.
1487 if (stack_trace->Length() > 1) { 1465 if (stack_trace->Length() > 1) {
1488 ActivationFrame* caller_frame = stack_trace->ActivationFrameAt(1); 1466 ActivationFrame* caller_frame = stack_trace->ActivationFrameAt(1);
1489 func_to_instrument = caller_frame->DartFunction().raw(); 1467 func_to_instrument = caller_frame->function().raw();
1490 } 1468 }
1491 } 1469 }
1492 } else if (resume_action_ == kStepInto) { 1470 } else if (resume_action_ == kStepInto) {
1493 // If the call target is not debuggable, we treat StepInto like 1471 // If the call target is not debuggable, we treat StepInto like
1494 // a StepOver, that is we instrument the current function. 1472 // a StepOver, that is we instrument the current function.
1495 if (bpt->breakpoint_kind_ == PcDescriptors::kIcCall) { 1473 if (bpt->breakpoint_kind_ == PcDescriptors::kIcCall) {
1496 func_to_instrument = bpt->function(); 1474 func_to_instrument = bpt->function();
1497 ICData& ic_data = ICData::Handle(); 1475 ICData& ic_data = ICData::Handle();
1498 Array& descriptor = Array::Handle(); 1476 Array& descriptor = Array::Handle();
1499 CodePatcher::GetInstanceCallAt(bpt->pc_, &ic_data, &descriptor); 1477 CodePatcher::GetInstanceCallAt(bpt->pc_, &ic_data, &descriptor);
(...skipping 19 matching lines...) Expand all
1519 Function::Handle(code.GetStaticCallTargetFunctionAt(bpt->pc_)); 1497 Function::Handle(code.GetStaticCallTargetFunctionAt(bpt->pc_));
1520 ASSERT(!callee.IsNull()); 1498 ASSERT(!callee.IsNull());
1521 if (IsDebuggable(callee)) { 1499 if (IsDebuggable(callee)) {
1522 func_to_instrument = callee.raw(); 1500 func_to_instrument = callee.raw();
1523 } 1501 }
1524 } else { 1502 } else {
1525 ASSERT(bpt->breakpoint_kind_ == PcDescriptors::kReturn); 1503 ASSERT(bpt->breakpoint_kind_ == PcDescriptors::kReturn);
1526 // Treat like stepping out to caller. 1504 // Treat like stepping out to caller.
1527 if (stack_trace->Length() > 1) { 1505 if (stack_trace->Length() > 1) {
1528 ActivationFrame* caller_frame = stack_trace->ActivationFrameAt(1); 1506 ActivationFrame* caller_frame = stack_trace->ActivationFrameAt(1);
1529 func_to_instrument = caller_frame->DartFunction().raw(); 1507 func_to_instrument = caller_frame->function().raw();
1530 } 1508 }
1531 } 1509 }
1532 } else { 1510 } else {
1533 ASSERT(resume_action_ == kStepOut); 1511 ASSERT(resume_action_ == kStepOut);
1534 // Set stepping breakpoints in the caller. 1512 // Set stepping breakpoints in the caller.
1535 if (stack_trace->Length() > 1) { 1513 if (stack_trace->Length() > 1) {
1536 ActivationFrame* caller_frame = stack_trace->ActivationFrameAt(1); 1514 ActivationFrame* caller_frame = stack_trace->ActivationFrameAt(1);
1537 func_to_instrument = caller_frame->DartFunction().raw(); 1515 func_to_instrument = caller_frame->function().raw();
1538 } 1516 }
1539 } 1517 }
1540 1518
1541 if (func_to_instrument.IsNull() || 1519 if (func_to_instrument.IsNull() ||
1542 (func_to_instrument.raw() != currently_instrumented_func.raw())) { 1520 (func_to_instrument.raw() != currently_instrumented_func.raw())) {
1543 last_bpt_line_ = -1; 1521 last_bpt_line_ = -1;
1544 RemoveInternalBreakpoints(); // *bpt is now invalid. 1522 RemoveInternalBreakpoints(); // *bpt is now invalid.
1545 if (!func_to_instrument.IsNull()) { 1523 if (!func_to_instrument.IsNull()) {
1546 InstrumentForStepping(func_to_instrument); 1524 InstrumentForStepping(func_to_instrument);
1547 } 1525 }
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1728 } 1706 }
1729 1707
1730 1708
1731 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { 1709 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) {
1732 ASSERT(bpt->next() == NULL); 1710 ASSERT(bpt->next() == NULL);
1733 bpt->set_next(code_breakpoints_); 1711 bpt->set_next(code_breakpoints_);
1734 code_breakpoints_ = bpt; 1712 code_breakpoints_ = bpt;
1735 } 1713 }
1736 1714
1737 } // namespace dart 1715 } // namespace dart
OLDNEW
« no previous file with comments | « vm/debugger.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698