| 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 // This module provides an object for handling RSP responsibilities of | 7 // This module provides an object for handling RSP responsibilities of |
| 8 // the host side of the connection. The host behaves like a cache, and | 8 // the host side of the connection. The host behaves like a cache, and |
| 9 // is responsible for syncronization of state between the Target and Host. | 9 // is responsible for syncronization of state between the Target and Host. |
| 10 // For example, the Host is responsible for updating the thread context | 10 // For example, the Host is responsible for updating the thread context |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 const Abi *abi_; | 57 const Abi *abi_; |
| 58 | 58 |
| 59 friend class Host; | 59 friend class Host; |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 typedef std::map<uint32_t, Host::Thread*> ThreadMap_t; | 62 typedef std::map<uint32_t, Host::Thread*> ThreadMap_t; |
| 63 typedef std::map<std::string, std::string> PropertyMap_t; | 63 typedef std::map<std::string, std::string> PropertyMap_t; |
| 64 typedef std::vector<uint32_t> ThreadVector_t; | 64 typedef std::vector<uint32_t> ThreadVector_t; |
| 65 | 65 |
| 66 explicit Host(Session *session); | 66 explicit Host(Session *session); |
| 67 ~Host(); | 67 virtual ~Host(); |
| 68 bool Init(); | 68 virtual bool Init(); |
| 69 | 69 |
| 70 // The following functions are provided cached values when possible. | 70 // The following functions are provided cached values when possible. |
| 71 // For instance, GetSignal, GetThreads, and GetThread, will return | 71 // For instance, GetSignal, GetThreads, and GetThread, will return |
| 72 // values that were computed during Update. | 72 // values that were computed during Update. |
| 73 // cause a communication between the host and target, so the public | 73 // cause a communication between the host and target, so the public |
| 74 // functions above should be used when possible. | 74 // functions above should be used when possible. |
| 75 | 75 |
| 76 // Issue a break request if the target is still running. This is | 76 // Issue a break request if the target is still running. This is |
| 77 // asynchronous, we won't actually be "broken" until we get the signal | 77 // asynchronous, we won't actually be "broken" until we get the signal |
| 78 bool Break(); | 78 virtual bool Break(); |
| 79 | 79 |
| 80 // Requests that we cleanly detach from the target. | 80 // Requests that we cleanly detach from the target. |
| 81 bool Detach(); | 81 virtual bool Detach(); |
| 82 | 82 |
| 83 // Get the current status of the Target. | 83 // Get the current status of the Target. |
| 84 Status GetStatus(); | 84 virtual Status GetStatus(); |
| 85 | 85 |
| 86 // Get the last signal (which put us into the broken state) | 86 // Get the last signal (which put us into the broken state) |
| 87 int32_t GetSignal(); | 87 virtual int32_t GetSignal(); |
| 88 | 88 |
| 89 // Get a list of currently active threads | 89 // Get a list of currently active threads |
| 90 bool GetThreads(ThreadVector_t *threads) const; | 90 virtual bool GetThreads(ThreadVector_t *threads) const; |
| 91 | 91 |
| 92 // Get a thread object by ID. | 92 // Get a thread object by ID. |
| 93 Thread *GetThread(uint32_t id); | 93 virtual Thread *GetThread(uint32_t id); |
| 94 | 94 |
| 95 // Get and set a block of target memory. | 95 // Get and set a block of target memory. |
| 96 bool GetMemory(void *dst, uint64_t addr, uint32_t size); | 96 virtual bool GetMemory(void *dst, uint64_t addr, uint32_t size); |
| 97 bool SetMemory(const void *src, uint64_t addr, uint32_t size); | 97 virtual bool SetMemory(const void *src, uint64_t addr, uint32_t size); |
| 98 | 98 |
| 99 // Read locally cached properties | 99 // Read locally cached properties |
| 100 bool HasProperty(const char *name) const; | 100 virtual bool HasProperty(const char *name) const; |
| 101 bool ReadProperty(const char *name, std::string *val) const; | 101 virtual bool ReadProperty(const char *name, std::string *val) const; |
| 102 | 102 |
| 103 // Read remote object | 103 // Read remote object |
| 104 bool ReadObject(const char *type, const char *name, std::string *val); | 104 virtual bool ReadObject(const char *type, const char *name, std::string *val); |
| 105 |
| 106 // Issues a request to the host and return the host's response. |
| 107 virtual bool Request(const std::string &req, std::string *resp); |
| 105 | 108 |
| 106 // Set the SINGLE STEP flag on the current thread context, and | 109 // Set the SINGLE STEP flag on the current thread context, and |
| 107 // putting the target back into the RUN state. | 110 // putting the target back into the RUN state. |
| 108 bool Step(); | 111 virtual bool Step(); |
| 109 | 112 |
| 110 // Issue a step request, putting us back into the RUN state. | 113 // Issue a step request, putting us back into the RUN state. |
| 111 bool Continue(); | 114 virtual bool Continue(); |
| 112 | 115 |
| 113 // Wait upto the session's packet timeout to see if we receive a break | 116 // Wait upto the session's packet timeout to see if we receive a break |
| 114 bool WaitForBreak(); | 117 virtual bool WaitForBreak(); |
| 115 | 118 |
| 116 // The following functions are internal only and cause communication to | 119 // The following functions are internal only and cause communication to |
| 117 // happen between the target and host. These functions will always | 120 // happen between the target and host. These functions will always |
| 118 // cause a communication between the host and target, so the public | 121 // cause a communication between the host and target, so the public |
| 119 // functions above should be used when possible. | 122 // functions above should be used when possible. |
| 120 protected: | 123 protected: |
| 121 // Called whenever the target transitions from running to stopped to | 124 // Called whenever the target transitions from running to stopped to |
| 122 // fetch information about the current state. | 125 // fetch information about the current state. |
| 123 bool Update(); | 126 virtual bool Update(); |
| 124 | 127 |
| 125 bool Send(Packet *req, Packet *resp); | 128 virtual bool Send(Packet *req, Packet *resp); |
| 126 bool SendOnly(Packet *req); | 129 virtual bool SendOnly(Packet *req); |
| 127 | 130 |
| 128 bool Request(const std::string &req, std::string *resp); | 131 virtual bool RequestOnly(const std::string &req); |
| 129 bool RequestOnly(const std::string &req); | 132 virtual bool RequestThreadList(ThreadVector_t *ids); |
| 130 bool RequestThreadList(ThreadVector_t *ids); | |
| 131 | 133 |
| 132 // Parse a string, returning true and update if a valid stop packet | 134 // Parse a string, returning true and update if a valid stop packet |
| 133 bool ParseStopPacket(const char *data); | 135 virtual bool ParseStopPacket(const char *data); |
| 134 | 136 |
| 135 private: | 137 // Note that that this used to be private. It was made public to enable unit |
| 138 // testing of the debug stub, using a mock host. |
| 139 protected: |
| 136 Session *session_; | 140 Session *session_; |
| 137 const Abi *abi_; | 141 const Abi *abi_; |
| 138 | 142 |
| 139 PropertyMap_t properties_; | 143 PropertyMap_t properties_; |
| 140 ThreadMap_t threads_; | 144 ThreadMap_t threads_; |
| 141 int32_t lastSignal_; | 145 int32_t lastSignal_; |
| 142 Status status_; | 146 Status status_; |
| 143 }; | 147 }; |
| 144 | 148 |
| 145 | 149 |
| 146 } // namespace gdb_rsp | 150 } // namespace gdb_rsp |
| 147 | 151 |
| 148 #endif // NATIVE_CLIENT_GDB_RSP_HOST_H_ | 152 #endif // NATIVE_CLIENT_GDB_RSP_HOST_H_ |
| 149 | 153 |
| OLD | NEW |