]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
MFC r258054: Update LLDB to upstream r194122 snapshot
[FreeBSD/stable/10.git] / contrib / llvm / tools / lldb / source / Plugins / Process / gdb-remote / GDBRemoteCommunicationClient.h
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
15 #include <vector>
16
17 // Other libraries and framework includes
18 // Project includes
19 #include "lldb/Core/ArchSpec.h"
20 #include "lldb/Target/Process.h"
21
22 #include "GDBRemoteCommunication.h"
23
24 typedef enum 
25 {
26     eBreakpointSoftware = 0,
27     eBreakpointHardware,
28     eWatchpointWrite,
29     eWatchpointRead,
30     eWatchpointReadWrite
31 } GDBStoppointType;
32
33 class GDBRemoteCommunicationClient : public GDBRemoteCommunication
34 {
35 public:
36     //------------------------------------------------------------------
37     // Constructors and Destructors
38     //------------------------------------------------------------------
39     GDBRemoteCommunicationClient(bool is_platform);
40
41     virtual
42     ~GDBRemoteCommunicationClient();
43
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
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
71     void
72     QueryNoAckModeSupported ();
73
74     void
75     GetListThreadsInStopReplySupported ();
76
77     bool
78     SendAsyncSignal (int signo);
79
80     bool
81     SendInterrupt (lldb_private::Mutex::Locker &locker, 
82                    uint32_t seconds_to_wait_for_stop, 
83                    bool &timed_out);
84
85     lldb::pid_t
86     GetCurrentProcessID ();
87
88     bool
89     GetLaunchSuccess (std::string &error_str);
90
91     uint16_t
92     LaunchGDBserverAndGetPort (lldb::pid_t &pid);
93     
94     bool
95     KillSpawnedProcess (lldb::pid_t pid);
96
97     //------------------------------------------------------------------
98     /// Sends a GDB remote protocol 'A' packet that delivers program
99     /// arguments to the remote server.
100     ///
101     /// @param[in] argv
102     ///     A NULL terminated array of const C strings to use as the
103     ///     arguments.
104     ///
105     /// @return
106     ///     Zero if the response was "OK", a positive value if the
107     ///     the response was "Exx" where xx are two hex digits, or
108     ///     -1 if the call is unsupported or any other unexpected
109     ///     response was received.
110     //------------------------------------------------------------------
111     int
112     SendArgumentsPacket (char const *argv[]);
113
114     //------------------------------------------------------------------
115     /// Sends a "QEnvironment:NAME=VALUE" packet that will build up the
116     /// environment that will get used when launching an application
117     /// in conjunction with the 'A' packet. This function can be called
118     /// multiple times in a row in order to pass on the desired
119     /// environment that the inferior should be launched with.
120     ///
121     /// @param[in] name_equal_value
122     ///     A NULL terminated C string that contains a single environment
123     ///     in the format "NAME=VALUE".
124     ///
125     /// @return
126     ///     Zero if the response was "OK", a positive value if the
127     ///     the response was "Exx" where xx are two hex digits, or
128     ///     -1 if the call is unsupported or any other unexpected
129     ///     response was received.
130     //------------------------------------------------------------------
131     int
132     SendEnvironmentPacket (char const *name_equal_value);
133
134     int
135     SendLaunchArchPacket (const char *arch);
136     //------------------------------------------------------------------
137     /// Sends a "vAttach:PID" where PID is in hex. 
138     ///
139     /// @param[in] pid
140     ///     A process ID for the remote gdb server to attach to.
141     ///
142     /// @param[out] response
143     ///     The response received from the gdb server. If the return
144     ///     value is zero, \a response will contain a stop reply 
145     ///     packet.
146     ///
147     /// @return
148     ///     Zero if the attach was successful, or an error indicating
149     ///     an error code.
150     //------------------------------------------------------------------
151     int
152     SendAttach (lldb::pid_t pid, 
153                 StringExtractorGDBRemote& response);
154
155
156     //------------------------------------------------------------------
157     /// Sets the path to use for stdin/out/err for a process
158     /// that will be launched with the 'A' packet.
159     ///
160     /// @param[in] path
161     ///     The path to use for stdin/out/err
162     ///
163     /// @return
164     ///     Zero if the for success, or an error code for failure.
165     //------------------------------------------------------------------
166     int
167     SetSTDIN (char const *path);
168     int
169     SetSTDOUT (char const *path);
170     int
171     SetSTDERR (char const *path);
172
173     //------------------------------------------------------------------
174     /// Sets the disable ASLR flag to \a enable for a process that will 
175     /// be launched with the 'A' packet.
176     ///
177     /// @param[in] enable
178     ///     A boolean value indicating wether to disable ASLR or not.
179     ///
180     /// @return
181     ///     Zero if the for success, or an error code for failure.
182     //------------------------------------------------------------------
183     int
184     SetDisableASLR (bool enable);
185
186     //------------------------------------------------------------------
187     /// Sets the working directory to \a path for a process that will 
188     /// be launched with the 'A' packet.
189     ///
190     /// @param[in] path
191     ///     The path to a directory to use when launching our processs
192     ///
193     /// @return
194     ///     Zero if the for success, or an error code for failure.
195     //------------------------------------------------------------------
196     int
197     SetWorkingDir (char const *path);
198
199     lldb::addr_t
200     AllocateMemory (size_t size, uint32_t permissions);
201
202     bool
203     DeallocateMemory (lldb::addr_t addr);
204
205     lldb_private::Error
206     Detach (bool keep_stopped);
207
208     lldb_private::Error
209     GetMemoryRegionInfo (lldb::addr_t addr, 
210                         lldb_private::MemoryRegionInfo &range_info); 
211
212     lldb_private::Error
213     GetWatchpointSupportInfo (uint32_t &num); 
214
215     lldb_private::Error
216     GetWatchpointSupportInfo (uint32_t &num, bool& after);
217     
218     lldb_private::Error
219     GetWatchpointsTriggerAfterInstruction (bool &after);
220
221     const lldb_private::ArchSpec &
222     GetHostArchitecture ();
223     
224     uint32_t
225     GetHostDefaultPacketTimeout();
226
227     const lldb_private::ArchSpec &
228     GetProcessArchitecture ();
229
230     bool
231     GetVContSupported (char flavor);
232
233     bool
234     GetpPacketSupported (lldb::tid_t tid);
235
236     bool
237     GetVAttachOrWaitSupported ();
238     
239     bool
240     GetSyncThreadStateSupported();
241     
242     void
243     ResetDiscoverableSettings();
244
245     bool
246     GetHostInfo (bool force = false);
247     
248     bool
249     GetOSVersion (uint32_t &major, 
250                   uint32_t &minor, 
251                   uint32_t &update);
252
253     bool
254     GetOSBuildString (std::string &s);
255     
256     bool
257     GetOSKernelDescription (std::string &s);
258
259     lldb_private::ArchSpec
260     GetSystemArchitecture ();
261
262     bool
263     GetHostname (std::string &s);
264
265     lldb::addr_t
266     GetShlibInfoAddr();
267
268     bool
269     GetSupportsThreadSuffix ();
270
271     bool
272     GetProcessInfo (lldb::pid_t pid, 
273                     lldb_private::ProcessInstanceInfo &process_info);
274
275     uint32_t
276     FindProcesses (const lldb_private::ProcessInstanceInfoMatch &process_match_info,
277                    lldb_private::ProcessInstanceInfoList &process_infos);
278
279     bool
280     GetUserName (uint32_t uid, std::string &name);
281     
282     bool
283     GetGroupName (uint32_t gid, std::string &name);
284
285     bool
286     HasFullVContSupport ()
287     {
288         return GetVContSupported ('A');
289     }
290
291     bool
292     HasAnyVContSupport ()
293     {
294         return GetVContSupported ('a');
295     }
296     
297     bool
298     GetStopReply (StringExtractorGDBRemote &response);
299
300     bool
301     GetThreadStopInfo (lldb::tid_t tid, 
302                        StringExtractorGDBRemote &response);
303
304     bool
305     SupportsGDBStoppointPacket (GDBStoppointType type)
306     {
307         switch (type)
308         {
309         case eBreakpointSoftware:   return m_supports_z0;
310         case eBreakpointHardware:   return m_supports_z1;
311         case eWatchpointWrite:      return m_supports_z2;
312         case eWatchpointRead:       return m_supports_z3;
313         case eWatchpointReadWrite:  return m_supports_z4;
314         }
315         return false;
316     }
317     uint8_t
318     SendGDBStoppointTypePacket (GDBStoppointType type,   // Type of breakpoint or watchpoint
319                                 bool insert,              // Insert or remove?
320                                 lldb::addr_t addr,        // Address of breakpoint or watchpoint
321                                 uint32_t length);         // Byte Size of breakpoint or watchpoint
322
323     void
324     TestPacketSpeed (const uint32_t num_packets);
325
326     // This packet is for testing the speed of the interface only. Both
327     // the client and server need to support it, but this allows us to
328     // measure the packet speed without any other work being done on the
329     // other end and avoids any of that work affecting the packet send
330     // and response times.
331     bool
332     SendSpeedTestPacket (uint32_t send_size, 
333                          uint32_t recv_size);
334     
335     bool
336     SetCurrentThread (uint64_t tid);
337     
338     bool
339     SetCurrentThreadForRun (uint64_t tid);
340
341     lldb_private::LazyBool
342     SupportsAllocDeallocMemory () // const
343     {
344         // Uncomment this to have lldb pretend the debug server doesn't respond to alloc/dealloc memory packets.
345         // m_supports_alloc_dealloc_memory = lldb_private::eLazyBoolNo;
346         return m_supports_alloc_dealloc_memory;
347     }
348
349     size_t
350     GetCurrentThreadIDs (std::vector<lldb::tid_t> &thread_ids,
351                          bool &sequence_mutex_unavailable);
352     
353     bool
354     GetInterruptWasSent () const
355     {
356         return m_interrupt_sent;
357     }
358     
359     virtual lldb::user_id_t
360     OpenFile (const lldb_private::FileSpec& file_spec,
361               uint32_t flags,
362               mode_t mode,
363               lldb_private::Error &error);
364     
365     virtual bool
366     CloseFile (lldb::user_id_t fd,
367                lldb_private::Error &error);
368     
369     virtual lldb::user_id_t
370     GetFileSize (const lldb_private::FileSpec& file_spec);
371     
372     virtual uint32_t
373     GetFilePermissions(const lldb_private::FileSpec& file_spec,
374                        lldb_private::Error &error);
375
376     virtual uint64_t
377     ReadFile (lldb::user_id_t fd,
378               uint64_t offset,
379               void *dst,
380               uint64_t dst_len,
381               lldb_private::Error &error);
382     
383     virtual uint64_t
384     WriteFile (lldb::user_id_t fd,
385                uint64_t offset,
386                const void* src,
387                uint64_t src_len,
388                lldb_private::Error &error);
389     
390     virtual uint32_t
391     MakeDirectory (const std::string &path,
392                    mode_t mode);
393     
394     virtual bool
395     GetFileExists (const lldb_private::FileSpec& file_spec);
396     
397     virtual lldb_private::Error
398     RunShellCommand (const char *command,           // Shouldn't be NULL
399                      const char *working_dir,       // Pass NULL to use the current working directory
400                      int *status_ptr,               // Pass NULL if you don't want the process exit status
401                      int *signo_ptr,                // Pass NULL if you don't want the signal that caused the process to exit
402                      std::string *command_output,   // Pass NULL if you don't want the command output
403                      uint32_t timeout_sec);         // Timeout in seconds to wait for shell program to finish
404     
405     virtual bool
406     CalculateMD5 (const lldb_private::FileSpec& file_spec,
407                   uint64_t &high,
408                   uint64_t &low);
409     
410     std::string
411     HarmonizeThreadIdsForProfileData (ProcessGDBRemote *process,
412                                       StringExtractorGDBRemote &inputStringExtractor);
413
414 protected:
415
416     bool
417     GetCurrentProcessInfo ();
418
419     //------------------------------------------------------------------
420     // Classes that inherit from GDBRemoteCommunicationClient can see and modify these
421     //------------------------------------------------------------------
422     lldb_private::LazyBool m_supports_not_sending_acks;
423     lldb_private::LazyBool m_supports_thread_suffix;
424     lldb_private::LazyBool m_supports_threads_in_stop_reply;
425     lldb_private::LazyBool m_supports_vCont_all;
426     lldb_private::LazyBool m_supports_vCont_any;
427     lldb_private::LazyBool m_supports_vCont_c;
428     lldb_private::LazyBool m_supports_vCont_C;
429     lldb_private::LazyBool m_supports_vCont_s;
430     lldb_private::LazyBool m_supports_vCont_S;
431     lldb_private::LazyBool m_qHostInfo_is_valid;
432     lldb_private::LazyBool m_qProcessInfo_is_valid;
433     lldb_private::LazyBool m_supports_alloc_dealloc_memory;
434     lldb_private::LazyBool m_supports_memory_region_info;
435     lldb_private::LazyBool m_supports_watchpoint_support_info;
436     lldb_private::LazyBool m_supports_detach_stay_stopped;
437     lldb_private::LazyBool m_watchpoints_trigger_after_instruction;
438     lldb_private::LazyBool m_attach_or_wait_reply;
439     lldb_private::LazyBool m_prepare_for_reg_writing_reply;
440     lldb_private::LazyBool m_supports_p;
441     
442     bool
443         m_supports_qProcessInfoPID:1,
444         m_supports_qfProcessInfo:1,
445         m_supports_qUserName:1,
446         m_supports_qGroupName:1,
447         m_supports_qThreadStopInfo:1,
448         m_supports_z0:1,
449         m_supports_z1:1,
450         m_supports_z2:1,
451         m_supports_z3:1,
452         m_supports_z4:1,
453         m_supports_QEnvironment:1,
454         m_supports_QEnvironmentHexEncoded:1;
455     
456
457     lldb::tid_t m_curr_tid;         // Current gdb remote protocol thread index for all other operations
458     lldb::tid_t m_curr_tid_run;     // Current gdb remote protocol thread index for continue, step, etc
459
460
461     uint32_t m_num_supported_hardware_watchpoints;
462
463     // If we need to send a packet while the target is running, the m_async_XXX
464     // member variables take care of making this happen.
465     lldb_private::Mutex m_async_mutex;
466     lldb_private::Predicate<bool> m_async_packet_predicate;
467     std::string m_async_packet;
468     StringExtractorGDBRemote m_async_response;
469     int m_async_signal; // We were asked to deliver a signal to the inferior process.
470     bool m_interrupt_sent;
471     std::string m_partial_profile_data;
472     std::map<uint64_t, uint32_t> m_thread_id_to_used_usec_map;
473     
474     lldb_private::ArchSpec m_host_arch;
475     lldb_private::ArchSpec m_process_arch;
476     uint32_t m_os_version_major;
477     uint32_t m_os_version_minor;
478     uint32_t m_os_version_update;
479     std::string m_os_build;
480     std::string m_os_kernel;
481     std::string m_hostname;
482     uint32_t m_default_packet_timeout;
483     
484     bool
485     DecodeProcessInfoResponse (StringExtractorGDBRemote &response, 
486                                lldb_private::ProcessInstanceInfo &process_info);
487 private:
488     //------------------------------------------------------------------
489     // For GDBRemoteCommunicationClient only
490     //------------------------------------------------------------------
491     DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunicationClient);
492 };
493
494 #endif  // liblldb_GDBRemoteCommunicationClient_h_