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);
42 ~GDBRemoteCommunicationClient();
44 //------------------------------------------------------------------
45 // After connecting, send the handshake to the server to make sure
46 // we are communicating with it.
47 //------------------------------------------------------------------
49 HandshakeWithServer (lldb_private::Error *error_ptr);
52 SendPacketAndWaitForResponse (const char *send_payload,
53 StringExtractorGDBRemote &response,
57 SendPacketAndWaitForResponse (const char *send_payload,
59 StringExtractorGDBRemote &response,
63 SendContinuePacketAndWaitForResponse (ProcessGDBRemote *process,
64 const char *packet_payload,
66 StringExtractorGDBRemote &response);
69 GetThreadSuffixSupported ();
72 QueryNoAckModeSupported ();
75 GetListThreadsInStopReplySupported ();
78 SendAsyncSignal (int signo);
81 SendInterrupt (lldb_private::Mutex::Locker &locker,
82 uint32_t seconds_to_wait_for_stop,
86 GetCurrentProcessID ();
89 GetLaunchSuccess (std::string &error_str);
92 LaunchGDBserverAndGetPort ();
94 //------------------------------------------------------------------
95 /// Sends a GDB remote protocol 'A' packet that delivers program
96 /// arguments to the remote server.
99 /// A NULL terminated array of const C strings to use as the
103 /// Zero if the response was "OK", a positive value if the
104 /// the response was "Exx" where xx are two hex digits, or
105 /// -1 if the call is unsupported or any other unexpected
106 /// response was received.
107 //------------------------------------------------------------------
109 SendArgumentsPacket (char const *argv[]);
111 //------------------------------------------------------------------
112 /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the
113 /// environment that will get used when launching an application
114 /// in conjunction with the 'A' packet. This function can be called
115 /// multiple times in a row in order to pass on the desired
116 /// environment that the inferior should be launched with.
118 /// @param[in] name_equal_value
119 /// A NULL terminated C string that contains a single environment
120 /// in the format "NAME=VALUE".
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 //------------------------------------------------------------------
129 SendEnvironmentPacket (char const *name_equal_value);
132 SendLaunchArchPacket (const char *arch);
133 //------------------------------------------------------------------
134 /// Sends a "vAttach:PID" where PID is in hex.
137 /// A process ID for the remote gdb server to attach to.
139 /// @param[out] response
140 /// The response received from the gdb server. If the return
141 /// value is zero, \a response will contain a stop reply
145 /// Zero if the attach was successful, or an error indicating
147 //------------------------------------------------------------------
149 SendAttach (lldb::pid_t pid,
150 StringExtractorGDBRemote& response);
153 //------------------------------------------------------------------
154 /// Sets the path to use for stdin/out/err for a process
155 /// that will be launched with the 'A' packet.
158 /// The path to use for stdin/out/err
161 /// Zero if the for success, or an error code for failure.
162 //------------------------------------------------------------------
164 SetSTDIN (char const *path);
166 SetSTDOUT (char const *path);
168 SetSTDERR (char const *path);
170 //------------------------------------------------------------------
171 /// Sets the disable ASLR flag to \a enable for a process that will
172 /// be launched with the 'A' packet.
174 /// @param[in] enable
175 /// A boolean value indicating wether to disable ASLR or not.
178 /// Zero if the for success, or an error code for failure.
179 //------------------------------------------------------------------
181 SetDisableASLR (bool enable);
183 //------------------------------------------------------------------
184 /// Sets the working directory to \a path for a process that will
185 /// be launched with the 'A' packet.
188 /// The path to a directory to use when launching our processs
191 /// Zero if the for success, or an error code for failure.
192 //------------------------------------------------------------------
194 SetWorkingDir (char const *path);
197 AllocateMemory (size_t size, uint32_t permissions);
200 DeallocateMemory (lldb::addr_t addr);
203 Detach (bool keep_stopped);
206 GetMemoryRegionInfo (lldb::addr_t addr,
207 lldb_private::MemoryRegionInfo &range_info);
210 GetWatchpointSupportInfo (uint32_t &num);
213 GetWatchpointSupportInfo (uint32_t &num, bool& after);
216 GetWatchpointsTriggerAfterInstruction (bool &after);
218 const lldb_private::ArchSpec &
219 GetHostArchitecture ();
221 const lldb_private::ArchSpec &
222 GetProcessArchitecture ();
225 GetVContSupported (char flavor);
228 GetVAttachOrWaitSupported ();
231 GetSyncThreadStateSupported();
234 ResetDiscoverableSettings();
237 GetHostInfo (bool force = false);
240 GetOSVersion (uint32_t &major,
245 GetOSBuildString (std::string &s);
248 GetOSKernelDescription (std::string &s);
250 lldb_private::ArchSpec
251 GetSystemArchitecture ();
254 GetHostname (std::string &s);
260 GetSupportsThreadSuffix ();
263 GetProcessInfo (lldb::pid_t pid,
264 lldb_private::ProcessInstanceInfo &process_info);
267 FindProcesses (const lldb_private::ProcessInstanceInfoMatch &process_match_info,
268 lldb_private::ProcessInstanceInfoList &process_infos);
271 GetUserName (uint32_t uid, std::string &name);
274 GetGroupName (uint32_t gid, std::string &name);
277 HasFullVContSupport ()
279 return GetVContSupported ('A');
283 HasAnyVContSupport ()
285 return GetVContSupported ('a');
289 GetStopReply (StringExtractorGDBRemote &response);
292 GetThreadStopInfo (lldb::tid_t tid,
293 StringExtractorGDBRemote &response);
296 SupportsGDBStoppointPacket (GDBStoppointType type)
300 case eBreakpointSoftware: return m_supports_z0;
301 case eBreakpointHardware: return m_supports_z1;
302 case eWatchpointWrite: return m_supports_z2;
303 case eWatchpointRead: return m_supports_z3;
304 case eWatchpointReadWrite: return m_supports_z4;
309 SendGDBStoppointTypePacket (GDBStoppointType type, // Type of breakpoint or watchpoint
310 bool insert, // Insert or remove?
311 lldb::addr_t addr, // Address of breakpoint or watchpoint
312 uint32_t length); // Byte Size of breakpoint or watchpoint
315 TestPacketSpeed (const uint32_t num_packets);
317 // This packet is for testing the speed of the interface only. Both
318 // the client and server need to support it, but this allows us to
319 // measure the packet speed without any other work being done on the
320 // other end and avoids any of that work affecting the packet send
321 // and response times.
323 SendSpeedTestPacket (uint32_t send_size,
327 SetCurrentThread (uint64_t tid);
330 SetCurrentThreadForRun (uint64_t tid);
332 lldb_private::LazyBool
333 SupportsAllocDeallocMemory () // const
335 // Uncomment this to have lldb pretend the debug server doesn't respond to alloc/dealloc memory packets.
336 // m_supports_alloc_dealloc_memory = lldb_private::eLazyBoolNo;
337 return m_supports_alloc_dealloc_memory;
341 GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids,
342 bool &sequence_mutex_unavailable);
345 GetInterruptWasSent () const
347 return m_interrupt_sent;
351 HarmonizeThreadIdsForProfileData (ProcessGDBRemote *process,
352 StringExtractorGDBRemote &inputStringExtractor);
357 GetCurrentProcessInfo ();
359 //------------------------------------------------------------------
360 // Classes that inherit from GDBRemoteCommunicationClient can see and modify these
361 //------------------------------------------------------------------
362 lldb_private::LazyBool m_supports_not_sending_acks;
363 lldb_private::LazyBool m_supports_thread_suffix;
364 lldb_private::LazyBool m_supports_threads_in_stop_reply;
365 lldb_private::LazyBool m_supports_vCont_all;
366 lldb_private::LazyBool m_supports_vCont_any;
367 lldb_private::LazyBool m_supports_vCont_c;
368 lldb_private::LazyBool m_supports_vCont_C;
369 lldb_private::LazyBool m_supports_vCont_s;
370 lldb_private::LazyBool m_supports_vCont_S;
371 lldb_private::LazyBool m_qHostInfo_is_valid;
372 lldb_private::LazyBool m_qProcessInfo_is_valid;
373 lldb_private::LazyBool m_supports_alloc_dealloc_memory;
374 lldb_private::LazyBool m_supports_memory_region_info;
375 lldb_private::LazyBool m_supports_watchpoint_support_info;
376 lldb_private::LazyBool m_supports_detach_stay_stopped;
377 lldb_private::LazyBool m_watchpoints_trigger_after_instruction;
378 lldb_private::LazyBool m_attach_or_wait_reply;
379 lldb_private::LazyBool m_prepare_for_reg_writing_reply;
382 m_supports_qProcessInfoPID:1,
383 m_supports_qfProcessInfo:1,
384 m_supports_qUserName:1,
385 m_supports_qGroupName:1,
386 m_supports_qThreadStopInfo:1,
394 lldb::tid_t m_curr_tid; // Current gdb remote protocol thread index for all other operations
395 lldb::tid_t m_curr_tid_run; // Current gdb remote protocol thread index for continue, step, etc
398 uint32_t m_num_supported_hardware_watchpoints;
400 // If we need to send a packet while the target is running, the m_async_XXX
401 // member variables take care of making this happen.
402 lldb_private::Mutex m_async_mutex;
403 lldb_private::Predicate<bool> m_async_packet_predicate;
404 std::string m_async_packet;
405 StringExtractorGDBRemote m_async_response;
406 int m_async_signal; // We were asked to deliver a signal to the inferior process.
407 bool m_interrupt_sent;
408 std::string m_partial_profile_data;
409 std::map<uint64_t, uint32_t> m_thread_id_to_used_usec_map;
411 lldb_private::ArchSpec m_host_arch;
412 lldb_private::ArchSpec m_process_arch;
413 uint32_t m_os_version_major;
414 uint32_t m_os_version_minor;
415 uint32_t m_os_version_update;
416 std::string m_os_build;
417 std::string m_os_kernel;
418 std::string m_hostname;
421 DecodeProcessInfoResponse (StringExtractorGDBRemote &response,
422 lldb_private::ProcessInstanceInfo &process_info);
424 //------------------------------------------------------------------
425 // For GDBRemoteCommunicationClient only
426 //------------------------------------------------------------------
427 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationClient);
430 #endif // liblldb_GDBRemoteCommunicationClient_h_