blob: 77e3e1a5d7c7cf90ff0ae6c5e5806d91ccf5f5df [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"
25
Greg Clayton54e7afa2010-07-09 20:39:50 +000026#include "Utility/StringExtractorGDBRemote.h"
Chris Lattner24943d22010-06-08 16:52:24 +000027
28class ProcessGDBRemote;
29
Greg Clayton61d043b2011-03-22 04:00:09 +000030class GDBRemoteCommunication : public lldb_private::Communication
Chris Lattner24943d22010-06-08 16:52:24 +000031{
32public:
Greg Claytonb749a262010-12-03 06:02:24 +000033 enum
34 {
35 eBroadcastBitRunPacketSent = kLoUserBroadcastBit
36 };
Chris Lattner24943d22010-06-08 16:52:24 +000037 //------------------------------------------------------------------
38 // Constructors and Destructors
39 //------------------------------------------------------------------
Greg Claytonb72d0f02011-04-12 05:54:46 +000040 GDBRemoteCommunication(const char *comm_name,
41 const char *listener_name,
42 bool is_platform);
Chris Lattner24943d22010-06-08 16:52:24 +000043
44 virtual
45 ~GDBRemoteCommunication();
46
47 size_t
48 SendPacket (const char *payload);
49
50 size_t
51 SendPacket (const char *payload,
52 size_t payload_length);
53
Greg Clayton24bc5d92011-03-30 18:16:51 +000054 size_t
55 SendPacket (lldb_private::StreamString &response);
56
Chris Lattner24943d22010-06-08 16:52:24 +000057 // Wait for a packet within 'nsec' seconds
58 size_t
59 WaitForPacket (StringExtractorGDBRemote &response,
Greg Claytonc97bfdb2011-03-10 02:26:48 +000060 uint32_t sec);
Chris Lattner24943d22010-06-08 16:52:24 +000061
62 // Wait for a packet with an absolute timeout time. If 'timeout' is NULL
63 // wait indefinitely.
64 size_t
65 WaitForPacket (StringExtractorGDBRemote &response,
Greg Clayton72e1c782011-01-22 23:43:18 +000066 const lldb_private::TimeValue* timeout);
Chris Lattner24943d22010-06-08 16:52:24 +000067
68 char
Greg Claytonc97bfdb2011-03-10 02:26:48 +000069 GetAck ();
Chris Lattner24943d22010-06-08 16:52:24 +000070
71 size_t
Greg Claytona4881d02011-01-22 07:12:45 +000072 SendAck ();
73
74 size_t
75 SendNack ();
76
Chris Lattner24943d22010-06-08 16:52:24 +000077 char
78 CalculcateChecksum (const char *payload,
79 size_t payload_length);
80
Chris Lattner24943d22010-06-08 16:52:24 +000081 bool
Chris Lattner24943d22010-06-08 16:52:24 +000082 GetSequenceMutex(lldb_private::Mutex::Locker& locker);
83
84 //------------------------------------------------------------------
85 // Communication overrides
86 //------------------------------------------------------------------
87 virtual void
Caroline Ticec4f55fe2010-11-19 20:47:54 +000088 AppendBytesToCache (const uint8_t *src, size_t src_len, bool broadcast, lldb::ConnectionStatus status);
Chris Lattner24943d22010-06-08 16:52:24 +000089
Chris Lattner24943d22010-06-08 16:52:24 +000090 bool
91 IsRunning() const
92 {
Greg Claytoncecf3482011-01-20 07:53:45 +000093 return m_public_is_running.GetValue();
Chris Lattner24943d22010-06-08 16:52:24 +000094 }
Greg Clayton72e1c782011-01-22 23:43:18 +000095
Greg Clayton58e26e02011-03-24 04:28:38 +000096 bool
97 GetSendAcks ()
98 {
99 return m_send_acks;
100 }
101
Greg Clayton61d043b2011-03-22 04:00:09 +0000102 //------------------------------------------------------------------
103 // Client and server must implement these pure virtual functions
104 //------------------------------------------------------------------
105 virtual bool
106 GetThreadSuffixSupported () = 0;
Chris Lattner24943d22010-06-08 16:52:24 +0000107
Greg Clayton61d043b2011-03-22 04:00:09 +0000108 //------------------------------------------------------------------
109 // Set the global packet timeout.
110 //
111 // For clients, this is the timeout that gets used when sending
112 // packets and waiting for responses. For servers, this might not
113 // get used, and if it doesn't this should be moved to the
114 // GDBRemoteCommunicationClient.
115 //------------------------------------------------------------------
Greg Claytonc97bfdb2011-03-10 02:26:48 +0000116 uint32_t
117 SetPacketTimeout (uint32_t packet_timeout)
118 {
119 const uint32_t old_packet_timeout = m_packet_timeout;
120 m_packet_timeout = packet_timeout;
121 return old_packet_timeout;
122 }
Greg Claytonc1f45872011-02-12 06:28:37 +0000123
Greg Claytonb72d0f02011-04-12 05:54:46 +0000124 //------------------------------------------------------------------
125 // Start a debugserver instance on the current host using the
126 // supplied connection URL.
127 //------------------------------------------------------------------
128 lldb_private::Error
129 StartDebugserverProcess (const char *connect_url,
130 const char *unix_socket_name,
131 lldb_private::ProcessLaunchInfo &launch_info);
132
Chris Lattner24943d22010-06-08 16:52:24 +0000133protected:
134 typedef std::list<std::string> packet_collection;
135
136 size_t
137 SendPacketNoLock (const char *payload,
138 size_t payload_length);
139
140 size_t
141 WaitForPacketNoLock (StringExtractorGDBRemote &response,
Greg Clayton72e1c782011-01-22 23:43:18 +0000142 const lldb_private::TimeValue* timeout_ptr);
143
144 bool
145 WaitForNotRunningPrivate (const lldb_private::TimeValue *timeout_ptr);
Chris Lattner24943d22010-06-08 16:52:24 +0000146
147 //------------------------------------------------------------------
148 // Classes that inherit from GDBRemoteCommunication can see and modify these
149 //------------------------------------------------------------------
Greg Claytonc97bfdb2011-03-10 02:26:48 +0000150 uint32_t m_packet_timeout;
Chris Lattner24943d22010-06-08 16:52:24 +0000151 lldb_private::Listener m_rx_packet_listener;
152 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 +0000153 lldb_private::Predicate<bool> m_public_is_running;
154 lldb_private::Predicate<bool> m_private_is_running;
Greg Clayton58e26e02011-03-24 04:28:38 +0000155 bool m_send_acks;
Greg Claytonb72d0f02011-04-12 05:54:46 +0000156 bool m_is_platform; // Set to true if this class represents a platform,
157 // false if this class represents a debug session for
158 // a single process
Greg Clayton58e26e02011-03-24 04:28:38 +0000159
160
Chris Lattner24943d22010-06-08 16:52:24 +0000161
Greg Claytonb72d0f02011-04-12 05:54:46 +0000162
Chris Lattner24943d22010-06-08 16:52:24 +0000163private:
164 //------------------------------------------------------------------
165 // For GDBRemoteCommunication only
166 //------------------------------------------------------------------
167 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunication);
168};
169
170#endif // liblldb_GDBRemoteCommunication_h_