1 //===-- GDBRemoteCommunicationClient.h --------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_GDBRemoteCommunicationClient_h_
11 #define liblldb_GDBRemoteCommunicationClient_h_
17 // Other libraries and framework includes
19 #include "lldb/Core/ArchSpec.h"
20 #include "lldb/Target/Process.h"
22 #include "GDBRemoteCommunication.h"
26 eBreakpointSoftware = 0,
33 class GDBRemoteCommunicationClient : public GDBRemoteCommunication
36 //------------------------------------------------------------------
37 // Constructors and Destructors
38 //------------------------------------------------------------------
39 GDBRemoteCommunicationClient(bool is_platform);
41 ~GDBRemoteCommunicationClient();
43 //------------------------------------------------------------------
44 // After connecting, send the handshake to the server to make sure
45 // we are communicating with it.
46 //------------------------------------------------------------------
48 HandshakeWithServer (lldb_private::Error *error_ptr);
51 SendPacketAndWaitForResponse (const char *send_payload,
52 StringExtractorGDBRemote &response,
56 SendPacketAndWaitForResponse (const char *send_payload,
58 StringExtractorGDBRemote &response,
61 // For packets which specify a range of output to be returned,
62 // return all of the output via a series of request packets of the form
64 // <prefix><size>,<size>
65 // <prefix><size>*2,<size>
66 // <prefix><size>*3,<size>
68 // until a "$l..." packet is received, indicating the end.
69 // (size is in hex; this format is used by a standard gdbserver to
70 // return the given portion of the output specified by <prefix>;
71 // for example, "qXfer:libraries-svr4:read::fff,1000" means
72 // "return a chunk of the xml description file for shared
73 // library load addresses, where the chunk starts at offset 0xfff
74 // and continues for 0x1000 bytes").
75 // Concatenate the resulting server response packets together and
76 // return in response_string. If any packet fails, the return value
77 // indicates that failure and the returned string value is undefined.
79 SendPacketsAndConcatenateResponses (const char *send_payload_prefix,
80 std::string &response_string);
83 SendContinuePacketAndWaitForResponse (ProcessGDBRemote *process,
84 const char *packet_payload,
86 StringExtractorGDBRemote &response);
89 GetThreadSuffixSupported ();
91 // This packet is usually sent first and the boolean return value
92 // indicates if the packet was send and any response was received
93 // even in the response is UNIMPLEMENTED. If the packet failed to
94 // get a response, then false is returned. This quickly tells us
95 // if we were able to connect and communicte with the remote GDB
98 QueryNoAckModeSupported ();
101 GetListThreadsInStopReplySupported ();
104 SendAsyncSignal (int signo);
107 SendInterrupt (lldb_private::Mutex::Locker &locker,
108 uint32_t seconds_to_wait_for_stop,
112 GetCurrentProcessID ();
115 GetLaunchSuccess (std::string &error_str);
118 LaunchGDBserverAndGetPort (lldb::pid_t &pid, const char *remote_accept_hostname);
121 KillSpawnedProcess (lldb::pid_t pid);
123 //------------------------------------------------------------------
124 /// Sends a GDB remote protocol 'A' packet that delivers program
125 /// arguments to the remote server.
128 /// A NULL terminated array of const C strings to use as the
132 /// Zero if the response was "OK", a positive value if the
133 /// the response was "Exx" where xx are two hex digits, or
134 /// -1 if the call is unsupported or any other unexpected
135 /// response was received.
136 //------------------------------------------------------------------
138 SendArgumentsPacket (const lldb_private::ProcessLaunchInfo &launch_info);
140 //------------------------------------------------------------------
141 /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the
142 /// environment that will get used when launching an application
143 /// in conjunction with the 'A' packet. This function can be called
144 /// multiple times in a row in order to pass on the desired
145 /// environment that the inferior should be launched with.
147 /// @param[in] name_equal_value
148 /// A NULL terminated C string that contains a single environment
149 /// in the format "NAME=VALUE".
152 /// Zero if the response was "OK", a positive value if the
153 /// the response was "Exx" where xx are two hex digits, or
154 /// -1 if the call is unsupported or any other unexpected
155 /// response was received.
156 //------------------------------------------------------------------
158 SendEnvironmentPacket (char const *name_equal_value);
161 SendLaunchArchPacket (const char *arch);
162 //------------------------------------------------------------------
163 /// Sends a "vAttach:PID" where PID is in hex.
166 /// A process ID for the remote gdb server to attach to.
168 /// @param[out] response
169 /// The response received from the gdb server. If the return
170 /// value is zero, \a response will contain a stop reply
174 /// Zero if the attach was successful, or an error indicating
176 //------------------------------------------------------------------
178 SendAttach (lldb::pid_t pid,
179 StringExtractorGDBRemote& response);
182 //------------------------------------------------------------------
183 /// Sets the path to use for stdin/out/err for a process
184 /// that will be launched with the 'A' packet.
187 /// The path to use for stdin/out/err
190 /// Zero if the for success, or an error code for failure.
191 //------------------------------------------------------------------
193 SetSTDIN (char const *path);
195 SetSTDOUT (char const *path);
197 SetSTDERR (char const *path);
199 //------------------------------------------------------------------
200 /// Sets the disable ASLR flag to \a enable for a process that will
201 /// be launched with the 'A' packet.
203 /// @param[in] enable
204 /// A boolean value indicating wether to disable ASLR or not.
207 /// Zero if the for success, or an error code for failure.
208 //------------------------------------------------------------------
210 SetDisableASLR (bool enable);
212 //------------------------------------------------------------------
213 /// Sets the working directory to \a path for a process that will
214 /// be launched with the 'A' packet for non platform based
215 /// connections. If this packet is sent to a GDB server that
216 /// implements the platform, it will change the current working
217 /// directory for the platform process.
220 /// The path to a directory to use when launching our processs
223 /// Zero if the for success, or an error code for failure.
224 //------------------------------------------------------------------
226 SetWorkingDir (char const *path);
228 //------------------------------------------------------------------
229 /// Gets the current working directory of a remote platform GDB
233 /// The current working directory on the remote platform.
236 /// Boolean for success
237 //------------------------------------------------------------------
239 GetWorkingDir (std::string &cwd);
242 AllocateMemory (size_t size, uint32_t permissions);
245 DeallocateMemory (lldb::addr_t addr);
248 Detach (bool keep_stopped);
251 GetMemoryRegionInfo (lldb::addr_t addr,
252 lldb_private::MemoryRegionInfo &range_info);
255 GetWatchpointSupportInfo (uint32_t &num);
258 GetWatchpointSupportInfo (uint32_t &num, bool& after);
261 GetWatchpointsTriggerAfterInstruction (bool &after);
263 const lldb_private::ArchSpec &
264 GetHostArchitecture ();
267 GetHostDefaultPacketTimeout();
269 const lldb_private::ArchSpec &
270 GetProcessArchitecture ();
273 GetRemoteQSupported();
276 GetVContSupported (char flavor);
279 GetpPacketSupported (lldb::tid_t tid);
282 GetVAttachOrWaitSupported ();
285 GetSyncThreadStateSupported();
288 ResetDiscoverableSettings();
291 GetHostInfo (bool force = false);
294 GetOSVersion (uint32_t &major,
299 GetOSBuildString (std::string &s);
302 GetOSKernelDescription (std::string &s);
304 lldb_private::ArchSpec
305 GetSystemArchitecture ();
308 GetHostname (std::string &s);
314 GetSupportsThreadSuffix ();
317 GetProcessInfo (lldb::pid_t pid,
318 lldb_private::ProcessInstanceInfo &process_info);
321 FindProcesses (const lldb_private::ProcessInstanceInfoMatch &process_match_info,
322 lldb_private::ProcessInstanceInfoList &process_infos);
325 GetUserName (uint32_t uid, std::string &name);
328 GetGroupName (uint32_t gid, std::string &name);
331 HasFullVContSupport ()
333 return GetVContSupported ('A');
337 HasAnyVContSupport ()
339 return GetVContSupported ('a');
343 GetStopReply (StringExtractorGDBRemote &response);
346 GetThreadStopInfo (lldb::tid_t tid,
347 StringExtractorGDBRemote &response);
350 SupportsGDBStoppointPacket (GDBStoppointType type)
354 case eBreakpointSoftware: return m_supports_z0;
355 case eBreakpointHardware: return m_supports_z1;
356 case eWatchpointWrite: return m_supports_z2;
357 case eWatchpointRead: return m_supports_z3;
358 case eWatchpointReadWrite: return m_supports_z4;
363 SendGDBStoppointTypePacket (GDBStoppointType type, // Type of breakpoint or watchpoint
364 bool insert, // Insert or remove?
365 lldb::addr_t addr, // Address of breakpoint or watchpoint
366 uint32_t length); // Byte Size of breakpoint or watchpoint
369 TestPacketSpeed (const uint32_t num_packets);
371 // This packet is for testing the speed of the interface only. Both
372 // the client and server need to support it, but this allows us to
373 // measure the packet speed without any other work being done on the
374 // other end and avoids any of that work affecting the packet send
375 // and response times.
377 SendSpeedTestPacket (uint32_t send_size,
381 SetCurrentThread (uint64_t tid);
384 SetCurrentThreadForRun (uint64_t tid);
387 GetQXferLibrariesReadSupported ();
390 GetQXferLibrariesSVR4ReadSupported ();
393 GetRemoteMaxPacketSize();
396 GetAugmentedLibrariesSVR4ReadSupported ();
398 lldb_private::LazyBool
399 SupportsAllocDeallocMemory () // const
401 // Uncomment this to have lldb pretend the debug server doesn't respond to alloc/dealloc memory packets.
402 // m_supports_alloc_dealloc_memory = lldb_private::eLazyBoolNo;
403 return m_supports_alloc_dealloc_memory;
407 GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids,
408 bool &sequence_mutex_unavailable);
411 GetInterruptWasSent () const
413 return m_interrupt_sent;
417 OpenFile (const lldb_private::FileSpec& file_spec,
420 lldb_private::Error &error);
423 CloseFile (lldb::user_id_t fd,
424 lldb_private::Error &error);
427 GetFileSize (const lldb_private::FileSpec& file_spec);
430 GetFilePermissions(const char *path, uint32_t &file_permissions);
433 SetFilePermissions(const char *path, uint32_t file_permissions);
436 ReadFile (lldb::user_id_t fd,
440 lldb_private::Error &error);
443 WriteFile (lldb::user_id_t fd,
447 lldb_private::Error &error);
450 CreateSymlink (const char *src,
454 Unlink (const char *path);
457 MakeDirectory (const char *path,
461 GetFileExists (const lldb_private::FileSpec& file_spec);
464 RunShellCommand (const char *command, // Shouldn't be NULL
465 const char *working_dir, // Pass NULL to use the current working directory
466 int *status_ptr, // Pass NULL if you don't want the process exit status
467 int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit
468 std::string *command_output, // Pass NULL if you don't want the command output
469 uint32_t timeout_sec); // Timeout in seconds to wait for shell program to finish
472 CalculateMD5 (const lldb_private::FileSpec& file_spec,
477 HarmonizeThreadIdsForProfileData (ProcessGDBRemote *process,
478 StringExtractorGDBRemote &inputStringExtractor);
481 ReadRegister(lldb::tid_t tid,
483 StringExtractorGDBRemote &response);
486 ReadAllRegisters (lldb::tid_t tid,
487 StringExtractorGDBRemote &response);
490 SaveRegisterState (lldb::tid_t tid, uint32_t &save_id);
493 RestoreRegisterState (lldb::tid_t tid, uint32_t save_id);
498 SendPacketAndWaitForResponseNoLock (const char *payload,
499 size_t payload_length,
500 StringExtractorGDBRemote &response);
503 GetCurrentProcessInfo ();
505 //------------------------------------------------------------------
506 // Classes that inherit from GDBRemoteCommunicationClient can see and modify these
507 //------------------------------------------------------------------
508 lldb_private::LazyBool m_supports_not_sending_acks;
509 lldb_private::LazyBool m_supports_thread_suffix;
510 lldb_private::LazyBool m_supports_threads_in_stop_reply;
511 lldb_private::LazyBool m_supports_vCont_all;
512 lldb_private::LazyBool m_supports_vCont_any;
513 lldb_private::LazyBool m_supports_vCont_c;
514 lldb_private::LazyBool m_supports_vCont_C;
515 lldb_private::LazyBool m_supports_vCont_s;
516 lldb_private::LazyBool m_supports_vCont_S;
517 lldb_private::LazyBool m_qHostInfo_is_valid;
518 lldb_private::LazyBool m_qProcessInfo_is_valid;
519 lldb_private::LazyBool m_supports_alloc_dealloc_memory;
520 lldb_private::LazyBool m_supports_memory_region_info;
521 lldb_private::LazyBool m_supports_watchpoint_support_info;
522 lldb_private::LazyBool m_supports_detach_stay_stopped;
523 lldb_private::LazyBool m_watchpoints_trigger_after_instruction;
524 lldb_private::LazyBool m_attach_or_wait_reply;
525 lldb_private::LazyBool m_prepare_for_reg_writing_reply;
526 lldb_private::LazyBool m_supports_p;
527 lldb_private::LazyBool m_supports_QSaveRegisterState;
528 lldb_private::LazyBool m_supports_qXfer_libraries_read;
529 lldb_private::LazyBool m_supports_qXfer_libraries_svr4_read;
530 lldb_private::LazyBool m_supports_augmented_libraries_svr4_read;
533 m_supports_qProcessInfoPID:1,
534 m_supports_qfProcessInfo:1,
535 m_supports_qUserName:1,
536 m_supports_qGroupName:1,
537 m_supports_qThreadStopInfo:1,
543 m_supports_QEnvironment:1,
544 m_supports_QEnvironmentHexEncoded:1;
547 lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all other operations
548 lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for continue, step, etc
551 uint32_t m_num_supported_hardware_watchpoints;
553 // If we need to send a packet while the target is running, the m_async_XXX
554 // member variables take care of making this happen.
555 lldb_private::Mutex m_async_mutex;
556 lldb_private::Predicate<bool> m_async_packet_predicate;
557 std::string m_async_packet;
558 PacketResult m_async_result;
559 StringExtractorGDBRemote m_async_response;
560 int m_async_signal; // We were asked to deliver a signal to the inferior process.
561 bool m_interrupt_sent;
562 std::string m_partial_profile_data;
563 std::map<uint64_t, uint32_t> m_thread_id_to_used_usec_map;
565 lldb_private::ArchSpec m_host_arch;
566 lldb_private::ArchSpec m_process_arch;
567 uint32_t m_os_version_major;
568 uint32_t m_os_version_minor;
569 uint32_t m_os_version_update;
570 std::string m_os_build;
571 std::string m_os_kernel;
572 std::string m_hostname;
573 uint32_t m_default_packet_timeout;
574 uint64_t m_max_packet_size; // as returned by qSupported
577 DecodeProcessInfoResponse (StringExtractorGDBRemote &response,
578 lldb_private::ProcessInstanceInfo &process_info);
580 //------------------------------------------------------------------
581 // For GDBRemoteCommunicationClient only
582 //------------------------------------------------------------------
583 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationClient);
586 #endif // liblldb_GDBRemoteCommunicationClient_h_