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