| 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 #ifndef VM_DEBUGGER_H_ | 5 #ifndef VM_DEBUGGER_H_ |
| 6 #define VM_DEBUGGER_H_ | 6 #define VM_DEBUGGER_H_ |
| 7 | 7 |
| 8 #include "vm/object.h" | 8 #include "vm/object.h" |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| 11 | 11 |
| 12 class SourceBreakpoint; | 12 class SourceBreakpoint; |
| 13 class CodeBreakpoint; | 13 class CodeBreakpoint; |
| 14 class Isolate; | 14 class Isolate; |
| 15 class ObjectPointerVisitor; | 15 class ObjectPointerVisitor; |
| 16 class ActiveVariables; | 16 class ActiveVariables; |
| 17 | 17 |
| 18 | 18 |
| 19 // SourceBreakpoint represents a user-specified breakpoint location in | 19 // SourceBreakpoint represents a user-specified breakpoint location in |
| 20 // Dart source. There may be more than one CodeBreakpoint object per | 20 // Dart source. There may be more than one CodeBreakpoint object per |
| 21 // SourceBreakpoint. | 21 // SourceBreakpoint. |
| 22 class SourceBreakpoint { | 22 class SourceBreakpoint { |
| 23 public: | 23 public: |
| 24 SourceBreakpoint(const Function& func, intptr_t token_index); | 24 SourceBreakpoint(intptr_t id, const Function& func, intptr_t token_index); |
| 25 | 25 |
| 26 RawFunction* function() const { return function_; } | 26 RawFunction* function() const { return function_; } |
| 27 intptr_t token_index() const { return token_index_; } | 27 intptr_t token_index() const { return token_index_; } |
| 28 intptr_t id() const { return id_; } |
| 28 | 29 |
| 29 RawScript* SourceCode(); | 30 RawScript* SourceCode(); |
| 30 RawString* SourceUrl(); | 31 RawString* SourceUrl(); |
| 31 intptr_t LineNumber(); | 32 intptr_t LineNumber(); |
| 32 | 33 |
| 33 void Enable(); | 34 void Enable(); |
| 34 void Disable(); | 35 void Disable(); |
| 35 bool IsEnabled() const { return is_enabled_; } | 36 bool IsEnabled() const { return is_enabled_; } |
| 36 | 37 |
| 37 private: | 38 private: |
| 38 void VisitObjectPointers(ObjectPointerVisitor* visitor); | 39 void VisitObjectPointers(ObjectPointerVisitor* visitor); |
| 39 | 40 |
| 40 void set_function(const Function& func); | 41 void set_function(const Function& func); |
| 41 void set_next(SourceBreakpoint* value) { next_ = value; } | 42 void set_next(SourceBreakpoint* value) { next_ = value; } |
| 42 SourceBreakpoint* next() const { return this->next_; } | 43 SourceBreakpoint* next() const { return this->next_; } |
| 43 | 44 |
| 45 const intptr_t id_; |
| 44 RawFunction* function_; | 46 RawFunction* function_; |
| 45 intptr_t token_index_; | 47 const intptr_t token_index_; |
| 46 intptr_t line_number_; | 48 intptr_t line_number_; |
| 47 bool is_enabled_; | 49 bool is_enabled_; |
| 48 | 50 |
| 49 SourceBreakpoint* next_; | 51 SourceBreakpoint* next_; |
| 50 | 52 |
| 51 friend class Debugger; | 53 friend class Debugger; |
| 52 DISALLOW_COPY_AND_ASSIGN(SourceBreakpoint); | 54 DISALLOW_COPY_AND_ASSIGN(SourceBreakpoint); |
| 53 }; | 55 }; |
| 54 | 56 |
| 55 | 57 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 179 |
| 178 friend class Debugger; | 180 friend class Debugger; |
| 179 DISALLOW_COPY_AND_ASSIGN(DebuggerStackTrace); | 181 DISALLOW_COPY_AND_ASSIGN(DebuggerStackTrace); |
| 180 }; | 182 }; |
| 181 | 183 |
| 182 | 184 |
| 183 typedef void BreakpointHandler(SourceBreakpoint* bpt, | 185 typedef void BreakpointHandler(SourceBreakpoint* bpt, |
| 184 DebuggerStackTrace* stack); | 186 DebuggerStackTrace* stack); |
| 185 | 187 |
| 186 | 188 |
| 189 |
| 187 class Debugger { | 190 class Debugger { |
| 188 public: | 191 public: |
| 192 enum EventType { |
| 193 kPaused = 1, |
| 194 kBreakpointResolved = 2, |
| 195 }; |
| 196 struct DebuggerEvent { |
| 197 EventType type; |
| 198 union { |
| 199 DebuggerStackTrace* stack_trace; |
| 200 SourceBreakpoint* breakpoint; |
| 201 }; |
| 202 }; |
| 203 typedef void EventHandler(DebuggerEvent *event); |
| 204 |
| 189 Debugger(); | 205 Debugger(); |
| 190 ~Debugger(); | 206 ~Debugger(); |
| 191 | 207 |
| 192 void Initialize(Isolate* isolate); | 208 void Initialize(Isolate* isolate); |
| 193 void Shutdown(); | 209 void Shutdown(); |
| 194 bool IsActive(); | 210 bool IsActive(); |
| 195 | 211 |
| 196 void NotifyCompilation(const Function& func); | 212 void NotifyCompilation(const Function& func); |
| 197 | 213 |
| 214 void SetEventHandler(EventHandler* handler); |
| 198 void SetBreakpointHandler(BreakpointHandler* handler); | 215 void SetBreakpointHandler(BreakpointHandler* handler); |
| 199 | 216 |
| 200 RawFunction* ResolveFunction(const Library& library, | 217 RawFunction* ResolveFunction(const Library& library, |
| 201 const String& class_name, | 218 const String& class_name, |
| 202 const String& function_name); | 219 const String& function_name); |
| 203 | 220 |
| 204 // Set breakpoint at closest location to function entry. | 221 // Set breakpoint at closest location to function entry. |
| 205 SourceBreakpoint* SetBreakpointAtEntry(const Function& target_function); | 222 SourceBreakpoint* SetBreakpointAtEntry(const Function& target_function); |
| 206 SourceBreakpoint* SetBreakpointAtLine(const String& script_url, | 223 SourceBreakpoint* SetBreakpointAtLine(const String& script_url, |
| 207 intptr_t line_number); | 224 intptr_t line_number); |
| 208 | 225 |
| 209 void RemoveBreakpoint(SourceBreakpoint* bpt); | 226 void RemoveBreakpoint(intptr_t bp_id); |
| 227 SourceBreakpoint* GetBreakpointById(intptr_t id); |
| 210 | 228 |
| 211 void SetStepOver() { resume_action_ = kStepOver; } | 229 void SetStepOver() { resume_action_ = kStepOver; } |
| 212 void SetStepInto() { resume_action_ = kStepInto; } | 230 void SetStepInto() { resume_action_ = kStepInto; } |
| 213 void SetStepOut() { resume_action_ = kStepOut; } | 231 void SetStepOut() { resume_action_ = kStepOut; } |
| 214 | 232 |
| 215 void VisitObjectPointers(ObjectPointerVisitor* visitor); | 233 void VisitObjectPointers(ObjectPointerVisitor* visitor); |
| 216 | 234 |
| 217 // Called from Runtime when a breakpoint in Dart code is reached. | 235 // Called from Runtime when a breakpoint in Dart code is reached. |
| 218 void BreakpointCallback(); | 236 void BreakpointCallback(); |
| 219 | 237 |
| 238 DebuggerStackTrace* StackTrace() const { return stack_trace_; } |
| 239 |
| 220 RawArray* GetInstanceFields(const Instance& obj); | 240 RawArray* GetInstanceFields(const Instance& obj); |
| 221 RawArray* GetStaticFields(const Class& cls); | 241 RawArray* GetStaticFields(const Class& cls); |
| 222 | 242 |
| 223 // Utility functions. | 243 // Utility functions. |
| 224 static const char* QualifiedFunctionName(const Function& func); | 244 static const char* QualifiedFunctionName(const Function& func); |
| 225 | 245 |
| 226 RawObject* GetInstanceField(const Class& cls, | 246 RawObject* GetInstanceField(const Class& cls, |
| 227 const String& field_name, | 247 const String& field_name, |
| 228 const Instance& object); | 248 const Instance& object); |
| 229 RawObject* GetStaticField(const Class& cls, | 249 RawObject* GetStaticField(const Class& cls, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 248 SourceBreakpoint* GetSourceBreakpoint(const Function& func, | 268 SourceBreakpoint* GetSourceBreakpoint(const Function& func, |
| 249 intptr_t token_index); | 269 intptr_t token_index); |
| 250 CodeBreakpoint* MakeCodeBreakpoint(const Function& func, | 270 CodeBreakpoint* MakeCodeBreakpoint(const Function& func, |
| 251 intptr_t token_index); | 271 intptr_t token_index); |
| 252 | 272 |
| 253 // Returns NULL if no breakpoint exists for the given address. | 273 // Returns NULL if no breakpoint exists for the given address. |
| 254 CodeBreakpoint* GetCodeBreakpoint(uword breakpoint_address); | 274 CodeBreakpoint* GetCodeBreakpoint(uword breakpoint_address); |
| 255 | 275 |
| 256 void SyncBreakpoint(SourceBreakpoint* bpt); | 276 void SyncBreakpoint(SourceBreakpoint* bpt); |
| 257 | 277 |
| 278 void SignalBpResolved(SourceBreakpoint *bpt); |
| 279 |
| 280 intptr_t nextId() { return next_id_++; } |
| 281 |
| 258 Isolate* isolate_; | 282 Isolate* isolate_; |
| 259 bool initialized_; | 283 bool initialized_; |
| 260 BreakpointHandler* bp_handler_; | 284 BreakpointHandler* bp_handler_; |
| 285 EventHandler* event_handler_; |
| 286 |
| 287 // ID number generator. |
| 288 intptr_t next_id_; |
| 289 |
| 290 // Current stack trace. Valid while executing breakpoint callback code. |
| 291 DebuggerStackTrace* stack_trace_; |
| 292 |
| 261 SourceBreakpoint* src_breakpoints_; | 293 SourceBreakpoint* src_breakpoints_; |
| 262 CodeBreakpoint* code_breakpoints_; | 294 CodeBreakpoint* code_breakpoints_; |
| 263 | 295 |
| 264 // Tells debugger what to do when resuming execution after a breakpoint. | 296 // Tells debugger what to do when resuming execution after a breakpoint. |
| 265 ResumeAction resume_action_; | 297 ResumeAction resume_action_; |
| 266 | 298 |
| 267 // Do not call back to breakpoint handler if this flag is set. | 299 // Do not call back to breakpoint handler if this flag is set. |
| 268 // Effectively this means ignoring breakpoints. Set when Dart code may | 300 // Effectively this means ignoring breakpoints. Set when Dart code may |
| 269 // be run as a side effect of getting values of fields. | 301 // be run as a side effect of getting values of fields. |
| 270 bool ignore_breakpoints_; | 302 bool ignore_breakpoints_; |
| 271 | 303 |
| 272 friend class SourceBreakpoint; | 304 friend class SourceBreakpoint; |
| 273 DISALLOW_COPY_AND_ASSIGN(Debugger); | 305 DISALLOW_COPY_AND_ASSIGN(Debugger); |
| 274 }; | 306 }; |
| 275 | 307 |
| 276 | 308 |
| 277 } // namespace dart | 309 } // namespace dart |
| 278 | 310 |
| 279 #endif // VM_DEBUGGER_H_ | 311 #endif // VM_DEBUGGER_H_ |
| OLD | NEW |