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" |
Greg Clayton | a938553 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 20 | #include "lldb/Target/Process.h" |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 21 | |
| 22 | #include "GDBRemoteCommunication.h" |
| 23 | |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 24 | typedef enum |
| 25 | { |
| 26 | eBreakpointSoftware = 0, |
| 27 | eBreakpointHardware, |
| 28 | eWatchpointWrite, |
| 29 | eWatchpointRead, |
| 30 | eWatchpointReadWrite |
| 31 | } GDBStoppointType; |
| 32 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 33 | class GDBRemoteCommunicationClient : public GDBRemoteCommunication |
| 34 | { |
| 35 | public: |
| 36 | //------------------------------------------------------------------ |
| 37 | // Constructors and Destructors |
| 38 | //------------------------------------------------------------------ |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 39 | GDBRemoteCommunicationClient(bool is_platform); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 40 | |
| 41 | virtual |
| 42 | ~GDBRemoteCommunicationClient(); |
| 43 | |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 44 | //------------------------------------------------------------------ |
| 45 | // After connecting, send the handshake to the server to make sure |
| 46 | // we are communicating with it. |
| 47 | //------------------------------------------------------------------ |
| 48 | bool |
| 49 | HandshakeWithServer (lldb_private::Error *error_ptr); |
| 50 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 51 | size_t |
| 52 | SendPacketAndWaitForResponse (const char *send_payload, |
| 53 | StringExtractorGDBRemote &response, |
| 54 | bool send_async); |
| 55 | |
| 56 | size_t |
| 57 | SendPacketAndWaitForResponse (const char *send_payload, |
| 58 | size_t send_length, |
| 59 | StringExtractorGDBRemote &response, |
| 60 | bool send_async); |
| 61 | |
| 62 | lldb::StateType |
| 63 | SendContinuePacketAndWaitForResponse (ProcessGDBRemote *process, |
| 64 | const char *packet_payload, |
| 65 | size_t packet_length, |
| 66 | StringExtractorGDBRemote &response); |
| 67 | |
| 68 | virtual bool |
| 69 | GetThreadSuffixSupported (); |
| 70 | |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 71 | void |
| 72 | QueryNoAckModeSupported (); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 73 | |
| 74 | bool |
| 75 | SendAsyncSignal (int signo); |
| 76 | |
| 77 | bool |
| 78 | SendInterrupt (lldb_private::Mutex::Locker &locker, |
| 79 | uint32_t seconds_to_wait_for_stop, |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 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 | |
Greg Clayton | a938553 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 199 | lldb_private::Error |
| 200 | GetMemoryRegionInfo (lldb::addr_t addr, |
| 201 | lldb_private::MemoryRegionInfo &range_info); |
| 202 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 203 | const lldb_private::ArchSpec & |
| 204 | GetHostArchitecture (); |
| 205 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 206 | bool |
| 207 | GetVContSupported (char flavor); |
| 208 | |
| 209 | void |
| 210 | ResetDiscoverableSettings(); |
| 211 | |
| 212 | bool |
Greg Clayton | 06d7cc8 | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 213 | GetHostInfo (bool force = false); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 214 | |
| 215 | bool |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 216 | GetOSVersion (uint32_t &major, |
| 217 | uint32_t &minor, |
| 218 | uint32_t &update); |
| 219 | |
| 220 | bool |
| 221 | GetOSBuildString (std::string &s); |
| 222 | |
| 223 | bool |
| 224 | GetOSKernelDescription (std::string &s); |
| 225 | |
| 226 | lldb_private::ArchSpec |
| 227 | GetSystemArchitecture (); |
| 228 | |
| 229 | bool |
| 230 | GetHostname (std::string &s); |
| 231 | |
| 232 | bool |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 233 | GetSupportsThreadSuffix (); |
| 234 | |
| 235 | bool |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 236 | GetProcessInfo (lldb::pid_t pid, |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 237 | lldb_private::ProcessInstanceInfo &process_info); |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 238 | |
| 239 | uint32_t |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 240 | FindProcesses (const lldb_private::ProcessInstanceInfoMatch &process_match_info, |
| 241 | lldb_private::ProcessInstanceInfoList &process_infos); |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 242 | |
| 243 | bool |
| 244 | GetUserName (uint32_t uid, std::string &name); |
| 245 | |
| 246 | bool |
| 247 | GetGroupName (uint32_t gid, std::string &name); |
| 248 | |
| 249 | bool |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 250 | HasFullVContSupport () |
| 251 | { |
| 252 | return GetVContSupported ('A'); |
| 253 | } |
| 254 | |
| 255 | bool |
| 256 | HasAnyVContSupport () |
| 257 | { |
| 258 | return GetVContSupported ('a'); |
| 259 | } |
| 260 | |
| 261 | uint32_t |
| 262 | SetPacketTimeout (uint32_t packet_timeout) |
| 263 | { |
| 264 | const uint32_t old_packet_timeout = m_packet_timeout; |
| 265 | m_packet_timeout = packet_timeout; |
| 266 | return old_packet_timeout; |
| 267 | } |
| 268 | |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 269 | bool |
| 270 | GetStopReply (StringExtractorGDBRemote &response); |
| 271 | |
| 272 | bool |
| 273 | GetThreadStopInfo (uint32_t tid, |
| 274 | StringExtractorGDBRemote &response); |
| 275 | |
| 276 | bool |
| 277 | SupportsGDBStoppointPacket (GDBStoppointType type) |
| 278 | { |
| 279 | switch (type) |
| 280 | { |
| 281 | case eBreakpointSoftware: return m_supports_z0; |
| 282 | case eBreakpointHardware: return m_supports_z1; |
| 283 | case eWatchpointWrite: return m_supports_z2; |
| 284 | case eWatchpointRead: return m_supports_z3; |
| 285 | case eWatchpointReadWrite: return m_supports_z4; |
| 286 | default: break; |
| 287 | } |
| 288 | return false; |
| 289 | } |
| 290 | uint8_t |
| 291 | SendGDBStoppointTypePacket (GDBStoppointType type, // Type of breakpoint or watchpoint |
| 292 | bool insert, // Insert or remove? |
| 293 | lldb::addr_t addr, // Address of breakpoint or watchpoint |
| 294 | uint32_t length); // Byte Size of breakpoint or watchpoint |
| 295 | |
Greg Clayton | 06d7cc8 | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 296 | void |
| 297 | TestPacketSpeed (const uint32_t num_packets); |
| 298 | |
| 299 | // This packet is for testing the speed of the interface only. Both |
| 300 | // the client and server need to support it, but this allows us to |
| 301 | // measure the packet speed without any other work being done on the |
| 302 | // other end and avoids any of that work affecting the packet send |
| 303 | // and response times. |
| 304 | bool |
| 305 | SendSpeedTestPacket (uint32_t send_size, |
| 306 | uint32_t recv_size); |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 307 | |
| 308 | bool |
| 309 | SetCurrentThread (int tid); |
| 310 | |
| 311 | bool |
| 312 | SetCurrentThreadForRun (int tid); |
| 313 | |
Greg Clayton | 989816b | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 314 | lldb_private::LazyBool |
Jim Ingham | 1831e78 | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 315 | SupportsAllocDeallocMemory () // const |
Greg Clayton | 989816b | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 316 | { |
Jim Ingham | 1831e78 | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 317 | // Uncomment this to have lldb pretend the debug server doesn't respond to alloc/dealloc memory packets. |
| 318 | // m_supports_alloc_dealloc_memory = lldb_private::eLazyBoolNo; |
Greg Clayton | 2f085c6 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 319 | return m_supports_alloc_dealloc_memory; |
Greg Clayton | 989816b | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Greg Clayton | 4a60f9e | 2011-05-20 23:38:13 +0000 | [diff] [blame] | 322 | size_t |
| 323 | GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids, |
| 324 | bool &sequence_mutex_unavailable); |
| 325 | |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 326 | bool |
| 327 | GetInterruptWasSent () const |
| 328 | { |
| 329 | return m_interrupt_sent; |
| 330 | } |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 331 | protected: |
| 332 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 333 | //------------------------------------------------------------------ |
| 334 | // Classes that inherit from GDBRemoteCommunicationClient can see and modify these |
| 335 | //------------------------------------------------------------------ |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 336 | lldb_private::LazyBool m_supports_not_sending_acks; |
| 337 | lldb_private::LazyBool m_supports_thread_suffix; |
Greg Clayton | b344843 | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 338 | lldb_private::LazyBool m_supports_vCont_all; |
| 339 | lldb_private::LazyBool m_supports_vCont_any; |
| 340 | lldb_private::LazyBool m_supports_vCont_c; |
| 341 | lldb_private::LazyBool m_supports_vCont_C; |
| 342 | lldb_private::LazyBool m_supports_vCont_s; |
| 343 | lldb_private::LazyBool m_supports_vCont_S; |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 344 | lldb_private::LazyBool m_qHostInfo_is_valid; |
Greg Clayton | 2f085c6 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 345 | lldb_private::LazyBool m_supports_alloc_dealloc_memory; |
Greg Clayton | a938553 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 346 | lldb_private::LazyBool m_supports_memory_region_info; |
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 | bool |
| 349 | m_supports_qProcessInfoPID:1, |
| 350 | m_supports_qfProcessInfo:1, |
| 351 | m_supports_qUserName:1, |
| 352 | m_supports_qGroupName:1, |
| 353 | m_supports_qThreadStopInfo:1, |
| 354 | m_supports_z0:1, |
| 355 | m_supports_z1:1, |
| 356 | m_supports_z2:1, |
| 357 | m_supports_z3:1, |
| 358 | m_supports_z4:1; |
Greg Clayton | 989816b | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 359 | |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 360 | |
| 361 | lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all other operations |
| 362 | lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for continue, step, etc |
| 363 | |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 364 | |
| 365 | // If we need to send a packet while the target is running, the m_async_XXX |
| 366 | // member variables take care of making this happen. |
| 367 | lldb_private::Mutex m_async_mutex; |
| 368 | lldb_private::Predicate<bool> m_async_packet_predicate; |
| 369 | std::string m_async_packet; |
| 370 | StringExtractorGDBRemote m_async_response; |
| 371 | int m_async_signal; // We were asked to deliver a signal to the inferior process. |
Greg Clayton | 05e4d97 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 372 | bool m_interrupt_sent; |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 373 | |
Greg Clayton | cb8977d | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 374 | lldb_private::ArchSpec m_host_arch; |
Greg Clayton | 58e26e0 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 375 | uint32_t m_os_version_major; |
| 376 | uint32_t m_os_version_minor; |
| 377 | uint32_t m_os_version_update; |
| 378 | std::string m_os_build; |
| 379 | std::string m_os_kernel; |
| 380 | std::string m_hostname; |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 381 | |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 382 | bool |
| 383 | DecodeProcessInfoResponse (StringExtractorGDBRemote &response, |
Greg Clayton | b72d0f0 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 384 | lldb_private::ProcessInstanceInfo &process_info); |
Greg Clayton | 61d043b | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 385 | private: |
| 386 | //------------------------------------------------------------------ |
| 387 | // For GDBRemoteCommunicationClient only |
| 388 | //------------------------------------------------------------------ |
| 389 | DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationClient); |
| 390 | }; |
| 391 | |
| 392 | #endif // liblldb_GDBRemoteCommunicationClient_h_ |