OLD | NEW |
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" |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 } | 178 } |
179 | 179 |
180 | 180 |
181 Debugger::Debugger() | 181 Debugger::Debugger() |
182 : initialized_(false), | 182 : initialized_(false), |
183 bp_handler_(NULL), | 183 bp_handler_(NULL), |
184 breakpoints_(NULL) { | 184 breakpoints_(NULL) { |
185 } | 185 } |
186 | 186 |
187 | 187 |
188 static RawFunction* ResolveLibraryFunction(const String& fname) { | 188 static RawFunction* ResolveLibraryFunction( |
189 Isolate* isolate = Isolate::Current(); | 189 const Library& library, |
190 const Library& root_lib = | 190 const String& fname) { |
191 Library::Handle(isolate->object_store()->root_library()); | 191 ASSERT(!library.IsNull()); |
192 ASSERT(!root_lib.IsNull()); | |
193 Function& function = Function::Handle(); | 192 Function& function = Function::Handle(); |
194 const Object& object = Object::Handle(root_lib.LookupObject(fname)); | 193 const Object& object = Object::Handle(library.LookupObject(fname)); |
195 if (!object.IsNull() && object.IsFunction()) { | 194 if (!object.IsNull() && object.IsFunction()) { |
196 function ^= object.raw(); | 195 function ^= object.raw(); |
197 } | 196 } |
198 return function.raw(); | 197 return function.raw(); |
199 } | 198 } |
200 | 199 |
201 | 200 |
202 static RawFunction* ResolveFunction(const String& class_name, | 201 RawFunction* Debugger::ResolveFunction(const Library& library, |
203 const String& function_name) { | 202 const String& class_name, |
204 Isolate* isolate = Isolate::Current(); | 203 const String& function_name) { |
205 const Library& root_lib = | 204 ASSERT(!library.IsNull()); |
206 Library::Handle(isolate->object_store()->root_library()); | 205 ASSERT(!class_name.IsNull()); |
207 const Class& cls = Class::Handle(root_lib.LookupClass(class_name)); | 206 ASSERT(!function_name.IsNull()); |
208 | 207 if (class_name.Length() == 0) { |
| 208 return ResolveLibraryFunction(library, function_name); |
| 209 } |
| 210 const Class& cls = Class::Handle(library.LookupClass(class_name)); |
209 Function& function = Function::Handle(); | 211 Function& function = Function::Handle(); |
210 if (!cls.IsNull()) { | 212 if (!cls.IsNull()) { |
211 function = cls.LookupStaticFunction(function_name); | 213 function = cls.LookupStaticFunction(function_name); |
212 if (function.IsNull()) { | 214 if (function.IsNull()) { |
213 function = cls.LookupDynamicFunction(function_name); | 215 function = cls.LookupDynamicFunction(function_name); |
214 } | 216 } |
215 } | 217 } |
216 return function.raw(); | 218 return function.raw(); |
217 } | 219 } |
218 | 220 |
219 | 221 |
220 void Debugger::SetBreakpointAtEntry(const String& class_name, | 222 Breakpoint* Debugger::SetBreakpointAtEntry(const Function& target_function) { |
221 const String& function_name) { | 223 ASSERT(!target_function.IsNull()); |
222 Function& func = Function::Handle(); | 224 if (!target_function.HasCode()) { |
223 if (class_name.IsNull() || (class_name.Length() == 0)) { | 225 Compiler::CompileFunction(target_function); |
224 func = ResolveLibraryFunction(function_name); | |
225 } else { | |
226 func = ResolveFunction(class_name, function_name); | |
227 } | 226 } |
228 if (func.IsNull()) { | 227 Code& code = Code::Handle(target_function.code()); |
229 OS::Print("could not find function '%s'\n", function_name.ToCString()); | |
230 return; | |
231 } | |
232 if (!func.HasCode()) { | |
233 Compiler::CompileFunction(func); | |
234 } | |
235 Code& code = Code::Handle(func.code()); | |
236 ASSERT(!code.IsNull()); | 228 ASSERT(!code.IsNull()); |
237 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); | 229 PcDescriptors& desc = PcDescriptors::Handle(code.pc_descriptors()); |
238 for (int i = 0; i < desc.Length(); i++) { | 230 for (int i = 0; i < desc.Length(); i++) { |
239 PcDescriptors::Kind kind = desc.DescriptorKind(i); | 231 PcDescriptors::Kind kind = desc.DescriptorKind(i); |
240 Breakpoint* bpt = NULL; | 232 Breakpoint* bpt = NULL; |
241 if (kind == PcDescriptors::kIcCall) { | 233 if (kind == PcDescriptors::kIcCall) { |
242 CodePatcher::PatchInstanceCallAt( | 234 CodePatcher::PatchInstanceCallAt( |
243 desc.PC(i), StubCode::BreakpointDynamicEntryPoint()); | 235 desc.PC(i), StubCode::BreakpointDynamicEntryPoint()); |
244 bpt = new Breakpoint(func, i); | 236 bpt = new Breakpoint(target_function, i); |
245 } else if (kind == PcDescriptors::kOther) { | 237 } else if (kind == PcDescriptors::kOther) { |
246 if (CodePatcher::IsDartCall(desc.PC(i))) { | 238 if (CodePatcher::IsDartCall(desc.PC(i))) { |
247 CodePatcher::PatchStaticCallAt( | 239 CodePatcher::PatchStaticCallAt( |
248 desc.PC(i), StubCode::BreakpointStaticEntryPoint()); | 240 desc.PC(i), StubCode::BreakpointStaticEntryPoint()); |
249 bpt = new Breakpoint(func, i); | 241 bpt = new Breakpoint(target_function, i); |
250 } | 242 } |
251 } | 243 } |
252 if (bpt != NULL) { | 244 if (bpt != NULL) { |
253 OS::Print("Setting breakpoint at '%s' line %d (PC %p)\n", | 245 OS::Print("Setting breakpoint at '%s' line %d (PC %p)\n", |
254 String::Handle(bpt->SourceUrl()).ToCString(), | 246 String::Handle(bpt->SourceUrl()).ToCString(), |
255 bpt->LineNumber(), | 247 bpt->LineNumber(), |
256 bpt->pc()); | 248 bpt->pc()); |
257 AddBreakpoint(bpt); | 249 AddBreakpoint(bpt); |
258 return; | 250 return bpt; |
259 } | 251 } |
260 } | 252 } |
261 OS::Print("no breakpoint location found in function '%s'\n", | 253 return NULL; |
262 function_name.ToCString()); | |
263 } | 254 } |
264 | 255 |
265 | 256 |
266 void Debugger::VisitObjectPointers(ObjectPointerVisitor* visitor) { | 257 void Debugger::VisitObjectPointers(ObjectPointerVisitor* visitor) { |
267 ASSERT(visitor != NULL); | 258 ASSERT(visitor != NULL); |
268 Breakpoint* bpt = this->breakpoints_; | 259 Breakpoint* bpt = this->breakpoints_; |
269 while (bpt != NULL) { | 260 while (bpt != NULL) { |
270 bpt->VisitObjectPointers(visitor); | 261 bpt->VisitObjectPointers(visitor); |
271 bpt = bpt->next(); | 262 bpt = bpt->next(); |
272 } | 263 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 (*bp_handler_)(bpt, stack_trace); | 304 (*bp_handler_)(bpt, stack_trace); |
314 } | 305 } |
315 } | 306 } |
316 | 307 |
317 | 308 |
318 void Debugger::Initialize(Isolate* isolate) { | 309 void Debugger::Initialize(Isolate* isolate) { |
319 if (initialized_) { | 310 if (initialized_) { |
320 return; | 311 return; |
321 } | 312 } |
322 initialized_ = true; | 313 initialized_ = true; |
323 if (!FLAG_debugger) { | |
324 return; | |
325 } | |
326 if (FLAG_bpt == NULL) { | |
327 FLAG_bpt = "main"; | |
328 } | |
329 String& cname = String::Handle(); | |
330 String& fname = String::Handle(); | |
331 const char* dot = strchr(FLAG_bpt, '.'); | |
332 if (dot == NULL) { | |
333 fname = String::New(FLAG_bpt); | |
334 } else { | |
335 fname = String::New(dot + 1); | |
336 cname = String::New(reinterpret_cast<const uint8_t*>(FLAG_bpt), | |
337 dot - FLAG_bpt); | |
338 } | |
339 SetBreakpointHandler(DefaultBreakpointHandler); | 314 SetBreakpointHandler(DefaultBreakpointHandler); |
340 SetBreakpointAtEntry(cname, fname); | |
341 } | 315 } |
342 | 316 |
343 | 317 |
344 Breakpoint* Debugger::GetBreakpoint(uword breakpoint_address) { | 318 Breakpoint* Debugger::GetBreakpoint(uword breakpoint_address) { |
345 Breakpoint* bpt = this->breakpoints_; | 319 Breakpoint* bpt = this->breakpoints_; |
346 while (bpt != NULL) { | 320 while (bpt != NULL) { |
347 if (bpt->pc() == breakpoint_address) { | 321 if (bpt->pc() == breakpoint_address) { |
348 return bpt; | 322 return bpt; |
349 } | 323 } |
350 bpt = bpt->next(); | 324 bpt = bpt->next(); |
351 } | 325 } |
352 return NULL; | 326 return NULL; |
353 } | 327 } |
354 | 328 |
355 | 329 |
356 void Debugger::AddBreakpoint(Breakpoint* bpt) { | 330 void Debugger::AddBreakpoint(Breakpoint* bpt) { |
357 ASSERT(bpt->next() == NULL); | 331 ASSERT(bpt->next() == NULL); |
358 bpt->set_next(this->breakpoints_); | 332 bpt->set_next(this->breakpoints_); |
359 this->breakpoints_ = bpt; | 333 this->breakpoints_ = bpt; |
360 } | 334 } |
361 | 335 |
362 | 336 |
363 } // namespace dart | 337 } // namespace dart |
OLD | NEW |