| 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: | 56 public: |
| 63 // Contruct a Target object. By default use the native ABI. | 57 // Contruct a Target object. By default use the native ABI. |
| 64 explicit Target(const Abi *abi = NULL); | 58 explicit Target(const Abi *abi = NULL); |
| 65 ~Target(); | 59 ~Target(); |
| 66 | 60 |
| 67 // Init must be the first function called to correctlty | 61 // Init must be the first function called to correctlty |
| 68 // build the Target internal structures. | 62 // build the Target internal structures. |
| 69 bool Init(); | 63 bool Init(); |
| 70 | 64 |
| 65 // Set/Get locally cached properties |
| 66 bool SetProperty(const std::string &name, const std::string& val); |
| 67 bool GetProperty(const std::string &name, std::string* val) const; |
| 68 |
| 69 // MatchQuery does a longest prefix match against the locally cased |
| 70 // properties, and returns the length of the match, as well as the |
| 71 // requested value. |
| 72 size_t MatchQuery(const std::string& match, std::string* val) const; |
| 73 |
| 71 // Add and remove temporary breakpoints. These breakpoints | 74 // Add and remove temporary breakpoints. These breakpoints |
| 72 // must be added just before we start running, and removed | 75 // must be added just before we start running, and removed |
| 73 // just before we stop running to prevent the debugger from | 76 // just before we stop running to prevent the debugger from |
| 74 // seeing the modified memory. | 77 // seeing the modified memory. |
| 75 bool AddTemporaryBreakpoint(uint64_t address); | 78 bool AddTemporaryBreakpoint(uint64_t address); |
| 76 bool RemoveTemporaryBreakpoints(); | 79 bool RemoveTemporaryBreakpoints(); |
| 77 | 80 |
| 78 // This function should be called by a tracked thread when it takes | 81 // This function should be called by a tracked thread when it takes |
| 79 // an exception. It takes sig_start_ to prevent other exceptions | 82 // an exception. It takes sig_start_ to prevent other exceptions |
| 80 // from signalling thread. If wait is true, it will then block on | 83 // from signalling thread. If wait is true, it will then block on |
| 81 // sig_done_ until a continue is issued by the host. | 84 // sig_done_ until a continue is issued by the host. |
| 82 void Signal(uint32_t id, int8_t sig, bool wait); | 85 void Signal(uint32_t id, int8_t sig, bool wait); |
| 83 | 86 |
| 84 // This function will spin on a session, until it closes. If an | 87 // This function will spin on a session, until it closes. If an |
| 85 // exception is caught, it will signal the exception thread by | 88 // exception is caught, it will signal the exception thread by |
| 86 // setting sig_done_. | 89 // setting sig_done_. |
| 87 void Run(Session *ses); | 90 void Run(Session *ses); |
| 88 | 91 |
| 89 // This function causes the target to track the state | 92 // This function causes the target to track the state |
| 90 // of the specified thread and make it availible to | 93 // of the specified thread and make it availible to |
| 91 // a connected host. | 94 // a connected host. |
| 92 void TrackThread(port::IThread *thread); | 95 void TrackThread(port::IThread *thread); |
| 93 | 96 |
| 94 // This function causes the target to stop tracking the | 97 // This function causes the target to stop tracking the |
| 95 // state of the specified thread, which will no longer | 98 // state of the specified thread, which will no longer |
| 96 // be visible to the host. | 99 // be visible to the host. |
| 97 void IgnoreThread(port::IThread *thread); | 100 void IgnoreThread(port::IThread *thread); |
| 98 | 101 |
| 99 protected: | 102 protected: |
| 103 // Protected member functions, should only be called by the stub thread |
| 104 // from within "Run", at which point stateMutex_ is already held, so |
| 105 // it is always safe for a protected function to access the signal |
| 106 // state or thread map. |
| 107 |
| 108 // Called whenever the target transitions from running to stopped to |
| 109 // update information about the current state. |
| 110 void Update(); |
| 111 |
| 112 // Called to stop and start all debug threads |
| 113 void Pause(); |
| 114 void Resume(); |
| 115 |
| 100 // This function always succeedes, since all errors | 116 // This function always succeedes, since all errors |
| 101 // are reported as an error string of "E<##>" where | 117 // are reported as an error string of "E<##>" where |
| 102 // the two digit number. The error codes are not | 118 // the two digit number. The error codes are not |
| 103 // not documented, so this implementation uses | 119 // not documented, so this implementation uses |
| 104 // ErrDef as errors codes. This function returns | 120 // ErrDef as errors codes. This function returns |
| 105 // true a request to continue (or step) is processed. | 121 // true a request to continue (or step) is processed. |
| 106 bool ProcessPacket(Packet *pktIn, Packet *pktOut); | 122 bool ProcessPacket(Packet *pktIn, Packet *pktOut); |
| 107 | 123 |
| 108 void Destroy(); | 124 void Destroy(); |
| 109 void Detach(); | 125 void Detach(); |
| 110 | 126 |
| 111 bool GetFirstThreadId(uint32_t *id); | 127 bool GetFirstThreadId(uint32_t *id); |
| 112 bool GetNextThreadId(uint32_t *id); | 128 bool GetNextThreadId(uint32_t *id); |
| 113 | 129 |
| 114 uint32_t GetRegThreadId() const; | 130 uint32_t GetRegThreadId() const; |
| 115 uint32_t GetRunThreadId() const; | 131 uint32_t GetRunThreadId() const; |
| 116 port::IThread *GetThread(uint32_t id); | 132 port::IThread *GetThread(uint32_t id) const; |
| 117 | 133 |
| 118 public: | 134 private: |
| 119 const Abi *abi_; | 135 const Abi *abi_; |
| 120 | 136 |
| 121 // This mutex protects debugging state (threads_, cur_signal, sig_thread_) | 137 // This mutex protects debugging state (threads_, cur_signal, sig_thread_). |
| 122 port::IMutex *mutex_; | 138 // This mutex is held by the stub thread, while in a broken state. |
| 139 port::IMutex *stateMutex_; |
| 140 |
| 141 // This mutex protects the public data (breakpoint, property), and is only |
| 142 // held temporarily as needed. |
| 143 port::IMutex *publicMutex_; |
| 123 | 144 |
| 124 // This event is signalled when the target is really to process an | 145 // This event is signalled when the target is really to process an |
| 125 // exception. It ensures only one exception is processed at a time. | 146 // exception. It ensures only one exception is processed at a time. |
| 126 port::IEvent *sig_start_; | 147 port::IEvent *sig_start_; |
| 127 | 148 |
| 128 // This event is signalled when the target done processing an exception. | 149 // This event is signalled when the target done processing an exception. |
| 129 port::IEvent *sig_done_; | 150 port::IEvent *sig_done_; |
| 130 | 151 |
| 131 // This value is set if the exception cather is requesting a continue signal | 152 // This value is set if the exception cather is requesting a continue signal |
| 132 bool send_done_; | 153 bool send_done_; |
| 133 | 154 |
| 134 ThreadMap_t threads_; | 155 ThreadMap_t threads_; |
| 135 ThreadMap_t::const_iterator threadItr_; | 156 ThreadMap_t::const_iterator threadItr_; |
| 136 BreakMap_t breakMap_; | 157 BreakMap_t breakMap_; |
| 137 | 158 |
| 138 | 159 // A map of generic properties for the target. |
| 139 PropertyMap_t properties_; | 160 PropertyMap_t properties_; |
| 140 | 161 |
| 141 uint8_t *ctx_; // Context Scratchpad | 162 // Context Scratchpad |
| 163 uint8_t *ctx_; |
| 142 | 164 |
| 143 // The current signal and signaling thread data is protected by | 165 // The current signal and signaling thread data is protected by |
| 144 // the mutex, and can only be owned by one thread at a time. | 166 // the mutex, and can only be owned by one thread at a time. |
| 145 // These values should only be written via the "Signal" member, | 167 // These values should only be written via the "Signal" member, |
| 146 // which will ensure that a new signal does not overwrite a | 168 // which will ensure that a new signal does not overwrite a |
| 147 // previous signal. | 169 // previous signal. |
| 148 volatile int8_t cur_signal_; | 170 volatile int8_t cur_signal_; |
| 149 volatile uint32_t sig_thread_; | 171 volatile uint32_t sig_thread_; |
| 150 | 172 |
| 151 uint32_t run_thread_; // Which thread to issue step commands on | 173 // The debugger tracks two thread ids for its operations, one for |
| 152 uint32_t reg_thread_; // Which thread to issue context (reg) commands on | 174 // getting and setting registers, the other for step and continue. |
| 175 // The value can be 0 for any, -1 for all, or a specific ID for |
| 176 // a specific thread. The "_req_" variable stores the requested |
| 177 // id, while the "_last_" value stores the last value returned. |
| 178 uint32_t run_req_; // Requested thread for run operations. |
| 179 uint32_t reg_req_; // Requested thread for reg operations. |
| 180 mutable uint32_t run_last_; // Last result from a run thread query. |
| 181 mutable uint32_t reg_last_; // Last result from a reg thread query. |
| 153 }; | 182 }; |
| 154 | 183 |
| 155 | 184 |
| 156 } // namespace gdb_rsp | 185 } // namespace gdb_rsp |
| 157 | 186 |
| 158 #endif // NATIVE_CLIENT_GDB_RSP_TARGET_H_ | 187 #endif // NATIVE_CLIENT_GDB_RSP_TARGET_H_ |
| 159 | 188 |
| OLD | NEW |