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

Side by Side Diff: runtime/vm/debugger.cc

Issue 8872049: First debugger API unit test (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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_index_table.h" 7 #include "vm/code_index_table.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/flags.h" 10 #include "vm/flags.h"
11 #include "vm/globals.h" 11 #include "vm/globals.h"
12 #include "vm/object.h" 12 #include "vm/object.h"
13 #include "vm/object_store.h" 13 #include "vm/object_store.h"
14 #include "vm/os.h" 14 #include "vm/os.h"
15 #include "vm/stack_frame.h" 15 #include "vm/stack_frame.h"
16 #include "vm/stub_code.h" 16 #include "vm/stub_code.h"
17 #include "vm/visitor.h" 17 #include "vm/visitor.h"
18 18
19 19
20 namespace dart { 20 namespace dart {
21 21
22 22
23 DEFINE_FLAG(charp, bpt, NULL, "Debug breakpoint at <func>"); 23 DEFINE_FLAG(charp, bpt, NULL, "Debug breakpoint at <func>");
siva 2011/12/09 02:20:04 Is this flag used anymore?
hausner 2011/12/13 00:14:59 No. Good catch.
24 24
25 static const bool verbose = false;
siva 2011/12/09 02:20:04 Can this be turned on at the command line?
hausner 2011/12/13 00:14:59 No it's just for my own "debugger debugging" at th
25 26
26 Breakpoint::Breakpoint(const Function& func, intptr_t pc_desc_index) 27 Breakpoint::Breakpoint(const Function& func, intptr_t pc_desc_index)
27 : function_(func.raw()), 28 : function_(func.raw()),
28 pc_desc_index_(pc_desc_index), 29 pc_desc_index_(pc_desc_index),
29 pc_(0), 30 pc_(0),
30 line_number_(-1), 31 line_number_(-1),
31 next_(NULL) { 32 next_(NULL) {
32 Code& code = Code::Handle(func.code()); 33 Code& code = Code::Handle(func.code());
33 ASSERT(!code.IsNull()); // Function must be compiled. 34 ASSERT(!code.IsNull()); // Function must be compiled.
34 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); 35 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 if (function_ == Function::null()) { 83 if (function_ == Function::null()) {
83 ASSERT(Isolate::Current() != NULL); 84 ASSERT(Isolate::Current() != NULL);
84 CodeIndexTable* code_index_table = Isolate::Current()->code_index_table(); 85 CodeIndexTable* code_index_table = Isolate::Current()->code_index_table();
85 ASSERT(code_index_table != NULL); 86 ASSERT(code_index_table != NULL);
86 function_ = code_index_table->LookupFunction(pc_); 87 function_ = code_index_table->LookupFunction(pc_);
87 } 88 }
88 return function_; 89 return function_;
89 } 90 }
90 91
91 92
93 const char* Debugger::QualifiedFunctionName(const Function& func) {
94 String& func_name = String::Handle(func.name());
95 Class& func_class = Class::Handle(func.owner());
96 String& class_name = String::Handle(func_class.Name());
97
98 const char* kFormat = "%s%s%s";
99 intptr_t len = OS::SNPrint(NULL, 0, kFormat,
100 func_class.IsTopLevel() ? "" : class_name.ToCString(),
101 func_class.IsTopLevel() ? "" : ".",
102 func_name.ToCString());
siva 2011/12/09 02:20:04 ditto comment regarding library URL needed for ful
hausner 2011/12/13 00:14:59 Yes. Cf other comment.
103 len++; // String terminator.
104 char* chars = reinterpret_cast<char*>(
105 Isolate::Current()->current_zone()->Allocate(len));
106 OS::SNPrint(chars, len, kFormat,
107 func_class.IsTopLevel() ? "" : class_name.ToCString(),
108 func_class.IsTopLevel() ? "" : ".",
109 func_name.ToCString());
110 return chars;
111 }
112
113
114 RawString* ActivationFrame::QualifiedFunctionName() {
115 Function& func = Function::Handle(DartFunction());
116 return String::New(Debugger::QualifiedFunctionName(func));
117 }
118
119
92 RawString* ActivationFrame::SourceUrl() { 120 RawString* ActivationFrame::SourceUrl() {
93 const Script& script = Script::Handle(SourceScript()); 121 const Script& script = Script::Handle(SourceScript());
94 return script.url(); 122 return script.url();
95 } 123 }
96 124
97 125
98 RawScript* ActivationFrame::SourceScript() { 126 RawScript* ActivationFrame::SourceScript() {
99 const Function& func = Function::Handle(DartFunction()); 127 const Function& func = Function::Handle(DartFunction());
100 const Class& cls = Class::Handle(func.owner()); 128 const Class& cls = Class::Handle(func.owner());
101 return cls.script(); 129 return cls.script();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 165 }
138 166
139 167
140 RawInstance* ActivationFrame::Value(const String& variable_name) { 168 RawInstance* ActivationFrame::Value(const String& variable_name) {
141 UNIMPLEMENTED(); 169 UNIMPLEMENTED();
142 return NULL; 170 return NULL;
143 } 171 }
144 172
145 173
146 const char* ActivationFrame::ToCString() { 174 const char* ActivationFrame::ToCString() {
147 const char* kFormat = "Function: '%s%s%s' url: '%s' line: %d"; 175 const char* kFormat = "Function: '%s' url: '%s' line: %d";
148 176
149 Function& func = Function::Handle(DartFunction()); 177 Function& func = Function::Handle(DartFunction());
150 String& func_name = String::Handle(func.name());
151 Class& func_class = Class::Handle(func.owner());
152 String& class_name = String::Handle(func_class.Name());
153 String& url = String::Handle(SourceUrl()); 178 String& url = String::Handle(SourceUrl());
154 intptr_t line = LineNumber(); 179 intptr_t line = LineNumber();
180 const char* func_name = Debugger::QualifiedFunctionName(func);
155 181
156 intptr_t len = OS::SNPrint(NULL, 0, kFormat, 182 intptr_t len =
157 class_name.ToCString(), 183 OS::SNPrint(NULL, 0, kFormat, func_name, url.ToCString(), line);
158 func_class.IsTopLevel() ? "" : ".",
159 func_name.ToCString(),
160 url.ToCString(),
161 line);
162 len++; // String terminator. 184 len++; // String terminator.
163 char* chars = reinterpret_cast<char*>( 185 char* chars = reinterpret_cast<char*>(
164 Isolate::Current()->current_zone()->Allocate(len)); 186 Isolate::Current()->current_zone()->Allocate(len));
165 OS::SNPrint(chars, len, kFormat, 187 OS::SNPrint(chars, len, kFormat, func_name, url.ToCString(), line);
166 class_name.ToCString(),
167 func_class.IsTopLevel() ? "" : ".",
168 func_name.ToCString(),
169 url.ToCString(),
170 line);
171 return chars; 188 return chars;
172 } 189 }
173 190
174 191
175 void StackTrace::AddActivation(ActivationFrame* frame) { 192 void StackTrace::AddActivation(ActivationFrame* frame) {
176 this->trace_.Add(frame); 193 this->trace_.Add(frame);
177 } 194 }
178 195
179 196
180 Debugger::Debugger() 197 Debugger::Debugger()
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 desc.PC(i), StubCode::BreakpointDynamicEntryPoint()); 261 desc.PC(i), StubCode::BreakpointDynamicEntryPoint());
245 bpt = new Breakpoint(target_function, i); 262 bpt = new Breakpoint(target_function, i);
246 } else if (kind == PcDescriptors::kOther) { 263 } else if (kind == PcDescriptors::kOther) {
247 if (CodePatcher::IsDartCall(desc.PC(i))) { 264 if (CodePatcher::IsDartCall(desc.PC(i))) {
248 CodePatcher::PatchStaticCallAt( 265 CodePatcher::PatchStaticCallAt(
249 desc.PC(i), StubCode::BreakpointStaticEntryPoint()); 266 desc.PC(i), StubCode::BreakpointStaticEntryPoint());
250 bpt = new Breakpoint(target_function, i); 267 bpt = new Breakpoint(target_function, i);
251 } 268 }
252 } 269 }
253 if (bpt != NULL) { 270 if (bpt != NULL) {
254 OS::Print("Setting breakpoint at '%s' line %d (PC %p)\n", 271 if (verbose) {
255 String::Handle(bpt->SourceUrl()).ToCString(), 272 OS::Print("Setting breakpoint at '%s' line %d (PC %p)\n",
256 bpt->LineNumber(), 273 String::Handle(bpt->SourceUrl()).ToCString(),
257 bpt->pc()); 274 bpt->LineNumber(),
275 bpt->pc());
276 }
258 AddBreakpoint(bpt); 277 AddBreakpoint(bpt);
259 return bpt; 278 return bpt;
260 } 279 }
261 } 280 }
262 return NULL; 281 return NULL;
263 } 282 }
264 283
265 284
266 void Debugger::VisitObjectPointers(ObjectPointerVisitor* visitor) { 285 void Debugger::VisitObjectPointers(ObjectPointerVisitor* visitor) {
267 ASSERT(visitor != NULL); 286 ASSERT(visitor != NULL);
(...skipping 21 matching lines...) Expand all
289 } 308 }
290 309
291 310
292 void Debugger::BreakpointCallback() { 311 void Debugger::BreakpointCallback() {
293 ASSERT(initialized_); 312 ASSERT(initialized_);
294 DartFrameIterator iterator; 313 DartFrameIterator iterator;
295 DartFrame* frame = iterator.NextFrame(); 314 DartFrame* frame = iterator.NextFrame();
296 ASSERT(frame != NULL); 315 ASSERT(frame != NULL);
297 Breakpoint* bpt = GetBreakpoint(frame->pc()); 316 Breakpoint* bpt = GetBreakpoint(frame->pc());
298 ASSERT(bpt != NULL); 317 ASSERT(bpt != NULL);
299 OS::Print(">>> Breakpoint at %s:%d (Address %p)\n", 318 if (verbose) {
300 bpt ? String::Handle(bpt->SourceUrl()).ToCString() : "?", 319 OS::Print(">>> Breakpoint at %s:%d (Address %p)\n",
301 bpt ? bpt->LineNumber() : 0, 320 bpt ? String::Handle(bpt->SourceUrl()).ToCString() : "?",
302 frame->pc()); 321 bpt ? bpt->LineNumber() : 0,
322 frame->pc());
323 }
303 StackTrace* stack_trace = new StackTrace(8); 324 StackTrace* stack_trace = new StackTrace(8);
304 while (frame != NULL) { 325 while (frame != NULL) {
305 ASSERT(frame->IsValid()); 326 ASSERT(frame->IsValid());
306 ASSERT(frame->IsDartFrame()); 327 ASSERT(frame->IsDartFrame());
307 ActivationFrame* activation = new ActivationFrame(frame->pc()); 328 ActivationFrame* activation = new ActivationFrame(frame->pc());
308 stack_trace->AddActivation(activation); 329 stack_trace->AddActivation(activation);
309 frame = iterator.NextFrame(); 330 frame = iterator.NextFrame();
310 } 331 }
311 332
312 if (bp_handler_ != NULL) { 333 if (bp_handler_ != NULL) {
siva 2011/12/09 02:20:04 Can bp_handler_ ever be NULL, it ties back to the
hausner 2011/12/13 00:14:59 Yes, it can be NULL if the caller would like to re
313 (*bp_handler_)(bpt, stack_trace); 334 (*bp_handler_)(bpt, stack_trace);
314 } 335 }
315 } 336 }
316 337
317 338
318 void Debugger::Initialize(Isolate* isolate) { 339 void Debugger::Initialize(Isolate* isolate) {
319 if (initialized_) { 340 if (initialized_) {
320 return; 341 return;
321 } 342 }
322 initialized_ = true; 343 initialized_ = true;
(...skipping 14 matching lines...) Expand all
337 358
338 359
339 void Debugger::AddBreakpoint(Breakpoint* bpt) { 360 void Debugger::AddBreakpoint(Breakpoint* bpt) {
340 ASSERT(bpt->next() == NULL); 361 ASSERT(bpt->next() == NULL);
341 bpt->set_next(this->breakpoints_); 362 bpt->set_next(this->breakpoints_);
342 this->breakpoints_ = bpt; 363 this->breakpoints_ = bpt;
343 } 364 }
344 365
345 366
346 } // namespace dart 367 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698