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,
62 SendContinuePacketAndWaitForResponse (ProcessGDBRemote *process,
63 const char *packet_payload,
65 StringExtractorGDBRemote &response);
68 GetThreadSuffixSupported ();
70 // This packet is usually sent first and the boolean return value
71 // indicates if the packet was send and any response was received
72 // even in the response is UNIMPLEMENTED. If the packet failed to
73 // get a response, then false is returned. This quickly tells us
74 // if we were able to connect and communicte with the remote GDB
77 QueryNoAckModeSupported ();
80 GetListThreadsInStopReplySupported ();
83 SendAsyncSignal (int signo);
86 SendInterrupt (lldb_private::Mutex::Locker &locker,
87 uint32_t seconds_to_wait_for_stop,
91 GetCurrentProcessID ();
94 GetLaunchSuccess (std::string &error_str);
97 LaunchGDBserverAndGetPort (lldb::pid_t &pid);
100 KillSpawnedProcess (lldb::pid_t pid);
102 //------------------------------------------------------------------
103 /// Sends a GDB remote protocol 'A' packet that delivers program
104 /// arguments to the remote server.
107 /// A NULL terminated array of const C strings to use as the
111 /// Zero if the response was "OK", a positive value if the
112 /// the response was "Exx" where xx are two hex digits, or
113 /// -1 if the call is unsupported or any other unexpected
114 /// response was received.
115 //------------------------------------------------------------------
117 SendArgumentsPacket (const lldb_private::ProcessLaunchInfo &launch_info);
119 //------------------------------------------------------------------
120 /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the
121 /// environment that will get used when launching an application
122 /// in conjunction with the 'A' packet. This function can be called
123 /// multiple times in a row in order to pass on the desired
124 /// environment that the inferior should be launched with.
126 /// @param[in] name_equal_value
127 /// A NULL terminated C string that contains a single environment
128 /// in the format "NAME=VALUE".
131 /// Zero if the response was "OK", a positive value if the
132 /// the response was "Exx" where xx are two hex digits, or
133 /// -1 if the call is unsupported or any other unexpected
134 /// response was received.
135 //------------------------------------------------------------------
137 SendEnvironmentPacket (char const *name_equal_value);
140 SendLaunchArchPacket (const char *arch);
141 //------------------------------------------------------------------
142 /// Sends a "vAttach:PID" where PID is in hex.
145 /// A process ID for the remote gdb server to attach to.
147 /// @param[out] response
148 /// The response received from the gdb server. If the return
149 /// value is zero, \a response will contain a stop reply
153 /// Zero if the attach was successful, or an error indicating
155 //------------------------------------------------------------------
157 SendAttach (lldb::pid_t pid,
158 StringExtractorGDBRemote& response);
161 //------------------------------------------------------------------
162 /// Sets the path to use for stdin/out/err for a process
163 /// that will be launched with the 'A' packet.
166 /// The path to use for stdin/out/err
169 /// Zero if the for success, or an error code for failure.
170 //------------------------------------------------------------------
172 SetSTDIN (char const *path);
174 SetSTDOUT (char const *path);
176 SetSTDERR (char const *path);
178 //------------------------------------------------------------------
179 /// Sets the disable ASLR flag to \a enable for a process that will
180 /// be launched with the 'A' packet.
182 /// @param[in] enable
183 /// A boolean value indicating wether to disable ASLR or not.
186 /// Zero if the for success, or an error code for failure.
187 //------------------------------------------------------------------
189 SetDisableASLR (bool enable);
191 //------------------------------------------------------------------
192 /// Sets the working directory to \a path for a process that will
193 /// be launched with the 'A' packet for non platform based
194 /// connections. If this packet is sent to a GDB server that
195 /// implements the platform, it will change the current working
196 /// directory for the platform process.
199 /// The path to a directory to use when launching our processs
202 /// Zero if the for success, or an error code for failure.
203 //------------------------------------------------------------------
205 SetWorkingDir (char const *path);
207 //------------------------------------------------------------------
208 /// Gets the current working directory of a remote platform GDB
212 /// The current working directory on the remote platform.
215 /// Boolean for success
216 //------------------------------------------------------------------
218 GetWorkingDir (std::string &cwd);
221 AllocateMemory (size_t size, uint32_t permissions);
224 DeallocateMemory (lldb::addr_t addr);
227 Detach (bool keep_stopped);
230 GetMemoryRegionInfo (lldb::addr_t addr,
231 lldb_private::MemoryRegionInfo &range_info);
234 GetWatchpointSupportInfo (uint32_t &num);
237 GetWatchpointSupportInfo (uint32_t &num, bool& after);
240 GetWatchpointsTriggerAfterInstruction (bool &after);
242 const lldb_private::ArchSpec &
243 GetHostArchitecture ();
246 GetHostDefaultPacketTimeout();
248 const lldb_private::ArchSpec &
249 GetProcessArchitecture ();
252 GetVContSupported (char flavor);
255 GetpPacketSupported (lldb::tid_t tid);
258 GetVAttachOrWaitSupported ();
261 GetSyncThreadStateSupported();
264 ResetDiscoverableSettings();
267 GetHostInfo (bool force = false);
270 GetOSVersion (uint32_t &major,
275 GetOSBuildString (std::string &s);
278 GetOSKernelDescription (std::string &s);
280 lldb_private::ArchSpec
281 GetSystemArchitecture ();
284 GetHostname (std::string &s);
290 GetSupportsThreadSuffix ();
293 GetProcessInfo (lldb::pid_t pid,
294 lldb_private::ProcessInstanceInfo &process_info);
297 FindProcesses (const lldb_private::ProcessInstanceInfoMatch &process_match_info,
298 lldb_private::ProcessInstanceInfoList &process_infos);
301 GetUserName (uint32_t uid, std::string &name);
304 GetGroupName (uint32_t gid, std::string &name);
307 HasFullVContSupport ()
309 return GetVContSupported ('A');
313 HasAnyVContSupport ()
315 return GetVContSupported ('a');
319 GetStopReply (StringExtractorGDBRemote &response);
322 GetThreadStopInfo (lldb::tid_t tid,
323 StringExtractorGDBRemote &response);
326 SupportsGDBStoppointPacket (GDBStoppointType type)
330 case eBreakpointSoftware: return m_supports_z0;
331 case eBreakpointHardware: return m_supports_z1;
332 case eWatchpointWrite: return m_supports_z2;
333 case eWatchpointRead: return m_supports_z3;
334 case eWatchpointReadWrite: return m_supports_z4;
339 SendGDBStoppointTypePacket (GDBStoppointType type, // Type of breakpoint or watchpoint
340 bool insert, // Insert or remove?
341 lldb::addr_t addr, // Address of breakpoint or watchpoint
342 uint32_t length); // Byte Size of breakpoint or watchpoint
345 TestPacketSpeed (const uint32_t num_packets);
347 // This packet is for testing the speed of the interface only. Both
348 // the client and server need to support it, but this allows us to
349 // measure the packet speed without any other work being done on the
350 // other end and avoids any of that work affecting the packet send
351 // and response times.
353 SendSpeedTestPacket (uint32_t send_size,
357 SetCurrentThread (uint64_t tid);
360 SetCurrentThreadForRun (uint64_t tid);
362 lldb_private::LazyBool
363 SupportsAllocDeallocMemory () // const
365 // Uncomment this to have lldb pretend the debug server doesn't respond to alloc/dealloc memory packets.
366 // m_supports_alloc_dealloc_memory = lldb_private::eLazyBoolNo;
367 return m_supports_alloc_dealloc_memory;
371 GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids,
372 bool &sequence_mutex_unavailable);
375 GetInterruptWasSent () const
377 return m_interrupt_sent;
381 OpenFile (const lldb_private::FileSpec& file_spec,
384 lldb_private::Error &error);
387 CloseFile (lldb::user_id_t fd,
388 lldb_private::Error &error);
391 GetFileSize (const lldb_private::FileSpec& file_spec);
394 GetFilePermissions(const char *path, uint32_t &file_permissions);
397 SetFilePermissions(const char *path, uint32_t file_permissions);
400 ReadFile (lldb::user_id_t fd,
404 lldb_private::Error &error);
407 WriteFile (lldb::user_id_t fd,
411 lldb_private::Error &error);
414 CreateSymlink (const char *src,
418 Unlink (const char *path);
421 MakeDirectory (const char *path,
425 GetFileExists (const lldb_private::FileSpec& file_spec);
428 RunShellCommand (const char *command, // Shouldn't be NULL
429 const char *working_dir, // Pass NULL to use the current working directory
430 int *status_ptr, // Pass NULL if you don't want the process exit status
431 int *signo_ptr, // Pass NULL if you don't want the signal that caused the process to exit
432 std::string *command_output, // Pass NULL if you don't want the command output
433 uint32_t timeout_sec); // Timeout in seconds to wait for shell program to finish
436 CalculateMD5 (const lldb_private::FileSpec& file_spec,
441 HarmonizeThreadIdsForProfileData (ProcessGDBRemote *process,
442 StringExtractorGDBRemote &inputStringExtractor);
445 ReadRegister(lldb::tid_t tid,
447 StringExtractorGDBRemote &response);
450 ReadAllRegisters (lldb::tid_t tid,
451 StringExtractorGDBRemote &response);
454 SaveRegisterState (lldb::tid_t tid, uint32_t &save_id);
457 RestoreRegisterState (lldb::tid_t tid, uint32_t save_id);
462 GetCurrentProcessInfo ();
464 //------------------------------------------------------------------
465 // Classes that inherit from GDBRemoteCommunicationClient can see and modify these
466 //------------------------------------------------------------------
467 lldb_private::LazyBool m_supports_not_sending_acks;
468 lldb_private::LazyBool m_supports_thread_suffix;
469 lldb_private::LazyBool m_supports_threads_in_stop_reply;
470 lldb_private::LazyBool m_supports_vCont_all;
471 lldb_private::LazyBool m_supports_vCont_any;
472 lldb_private::LazyBool m_supports_vCont_c;
473 lldb_private::LazyBool m_supports_vCont_C;
474 lldb_private::LazyBool m_supports_vCont_s;
475 lldb_private::LazyBool m_supports_vCont_S;
476 lldb_private::LazyBool m_qHostInfo_is_valid;
477 lldb_private::LazyBool m_qProcessInfo_is_valid;
478 lldb_private::LazyBool m_supports_alloc_dealloc_memory;
479 lldb_private::LazyBool m_supports_memory_region_info;
480 lldb_private::LazyBool m_supports_watchpoint_support_info;
481 lldb_private::LazyBool m_supports_detach_stay_stopped;
482 lldb_private::LazyBool m_watchpoints_trigger_after_instruction;
483 lldb_private::LazyBool m_attach_or_wait_reply;
484 lldb_private::LazyBool m_prepare_for_reg_writing_reply;
485 lldb_private::LazyBool m_supports_p;
486 lldb_private::LazyBool m_supports_QSaveRegisterState;
489 m_supports_qProcessInfoPID:1,
490 m_supports_qfProcessInfo:1,
491 m_supports_qUserName:1,
492 m_supports_qGroupName:1,
493 m_supports_qThreadStopInfo:1,
499 m_supports_QEnvironment:1,
500 m_supports_QEnvironmentHexEncoded:1;
503 lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all other operations
504 lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for continue, step, etc
507 uint32_t m_num_supported_hardware_watchpoints;
509 // If we need to send a packet while the target is running, the m_async_XXX
510 // member variables take care of making this happen.
511 lldb_private::Mutex m_async_mutex;
512 lldb_private::Predicate<bool> m_async_packet_predicate;
513 std::string m_async_packet;
514 StringExtractorGDBRemote m_async_response;
515 int m_async_signal; // We were asked to deliver a signal to the inferior process.
516 bool m_interrupt_sent;
517 std::string m_partial_profile_data;
518 std::map<uint64_t, uint32_t> m_thread_id_to_used_usec_map;
520 lldb_private::ArchSpec m_host_arch;
521 lldb_private::ArchSpec m_process_arch;
522 uint32_t m_os_version_major;
523 uint32_t m_os_version_minor;
524 uint32_t m_os_version_update;
525 std::string m_os_build;
526 std::string m_os_kernel;
527 std::string m_hostname;
528 uint32_t m_default_packet_timeout;
531 DecodeProcessInfoResponse (StringExtractorGDBRemote &response,
532 lldb_private::ProcessInstanceInfo &process_info);
534 //------------------------------------------------------------------
535 // For GDBRemoteCommunicationClient only
536 //------------------------------------------------------------------
537 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationClient);
540 #endif // liblldb_GDBRemoteCommunicationClient_h_