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" |
| 8 |
7 #include "vm/code_generator.h" | 9 #include "vm/code_generator.h" |
8 #include "vm/code_patcher.h" | 10 #include "vm/code_patcher.h" |
9 #include "vm/compiler.h" | 11 #include "vm/compiler.h" |
10 #include "vm/dart_entry.h" | 12 #include "vm/dart_entry.h" |
11 #include "vm/flags.h" | 13 #include "vm/flags.h" |
12 #include "vm/globals.h" | 14 #include "vm/globals.h" |
13 #include "vm/longjump.h" | 15 #include "vm/longjump.h" |
14 #include "vm/object.h" | 16 #include "vm/object.h" |
15 #include "vm/object_store.h" | 17 #include "vm/object_store.h" |
16 #include "vm/os.h" | 18 #include "vm/os.h" |
| 19 #include "vm/port.h" |
17 #include "vm/stack_frame.h" | 20 #include "vm/stack_frame.h" |
18 #include "vm/stub_code.h" | 21 #include "vm/stub_code.h" |
19 #include "vm/symbols.h" | 22 #include "vm/symbols.h" |
20 #include "vm/visitor.h" | 23 #include "vm/visitor.h" |
21 | 24 |
22 | 25 |
23 namespace dart { | 26 namespace dart { |
24 | 27 |
25 DEFINE_FLAG(bool, verbose_debug, false, "Verbose debugger messages"); | 28 DEFINE_FLAG(bool, verbose_debug, false, "Verbose debugger messages"); |
26 | 29 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 ASSERT(isolate != NULL); | 155 ASSERT(isolate != NULL); |
153 const Code& code = Code::Handle(Code::LookupCode(pc_)); | 156 const Code& code = Code::Handle(Code::LookupCode(pc_)); |
154 function_ = code.function(); | 157 function_ = code.function(); |
155 } | 158 } |
156 return function_; | 159 return function_; |
157 } | 160 } |
158 | 161 |
159 | 162 |
160 void Debugger::SignalIsolateEvent(EventType type) { | 163 void Debugger::SignalIsolateEvent(EventType type) { |
161 if (event_handler_ != NULL) { | 164 if (event_handler_ != NULL) { |
| 165 Debugger* debugger = Isolate::Current()->debugger(); |
| 166 ASSERT(debugger != NULL); |
162 DebuggerEvent event; | 167 DebuggerEvent event; |
163 event.type = type; | 168 event.type = type; |
164 event.isolate = Isolate::Current(); | 169 event.isolate_id = debugger->GetIsolateId(); |
| 170 ASSERT(event.isolate_id != ILLEGAL_ISOLATE_ID); |
165 (*event_handler_)(&event); | 171 (*event_handler_)(&event); |
166 } | 172 } |
167 } | 173 } |
168 | 174 |
169 | 175 |
170 const char* Debugger::QualifiedFunctionName(const Function& func) { | 176 const char* Debugger::QualifiedFunctionName(const Function& func) { |
171 const String& func_name = String::Handle(func.name()); | 177 const String& func_name = String::Handle(func.name()); |
172 Class& func_class = Class::Handle(func.Owner()); | 178 Class& func_class = Class::Handle(func.Owner()); |
173 String& class_name = String::Handle(func_class.Name()); | 179 String& class_name = String::Handle(func_class.Name()); |
174 | 180 |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 | 630 |
625 | 631 |
626 RawObject* RemoteObjectCache::GetObj(intptr_t obj_id) const { | 632 RawObject* RemoteObjectCache::GetObj(intptr_t obj_id) const { |
627 ASSERT(IsValidId(obj_id)); | 633 ASSERT(IsValidId(obj_id)); |
628 return objs_->At(obj_id); | 634 return objs_->At(obj_id); |
629 } | 635 } |
630 | 636 |
631 | 637 |
632 Debugger::Debugger() | 638 Debugger::Debugger() |
633 : isolate_(NULL), | 639 : isolate_(NULL), |
| 640 isolate_id_(ILLEGAL_ISOLATE_ID), |
634 initialized_(false), | 641 initialized_(false), |
635 next_id_(1), | 642 next_id_(1), |
636 stack_trace_(NULL), | 643 stack_trace_(NULL), |
637 obj_cache_(NULL), | 644 obj_cache_(NULL), |
638 src_breakpoints_(NULL), | 645 src_breakpoints_(NULL), |
639 code_breakpoints_(NULL), | 646 code_breakpoints_(NULL), |
640 resume_action_(kContinue), | 647 resume_action_(kContinue), |
641 last_bpt_line_(-1), | 648 last_bpt_line_(-1), |
642 ignore_breakpoints_(false), | 649 ignore_breakpoints_(false), |
643 exc_pause_info_(kNoPauseOnExceptions) { | 650 exc_pause_info_(kNoPauseOnExceptions) { |
644 } | 651 } |
645 | 652 |
646 | 653 |
647 Debugger::~Debugger() { | 654 Debugger::~Debugger() { |
| 655 PortMap::ClosePort(isolate_id_); |
| 656 isolate_id_ = ILLEGAL_ISOLATE_ID; |
648 ASSERT(src_breakpoints_ == NULL); | 657 ASSERT(src_breakpoints_ == NULL); |
649 ASSERT(code_breakpoints_ == NULL); | 658 ASSERT(code_breakpoints_ == NULL); |
650 ASSERT(stack_trace_ == NULL); | 659 ASSERT(stack_trace_ == NULL); |
651 ASSERT(obj_cache_ == NULL); | 660 ASSERT(obj_cache_ == NULL); |
652 } | 661 } |
653 | 662 |
654 | 663 |
655 void Debugger::Shutdown() { | 664 void Debugger::Shutdown() { |
656 while (src_breakpoints_ != NULL) { | 665 while (src_breakpoints_ != NULL) { |
657 SourceBreakpoint* bpt = src_breakpoints_; | 666 SourceBreakpoint* bpt = src_breakpoints_; |
658 src_breakpoints_ = src_breakpoints_->next(); | 667 src_breakpoints_ = src_breakpoints_->next(); |
659 delete bpt; | 668 delete bpt; |
660 } | 669 } |
661 while (code_breakpoints_ != NULL) { | 670 while (code_breakpoints_ != NULL) { |
662 CodeBreakpoint* bpt = code_breakpoints_; | 671 CodeBreakpoint* bpt = code_breakpoints_; |
663 code_breakpoints_ = code_breakpoints_->next(); | 672 code_breakpoints_ = code_breakpoints_->next(); |
664 bpt->Disable(); | 673 bpt->Disable(); |
665 delete bpt; | 674 delete bpt; |
666 } | 675 } |
| 676 // Signal isolate shutdown event. |
| 677 SignalIsolateEvent(Debugger::kIsolateShutdown); |
667 } | 678 } |
668 | 679 |
669 | 680 |
670 bool Debugger::IsActive() { | 681 bool Debugger::IsActive() { |
671 // TODO(hausner): The code generator uses this function to prevent | 682 // TODO(hausner): The code generator uses this function to prevent |
672 // generation of optimized code when Dart code is being debugged. | 683 // generation of optimized code when Dart code is being debugged. |
673 // This is probably not conservative enough (we could set the first | 684 // This is probably not conservative enough (we could set the first |
674 // breakpoint after optimized code has already been produced). | 685 // breakpoint after optimized code has already been produced). |
675 // Long-term, we need to be able to de-optimize code. | 686 // Long-term, we need to be able to de-optimize code. |
676 return (src_breakpoints_ != NULL) || | 687 return (src_breakpoints_ != NULL) || |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1409 } | 1420 } |
1410 } | 1421 } |
1411 } | 1422 } |
1412 | 1423 |
1413 | 1424 |
1414 void Debugger::Initialize(Isolate* isolate) { | 1425 void Debugger::Initialize(Isolate* isolate) { |
1415 if (initialized_) { | 1426 if (initialized_) { |
1416 return; | 1427 return; |
1417 } | 1428 } |
1418 isolate_ = isolate; | 1429 isolate_ = isolate; |
| 1430 // Create a port here, we don't expect to receive any messages on this port. |
| 1431 // This port will be used as a unique ID to represet the isolate in the |
| 1432 // debugger wire protocol messages. |
| 1433 // NOTE: SetLive is never called on this port. |
| 1434 isolate_id_ = PortMap::CreatePort(isolate->message_handler()); |
1419 initialized_ = true; | 1435 initialized_ = true; |
| 1436 |
| 1437 // Signal isolate creation event. |
| 1438 SignalIsolateEvent(Debugger::kIsolateCreated); |
1420 } | 1439 } |
1421 | 1440 |
1422 | 1441 |
1423 void Debugger::NotifyCompilation(const Function& func) { | 1442 void Debugger::NotifyCompilation(const Function& func) { |
1424 if (src_breakpoints_ == NULL) { | 1443 if (src_breakpoints_ == NULL) { |
1425 // Return with minimal overhead if there are no breakpoints. | 1444 // Return with minimal overhead if there are no breakpoints. |
1426 return; | 1445 return; |
1427 } | 1446 } |
1428 Function& lookup_function = Function::Handle(func.raw()); | 1447 Function& lookup_function = Function::Handle(func.raw()); |
1429 if (func.IsImplicitClosureFunction()) { | 1448 if (func.IsImplicitClosureFunction()) { |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1582 } | 1601 } |
1583 | 1602 |
1584 | 1603 |
1585 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { | 1604 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { |
1586 ASSERT(bpt->next() == NULL); | 1605 ASSERT(bpt->next() == NULL); |
1587 bpt->set_next(code_breakpoints_); | 1606 bpt->set_next(code_breakpoints_); |
1588 code_breakpoints_ = bpt; | 1607 code_breakpoints_ = bpt; |
1589 } | 1608 } |
1590 | 1609 |
1591 } // namespace dart | 1610 } // namespace dart |
OLD | NEW |