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

Side by Side Diff: vm/debugger.cc

Issue 11026011: Add isolate event handler setup in order to be able to propagate isolate (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 2 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
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 "vm/code_generator.h" 7 #include "vm/code_generator.h"
8 #include "vm/code_patcher.h" 8 #include "vm/code_patcher.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
11 #include "vm/flags.h" 11 #include "vm/flags.h"
12 #include "vm/globals.h" 12 #include "vm/globals.h"
13 #include "vm/longjump.h" 13 #include "vm/longjump.h"
14 #include "vm/object.h" 14 #include "vm/object.h"
15 #include "vm/object_store.h" 15 #include "vm/object_store.h"
16 #include "vm/os.h" 16 #include "vm/os.h"
17 #include "vm/stack_frame.h" 17 #include "vm/stack_frame.h"
18 #include "vm/stub_code.h" 18 #include "vm/stub_code.h"
19 #include "vm/symbols.h" 19 #include "vm/symbols.h"
20 #include "vm/visitor.h" 20 #include "vm/visitor.h"
21 21
22 22
23 namespace dart { 23 namespace dart {
24 24
25 DEFINE_FLAG(bool, verbose_debug, false, "Verbose debugger messages"); 25 DEFINE_FLAG(bool, verbose_debug, false, "Verbose debugger messages");
26 26
27
28 static void DefaultBreakpointHandler(SourceBreakpoint* bpt,
29 DebuggerStackTrace* stack) {
30 String& var_name = String::Handle();
31 Instance& value = Instance::Handle();
32 for (intptr_t i = 0; i < stack->Length(); i++) {
33 ActivationFrame* frame = stack->ActivationFrameAt(i);
34 OS::Print(" %"Pd". %s\n",
35 i + 1, frame->ToCString());
36 intptr_t num_locals = frame->NumLocalVariables();
37 for (intptr_t i = 0; i < num_locals; i++) {
38 intptr_t token_pos, end_pos;
39 frame->VariableAt(i, &var_name, &token_pos, &end_pos, &value);
40 OS::Print(" var %s (pos %"Pd") = %s\n",
41 var_name.ToCString(), token_pos, value.ToCString());
42 }
43 }
44 }
45
46
47 BreakpointHandler* Debugger::bp_handler_ = DefaultBreakpointHandler;
48 Debugger::EventHandler* Debugger::event_handler_ = NULL;
49
50
27 class RemoteObjectCache : public ZoneAllocated { 51 class RemoteObjectCache : public ZoneAllocated {
28 public: 52 public:
29 explicit RemoteObjectCache(intptr_t initial_size); 53 explicit RemoteObjectCache(intptr_t initial_size);
30 intptr_t AddObject(const Object& obj); 54 intptr_t AddObject(const Object& obj);
31 RawObject* GetObj(intptr_t obj_id) const; 55 RawObject* GetObj(intptr_t obj_id) const;
32 bool IsValidId(intptr_t obj_id) const { 56 bool IsValidId(intptr_t obj_id) const {
33 return obj_id < objs_->Length(); 57 return obj_id < objs_->Length();
34 } 58 }
35 59
36 private: 60 private:
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 if (function_.IsNull()) { 150 if (function_.IsNull()) {
127 Isolate* isolate = Isolate::Current(); 151 Isolate* isolate = Isolate::Current();
128 ASSERT(isolate != NULL); 152 ASSERT(isolate != NULL);
129 const Code& code = Code::Handle(Code::LookupCode(pc_)); 153 const Code& code = Code::Handle(Code::LookupCode(pc_));
130 function_ = code.function(); 154 function_ = code.function();
131 } 155 }
132 return function_; 156 return function_;
133 } 157 }
134 158
135 159
160 void Debugger::SignalIsolateEvent(EventType type) {
161 if (event_handler_ != NULL) {
162 DebuggerEvent event;
163 event.type = type;
164 event.isolate = Isolate::Current();
165 (*event_handler_)(&event);
166 }
167 }
168
169
136 const char* Debugger::QualifiedFunctionName(const Function& func) { 170 const char* Debugger::QualifiedFunctionName(const Function& func) {
137 const String& func_name = String::Handle(func.name()); 171 const String& func_name = String::Handle(func.name());
138 Class& func_class = Class::Handle(func.Owner()); 172 Class& func_class = Class::Handle(func.Owner());
139 String& class_name = String::Handle(func_class.Name()); 173 String& class_name = String::Handle(func_class.Name());
140 174
141 const char* kFormat = "%s%s%s"; 175 const char* kFormat = "%s%s%s";
142 intptr_t len = OS::SNPrint(NULL, 0, kFormat, 176 intptr_t len = OS::SNPrint(NULL, 0, kFormat,
143 func_class.IsTopLevel() ? "" : class_name.ToCString(), 177 func_class.IsTopLevel() ? "" : class_name.ToCString(),
144 func_class.IsTopLevel() ? "" : ".", 178 func_class.IsTopLevel() ? "" : ".",
145 func_name.ToCString()); 179 func_name.ToCString());
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 625
592 RawObject* RemoteObjectCache::GetObj(intptr_t obj_id) const { 626 RawObject* RemoteObjectCache::GetObj(intptr_t obj_id) const {
593 ASSERT(IsValidId(obj_id)); 627 ASSERT(IsValidId(obj_id));
594 return objs_->At(obj_id); 628 return objs_->At(obj_id);
595 } 629 }
596 630
597 631
598 Debugger::Debugger() 632 Debugger::Debugger()
599 : isolate_(NULL), 633 : isolate_(NULL),
600 initialized_(false), 634 initialized_(false),
601 bp_handler_(NULL),
602 event_handler_(NULL),
603 next_id_(1), 635 next_id_(1),
604 stack_trace_(NULL), 636 stack_trace_(NULL),
605 obj_cache_(NULL), 637 obj_cache_(NULL),
606 src_breakpoints_(NULL), 638 src_breakpoints_(NULL),
607 code_breakpoints_(NULL), 639 code_breakpoints_(NULL),
608 resume_action_(kContinue), 640 resume_action_(kContinue),
609 last_bpt_line_(-1), 641 last_bpt_line_(-1),
610 ignore_breakpoints_(false), 642 ignore_breakpoints_(false),
611 exc_pause_info_(kNoPauseOnExceptions) { 643 exc_pause_info_(kNoPauseOnExceptions) {
612 } 644 }
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 bpt = bpt->next(); 1264 bpt = bpt->next();
1233 } 1265 }
1234 CodeBreakpoint* cbpt = code_breakpoints_; 1266 CodeBreakpoint* cbpt = code_breakpoints_;
1235 while (cbpt != NULL) { 1267 while (cbpt != NULL) {
1236 cbpt->VisitObjectPointers(visitor); 1268 cbpt->VisitObjectPointers(visitor);
1237 cbpt = cbpt->next(); 1269 cbpt = cbpt->next();
1238 } 1270 }
1239 } 1271 }
1240 1272
1241 1273
1242 static void DefaultBreakpointHandler(SourceBreakpoint* bpt,
1243 DebuggerStackTrace* stack) {
1244 String& var_name = String::Handle();
1245 Instance& value = Instance::Handle();
1246 for (intptr_t i = 0; i < stack->Length(); i++) {
1247 ActivationFrame* frame = stack->ActivationFrameAt(i);
1248 OS::Print(" %"Pd". %s\n",
1249 i + 1, frame->ToCString());
1250 intptr_t num_locals = frame->NumLocalVariables();
1251 for (intptr_t i = 0; i < num_locals; i++) {
1252 intptr_t token_pos, end_pos;
1253 frame->VariableAt(i, &var_name, &token_pos, &end_pos, &value);
1254 OS::Print(" var %s (pos %"Pd") = %s\n",
1255 var_name.ToCString(), token_pos, value.ToCString());
1256 }
1257 }
1258 }
1259
1260
1261 void Debugger::SetBreakpointHandler(BreakpointHandler* handler) { 1274 void Debugger::SetBreakpointHandler(BreakpointHandler* handler) {
1262 bp_handler_ = handler; 1275 if (bp_handler_ != NULL) {
1263 if (bp_handler_ == NULL) { 1276 bp_handler_ = handler;
1264 bp_handler_ = &DefaultBreakpointHandler;
1265 } 1277 }
1266 } 1278 }
1267 1279
1268 1280
1269 void Debugger::SetEventHandler(EventHandler* handler) { 1281 void Debugger::SetEventHandler(EventHandler* handler) {
1270 event_handler_ = handler; 1282 event_handler_ = handler;
1271 } 1283 }
1272 1284
1273 1285
1274 bool Debugger::IsDebuggable(const Function& func) { 1286 bool Debugger::IsDebuggable(const Function& func) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 } 1410 }
1399 } 1411 }
1400 1412
1401 1413
1402 void Debugger::Initialize(Isolate* isolate) { 1414 void Debugger::Initialize(Isolate* isolate) {
1403 if (initialized_) { 1415 if (initialized_) {
1404 return; 1416 return;
1405 } 1417 }
1406 isolate_ = isolate; 1418 isolate_ = isolate;
1407 initialized_ = true; 1419 initialized_ = true;
1408 SetBreakpointHandler(DefaultBreakpointHandler);
1409 } 1420 }
1410 1421
1411 1422
1412 void Debugger::NotifyCompilation(const Function& func) { 1423 void Debugger::NotifyCompilation(const Function& func) {
1413 if (src_breakpoints_ == NULL) { 1424 if (src_breakpoints_ == NULL) {
1414 // Return with minimal overhead if there are no breakpoints. 1425 // Return with minimal overhead if there are no breakpoints.
1415 return; 1426 return;
1416 } 1427 }
1417 Function& lookup_function = Function::Handle(func.raw()); 1428 Function& lookup_function = Function::Handle(func.raw());
1418 if (func.IsImplicitClosureFunction()) { 1429 if (func.IsImplicitClosureFunction()) {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1571 } 1582 }
1572 1583
1573 1584
1574 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) { 1585 void Debugger::RegisterCodeBreakpoint(CodeBreakpoint* bpt) {
1575 ASSERT(bpt->next() == NULL); 1586 ASSERT(bpt->next() == NULL);
1576 bpt->set_next(code_breakpoints_); 1587 bpt->set_next(code_breakpoints_);
1577 code_breakpoints_ = bpt; 1588 code_breakpoints_ = bpt;
1578 } 1589 }
1579 1590
1580 } // namespace dart 1591 } // namespace dart
OLDNEW
« vm/debugger.h ('K') | « vm/debugger.h ('k') | vm/debugger_api_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698