Greg Clayton | 576d883 | 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 | adc00cb | 2011-05-20 23:38:13 +0000 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
Greg Clayton | 576d883 | 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 | 46fb558 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 20 | #include "lldb/Target/Process.h" |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 21 | |
| 22 | #include "GDBRemoteCommunication.h" |
| 23 | |
| 24 | class GDBRemoteCommunicationClient : public GDBRemoteCommunication |
| 25 | { |
| 26 | public: |
| 27 | //------------------------------------------------------------------ |
| 28 | // Constructors and Destructors |
| 29 | //------------------------------------------------------------------ |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 30 | GDBRemoteCommunicationClient(bool is_platform); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 31 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 32 | ~GDBRemoteCommunicationClient(); |
| 33 | |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 34 | //------------------------------------------------------------------ |
| 35 | // After connecting, send the handshake to the server to make sure |
| 36 | // we are communicating with it. |
| 37 | //------------------------------------------------------------------ |
| 38 | bool |
| 39 | HandshakeWithServer (lldb_private::Error *error_ptr); |
| 40 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 41 | PacketResult |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 42 | SendPacketAndWaitForResponse (const char *send_payload, |
| 43 | StringExtractorGDBRemote &response, |
| 44 | bool send_async); |
| 45 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 46 | PacketResult |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 47 | SendPacketAndWaitForResponse (const char *send_payload, |
| 48 | size_t send_length, |
| 49 | StringExtractorGDBRemote &response, |
| 50 | bool send_async); |
| 51 | |
Steve Pucci | 5ae54ae | 2014-01-25 05:46:51 +0000 | [diff] [blame] | 52 | // For packets which specify a range of output to be returned, |
| 53 | // return all of the output via a series of request packets of the form |
| 54 | // <prefix>0,<size> |
| 55 | // <prefix><size>,<size> |
| 56 | // <prefix><size>*2,<size> |
| 57 | // <prefix><size>*3,<size> |
| 58 | // ... |
| 59 | // until a "$l..." packet is received, indicating the end. |
| 60 | // (size is in hex; this format is used by a standard gdbserver to |
| 61 | // return the given portion of the output specified by <prefix>; |
| 62 | // for example, "qXfer:libraries-svr4:read::fff,1000" means |
| 63 | // "return a chunk of the xml description file for shared |
| 64 | // library load addresses, where the chunk starts at offset 0xfff |
| 65 | // and continues for 0x1000 bytes"). |
| 66 | // Concatenate the resulting server response packets together and |
| 67 | // return in response_string. If any packet fails, the return value |
| 68 | // indicates that failure and the returned string value is undefined. |
| 69 | PacketResult |
| 70 | SendPacketsAndConcatenateResponses (const char *send_payload_prefix, |
| 71 | std::string &response_string); |
| 72 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 73 | lldb::StateType |
| 74 | SendContinuePacketAndWaitForResponse (ProcessGDBRemote *process, |
| 75 | const char *packet_payload, |
| 76 | size_t packet_length, |
| 77 | StringExtractorGDBRemote &response); |
| 78 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 79 | bool |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 80 | GetThreadSuffixSupported (); |
| 81 | |
Greg Clayton | fb90931 | 2013-11-23 01:58:15 +0000 | [diff] [blame] | 82 | // This packet is usually sent first and the boolean return value |
| 83 | // indicates if the packet was send and any response was received |
| 84 | // even in the response is UNIMPLEMENTED. If the packet failed to |
| 85 | // get a response, then false is returned. This quickly tells us |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 86 | // if we were able to connect and communicate with the remote GDB |
Greg Clayton | fb90931 | 2013-11-23 01:58:15 +0000 | [diff] [blame] | 87 | // server |
| 88 | bool |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 89 | QueryNoAckModeSupported (); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 90 | |
Greg Clayton | 4463399 | 2012-04-10 03:22:03 +0000 | [diff] [blame] | 91 | void |
| 92 | GetListThreadsInStopReplySupported (); |
| 93 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 94 | bool |
| 95 | SendAsyncSignal (int signo); |
| 96 | |
| 97 | bool |
| 98 | SendInterrupt (lldb_private::Mutex::Locker &locker, |
| 99 | uint32_t seconds_to_wait_for_stop, |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 100 | bool &timed_out); |
| 101 | |
| 102 | lldb::pid_t |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 103 | GetCurrentProcessID (bool allow_lazy = true); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 104 | |
| 105 | bool |
| 106 | GetLaunchSuccess (std::string &error_str); |
| 107 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 108 | uint16_t |
Greg Clayton | dbf0457 | 2013-12-04 19:40:33 +0000 | [diff] [blame] | 109 | LaunchGDBserverAndGetPort (lldb::pid_t &pid, const char *remote_accept_hostname); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 110 | |
| 111 | bool |
| 112 | KillSpawnedProcess (lldb::pid_t pid); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 113 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 114 | //------------------------------------------------------------------ |
| 115 | /// Sends a GDB remote protocol 'A' packet that delivers program |
| 116 | /// arguments to the remote server. |
| 117 | /// |
| 118 | /// @param[in] argv |
| 119 | /// A NULL terminated array of const C strings to use as the |
| 120 | /// arguments. |
| 121 | /// |
| 122 | /// @return |
| 123 | /// Zero if the response was "OK", a positive value if the |
| 124 | /// the response was "Exx" where xx are two hex digits, or |
| 125 | /// -1 if the call is unsupported or any other unexpected |
| 126 | /// response was received. |
| 127 | //------------------------------------------------------------------ |
| 128 | int |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 129 | SendArgumentsPacket (const lldb_private::ProcessLaunchInfo &launch_info); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 130 | |
| 131 | //------------------------------------------------------------------ |
| 132 | /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the |
| 133 | /// environment that will get used when launching an application |
| 134 | /// in conjunction with the 'A' packet. This function can be called |
| 135 | /// multiple times in a row in order to pass on the desired |
| 136 | /// environment that the inferior should be launched with. |
| 137 | /// |
| 138 | /// @param[in] name_equal_value |
| 139 | /// A NULL terminated C string that contains a single environment |
| 140 | /// in the format "NAME=VALUE". |
| 141 | /// |
| 142 | /// @return |
| 143 | /// Zero if the response was "OK", a positive value if the |
| 144 | /// the response was "Exx" where xx are two hex digits, or |
| 145 | /// -1 if the call is unsupported or any other unexpected |
| 146 | /// response was received. |
| 147 | //------------------------------------------------------------------ |
| 148 | int |
| 149 | SendEnvironmentPacket (char const *name_equal_value); |
| 150 | |
Greg Clayton | c4103b3 | 2011-05-08 04:53:50 +0000 | [diff] [blame] | 151 | int |
| 152 | SendLaunchArchPacket (const char *arch); |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 153 | |
| 154 | int |
| 155 | SendLaunchEventDataPacket (const char *data, bool *was_supported = NULL); |
| 156 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 157 | //------------------------------------------------------------------ |
| 158 | /// Sends a "vAttach:PID" where PID is in hex. |
| 159 | /// |
| 160 | /// @param[in] pid |
| 161 | /// A process ID for the remote gdb server to attach to. |
| 162 | /// |
| 163 | /// @param[out] response |
| 164 | /// The response received from the gdb server. If the return |
| 165 | /// value is zero, \a response will contain a stop reply |
| 166 | /// packet. |
| 167 | /// |
| 168 | /// @return |
| 169 | /// Zero if the attach was successful, or an error indicating |
| 170 | /// an error code. |
| 171 | //------------------------------------------------------------------ |
| 172 | int |
| 173 | SendAttach (lldb::pid_t pid, |
| 174 | StringExtractorGDBRemote& response); |
| 175 | |
| 176 | |
| 177 | //------------------------------------------------------------------ |
Vince Harron | e0be425 | 2015-02-06 18:32:57 +0000 | [diff] [blame^] | 178 | /// Sends a GDB remote protocol 'I' packet that delivers stdin |
| 179 | /// data to the remote process. |
| 180 | /// |
| 181 | /// @param[in] data |
| 182 | /// A pointer to stdin data. |
| 183 | /// |
| 184 | /// @param[in] data_len |
| 185 | /// The number of bytes available at \a data. |
| 186 | /// |
| 187 | /// @return |
| 188 | /// Zero if the attach was successful, or an error indicating |
| 189 | /// an error code. |
| 190 | //------------------------------------------------------------------ |
| 191 | int |
| 192 | SendStdinNotification(const char* data, size_t data_len); |
| 193 | |
| 194 | //------------------------------------------------------------------ |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 195 | /// Sets the path to use for stdin/out/err for a process |
| 196 | /// that will be launched with the 'A' packet. |
| 197 | /// |
| 198 | /// @param[in] path |
| 199 | /// The path to use for stdin/out/err |
| 200 | /// |
| 201 | /// @return |
| 202 | /// Zero if the for success, or an error code for failure. |
| 203 | //------------------------------------------------------------------ |
| 204 | int |
| 205 | SetSTDIN (char const *path); |
| 206 | int |
| 207 | SetSTDOUT (char const *path); |
| 208 | int |
| 209 | SetSTDERR (char const *path); |
| 210 | |
| 211 | //------------------------------------------------------------------ |
| 212 | /// Sets the disable ASLR flag to \a enable for a process that will |
| 213 | /// be launched with the 'A' packet. |
| 214 | /// |
| 215 | /// @param[in] enable |
Jim Ingham | 106d028 | 2014-06-25 02:32:56 +0000 | [diff] [blame] | 216 | /// A boolean value indicating whether to disable ASLR or not. |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 217 | /// |
| 218 | /// @return |
| 219 | /// Zero if the for success, or an error code for failure. |
| 220 | //------------------------------------------------------------------ |
| 221 | int |
| 222 | SetDisableASLR (bool enable); |
Jim Ingham | 106d028 | 2014-06-25 02:32:56 +0000 | [diff] [blame] | 223 | |
| 224 | //------------------------------------------------------------------ |
| 225 | /// Sets the DetachOnError flag to \a enable for the process controlled by the stub. |
| 226 | /// |
| 227 | /// @param[in] enable |
| 228 | /// A boolean value indicating whether to detach on error or not. |
| 229 | /// |
| 230 | /// @return |
| 231 | /// Zero if the for success, or an error code for failure. |
| 232 | //------------------------------------------------------------------ |
| 233 | int |
| 234 | SetDetachOnError (bool enable); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 235 | |
| 236 | //------------------------------------------------------------------ |
| 237 | /// Sets the working directory to \a path for a process that will |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 238 | /// be launched with the 'A' packet for non platform based |
| 239 | /// connections. If this packet is sent to a GDB server that |
| 240 | /// implements the platform, it will change the current working |
| 241 | /// directory for the platform process. |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 242 | /// |
| 243 | /// @param[in] path |
Bruce Mitchener | d93c4a3 | 2014-07-01 21:22:11 +0000 | [diff] [blame] | 244 | /// The path to a directory to use when launching our process |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 245 | /// |
| 246 | /// @return |
| 247 | /// Zero if the for success, or an error code for failure. |
| 248 | //------------------------------------------------------------------ |
| 249 | int |
| 250 | SetWorkingDir (char const *path); |
| 251 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 252 | //------------------------------------------------------------------ |
| 253 | /// Gets the current working directory of a remote platform GDB |
| 254 | /// server. |
| 255 | /// |
| 256 | /// @param[out] cwd |
| 257 | /// The current working directory on the remote platform. |
| 258 | /// |
| 259 | /// @return |
| 260 | /// Boolean for success |
| 261 | //------------------------------------------------------------------ |
| 262 | bool |
| 263 | GetWorkingDir (std::string &cwd); |
| 264 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 265 | lldb::addr_t |
| 266 | AllocateMemory (size_t size, uint32_t permissions); |
| 267 | |
| 268 | bool |
| 269 | DeallocateMemory (lldb::addr_t addr); |
| 270 | |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 271 | lldb_private::Error |
| 272 | Detach (bool keep_stopped); |
Greg Clayton | 37a0a24 | 2012-04-11 00:24:49 +0000 | [diff] [blame] | 273 | |
Greg Clayton | 46fb558 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 274 | lldb_private::Error |
| 275 | GetMemoryRegionInfo (lldb::addr_t addr, |
| 276 | lldb_private::MemoryRegionInfo &range_info); |
| 277 | |
Johnny Chen | 6463720 | 2012-05-23 21:09:52 +0000 | [diff] [blame] | 278 | lldb_private::Error |
| 279 | GetWatchpointSupportInfo (uint32_t &num); |
| 280 | |
Enrico Granata | f04a219 | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 281 | lldb_private::Error |
| 282 | GetWatchpointSupportInfo (uint32_t &num, bool& after); |
| 283 | |
| 284 | lldb_private::Error |
| 285 | GetWatchpointsTriggerAfterInstruction (bool &after); |
| 286 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 287 | const lldb_private::ArchSpec & |
| 288 | GetHostArchitecture (); |
Greg Clayton | 9ac6d2d | 2013-10-25 18:13:17 +0000 | [diff] [blame] | 289 | |
| 290 | uint32_t |
| 291 | GetHostDefaultPacketTimeout(); |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 292 | |
| 293 | const lldb_private::ArchSpec & |
| 294 | GetProcessArchitecture (); |
| 295 | |
Steve Pucci | 5ae54ae | 2014-01-25 05:46:51 +0000 | [diff] [blame] | 296 | void |
| 297 | GetRemoteQSupported(); |
| 298 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 299 | bool |
| 300 | GetVContSupported (char flavor); |
| 301 | |
Jim Ingham | cd16df9 | 2012-07-20 21:37:13 +0000 | [diff] [blame] | 302 | bool |
Sean Callanan | b1de114 | 2013-09-04 23:24:15 +0000 | [diff] [blame] | 303 | GetpPacketSupported (lldb::tid_t tid); |
Hafiz Abid Qadeer | 9a78cdf | 2013-08-29 09:09:45 +0000 | [diff] [blame] | 304 | |
| 305 | bool |
Jason Molenda | bdc4f12 | 2014-05-06 02:59:39 +0000 | [diff] [blame] | 306 | GetxPacketSupported (); |
| 307 | |
| 308 | bool |
Jim Ingham | cd16df9 | 2012-07-20 21:37:13 +0000 | [diff] [blame] | 309 | GetVAttachOrWaitSupported (); |
| 310 | |
Jim Ingham | 279ceec | 2012-07-25 21:12:43 +0000 | [diff] [blame] | 311 | bool |
| 312 | GetSyncThreadStateSupported(); |
| 313 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 314 | void |
| 315 | ResetDiscoverableSettings(); |
| 316 | |
| 317 | bool |
Greg Clayton | 9b1e1cd | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 318 | GetHostInfo (bool force = false); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 319 | |
| 320 | bool |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 321 | GetOSVersion (uint32_t &major, |
| 322 | uint32_t &minor, |
| 323 | uint32_t &update); |
| 324 | |
| 325 | bool |
| 326 | GetOSBuildString (std::string &s); |
| 327 | |
| 328 | bool |
| 329 | GetOSKernelDescription (std::string &s); |
| 330 | |
| 331 | lldb_private::ArchSpec |
| 332 | GetSystemArchitecture (); |
| 333 | |
| 334 | bool |
| 335 | GetHostname (std::string &s); |
| 336 | |
Greg Clayton | 37a0a24 | 2012-04-11 00:24:49 +0000 | [diff] [blame] | 337 | lldb::addr_t |
| 338 | GetShlibInfoAddr(); |
| 339 | |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 340 | bool |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 341 | GetSupportsThreadSuffix (); |
| 342 | |
| 343 | bool |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 344 | GetProcessInfo (lldb::pid_t pid, |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 345 | lldb_private::ProcessInstanceInfo &process_info); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 346 | |
| 347 | uint32_t |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 348 | FindProcesses (const lldb_private::ProcessInstanceInfoMatch &process_match_info, |
| 349 | lldb_private::ProcessInstanceInfoList &process_infos); |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 350 | |
| 351 | bool |
| 352 | GetUserName (uint32_t uid, std::string &name); |
| 353 | |
| 354 | bool |
| 355 | GetGroupName (uint32_t gid, std::string &name); |
| 356 | |
| 357 | bool |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 358 | HasFullVContSupport () |
| 359 | { |
| 360 | return GetVContSupported ('A'); |
| 361 | } |
| 362 | |
| 363 | bool |
| 364 | HasAnyVContSupport () |
| 365 | { |
| 366 | return GetVContSupported ('a'); |
| 367 | } |
| 368 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 369 | bool |
| 370 | GetStopReply (StringExtractorGDBRemote &response); |
| 371 | |
| 372 | bool |
Greg Clayton | f402f78 | 2012-10-13 02:11:55 +0000 | [diff] [blame] | 373 | GetThreadStopInfo (lldb::tid_t tid, |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 374 | StringExtractorGDBRemote &response); |
| 375 | |
| 376 | bool |
| 377 | SupportsGDBStoppointPacket (GDBStoppointType type) |
| 378 | { |
| 379 | switch (type) |
| 380 | { |
| 381 | case eBreakpointSoftware: return m_supports_z0; |
| 382 | case eBreakpointHardware: return m_supports_z1; |
| 383 | case eWatchpointWrite: return m_supports_z2; |
| 384 | case eWatchpointRead: return m_supports_z3; |
| 385 | case eWatchpointReadWrite: return m_supports_z4; |
Chaoren Lin | 0be9ebb | 2015-02-03 01:51:50 +0000 | [diff] [blame] | 386 | case eStoppointInvalid: return false; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 387 | } |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 388 | } |
| 389 | uint8_t |
| 390 | SendGDBStoppointTypePacket (GDBStoppointType type, // Type of breakpoint or watchpoint |
| 391 | bool insert, // Insert or remove? |
| 392 | lldb::addr_t addr, // Address of breakpoint or watchpoint |
| 393 | uint32_t length); // Byte Size of breakpoint or watchpoint |
| 394 | |
Greg Clayton | 9b1e1cd | 2011-04-04 18:18:57 +0000 | [diff] [blame] | 395 | void |
| 396 | TestPacketSpeed (const uint32_t num_packets); |
| 397 | |
| 398 | // This packet is for testing the speed of the interface only. Both |
| 399 | // the client and server need to support it, but this allows us to |
| 400 | // measure the packet speed without any other work being done on the |
| 401 | // other end and avoids any of that work affecting the packet send |
| 402 | // and response times. |
| 403 | bool |
| 404 | SendSpeedTestPacket (uint32_t send_size, |
| 405 | uint32_t recv_size); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 406 | |
| 407 | bool |
Jason Molenda | e9ca4af | 2013-02-23 02:04:45 +0000 | [diff] [blame] | 408 | SetCurrentThread (uint64_t tid); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 409 | |
| 410 | bool |
Jason Molenda | e9ca4af | 2013-02-23 02:04:45 +0000 | [diff] [blame] | 411 | SetCurrentThreadForRun (uint64_t tid); |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 412 | |
Steve Pucci | 5ae54ae | 2014-01-25 05:46:51 +0000 | [diff] [blame] | 413 | bool |
Steve Pucci | 03904ac | 2014-03-04 23:18:46 +0000 | [diff] [blame] | 414 | GetQXferAuxvReadSupported (); |
| 415 | |
| 416 | bool |
Steve Pucci | 5ae54ae | 2014-01-25 05:46:51 +0000 | [diff] [blame] | 417 | GetQXferLibrariesReadSupported (); |
| 418 | |
| 419 | bool |
| 420 | GetQXferLibrariesSVR4ReadSupported (); |
| 421 | |
| 422 | uint64_t |
| 423 | GetRemoteMaxPacketSize(); |
| 424 | |
| 425 | bool |
| 426 | GetAugmentedLibrariesSVR4ReadSupported (); |
| 427 | |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 428 | lldb_private::LazyBool |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 429 | SupportsAllocDeallocMemory () // const |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 430 | { |
Jim Ingham | 372787f | 2012-04-07 00:00:41 +0000 | [diff] [blame] | 431 | // Uncomment this to have lldb pretend the debug server doesn't respond to alloc/dealloc memory packets. |
| 432 | // m_supports_alloc_dealloc_memory = lldb_private::eLazyBoolNo; |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 433 | return m_supports_alloc_dealloc_memory; |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Greg Clayton | adc00cb | 2011-05-20 23:38:13 +0000 | [diff] [blame] | 436 | size_t |
| 437 | GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids, |
| 438 | bool &sequence_mutex_unavailable); |
| 439 | |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 440 | bool |
| 441 | GetInterruptWasSent () const |
| 442 | { |
| 443 | return m_interrupt_sent; |
| 444 | } |
Han Ming Ong | 4b6459f | 2013-01-18 23:11:53 +0000 | [diff] [blame] | 445 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 446 | lldb::user_id_t |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 447 | OpenFile (const lldb_private::FileSpec& file_spec, |
| 448 | uint32_t flags, |
| 449 | mode_t mode, |
| 450 | lldb_private::Error &error); |
| 451 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 452 | bool |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 453 | CloseFile (lldb::user_id_t fd, |
| 454 | lldb_private::Error &error); |
| 455 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 456 | lldb::user_id_t |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 457 | GetFileSize (const lldb_private::FileSpec& file_spec); |
| 458 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 459 | lldb_private::Error |
| 460 | GetFilePermissions(const char *path, uint32_t &file_permissions); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 461 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 462 | lldb_private::Error |
| 463 | SetFilePermissions(const char *path, uint32_t file_permissions); |
| 464 | |
| 465 | uint64_t |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 466 | ReadFile (lldb::user_id_t fd, |
| 467 | uint64_t offset, |
| 468 | void *dst, |
| 469 | uint64_t dst_len, |
| 470 | lldb_private::Error &error); |
| 471 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 472 | uint64_t |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 473 | WriteFile (lldb::user_id_t fd, |
| 474 | uint64_t offset, |
| 475 | const void* src, |
| 476 | uint64_t src_len, |
| 477 | lldb_private::Error &error); |
| 478 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 479 | lldb_private::Error |
| 480 | CreateSymlink (const char *src, |
| 481 | const char *dst); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 482 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 483 | lldb_private::Error |
| 484 | Unlink (const char *path); |
| 485 | |
| 486 | lldb_private::Error |
| 487 | MakeDirectory (const char *path, |
| 488 | uint32_t mode); |
| 489 | |
| 490 | bool |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 491 | GetFileExists (const lldb_private::FileSpec& file_spec); |
| 492 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 493 | lldb_private::Error |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 494 | RunShellCommand (const char *command, // Shouldn't be NULL |
| 495 | const char *working_dir, // Pass NULL to use the current working directory |
| 496 | int *status_ptr, // Pass NULL if you don't want the process exit status |
| 497 | int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit |
| 498 | std::string *command_output, // Pass NULL if you don't want the command output |
| 499 | uint32_t timeout_sec); // Timeout in seconds to wait for shell program to finish |
| 500 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 501 | bool |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 502 | CalculateMD5 (const lldb_private::FileSpec& file_spec, |
| 503 | uint64_t &high, |
| 504 | uint64_t &low); |
| 505 | |
Han Ming Ong | 4b6459f | 2013-01-18 23:11:53 +0000 | [diff] [blame] | 506 | std::string |
| 507 | HarmonizeThreadIdsForProfileData (ProcessGDBRemote *process, |
| 508 | StringExtractorGDBRemote &inputStringExtractor); |
Daniel Malea | e0f8f57 | 2013-08-26 23:57:52 +0000 | [diff] [blame] | 509 | |
Greg Clayton | f74cf86 | 2013-11-13 23:28:31 +0000 | [diff] [blame] | 510 | bool |
| 511 | ReadRegister(lldb::tid_t tid, |
| 512 | uint32_t reg_num, |
| 513 | StringExtractorGDBRemote &response); |
| 514 | |
| 515 | bool |
| 516 | ReadAllRegisters (lldb::tid_t tid, |
| 517 | StringExtractorGDBRemote &response); |
| 518 | |
| 519 | bool |
| 520 | SaveRegisterState (lldb::tid_t tid, uint32_t &save_id); |
| 521 | |
| 522 | bool |
| 523 | RestoreRegisterState (lldb::tid_t tid, uint32_t save_id); |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 524 | |
| 525 | const char * |
| 526 | GetGDBServerProgramName(); |
Greg Clayton | f74cf86 | 2013-11-13 23:28:31 +0000 | [diff] [blame] | 527 | |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 528 | uint32_t |
| 529 | GetGDBServerProgramVersion(); |
| 530 | |
| 531 | bool |
| 532 | AvoidGPackets(ProcessGDBRemote *process); |
| 533 | |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 534 | bool |
| 535 | GetThreadExtendedInfoSupported(); |
| 536 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 537 | protected: |
| 538 | |
Greg Clayton | 3dedae1 | 2013-12-06 21:45:27 +0000 | [diff] [blame] | 539 | PacketResult |
| 540 | SendPacketAndWaitForResponseNoLock (const char *payload, |
| 541 | size_t payload_length, |
| 542 | StringExtractorGDBRemote &response); |
| 543 | |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 544 | bool |
Oleksiy Vyalov | 1ef7b2c | 2015-02-04 23:19:15 +0000 | [diff] [blame] | 545 | GetCurrentProcessInfo (bool allow_lazy_pid = true); |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 546 | |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 547 | bool |
| 548 | GetGDBServerVersion(); |
| 549 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 550 | //------------------------------------------------------------------ |
| 551 | // Classes that inherit from GDBRemoteCommunicationClient can see and modify these |
| 552 | //------------------------------------------------------------------ |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 553 | lldb_private::LazyBool m_supports_not_sending_acks; |
| 554 | lldb_private::LazyBool m_supports_thread_suffix; |
Greg Clayton | 4463399 | 2012-04-10 03:22:03 +0000 | [diff] [blame] | 555 | lldb_private::LazyBool m_supports_threads_in_stop_reply; |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 556 | lldb_private::LazyBool m_supports_vCont_all; |
| 557 | lldb_private::LazyBool m_supports_vCont_any; |
| 558 | lldb_private::LazyBool m_supports_vCont_c; |
| 559 | lldb_private::LazyBool m_supports_vCont_C; |
| 560 | lldb_private::LazyBool m_supports_vCont_s; |
| 561 | lldb_private::LazyBool m_supports_vCont_S; |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 562 | lldb_private::LazyBool m_qHostInfo_is_valid; |
Todd Fiala | 9f72b3a | 2014-05-07 19:28:21 +0000 | [diff] [blame] | 563 | lldb_private::LazyBool m_curr_pid_is_valid; |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 564 | lldb_private::LazyBool m_qProcessInfo_is_valid; |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 565 | lldb_private::LazyBool m_qGDBServerVersion_is_valid; |
Greg Clayton | 70b5765 | 2011-05-15 01:25:55 +0000 | [diff] [blame] | 566 | lldb_private::LazyBool m_supports_alloc_dealloc_memory; |
Greg Clayton | 46fb558 | 2011-11-18 07:03:08 +0000 | [diff] [blame] | 567 | lldb_private::LazyBool m_supports_memory_region_info; |
Johnny Chen | 6463720 | 2012-05-23 21:09:52 +0000 | [diff] [blame] | 568 | lldb_private::LazyBool m_supports_watchpoint_support_info; |
Jim Ingham | acff895 | 2013-05-02 00:27:30 +0000 | [diff] [blame] | 569 | lldb_private::LazyBool m_supports_detach_stay_stopped; |
Enrico Granata | f04a219 | 2012-07-13 23:18:48 +0000 | [diff] [blame] | 570 | lldb_private::LazyBool m_watchpoints_trigger_after_instruction; |
Jim Ingham | cd16df9 | 2012-07-20 21:37:13 +0000 | [diff] [blame] | 571 | lldb_private::LazyBool m_attach_or_wait_reply; |
Jim Ingham | 279ceec | 2012-07-25 21:12:43 +0000 | [diff] [blame] | 572 | lldb_private::LazyBool m_prepare_for_reg_writing_reply; |
Hafiz Abid Qadeer | 9a78cdf | 2013-08-29 09:09:45 +0000 | [diff] [blame] | 573 | lldb_private::LazyBool m_supports_p; |
Jason Molenda | bdc4f12 | 2014-05-06 02:59:39 +0000 | [diff] [blame] | 574 | lldb_private::LazyBool m_supports_x; |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 575 | lldb_private::LazyBool m_avoid_g_packets; |
Greg Clayton | f74cf86 | 2013-11-13 23:28:31 +0000 | [diff] [blame] | 576 | lldb_private::LazyBool m_supports_QSaveRegisterState; |
Steve Pucci | 03904ac | 2014-03-04 23:18:46 +0000 | [diff] [blame] | 577 | lldb_private::LazyBool m_supports_qXfer_auxv_read; |
Steve Pucci | 5ae54ae | 2014-01-25 05:46:51 +0000 | [diff] [blame] | 578 | lldb_private::LazyBool m_supports_qXfer_libraries_read; |
| 579 | lldb_private::LazyBool m_supports_qXfer_libraries_svr4_read; |
| 580 | lldb_private::LazyBool m_supports_augmented_libraries_svr4_read; |
Jason Molenda | 705b180 | 2014-06-13 02:37:02 +0000 | [diff] [blame] | 581 | lldb_private::LazyBool m_supports_jThreadExtendedInfo; |
Steve Pucci | 5ae54ae | 2014-01-25 05:46:51 +0000 | [diff] [blame] | 582 | |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 583 | bool |
| 584 | m_supports_qProcessInfoPID:1, |
| 585 | m_supports_qfProcessInfo:1, |
| 586 | m_supports_qUserName:1, |
| 587 | m_supports_qGroupName:1, |
| 588 | m_supports_qThreadStopInfo:1, |
| 589 | m_supports_z0:1, |
| 590 | m_supports_z1:1, |
| 591 | m_supports_z2:1, |
| 592 | m_supports_z3:1, |
Greg Clayton | 8960058 | 2013-10-10 17:53:50 +0000 | [diff] [blame] | 593 | m_supports_z4:1, |
| 594 | m_supports_QEnvironment:1, |
| 595 | m_supports_QEnvironmentHexEncoded:1; |
Greg Clayton | 2a48f52 | 2011-05-14 01:50:35 +0000 | [diff] [blame] | 596 | |
Todd Fiala | 9f72b3a | 2014-05-07 19:28:21 +0000 | [diff] [blame] | 597 | lldb::pid_t m_curr_pid; |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 598 | lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all other operations |
| 599 | lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for continue, step, etc |
| 600 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 601 | |
Johnny Chen | 6463720 | 2012-05-23 21:09:52 +0000 | [diff] [blame] | 602 | uint32_t m_num_supported_hardware_watchpoints; |
| 603 | |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 604 | // If we need to send a packet while the target is running, the m_async_XXX |
| 605 | // member variables take care of making this happen. |
| 606 | lldb_private::Mutex m_async_mutex; |
| 607 | lldb_private::Predicate<bool> m_async_packet_predicate; |
| 608 | std::string m_async_packet; |
Jim Ingham | a6195b7 | 2013-12-18 01:24:33 +0000 | [diff] [blame] | 609 | PacketResult m_async_result; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 610 | StringExtractorGDBRemote m_async_response; |
| 611 | int m_async_signal; // We were asked to deliver a signal to the inferior process. |
Greg Clayton | 2687cd1 | 2012-03-29 01:55:41 +0000 | [diff] [blame] | 612 | bool m_interrupt_sent; |
Han Ming Ong | 4b6459f | 2013-01-18 23:11:53 +0000 | [diff] [blame] | 613 | std::string m_partial_profile_data; |
| 614 | std::map<uint64_t, uint32_t> m_thread_id_to_used_usec_map; |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 615 | |
Greg Clayton | d314e81 | 2011-03-23 00:09:55 +0000 | [diff] [blame] | 616 | lldb_private::ArchSpec m_host_arch; |
Jason Molenda | f17b5ac | 2012-12-19 02:54:03 +0000 | [diff] [blame] | 617 | lldb_private::ArchSpec m_process_arch; |
Greg Clayton | 1cb6496 | 2011-03-24 04:28:38 +0000 | [diff] [blame] | 618 | uint32_t m_os_version_major; |
| 619 | uint32_t m_os_version_minor; |
| 620 | uint32_t m_os_version_update; |
| 621 | std::string m_os_build; |
| 622 | std::string m_os_kernel; |
| 623 | std::string m_hostname; |
Jason Molenda | a332978 | 2014-03-29 18:54:20 +0000 | [diff] [blame] | 624 | std::string m_gdb_server_name; // from reply to qGDBServerVersion, empty if qGDBServerVersion is not supported |
| 625 | uint32_t m_gdb_server_version; // from reply to qGDBServerVersion, zero if qGDBServerVersion is not supported |
Greg Clayton | 9ac6d2d | 2013-10-25 18:13:17 +0000 | [diff] [blame] | 626 | uint32_t m_default_packet_timeout; |
Steve Pucci | 5ae54ae | 2014-01-25 05:46:51 +0000 | [diff] [blame] | 627 | uint64_t m_max_packet_size; // as returned by qSupported |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 628 | |
Greg Clayton | 32e0a75 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 629 | bool |
| 630 | DecodeProcessInfoResponse (StringExtractorGDBRemote &response, |
Greg Clayton | 8b82f08 | 2011-04-12 05:54:46 +0000 | [diff] [blame] | 631 | lldb_private::ProcessInstanceInfo &process_info); |
Greg Clayton | 576d883 | 2011-03-22 04:00:09 +0000 | [diff] [blame] | 632 | private: |
| 633 | //------------------------------------------------------------------ |
| 634 | // For GDBRemoteCommunicationClient only |
| 635 | //------------------------------------------------------------------ |
| 636 | DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationClient); |
| 637 | }; |
| 638 | |
| 639 | #endif // liblldb_GDBRemoteCommunicationClient_h_ |