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 10 matching lines...) Expand all Loading... |
21 #include "vm/stub_code.h" | 21 #include "vm/stub_code.h" |
22 #include "vm/symbols.h" | 22 #include "vm/symbols.h" |
23 #include "vm/visitor.h" | 23 #include "vm/visitor.h" |
24 | 24 |
25 | 25 |
26 namespace dart { | 26 namespace dart { |
27 | 27 |
28 DEFINE_FLAG(bool, verbose_debug, false, "Verbose debugger messages"); | 28 DEFINE_FLAG(bool, verbose_debug, false, "Verbose debugger messages"); |
29 | 29 |
30 | 30 |
31 static void DefaultBreakpointHandler(Dart_Port isolate_id, | |
32 SourceBreakpoint* bpt, | |
33 DebuggerStackTrace* stack) { | |
34 String& var_name = String::Handle(); | |
35 Instance& value = Instance::Handle(); | |
36 for (intptr_t i = 0; i < stack->Length(); i++) { | |
37 ActivationFrame* frame = stack->ActivationFrameAt(i); | |
38 OS::Print(" %"Pd". %s\n", | |
39 i + 1, frame->ToCString()); | |
40 intptr_t num_locals = frame->NumLocalVariables(); | |
41 for (intptr_t i = 0; i < num_locals; i++) { | |
42 intptr_t token_pos, end_pos; | |
43 frame->VariableAt(i, &var_name, &token_pos, &end_pos, &value); | |
44 OS::Print(" var %s (pos %"Pd") = %s\n", | |
45 var_name.ToCString(), token_pos, value.ToCString()); | |
46 } | |
47 } | |
48 } | |
49 | |
50 | |
51 BreakpointHandler* Debugger::bp_handler_ = DefaultBreakpointHandler; | |
52 Debugger::EventHandler* Debugger::event_handler_ = NULL; | 31 Debugger::EventHandler* Debugger::event_handler_ = NULL; |
53 | 32 |
54 | 33 |
55 class RemoteObjectCache : public ZoneAllocated { | 34 class RemoteObjectCache : public ZoneAllocated { |
56 public: | 35 public: |
57 explicit RemoteObjectCache(intptr_t initial_size); | 36 explicit RemoteObjectCache(intptr_t initial_size); |
58 intptr_t AddObject(const Object& obj); | 37 intptr_t AddObject(const Object& obj); |
59 RawObject* GetObj(intptr_t obj_id) const; | 38 RawObject* GetObj(intptr_t obj_id) const; |
60 bool IsValidId(intptr_t obj_id) const { | 39 bool IsValidId(intptr_t obj_id) const { |
61 return obj_id < objs_->Length(); | 40 return obj_id < objs_->Length(); |
(...skipping 1358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1420 bpt = bpt->next(); | 1399 bpt = bpt->next(); |
1421 } | 1400 } |
1422 CodeBreakpoint* cbpt = code_breakpoints_; | 1401 CodeBreakpoint* cbpt = code_breakpoints_; |
1423 while (cbpt != NULL) { | 1402 while (cbpt != NULL) { |
1424 cbpt->VisitObjectPointers(visitor); | 1403 cbpt->VisitObjectPointers(visitor); |
1425 cbpt = cbpt->next(); | 1404 cbpt = cbpt->next(); |
1426 } | 1405 } |
1427 } | 1406 } |
1428 | 1407 |
1429 | 1408 |
1430 void Debugger::SetBreakpointHandler(BreakpointHandler* handler) { | |
1431 if (bp_handler_ != NULL) { | |
1432 bp_handler_ = handler; | |
1433 } | |
1434 } | |
1435 | |
1436 | |
1437 void Debugger::SetEventHandler(EventHandler* handler) { | 1409 void Debugger::SetEventHandler(EventHandler* handler) { |
1438 event_handler_ = handler; | 1410 event_handler_ = handler; |
1439 } | 1411 } |
1440 | 1412 |
1441 | 1413 |
1442 bool Debugger::IsDebuggable(const Function& func) { | 1414 bool Debugger::IsDebuggable(const Function& func) { |
1443 RawFunction::Kind fkind = func.kind(); | 1415 RawFunction::Kind fkind = func.kind(); |
1444 if ((fkind == RawFunction::kImplicitGetter) || | 1416 if ((fkind == RawFunction::kImplicitGetter) || |
1445 (fkind == RawFunction::kImplicitSetter) || | 1417 (fkind == RawFunction::kImplicitSetter) || |
1446 (fkind == RawFunction::kConstImplicitGetter) || | 1418 (fkind == RawFunction::kConstImplicitGetter) || |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1480 // This is a user-defined breakpoint so we call the breakpoint | 1452 // This is a user-defined breakpoint so we call the breakpoint |
1481 // callback even if it is on the same line as the previous breakpoint. | 1453 // callback even if it is on the same line as the previous breakpoint. |
1482 last_bpt_line_ = -1; | 1454 last_bpt_line_ = -1; |
1483 } | 1455 } |
1484 | 1456 |
1485 bool notify_frontend = | 1457 bool notify_frontend = |
1486 (last_bpt_line_ < 0) || (last_bpt_line_ != bpt->LineNumber()); | 1458 (last_bpt_line_ < 0) || (last_bpt_line_ != bpt->LineNumber()); |
1487 | 1459 |
1488 if (notify_frontend) { | 1460 if (notify_frontend) { |
1489 resume_action_ = kContinue; | 1461 resume_action_ = kContinue; |
1490 if (bp_handler_ != NULL) { | 1462 if (event_handler_ != NULL) { |
1491 SourceBreakpoint* src_bpt = bpt->src_bpt(); | |
1492 ASSERT(stack_trace_ == NULL); | 1463 ASSERT(stack_trace_ == NULL); |
1493 ASSERT(obj_cache_ == NULL); | 1464 ASSERT(obj_cache_ == NULL); |
1494 obj_cache_ = new RemoteObjectCache(64); | 1465 obj_cache_ = new RemoteObjectCache(64); |
1495 stack_trace_ = stack_trace; | 1466 stack_trace_ = stack_trace; |
1496 (*bp_handler_)(GetIsolateId(), src_bpt, stack_trace); | 1467 DebuggerEvent event; |
| 1468 event.type = kBreakpointReached; |
| 1469 ASSERT(stack_trace->Length() > 0); |
| 1470 event.top_frame = stack_trace->ActivationFrameAt(0); |
| 1471 (*event_handler_)(&event); |
1497 stack_trace_ = NULL; | 1472 stack_trace_ = NULL; |
1498 obj_cache_ = NULL; // Remote object cache is zone allocated. | 1473 obj_cache_ = NULL; // Remote object cache is zone allocated. |
1499 last_bpt_line_ = bpt->LineNumber(); | 1474 last_bpt_line_ = bpt->LineNumber(); |
1500 } | 1475 } |
1501 } | 1476 } |
1502 | 1477 |
1503 Function& currently_instrumented_func = Function::Handle(); | 1478 Function& currently_instrumented_func = Function::Handle(); |
1504 if (bpt->IsInternal()) { | 1479 if (bpt->IsInternal()) { |
1505 currently_instrumented_func = bpt->function(); | 1480 currently_instrumented_func = bpt->function(); |
1506 } | 1481 } |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1758 } | 1733 } |
1759 | 1734 |
1760 | 1735 |
1761 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { | 1736 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { |
1762 ASSERT(bpt->next() == NULL); | 1737 ASSERT(bpt->next() == NULL); |
1763 bpt->set_next(code_breakpoints_); | 1738 bpt->set_next(code_breakpoints_); |
1764 code_breakpoints_ = bpt; | 1739 code_breakpoints_ = bpt; |
1765 } | 1740 } |
1766 | 1741 |
1767 } // namespace dart | 1742 } // namespace dart |
OLD | NEW |