| 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 #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 Breakpoint; | 12 class Breakpoint; |
| 13 class Isolate; | 13 class Isolate; |
| 14 class ObjectPointerVisitor; | 14 class ObjectPointerVisitor; |
| 15 | 15 |
| 16 |
| 17 // Breakpoint represents a location in Dart source and the corresponding |
| 18 // address in compiled code. |
| 19 class Breakpoint { |
| 20 public: |
| 21 Breakpoint(const Function& func, intptr_t pc_desc_index); |
| 22 |
| 23 RawFunction* function() const { return function_; } |
| 24 uword pc() const { return pc_; } |
| 25 |
| 26 RawScript* SourceCode(); |
| 27 RawString* SourceUrl(); |
| 28 intptr_t LineNumber(); |
| 29 |
| 30 private: |
| 31 void VisitObjectPointers(ObjectPointerVisitor* visitor); |
| 32 |
| 33 void set_next(Breakpoint* value) { next_ = value; } |
| 34 Breakpoint* next() const { return this->next_; } |
| 35 |
| 36 RawFunction* function_; |
| 37 intptr_t pc_desc_index_; |
| 38 intptr_t token_index_; |
| 39 uword pc_; |
| 40 intptr_t line_number_; |
| 41 Breakpoint* next_; |
| 42 |
| 43 friend class Debugger; |
| 44 DISALLOW_COPY_AND_ASSIGN(Breakpoint); |
| 45 }; |
| 46 |
| 47 |
| 48 // ActivationFrame represents one dart function activation frame |
| 49 // on the call stack. |
| 50 class ActivationFrame : public ZoneAllocated { |
| 51 public: |
| 52 explicit ActivationFrame(uword pc); |
| 53 |
| 54 uword pc() const { return pc_; } |
| 55 |
| 56 RawFunction* DartFunction(); |
| 57 RawString* SourceUrl(); |
| 58 RawScript* SourceScript(); |
| 59 intptr_t TokenIndex(); |
| 60 intptr_t LineNumber(); |
| 61 const char* ToCString(); |
| 62 |
| 63 // Returns an array of String values containing variable names |
| 64 // in this activation frame. |
| 65 RawArray* Variables(); |
| 66 |
| 67 // Returns the value of the given variable in the context of the |
| 68 // activation frame. |
| 69 RawInstance* Value(const String& variable_name); |
| 70 |
| 71 private: |
| 72 uword pc_; |
| 73 RawFunction* function_; |
| 74 intptr_t token_index_; |
| 75 intptr_t line_number_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(ActivationFrame); |
| 78 }; |
| 79 |
| 80 |
| 81 // Array of function activations on the call stack. |
| 82 class StackTrace : public ZoneAllocated { |
| 83 public: |
| 84 explicit StackTrace(int capacity) : trace_(capacity) { } |
| 85 |
| 86 intptr_t Length() const { return trace_.length(); } |
| 87 |
| 88 ActivationFrame* ActivationFrameAt(int i) const { |
| 89 ASSERT(i < trace_.length()); |
| 90 return trace_[i]; |
| 91 } |
| 92 private: |
| 93 void AddActivation(ActivationFrame* frame); |
| 94 ZoneGrowableArray<ActivationFrame*> trace_; |
| 95 |
| 96 friend class Debugger; |
| 97 DISALLOW_COPY_AND_ASSIGN(StackTrace); |
| 98 }; |
| 99 |
| 100 |
| 101 typedef void BreakpointHandler(Breakpoint* bpt, StackTrace* stack); |
| 102 |
| 103 |
| 16 class Debugger { | 104 class Debugger { |
| 17 public: | 105 public: |
| 18 Debugger(); | 106 Debugger(); |
| 19 | 107 |
| 20 void Initialize(Isolate* isolate); | 108 void Initialize(Isolate* isolate); |
| 21 | 109 |
| 110 void SetBreakpointHandler(BreakpointHandler* handler); |
| 111 |
| 22 // Set breakpoint at closest location to function entry. | 112 // Set breakpoint at closest location to function entry. |
| 23 void SetBreakpointAtEntry(const String& class_name, | 113 void SetBreakpointAtEntry(const String& class_name, |
| 24 const String& function_name); | 114 const String& function_name); |
| 25 | 115 |
| 26 void VisitObjectPointers(ObjectPointerVisitor* visitor); | 116 void VisitObjectPointers(ObjectPointerVisitor* visitor); |
| 27 | 117 |
| 28 // Returns NULL if no breakpoint exists for the given address. | 118 // Returns NULL if no breakpoint exists for the given address. |
| 29 Breakpoint* GetBreakpoint(uword breakpoint_address); | 119 Breakpoint* GetBreakpoint(uword breakpoint_address); |
| 30 | 120 |
| 121 // Called from Runtime when a breakpoint in Dart code is reached. |
| 122 void BreakpointCallback(); |
| 123 |
| 31 private: | 124 private: |
| 32 void AddBreakpoint(Breakpoint* bpt); | 125 void AddBreakpoint(Breakpoint* bpt); |
| 33 | 126 |
| 34 bool initialized_; | 127 bool initialized_; |
| 128 BreakpointHandler* bp_handler_; |
| 35 Breakpoint* breakpoints_; | 129 Breakpoint* breakpoints_; |
| 36 DISALLOW_COPY_AND_ASSIGN(Debugger); | 130 DISALLOW_COPY_AND_ASSIGN(Debugger); |
| 37 }; | 131 }; |
| 38 | 132 |
| 39 | 133 |
| 40 } // namespace dart | 134 } // namespace dart |
| 41 | 135 |
| 42 #endif // VM_DEBUGGER_H_ | 136 #endif // VM_DEBUGGER_H_ |
| OLD | NEW |