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

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
« no previous file with comments | « runtime/vm/debugger.h ('k') | runtime/vm/debugger_api_impl.cc » ('j') | 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) 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 static const bool verbose = false;
23 DEFINE_FLAG(charp, bpt, NULL, "Debug breakpoint at <func>");
24
25 23
26 Breakpoint::Breakpoint(const Function& func, intptr_t pc_desc_index) 24 Breakpoint::Breakpoint(const Function& func, intptr_t pc_desc_index)
27 : function_(func.raw()), 25 : function_(func.raw()),
28 pc_desc_index_(pc_desc_index), 26 pc_desc_index_(pc_desc_index),
29 pc_(0), 27 pc_(0),
30 line_number_(-1), 28 line_number_(-1),
31 next_(NULL) { 29 next_(NULL) {
32 Code& code = Code::Handle(func.code()); 30 Code& code = Code::Handle(func.code());
33 ASSERT(!code.IsNull()); // Function must be compiled. 31 ASSERT(!code.IsNull()); // Function must be compiled.
34 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); 32 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 if (function_ == Function::null()) { 80 if (function_ == Function::null()) {
83 ASSERT(Isolate::Current() != NULL); 81 ASSERT(Isolate::Current() != NULL);
84 CodeIndexTable* code_index_table = Isolate::Current()->code_index_table(); 82 CodeIndexTable* code_index_table = Isolate::Current()->code_index_table();
85 ASSERT(code_index_table != NULL); 83 ASSERT(code_index_table != NULL);
86 function_ = code_index_table->LookupFunction(pc_); 84 function_ = code_index_table->LookupFunction(pc_);
87 } 85 }
88 return function_; 86 return function_;
89 } 87 }
90 88
91 89
90 const char* Debugger::QualifiedFunctionName(const Function& func) {
91 String& func_name = String::Handle(func.name());
92 Class& func_class = Class::Handle(func.owner());
93 String& class_name = String::Handle(func_class.Name());
94
95 const char* kFormat = "%s%s%s";
96 intptr_t len = OS::SNPrint(NULL, 0, kFormat,
97 func_class.IsTopLevel() ? "" : class_name.ToCString(),
98 func_class.IsTopLevel() ? "" : ".",
99 func_name.ToCString());
100 len++; // String terminator.
101 char* chars = reinterpret_cast<char*>(
102 Isolate::Current()->current_zone()->Allocate(len));
103 OS::SNPrint(chars, len, kFormat,
104 func_class.IsTopLevel() ? "" : class_name.ToCString(),
105 func_class.IsTopLevel() ? "" : ".",
106 func_name.ToCString());
107 return chars;
108 }
109
110
111 RawString* ActivationFrame::QualifiedFunctionName() {
112 Function& func = Function::Handle(DartFunction());
113 return String::New(Debugger::QualifiedFunctionName(func));
114 }
115
116
92 RawString* ActivationFrame::SourceUrl() { 117 RawString* ActivationFrame::SourceUrl() {
93 const Script& script = Script::Handle(SourceScript()); 118 const Script& script = Script::Handle(SourceScript());
94 return script.url(); 119 return script.url();
95 } 120 }
96 121
97 122
98 RawScript* ActivationFrame::SourceScript() { 123 RawScript* ActivationFrame::SourceScript() {
99 const Function& func = Function::Handle(DartFunction()); 124 const Function& func = Function::Handle(DartFunction());
100 const Class& cls = Class::Handle(func.owner()); 125 const Class& cls = Class::Handle(func.owner());
101 return cls.script(); 126 return cls.script();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 162 }
138 163
139 164
140 RawInstance* ActivationFrame::Value(const String& variable_name) { 165 RawInstance* ActivationFrame::Value(const String& variable_name) {
141 UNIMPLEMENTED(); 166 UNIMPLEMENTED();
142 return NULL; 167 return NULL;
143 } 168 }
144 169
145 170
146 const char* ActivationFrame::ToCString() { 171 const char* ActivationFrame::ToCString() {
147 const char* kFormat = "Function: '%s%s%s' url: '%s' line: %d"; 172 const char* kFormat = "Function: '%s' url: '%s' line: %d";
148 173
149 Function& func = Function::Handle(DartFunction()); 174 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()); 175 String& url = String::Handle(SourceUrl());
154 intptr_t line = LineNumber(); 176 intptr_t line = LineNumber();
177 const char* func_name = Debugger::QualifiedFunctionName(func);
155 178
156 intptr_t len = OS::SNPrint(NULL, 0, kFormat, 179 intptr_t len =
157 class_name.ToCString(), 180 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. 181 len++; // String terminator.
163 char* chars = reinterpret_cast<char*>( 182 char* chars = reinterpret_cast<char*>(
164 Isolate::Current()->current_zone()->Allocate(len)); 183 Isolate::Current()->current_zone()->Allocate(len));
165 OS::SNPrint(chars, len, kFormat, 184 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; 185 return chars;
172 } 186 }
173 187
174 188
175 void StackTrace::AddActivation(ActivationFrame* frame) { 189 void StackTrace::AddActivation(ActivationFrame* frame) {
176 this->trace_.Add(frame); 190 this->trace_.Add(frame);
177 } 191 }
178 192
179 193
180 Debugger::Debugger() 194 Debugger::Debugger()
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 desc.PC(i), StubCode::BreakpointDynamicEntryPoint()); 258 desc.PC(i), StubCode::BreakpointDynamicEntryPoint());
245 bpt = new Breakpoint(target_function, i); 259 bpt = new Breakpoint(target_function, i);
246 } else if (kind == PcDescriptors::kOther) { 260 } else if (kind == PcDescriptors::kOther) {
247 if (CodePatcher::IsDartCall(desc.PC(i))) { 261 if (CodePatcher::IsDartCall(desc.PC(i))) {
248 CodePatcher::PatchStaticCallAt( 262 CodePatcher::PatchStaticCallAt(
249 desc.PC(i), StubCode::BreakpointStaticEntryPoint()); 263 desc.PC(i), StubCode::BreakpointStaticEntryPoint());
250 bpt = new Breakpoint(target_function, i); 264 bpt = new Breakpoint(target_function, i);
251 } 265 }
252 } 266 }
253 if (bpt != NULL) { 267 if (bpt != NULL) {
254 OS::Print("Setting breakpoint at '%s' line %d (PC %p)\n", 268 if (verbose) {
255 String::Handle(bpt->SourceUrl()).ToCString(), 269 OS::Print("Setting breakpoint at '%s' line %d (PC %p)\n",
256 bpt->LineNumber(), 270 String::Handle(bpt->SourceUrl()).ToCString(),
257 bpt->pc()); 271 bpt->LineNumber(),
272 bpt->pc());
273 }
258 AddBreakpoint(bpt); 274 AddBreakpoint(bpt);
259 return bpt; 275 return bpt;
260 } 276 }
261 } 277 }
262 return NULL; 278 return NULL;
263 } 279 }
264 280
265 281
266 void Debugger::VisitObjectPointers(ObjectPointerVisitor* visitor) { 282 void Debugger::VisitObjectPointers(ObjectPointerVisitor* visitor) {
267 ASSERT(visitor != NULL); 283 ASSERT(visitor != NULL);
(...skipping 21 matching lines...) Expand all
289 } 305 }
290 306
291 307
292 void Debugger::BreakpointCallback() { 308 void Debugger::BreakpointCallback() {
293 ASSERT(initialized_); 309 ASSERT(initialized_);
294 DartFrameIterator iterator; 310 DartFrameIterator iterator;
295 DartFrame* frame = iterator.NextFrame(); 311 DartFrame* frame = iterator.NextFrame();
296 ASSERT(frame != NULL); 312 ASSERT(frame != NULL);
297 Breakpoint* bpt = GetBreakpoint(frame->pc()); 313 Breakpoint* bpt = GetBreakpoint(frame->pc());
298 ASSERT(bpt != NULL); 314 ASSERT(bpt != NULL);
299 OS::Print(">>> Breakpoint at %s:%d (Address %p)\n", 315 if (verbose) {
300 bpt ? String::Handle(bpt->SourceUrl()).ToCString() : "?", 316 OS::Print(">>> Breakpoint at %s:%d (Address %p)\n",
301 bpt ? bpt->LineNumber() : 0, 317 bpt ? String::Handle(bpt->SourceUrl()).ToCString() : "?",
302 frame->pc()); 318 bpt ? bpt->LineNumber() : 0,
319 frame->pc());
320 }
303 StackTrace* stack_trace = new StackTrace(8); 321 StackTrace* stack_trace = new StackTrace(8);
304 while (frame != NULL) { 322 while (frame != NULL) {
305 ASSERT(frame->IsValid()); 323 ASSERT(frame->IsValid());
306 ASSERT(frame->IsDartFrame()); 324 ASSERT(frame->IsDartFrame());
307 ActivationFrame* activation = new ActivationFrame(frame->pc()); 325 ActivationFrame* activation = new ActivationFrame(frame->pc());
308 stack_trace->AddActivation(activation); 326 stack_trace->AddActivation(activation);
309 frame = iterator.NextFrame(); 327 frame = iterator.NextFrame();
310 } 328 }
311 329
312 if (bp_handler_ != NULL) { 330 if (bp_handler_ != NULL) {
(...skipping 24 matching lines...) Expand all
337 355
338 356
339 void Debugger::AddBreakpoint(Breakpoint* bpt) { 357 void Debugger::AddBreakpoint(Breakpoint* bpt) {
340 ASSERT(bpt->next() == NULL); 358 ASSERT(bpt->next() == NULL);
341 bpt->set_next(this->breakpoints_); 359 bpt->set_next(this->breakpoints_);
342 this->breakpoints_ = bpt; 360 this->breakpoints_ = bpt;
343 } 361 }
344 362
345 363
346 } // namespace dart 364 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/debugger.h ('k') | runtime/vm/debugger_api_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698