blob: c50e52ab9e852e41a63374959a225b495f2b767d [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- GDBRemoteCommunication.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_GDBRemoteCommunication_h_
11#define liblldb_GDBRemoteCommunication_h_
12
13// C Includes
14// C++ Includes
15#include <list>
16#include <string>
17
18// Other libraries and framework includes
19// Project includes
20#include "lldb/lldb-private.h"
Chris Lattner24943d22010-06-08 16:52:24 +000021#include "lldb/Core/Communication.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022#include "lldb/Core/Listener.h"
23#include "lldb/Host/Mutex.h"
24#include "lldb/Host/Predicate.h"
Peter Collingbourne20fe30c2011-06-18 23:52:14 +000025#include "lldb/Host/TimeValue.h"
Chris Lattner24943d22010-06-08 16:52:24 +000026
Greg Clayton54e7afa2010-07-09 20:39:50 +000027#include "Utility/StringExtractorGDBRemote.h"
Chris Lattner24943d22010-06-08 16:52:24 +000028
29class ProcessGDBRemote;
30
Greg Clayton61d043b2011-03-22 04:00:09 +000031class GDBRemoteCommunication : public lldb_private::Communication
Chris Lattner24943d22010-06-08 16:52:24 +000032{
33public:
Greg Claytonb749a262010-12-03 06:02:24 +000034 enum
35 {
36 eBroadcastBitRunPacketSent = kLoUserBroadcastBit
37 };
Chris Lattner24943d22010-06-08 16:52:24 +000038 //------------------------------------------------------------------
39 // Constructors and Destructors
40 //------------------------------------------------------------------
Greg Claytonb72d0f02011-04-12 05:54:46 +000041 GDBRemoteCommunication(const char *comm_name,
42 const char *listener_name,
43 bool is_platform);
Chris Lattner24943d22010-06-08 16:52:24 +000044
45 virtual
46 ~GDBRemoteCommunication();
47
48 size_t
49 SendPacket (const char *payload);
50
51 size_t
52 SendPacket (const char *payload,
53 size_t payload_length);
54
Greg Clayton24bc5d92011-03-30 18:16:51 +000055 size_t
56 SendPacket (lldb_private::StreamString &response);
57
Chris Lattner24943d22010-06-08 16:52:24 +000058 // Wait for a packet within 'nsec' seconds
59 size_t
Greg Clayton63afdb02011-06-17 01:22:15 +000060 WaitForPacketWithTimeoutMicroSeconds (StringExtractorGDBRemote &response,
61 uint32_t usec);
Chris Lattner24943d22010-06-08 16:52:24 +000062
63 char
Greg Claytonc97bfdb2011-03-10 02:26:48 +000064 GetAck ();
Chris Lattner24943d22010-06-08 16:52:24 +000065
66 size_t
Greg Claytona4881d02011-01-22 07:12:45 +000067 SendAck ();
68
69 size_t
70 SendNack ();
71
Chris Lattner24943d22010-06-08 16:52:24 +000072 char
73 CalculcateChecksum (const char *payload,
74 size_t payload_length);
75
Chris Lattner24943d22010-06-08 16:52:24 +000076 bool
Chris Lattner24943d22010-06-08 16:52:24 +000077 GetSequenceMutex(lldb_private::Mutex::Locker& locker);
78
Greg Clayton63afdb02011-06-17 01:22:15 +000079 bool
80 CheckForPacket (const uint8_t *src,
81 size_t src_len,
82 StringExtractorGDBRemote &packet);
Chris Lattner24943d22010-06-08 16:52:24 +000083 bool
84 IsRunning() const
85 {
Greg Claytoncecf3482011-01-20 07:53:45 +000086 return m_public_is_running.GetValue();
Chris Lattner24943d22010-06-08 16:52:24 +000087 }
Greg Clayton72e1c782011-01-22 23:43:18 +000088
Greg Clayton58e26e02011-03-24 04:28:38 +000089 bool
90 GetSendAcks ()
91 {
92 return m_send_acks;
93 }
94
Greg Clayton61d043b2011-03-22 04:00:09 +000095 //------------------------------------------------------------------
96 // Client and server must implement these pure virtual functions
97 //------------------------------------------------------------------
98 virtual bool
99 GetThreadSuffixSupported () = 0;
Chris Lattner24943d22010-06-08 16:52:24 +0000100
Greg Clayton61d043b2011-03-22 04:00:09 +0000101 //------------------------------------------------------------------
102 // Set the global packet timeout.
103 //
104 // For clients, this is the timeout that gets used when sending
105 // packets and waiting for responses. For servers, this might not
106 // get used, and if it doesn't this should be moved to the
107 // GDBRemoteCommunicationClient.
108 //------------------------------------------------------------------
Greg Claytonc97bfdb2011-03-10 02:26:48 +0000109 uint32_t
110 SetPacketTimeout (uint32_t packet_timeout)
111 {
112 const uint32_t old_packet_timeout = m_packet_timeout;
113 m_packet_timeout = packet_timeout;
114 return old_packet_timeout;
115 }
Greg Claytonc1f45872011-02-12 06:28:37 +0000116
Greg Clayton63afdb02011-06-17 01:22:15 +0000117 uint32_t
118 GetPacketTimeoutInMicroSeconds () const
119 {
Peter Collingbourne20fe30c2011-06-18 23:52:14 +0000120 return m_packet_timeout * lldb_private::TimeValue::MicroSecPerSec;
Greg Clayton63afdb02011-06-17 01:22:15 +0000121 }
Greg Claytonb72d0f02011-04-12 05:54:46 +0000122 //------------------------------------------------------------------
123 // Start a debugserver instance on the current host using the
124 // supplied connection URL.
125 //------------------------------------------------------------------
126 lldb_private::Error
127 StartDebugserverProcess (const char *connect_url,
128 const char *unix_socket_name,
129 lldb_private::ProcessLaunchInfo &launch_info);
130
Greg Clayton63afdb02011-06-17 01:22:15 +0000131
Chris Lattner24943d22010-06-08 16:52:24 +0000132protected:
133 typedef std::list<std::string> packet_collection;
134
135 size_t
136 SendPacketNoLock (const char *payload,
137 size_t payload_length);
138
139 size_t
Greg Clayton63afdb02011-06-17 01:22:15 +0000140 WaitForPacketWithTimeoutMicroSecondsNoLock (StringExtractorGDBRemote &response,
141 uint32_t timeout_usec);
Greg Clayton72e1c782011-01-22 23:43:18 +0000142
143 bool
144 WaitForNotRunningPrivate (const lldb_private::TimeValue *timeout_ptr);
Chris Lattner24943d22010-06-08 16:52:24 +0000145
146 //------------------------------------------------------------------
147 // Classes that inherit from GDBRemoteCommunication can see and modify these
148 //------------------------------------------------------------------
Greg Claytonc97bfdb2011-03-10 02:26:48 +0000149 uint32_t m_packet_timeout;
Chris Lattner24943d22010-06-08 16:52:24 +0000150 lldb_private::Mutex m_sequence_mutex; // Restrict access to sending/receiving packets to a single thread at a time
Greg Claytoncecf3482011-01-20 07:53:45 +0000151 lldb_private::Predicate<bool> m_public_is_running;
152 lldb_private::Predicate<bool> m_private_is_running;
Greg Clayton58e26e02011-03-24 04:28:38 +0000153 bool m_send_acks;
Greg Claytonb72d0f02011-04-12 05:54:46 +0000154 bool m_is_platform; // Set to true if this class represents a platform,
155 // false if this class represents a debug session for
156 // a single process
Greg Clayton58e26e02011-03-24 04:28:38 +0000157
158
Chris Lattner24943d22010-06-08 16:52:24 +0000159
Greg Claytonb72d0f02011-04-12 05:54:46 +0000160
Chris Lattner24943d22010-06-08 16:52:24 +0000161private:
162 //------------------------------------------------------------------
163 // For GDBRemoteCommunication only
164 //------------------------------------------------------------------
165 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunication);
166};
167
168#endif // liblldb_GDBRemoteCommunication_h_