Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 1 | //===-- GDBRemoteCommunicationClient.h --------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef liblldb_GDBRemoteCommunicationClient_h_ |
| 11 | #define liblldb_GDBRemoteCommunicationClient_h_ |
| 12 | |
| 13 | // C Includes |
| 14 | // C++ Includes |
Greg Clayton | 4a60f9e | 2011-05-20 23:38:13 +0000 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 17 | // Other libraries and framework includes |
| 18 | // Project includes |
| 19 | #include "lldb/Core/ArchSpec.h" |
| 20 | |
| 21 | #include "GDBRemoteCommunication.h" |
| 22 | |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 23 | typedef enum |
| 24 | { |
| 25 | eBreakpointSoftware = 0, |
| 26 | eBreakpointHardware, |
| 27 | eWatchpointWrite, |
| 28 | eWatchpointRead, |
| 29 | eWatchpointReadWrite |
| 30 | } GDBStoppointType; |
| 31 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 32 | class GDBRemoteCommunicationClient : public GDBRemoteCommunication |
| 33 | { |
| 34 | public: |
| 35 | //------------------------------------------------------------------ |
| 36 | // Constructors and Destructors |
| 37 | //------------------------------------------------------------------ |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 38 | GDBRemoteCommunicationClient(bool is_platform); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 39 | |
| 40 | virtual |
| 41 | ~GDBRemoteCommunicationClient(); |
| 42 | |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 43 | //------------------------------------------------------------------ |
| 44 | // After connecting, send the handshake to the server to make sure |
| 45 | // we are communicating with it. |
| 46 | //------------------------------------------------------------------ |
| 47 | bool |
| 48 | HandshakeWithServer (lldb_private::Error *error_ptr); |
| 49 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 50 | size_t |
| 51 | SendPacketAndWaitForResponse (const char *send_payload, |
| 52 | StringExtractorGDBRemote &response, |
| 53 | bool send_async); |
| 54 | |
| 55 | size_t |
| 56 | SendPacketAndWaitForResponse (const char *send_payload, |
| 57 | size_t send_length, |
| 58 | StringExtractorGDBRemote &response, |
| 59 | bool send_async); |
| 60 | |
| 61 | lldb::StateType |
| 62 | SendContinuePacketAndWaitForResponse (ProcessGDBRemote *process, |
| 63 | const char *packet_payload, |
| 64 | size_t packet_length, |
| 65 | StringExtractorGDBRemote &response); |
| 66 | |
| 67 | virtual bool |
| 68 | GetThreadSuffixSupported (); |
| 69 | |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 70 | void |
| 71 | QueryNoAckModeSupported (); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 72 | |
| 73 | bool |
| 74 | SendAsyncSignal (int signo); |
| 75 | |
| 76 | bool |
| 77 | SendInterrupt (lldb_private::Mutex::Locker &locker, |
| 78 | uint32_t seconds_to_wait_for_stop, |
| 79 | bool &sent_interrupt, |
| 80 | bool &timed_out); |
| 81 | |
| 82 | lldb::pid_t |
| 83 | GetCurrentProcessID (); |
| 84 | |
| 85 | bool |
| 86 | GetLaunchSuccess (std::string &error_str); |
| 87 | |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 88 | uint16_t |
| 89 | LaunchGDBserverAndGetPort (); |
| 90 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 91 | //------------------------------------------------------------------ |
| 92 | /// Sends a GDB remote protocol 'A' packet that delivers program |
| 93 | /// arguments to the remote server. |
| 94 | /// |
| 95 | /// @param[in] argv |
| 96 | /// A NULL terminated array of const C strings to use as the |
| 97 | /// arguments. |
| 98 | /// |
| 99 | /// @return |
| 100 | /// Zero if the response was "OK", a positive value if the |
| 101 | /// the response was "Exx" where xx are two hex digits, or |
| 102 | /// -1 if the call is unsupported or any other unexpected |
| 103 | /// response was received. |
| 104 | //------------------------------------------------------------------ |
| 105 | int |
| 106 | SendArgumentsPacket (char const *argv[]); |
| 107 | |
| 108 | //------------------------------------------------------------------ |
| 109 | /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the |
| 110 | /// environment that will get used when launching an application |
| 111 | /// in conjunction with the 'A' packet. This function can be called |
| 112 | /// multiple times in a row in order to pass on the desired |
| 113 | /// environment that the inferior should be launched with. |
| 114 | /// |
| 115 | /// @param[in] name_equal_value |
| 116 | /// A NULL terminated C string that contains a single environment |
| 117 | /// in the format "NAME=VALUE". |
| 118 | /// |
| 119 | /// @return |
| 120 | /// Zero if the response was "OK", a positive value if the |
| 121 | /// the response was "Exx" where xx are two hex digits, or |
| 122 | /// -1 if the call is unsupported or any other unexpected |
| 123 | /// response was received. |
| 124 | //------------------------------------------------------------------ |
| 125 | int |
| 126 | SendEnvironmentPacket (char const *name_equal_value); |
| 127 | |
Greg Clayton | a458240 | 2011-05-08 04:53:50 +0000 | [diff] [blame] | 128 | int |
| 129 | SendLaunchArchPacket (const char *arch); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 130 | //------------------------------------------------------------------ |
| 131 | /// Sends a "vAttach:PID" where PID is in hex. |
| 132 | /// |
| 133 | /// @param[in] pid |
| 134 | /// A process ID for the remote gdb server to attach to. |
| 135 | /// |
| 136 | /// @param[out] response |
| 137 | /// The response received from the gdb server. If the return |
| 138 | /// value is zero, \a response will contain a stop reply |
| 139 | /// packet. |
| 140 | /// |
| 141 | /// @return |
| 142 | /// Zero if the attach was successful, or an error indicating |
| 143 | /// an error code. |
| 144 | //------------------------------------------------------------------ |
| 145 | int |
| 146 | SendAttach (lldb::pid_t pid, |
| 147 | StringExtractorGDBRemote& response); |
| 148 | |
| 149 | |
| 150 | //------------------------------------------------------------------ |
| 151 | /// Sets the path to use for stdin/out/err for a process |
| 152 | /// that will be launched with the 'A' packet. |
| 153 | /// |
| 154 | /// @param[in] path |
| 155 | /// The path to use for stdin/out/err |
| 156 | /// |
| 157 | /// @return |
| 158 | /// Zero if the for success, or an error code for failure. |
| 159 | //------------------------------------------------------------------ |
| 160 | int |
| 161 | SetSTDIN (char const *path); |
| 162 | int |
| 163 | SetSTDOUT (char const *path); |
| 164 | int |
| 165 | SetSTDERR (char const *path); |
| 166 | |
| 167 | //------------------------------------------------------------------ |
| 168 | /// Sets the disable ASLR flag to \a enable for a process that will |
| 169 | /// be launched with the 'A' packet. |
| 170 | /// |
| 171 | /// @param[in] enable |
| 172 | /// A boolean value indicating wether to disable ASLR or not. |
| 173 | /// |
| 174 | /// @return |
| 175 | /// Zero if the for success, or an error code for failure. |
| 176 | //------------------------------------------------------------------ |
| 177 | int |
| 178 | SetDisableASLR (bool enable); |
| 179 | |
| 180 | //------------------------------------------------------------------ |
| 181 | /// Sets the working directory to \a path for a process that will |
| 182 | /// be launched with the 'A' packet. |
| 183 | /// |
| 184 | /// @param[in] path |
| 185 | /// The path to a directory to use when launching our processs |
| 186 | /// |
| 187 | /// @return |
| 188 | /// Zero if the for success, or an error code for failure. |
| 189 | //------------------------------------------------------------------ |
| 190 | int |
| 191 | SetWorkingDir (char const *path); |
| 192 | |
| 193 | lldb::addr_t |
| 194 | AllocateMemory (size_t size, uint32_t permissions); |
| 195 | |
| 196 | bool |
| 197 | DeallocateMemory (lldb::addr_t addr); |
| 198 | |
| 199 | const lldb_private::ArchSpec & |
| 200 | GetHostArchitecture (); |
| 201 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 202 | bool |
| 203 | GetVContSupported (char flavor); |
| 204 | |
| 205 | void |
| 206 | ResetDiscoverableSettings(); |
| 207 | |
| 208 | bool |
Greg Clayton | 06d7cc8 | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 209 | GetHostInfo (bool force = false); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 210 | |
| 211 | bool |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 212 | GetOSVersion (uint32_t &major, |
| 213 | uint32_t &minor, |
| 214 | uint32_t &update); |
| 215 | |
| 216 | bool |
| 217 | GetOSBuildString (std::string &s); |
| 218 | |
| 219 | bool |
| 220 | GetOSKernelDescription (std::string &s); |
| 221 | |
| 222 | lldb_private::ArchSpec |
| 223 | GetSystemArchitecture (); |
| 224 | |
| 225 | bool |
| 226 | GetHostname (std::string &s); |
| 227 | |
| 228 | bool |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 229 | GetSupportsThreadSuffix (); |
| 230 | |
| 231 | bool |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 232 | GetProcessInfo (lldb::pid_t pid, |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 233 | lldb_private::ProcessInstanceInfo &process_info); |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 234 | |
| 235 | uint32_t |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 236 | FindProcesses (const lldb_private::ProcessInstanceInfoMatch &process_match_info, |
| 237 | lldb_private::ProcessInstanceInfoList &process_infos); |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 238 | |
| 239 | bool |
| 240 | GetUserName (uint32_t uid, std::string &name); |
| 241 | |
| 242 | bool |
| 243 | GetGroupName (uint32_t gid, std::string &name); |
| 244 | |
| 245 | bool |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 246 | HasFullVContSupport () |
| 247 | { |
| 248 | return GetVContSupported ('A'); |
| 249 | } |
| 250 | |
| 251 | bool |
| 252 | HasAnyVContSupport () |
| 253 | { |
| 254 | return GetVContSupported ('a'); |
| 255 | } |
| 256 | |
| 257 | uint32_t |
| 258 | SetPacketTimeout (uint32_t packet_timeout) |
| 259 | { |
| 260 | const uint32_t old_packet_timeout = m_packet_timeout; |
| 261 | m_packet_timeout = packet_timeout; |
| 262 | return old_packet_timeout; |
| 263 | } |
| 264 | |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 265 | bool |
| 266 | GetStopReply (StringExtractorGDBRemote &response); |
| 267 | |
| 268 | bool |
| 269 | GetThreadStopInfo (uint32_t tid, |
| 270 | StringExtractorGDBRemote &response); |
| 271 | |
| 272 | bool |
| 273 | SupportsGDBStoppointPacket (GDBStoppointType type) |
| 274 | { |
| 275 | switch (type) |
| 276 | { |
| 277 | case eBreakpointSoftware: return m_supports_z0; |
| 278 | case eBreakpointHardware: return m_supports_z1; |
| 279 | case eWatchpointWrite: return m_supports_z2; |
| 280 | case eWatchpointRead: return m_supports_z3; |
| 281 | case eWatchpointReadWrite: return m_supports_z4; |
| 282 | default: break; |
| 283 | } |
| 284 | return false; |
| 285 | } |
| 286 | uint8_t |
| 287 | SendGDBStoppointTypePacket (GDBStoppointType type, // Type of breakpoint or watchpoint |
| 288 | bool insert, // Insert or remove? |
| 289 | lldb::addr_t addr, // Address of breakpoint or watchpoint |
| 290 | uint32_t length); // Byte Size of breakpoint or watchpoint |
| 291 | |
Greg Clayton | 06d7cc8 | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 292 | void |
| 293 | TestPacketSpeed (const uint32_t num_packets); |
| 294 | |
| 295 | // This packet is for testing the speed of the interface only. Both |
| 296 | // the client and server need to support it, but this allows us to |
| 297 | // measure the packet speed without any other work being done on the |
| 298 | // other end and avoids any of that work affecting the packet send |
| 299 | // and response times. |
| 300 | bool |
| 301 | SendSpeedTestPacket (uint32_t send_size, |
| 302 | uint32_t recv_size); |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 303 | |
| 304 | bool |
| 305 | SetCurrentThread (int tid); |
| 306 | |
| 307 | bool |
| 308 | SetCurrentThreadForRun (int tid); |
| 309 | |
Greg Clayton | 989816b | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 310 | lldb_private::LazyBool |
Greg Clayton | 2f085c6 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 311 | SupportsAllocDeallocMemory () const |
Greg Clayton | 989816b | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 312 | { |
Greg Clayton | 2f085c6 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 313 | return m_supports_alloc_dealloc_memory; |
Greg Clayton | 989816b | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 314 | } |
| 315 | |
Greg Clayton | 4a60f9e | 2011-05-20 23:38:13 +0000 | [diff] [blame] | 316 | size_t |
| 317 | GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids, |
| 318 | bool &sequence_mutex_unavailable); |
| 319 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 320 | protected: |
| 321 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 322 | //------------------------------------------------------------------ |
| 323 | // Classes that inherit from GDBRemoteCommunicationClient can see and modify these |
| 324 | //------------------------------------------------------------------ |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 325 | lldb_private::LazyBool m_supports_not_sending_acks; |
| 326 | lldb_private::LazyBool m_supports_thread_suffix; |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 327 | lldb_private::LazyBool m_supports_vCont_all; |
| 328 | lldb_private::LazyBool m_supports_vCont_any; |
| 329 | lldb_private::LazyBool m_supports_vCont_c; |
| 330 | lldb_private::LazyBool m_supports_vCont_C; |
| 331 | lldb_private::LazyBool m_supports_vCont_s; |
| 332 | lldb_private::LazyBool m_supports_vCont_S; |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 333 | lldb_private::LazyBool m_qHostInfo_is_valid; |
Greg Clayton | 2f085c6 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 334 | lldb_private::LazyBool m_supports_alloc_dealloc_memory; |
Greg Clayton | 989816b | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 335 | |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 336 | bool |
| 337 | m_supports_qProcessInfoPID:1, |
| 338 | m_supports_qfProcessInfo:1, |
| 339 | m_supports_qUserName:1, |
| 340 | m_supports_qGroupName:1, |
| 341 | m_supports_qThreadStopInfo:1, |
| 342 | m_supports_z0:1, |
| 343 | m_supports_z1:1, |
| 344 | m_supports_z2:1, |
| 345 | m_supports_z3:1, |
| 346 | m_supports_z4:1; |
Greg Clayton | 989816b | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 347 | |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 348 | |
| 349 | lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all other operations |
| 350 | lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for continue, step, etc |
| 351 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 352 | |
| 353 | // If we need to send a packet while the target is running, the m_async_XXX |
| 354 | // member variables take care of making this happen. |
| 355 | lldb_private::Mutex m_async_mutex; |
| 356 | lldb_private::Predicate<bool> m_async_packet_predicate; |
| 357 | std::string m_async_packet; |
| 358 | StringExtractorGDBRemote m_async_response; |
| 359 | int m_async_signal; // We were asked to deliver a signal to the inferior process. |
| 360 | |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 361 | lldb_private::ArchSpec m_host_arch; |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 362 | uint32_t m_os_version_major; |
| 363 | uint32_t m_os_version_minor; |
| 364 | uint32_t m_os_version_update; |
| 365 | std::string m_os_build; |
| 366 | std::string m_os_kernel; |
| 367 | std::string m_hostname; |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 368 | |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 369 | bool |
| 370 | DecodeProcessInfoResponse (StringExtractorGDBRemote &response, |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 371 | lldb_private::ProcessInstanceInfo &process_info); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 372 | private: |
| 373 | //------------------------------------------------------------------ |
| 374 | // For GDBRemoteCommunicationClient only |
| 375 | //------------------------------------------------------------------ |
| 376 | DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationClient); |
| 377 | }; |
| 378 | |
| 379 | #endif // liblldb_GDBRemoteCommunicationClient_h_ |