Index: src/trusted/gdb_rsp/target.h |
=================================================================== |
--- src/trusted/gdb_rsp/target.h (revision 3954) |
+++ src/trusted/gdb_rsp/target.h (working copy) |
@@ -48,18 +48,11 @@ |
FAILED = 3 |
}; |
- enum State { |
- UNINIT = 0, |
- RUNNING = 1, |
- STOPPED = 2 |
- }; |
- |
typedef ErrDef (*QFunc_t)(Target *, stringvec&, std::string); |
typedef std::map<uint32_t, port::IThread*> ThreadMap_t; |
typedef std::map<std::string, std::string> PropertyMap_t; |
typedef std::map<uint64_t, uint8_t*> BreakMap_t; |
- public: |
// Contruct a Target object. By default use the native ABI. |
explicit Target(const Abi *abi = NULL); |
~Target(); |
@@ -68,6 +61,15 @@ |
// build the Target internal structures. |
bool Init(); |
+ // Set/Get locally cached properties |
+ bool SetProperty(const std::string &name, const std::string& val); |
+ bool GetProperty(const std::string &name, std::string* val) const; |
+ |
+ // MatchQuery does a longest prefix match against the locally cached |
+ // properties, and returns the length of the match, as well as the |
+ // requested value. |
+ size_t MatchQuery(const std::string& match, std::string* val) const; |
+ |
// Add and remove temporary breakpoints. These breakpoints |
// must be added just before we start running, and removed |
// just before we stop running to prevent the debugger from |
@@ -97,6 +99,19 @@ |
void IgnoreThread(port::IThread *thread); |
protected: |
+ // Protected member functions, should only be called by the stub thread |
+ // from within "Run", at which point stateMutex_ is already held, so |
+ // it is always safe for a protected function to access the signal |
+ // state or thread map. |
+ |
+ // Called whenever the target transitions from running to stopped to |
+ // update information about the current state. |
+ void Update(); |
+ |
+ // Called to stop and start all debug threads |
+ void Pause(); |
+ void Resume(); |
+ |
// This function always succeedes, since all errors |
// are reported as an error string of "E<##>" where |
// the two digit number. The error codes are not |
@@ -111,16 +126,33 @@ |
bool GetFirstThreadId(uint32_t *id); |
bool GetNextThreadId(uint32_t *id); |
- uint32_t GetRegThreadId() const; |
- uint32_t GetRunThreadId() const; |
- port::IThread *GetThread(uint32_t id); |
+ // If requested_thread_id differs from current_thread_id, updates |
+ // current_thread_id to the thread that the debugger wants to operate on. |
+ // Can be called with either the run_thread_ids or the register_thread_ids |
+ // to influence control flow, or to access register values. |
+ // Returns the value of current_thread_id. |
+ int32_t UpdateThreadId(int32_t requested_thread_id, |
+ int32_t *current_thread_id); |
+ port::IThread *GetThread(uint32_t id) const; |
- public: |
+ private: |
+ |
+ // This constant denotes an unintialized thread id. |
+ static const int32_t kUninitializedThreadId; |
+ // This constant denotes the maximum length of a thread-id query response. |
+ static const int32_t kMaxQCResponseLength; |
+ |
const Abi *abi_; |
- // This mutex protects debugging state (threads_, cur_signal, sig_thread_) |
- port::IMutex *mutex_; |
+ // This mutex protects debugging state (threads_, cur_signal, |
+ // signalling_thread_). This mutex is held by the stub thread, while in a |
+ // broken state. |
+ port::IMutex *stateMutex_; |
+ // This mutex protects the public data (breakpoint, property), and is only |
+ // held temporarily as needed. |
+ port::IMutex *publicMutex_; |
+ |
// This event is signalled when the target is really to process an |
// exception. It ensures only one exception is processed at a time. |
port::IEvent *sig_start_; |
@@ -128,31 +160,42 @@ |
// This event is signalled when the target done processing an exception. |
port::IEvent *sig_done_; |
- // This value is set if the exception cather is requesting a continue signal |
- bool send_done_; |
- |
ThreadMap_t threads_; |
ThreadMap_t::const_iterator threadItr_; |
BreakMap_t breakMap_; |
- |
+ // A map of generic properties for the target. |
PropertyMap_t properties_; |
- uint8_t *ctx_; // Context Scratchpad |
+ // Context Scratchpad |
+ uint8_t *ctx_; |
- // The current signal and signaling thread data is protected by |
+ // The current signal and signalling thread data is protected by |
// the mutex, and can only be owned by one thread at a time. |
// These values should only be written via the "Signal" member, |
// which will ensure that a new signal does not overwrite a |
// previous signal. |
volatile int8_t cur_signal_; |
- volatile uint32_t sig_thread_; |
+ volatile uint32_t signalling_thread_; |
- uint32_t run_thread_; // Which thread to issue step commands on |
- uint32_t reg_thread_; // Which thread to issue context (reg) commands on |
+ // The debugger tracks two thread ids for its operations, one for getting |
+ // and setting registers, the other for step and continue. |
+ // Though they are generally expected to be the same, this is a strict |
+ // implementation of the RSP spec. |
+ |
+ // The thread ID the debugger wants subsequent running related operations |
+ // to act on. |
+ int32_t requested_run_thread_id_; |
+ // The thread ID the debugger wants subsequent register related operations |
+ // act on. |
+ int32_t requested_register_thread_id_; |
+ // The thread ID that the debugger's stepping running operations currently |
+ // act on. |
+ int32_t current_run_thread_id_; |
+ // The thread ID that the debugger's register related operations currently |
+ // act on. |
+ int32_t current_register_thread_id_; |
}; |
- |
- |
} // namespace gdb_rsp |
#endif // NATIVE_CLIENT_GDB_RSP_TARGET_H_ |