OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 The Native Client Authors. All rights reserved. | 2 * Copyright 2010 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can | 3 * Use of this source code is governed by a BSD-style license that can |
4 * be found in the LICENSE file. | 4 * be found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 | 7 |
8 // This module provides interfaces for accessing the debugging state of | 8 // This module provides interfaces for accessing the debugging state of |
9 // the target. The target can use either the thread that took the | 9 // the target. The target can use either the thread that took the |
10 // exception or run in it's own thread. To respond to the host, the | 10 // exception or run in it's own thread. To respond to the host, the |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 class Target { | 42 class Target { |
43 public: | 43 public: |
44 enum ErrDef { | 44 enum ErrDef { |
45 NONE = 0, | 45 NONE = 0, |
46 BAD_FORMAT = 1, | 46 BAD_FORMAT = 1, |
47 BAD_ARGS = 2, | 47 BAD_ARGS = 2, |
48 FAILED = 3 | 48 FAILED = 3 |
49 }; | 49 }; |
50 | 50 |
51 enum State { | |
52 UNINIT = 0, | |
53 RUNNING = 1, | |
54 STOPPED = 2 | |
55 }; | |
56 | |
57 typedef ErrDef (*QFunc_t)(Target *, stringvec&, std::string); | 51 typedef ErrDef (*QFunc_t)(Target *, stringvec&, std::string); |
58 typedef std::map<uint32_t, port::IThread*> ThreadMap_t; | 52 typedef std::map<uint32_t, port::IThread*> ThreadMap_t; |
59 typedef std::map<std::string, std::string> PropertyMap_t; | 53 typedef std::map<std::string, std::string> PropertyMap_t; |
60 typedef std::map<uint64_t, uint8_t*> BreakMap_t; | 54 typedef std::map<uint64_t, uint8_t*> BreakMap_t; |
61 | 55 |
62 public: | |
63 // Contruct a Target object. By default use the native ABI. | 56 // Contruct a Target object. By default use the native ABI. |
64 explicit Target(const Abi *abi = NULL); | 57 explicit Target(const Abi *abi = NULL); |
65 ~Target(); | 58 ~Target(); |
66 | 59 |
67 // Init must be the first function called to correctlty | 60 // Init must be the first function called to correctlty |
68 // build the Target internal structures. | 61 // build the Target internal structures. |
69 bool Init(); | 62 bool Init(); |
70 | 63 |
| 64 // Set/Get locally cached properties |
| 65 bool SetProperty(const std::string &name, const std::string& val); |
| 66 bool GetProperty(const std::string &name, std::string* val) const; |
| 67 |
| 68 // MatchQuery does a longest prefix match against the locally cached |
| 69 // properties, and returns the length of the match, as well as the |
| 70 // requested value. |
| 71 size_t MatchQuery(const std::string& match, std::string* val) const; |
| 72 |
71 // Add and remove temporary breakpoints. These breakpoints | 73 // Add and remove temporary breakpoints. These breakpoints |
72 // must be added just before we start running, and removed | 74 // must be added just before we start running, and removed |
73 // just before we stop running to prevent the debugger from | 75 // just before we stop running to prevent the debugger from |
74 // seeing the modified memory. | 76 // seeing the modified memory. |
75 bool AddTemporaryBreakpoint(uint64_t address); | 77 bool AddTemporaryBreakpoint(uint64_t address); |
76 bool RemoveTemporaryBreakpoints(); | 78 bool RemoveTemporaryBreakpoints(); |
77 | 79 |
78 // This function should be called by a tracked thread when it takes | 80 // This function should be called by a tracked thread when it takes |
79 // an exception. It takes sig_start_ to prevent other exceptions | 81 // an exception. It takes sig_start_ to prevent other exceptions |
80 // from signalling thread. If wait is true, it will then block on | 82 // from signalling thread. If wait is true, it will then block on |
81 // sig_done_ until a continue is issued by the host. | 83 // sig_done_ until a continue is issued by the host. |
82 void Signal(uint32_t id, int8_t sig, bool wait); | 84 void Signal(uint32_t id, int8_t sig, bool wait); |
83 | 85 |
84 // This function will spin on a session, until it closes. If an | 86 // This function will spin on a session, until it closes. If an |
85 // exception is caught, it will signal the exception thread by | 87 // exception is caught, it will signal the exception thread by |
86 // setting sig_done_. | 88 // setting sig_done_. |
87 void Run(Session *ses); | 89 void Run(Session *ses); |
88 | 90 |
89 // This function causes the target to track the state | 91 // This function causes the target to track the state |
90 // of the specified thread and make it availible to | 92 // of the specified thread and make it availible to |
91 // a connected host. | 93 // a connected host. |
92 void TrackThread(port::IThread *thread); | 94 void TrackThread(port::IThread *thread); |
93 | 95 |
94 // This function causes the target to stop tracking the | 96 // This function causes the target to stop tracking the |
95 // state of the specified thread, which will no longer | 97 // state of the specified thread, which will no longer |
96 // be visible to the host. | 98 // be visible to the host. |
97 void IgnoreThread(port::IThread *thread); | 99 void IgnoreThread(port::IThread *thread); |
98 | 100 |
99 protected: | 101 protected: |
| 102 // Protected member functions, should only be called by the stub thread |
| 103 // from within "Run", at which point stateMutex_ is already held, so |
| 104 // it is always safe for a protected function to access the signal |
| 105 // state or thread map. |
| 106 |
| 107 // Called whenever the target transitions from running to stopped to |
| 108 // update information about the current state. |
| 109 void Update(); |
| 110 |
| 111 // Called to stop and start all debug threads |
| 112 void Pause(); |
| 113 void Resume(); |
| 114 |
100 // This function always succeedes, since all errors | 115 // This function always succeedes, since all errors |
101 // are reported as an error string of "E<##>" where | 116 // are reported as an error string of "E<##>" where |
102 // the two digit number. The error codes are not | 117 // the two digit number. The error codes are not |
103 // not documented, so this implementation uses | 118 // not documented, so this implementation uses |
104 // ErrDef as errors codes. This function returns | 119 // ErrDef as errors codes. This function returns |
105 // true a request to continue (or step) is processed. | 120 // true a request to continue (or step) is processed. |
106 bool ProcessPacket(Packet *pktIn, Packet *pktOut); | 121 bool ProcessPacket(Packet *pktIn, Packet *pktOut); |
107 | 122 |
108 void Destroy(); | 123 void Destroy(); |
109 void Detach(); | 124 void Detach(); |
110 | 125 |
111 bool GetFirstThreadId(uint32_t *id); | 126 bool GetFirstThreadId(uint32_t *id); |
112 bool GetNextThreadId(uint32_t *id); | 127 bool GetNextThreadId(uint32_t *id); |
113 | 128 |
114 uint32_t GetRegThreadId() const; | 129 // If requested_thread_id differs from current_thread_id, updates |
115 uint32_t GetRunThreadId() const; | 130 // current_thread_id to the thread that the debugger wants to operate on. |
116 port::IThread *GetThread(uint32_t id); | 131 // Can be called with either the run_thread_ids or the register_thread_ids |
| 132 // to influence control flow, or to access register values. |
| 133 // Returns the value of current_thread_id. |
| 134 int32_t UpdateThreadId(int32_t requested_thread_id, |
| 135 int32_t *current_thread_id); |
| 136 port::IThread *GetThread(uint32_t id) const; |
117 | 137 |
118 public: | 138 private: |
| 139 |
| 140 // This constant denotes an unintialized thread id. |
| 141 static const int32_t kUninitializedThreadId; |
| 142 // This constant denotes the maximum length of a thread-id query response. |
| 143 static const int32_t kMaxQCResponseLength; |
| 144 |
119 const Abi *abi_; | 145 const Abi *abi_; |
120 | 146 |
121 // This mutex protects debugging state (threads_, cur_signal, sig_thread_) | 147 // This mutex protects debugging state (threads_, cur_signal, |
122 port::IMutex *mutex_; | 148 // signalling_thread_). This mutex is held by the stub thread, while in a |
| 149 // broken state. |
| 150 port::IMutex *stateMutex_; |
| 151 |
| 152 // This mutex protects the public data (breakpoint, property), and is only |
| 153 // held temporarily as needed. |
| 154 port::IMutex *publicMutex_; |
123 | 155 |
124 // This event is signalled when the target is really to process an | 156 // This event is signalled when the target is really to process an |
125 // exception. It ensures only one exception is processed at a time. | 157 // exception. It ensures only one exception is processed at a time. |
126 port::IEvent *sig_start_; | 158 port::IEvent *sig_start_; |
127 | 159 |
128 // This event is signalled when the target done processing an exception. | 160 // This event is signalled when the target done processing an exception. |
129 port::IEvent *sig_done_; | 161 port::IEvent *sig_done_; |
130 | 162 |
131 // This value is set if the exception cather is requesting a continue signal | |
132 bool send_done_; | |
133 | |
134 ThreadMap_t threads_; | 163 ThreadMap_t threads_; |
135 ThreadMap_t::const_iterator threadItr_; | 164 ThreadMap_t::const_iterator threadItr_; |
136 BreakMap_t breakMap_; | 165 BreakMap_t breakMap_; |
137 | 166 |
138 | 167 // A map of generic properties for the target. |
139 PropertyMap_t properties_; | 168 PropertyMap_t properties_; |
140 | 169 |
141 uint8_t *ctx_; // Context Scratchpad | 170 // Context Scratchpad |
| 171 uint8_t *ctx_; |
142 | 172 |
143 // The current signal and signaling thread data is protected by | 173 // The current signal and signalling thread data is protected by |
144 // the mutex, and can only be owned by one thread at a time. | 174 // the mutex, and can only be owned by one thread at a time. |
145 // These values should only be written via the "Signal" member, | 175 // These values should only be written via the "Signal" member, |
146 // which will ensure that a new signal does not overwrite a | 176 // which will ensure that a new signal does not overwrite a |
147 // previous signal. | 177 // previous signal. |
148 volatile int8_t cur_signal_; | 178 volatile int8_t cur_signal_; |
149 volatile uint32_t sig_thread_; | 179 volatile uint32_t signalling_thread_; |
150 | 180 |
151 uint32_t run_thread_; // Which thread to issue step commands on | 181 // The debugger tracks two thread ids for its operations, one for getting |
152 uint32_t reg_thread_; // Which thread to issue context (reg) commands on | 182 // and setting registers, the other for step and continue. |
| 183 // Though they are generally expected to be the same, this is a strict |
| 184 // implementation of the RSP spec. |
| 185 |
| 186 // The thread ID the debugger wants subsequent running related operations |
| 187 // to act on. |
| 188 int32_t requested_run_thread_id_; |
| 189 // The thread ID the debugger wants subsequent register related operations |
| 190 // act on. |
| 191 int32_t requested_register_thread_id_; |
| 192 // The thread ID that the debugger's stepping running operations currently |
| 193 // act on. |
| 194 int32_t current_run_thread_id_; |
| 195 // The thread ID that the debugger's register related operations currently |
| 196 // act on. |
| 197 int32_t current_register_thread_id_; |
153 }; | 198 }; |
154 | |
155 | |
156 } // namespace gdb_rsp | 199 } // namespace gdb_rsp |
157 | 200 |
158 #endif // NATIVE_CLIENT_GDB_RSP_TARGET_H_ | 201 #endif // NATIVE_CLIENT_GDB_RSP_TARGET_H_ |
159 | 202 |
OLD | NEW |