blob: 858f67c6534482d372539fdfece825e6f6d67b3c [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 Clayton61d043b2011-03-22 04:00:09 +000040 GDBRemoteCommunication(const char *comm_name, const char *listener_name);
Chris Lattner24943d22010-06-08 16:52:24 +000041
42 virtual
43 ~GDBRemoteCommunication();
44
45 size_t
46 SendPacket (const char *payload);
47
48 size_t
49 SendPacket (const char *payload,
50 size_t payload_length);
51
Chris Lattner24943d22010-06-08 16:52:24 +000052 // Wait for a packet within 'nsec' seconds
53 size_t
54 WaitForPacket (StringExtractorGDBRemote &response,
Greg Claytonc97bfdb2011-03-10 02:26:48 +000055 uint32_t sec);
Chris Lattner24943d22010-06-08 16:52:24 +000056
57 // Wait for a packet with an absolute timeout time. If 'timeout' is NULL
58 // wait indefinitely.
59 size_t
60 WaitForPacket (StringExtractorGDBRemote &response,
Greg Clayton72e1c782011-01-22 23:43:18 +000061 const lldb_private::TimeValue* timeout);
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
79 //------------------------------------------------------------------
80 // Communication overrides
81 //------------------------------------------------------------------
82 virtual void
Caroline Ticec4f55fe2010-11-19 20:47:54 +000083 AppendBytesToCache (const uint8_t *src, size_t src_len, bool broadcast, lldb::ConnectionStatus status);
Chris Lattner24943d22010-06-08 16:52:24 +000084
Chris Lattner24943d22010-06-08 16:52:24 +000085 bool
86 IsRunning() const
87 {
Greg Claytoncecf3482011-01-20 07:53:45 +000088 return m_public_is_running.GetValue();
Chris Lattner24943d22010-06-08 16:52:24 +000089 }
Greg Clayton72e1c782011-01-22 23:43:18 +000090
Greg Clayton61d043b2011-03-22 04:00:09 +000091 //------------------------------------------------------------------
92 // Client and server must implement these pure virtual functions
93 //------------------------------------------------------------------
94 virtual bool
95 GetThreadSuffixSupported () = 0;
Chris Lattner24943d22010-06-08 16:52:24 +000096
Greg Clayton61d043b2011-03-22 04:00:09 +000097 virtual bool
98 GetSendAcks () = 0;
Greg Claytonc1f45872011-02-12 06:28:37 +000099
Greg Clayton61d043b2011-03-22 04:00:09 +0000100 //------------------------------------------------------------------
101 // Set the global packet timeout.
102 //
103 // For clients, this is the timeout that gets used when sending
104 // packets and waiting for responses. For servers, this might not
105 // get used, and if it doesn't this should be moved to the
106 // GDBRemoteCommunicationClient.
107 //------------------------------------------------------------------
Greg Claytonc97bfdb2011-03-10 02:26:48 +0000108 uint32_t
109 SetPacketTimeout (uint32_t packet_timeout)
110 {
111 const uint32_t old_packet_timeout = m_packet_timeout;
112 m_packet_timeout = packet_timeout;
113 return old_packet_timeout;
114 }
Greg Claytonc1f45872011-02-12 06:28:37 +0000115
Chris Lattner24943d22010-06-08 16:52:24 +0000116protected:
117 typedef std::list<std::string> packet_collection;
118
119 size_t
120 SendPacketNoLock (const char *payload,
121 size_t payload_length);
122
123 size_t
124 WaitForPacketNoLock (StringExtractorGDBRemote &response,
Greg Clayton72e1c782011-01-22 23:43:18 +0000125 const lldb_private::TimeValue* timeout_ptr);
126
127 bool
128 WaitForNotRunningPrivate (const lldb_private::TimeValue *timeout_ptr);
Chris Lattner24943d22010-06-08 16:52:24 +0000129
130 //------------------------------------------------------------------
131 // Classes that inherit from GDBRemoteCommunication can see and modify these
132 //------------------------------------------------------------------
Greg Claytonc97bfdb2011-03-10 02:26:48 +0000133 uint32_t m_packet_timeout;
Chris Lattner24943d22010-06-08 16:52:24 +0000134 lldb_private::Listener m_rx_packet_listener;
135 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 +0000136 lldb_private::Predicate<bool> m_public_is_running;
137 lldb_private::Predicate<bool> m_private_is_running;
Chris Lattner24943d22010-06-08 16:52:24 +0000138
Chris Lattner24943d22010-06-08 16:52:24 +0000139private:
140 //------------------------------------------------------------------
141 // For GDBRemoteCommunication only
142 //------------------------------------------------------------------
143 DISALLOW_COPY_AND_ASSIGN (GDBRemoteCommunication);
144};
145
146#endif // liblldb_GDBRemoteCommunication_h_