@@ -20,10 +20,7 @@ using namespace lldb_private;
20
20
using namespace lldb_private ::process_gdb_remote;
21
21
using namespace std ::chrono;
22
22
23
- // When we've sent a continue packet and are waiting for the target to stop,
24
- // we wake up the wait with this interval to make sure the stub hasn't gone
25
- // away while we were waiting.
26
- static const seconds kWakeupInterval (5 );
23
+ static const seconds kInterruptTimeout (5 );
27
24
28
25
// ///////////////////////
29
26
// GDBRemoteClientBase //
@@ -38,8 +35,7 @@ GDBRemoteClientBase::GDBRemoteClientBase(const char *comm_name,
38
35
39
36
StateType GDBRemoteClientBase::SendContinuePacketAndWaitForResponse (
40
37
ContinueDelegate &delegate, const UnixSignals &signals,
41
- llvm::StringRef payload, std::chrono::seconds interrupt_timeout,
42
- StringExtractorGDBRemote &response) {
38
+ llvm::StringRef payload, StringExtractorGDBRemote &response) {
43
39
Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS));
44
40
response.Clear ();
45
41
@@ -52,34 +48,16 @@ StateType GDBRemoteClientBase::SendContinuePacketAndWaitForResponse(
52
48
if (!cont_lock)
53
49
return eStateInvalid;
54
50
OnRunPacketSent (true );
55
- // The main ReadPacket loop wakes up at computed_timeout intervals, just to
56
- // check that the connection hasn't dropped. When we wake up we also check
57
- // whether there is an interrupt request that has reached its endpoint.
58
- // If we want a shorter interrupt timeout that kWakeupInterval, we need to
59
- // choose the shorter interval for the wake up as well.
60
- std::chrono::seconds computed_timeout = std::min (interrupt_timeout,
61
- kWakeupInterval );
51
+
62
52
for (;;) {
63
- PacketResult read_result = ReadPacket (response, computed_timeout , false );
53
+ PacketResult read_result = ReadPacket (response, kInterruptTimeout , false );
64
54
switch (read_result) {
65
55
case PacketResult::ErrorReplyTimeout: {
66
56
std::lock_guard<std::mutex> lock (m_mutex);
67
- if (m_async_count == 0 ) {
57
+ if (m_async_count == 0 )
68
58
continue ;
69
- }
70
- auto cur_time = steady_clock::now ();
71
- if (cur_time >= m_interrupt_endpoint)
59
+ if (steady_clock::now () >= m_interrupt_time + kInterruptTimeout )
72
60
return eStateInvalid;
73
- else {
74
- // We woke up and found an interrupt is in flight, but we haven't
75
- // exceeded the interrupt wait time. So reset the wait time to the
76
- // time left till the interrupt timeout. But don't wait longer
77
- // than our wakeup timeout.
78
- auto new_wait = m_interrupt_endpoint - cur_time;
79
- computed_timeout = std::min (kWakeupInterval ,
80
- std::chrono::duration_cast<std::chrono::seconds>(new_wait));
81
- continue ;
82
- }
83
61
break ;
84
62
}
85
63
case PacketResult::Success:
@@ -155,9 +133,8 @@ StateType GDBRemoteClientBase::SendContinuePacketAndWaitForResponse(
155
133
}
156
134
}
157
135
158
- bool GDBRemoteClientBase::SendAsyncSignal (
159
- int signo, std::chrono::seconds interrupt_timeout) {
160
- Lock lock (*this , interrupt_timeout);
136
+ bool GDBRemoteClientBase::SendAsyncSignal (int signo) {
137
+ Lock lock (*this , true );
161
138
if (!lock || !lock.DidInterrupt ())
162
139
return false ;
163
140
@@ -167,26 +144,25 @@ bool GDBRemoteClientBase::SendAsyncSignal(
167
144
return true ;
168
145
}
169
146
170
- bool GDBRemoteClientBase::Interrupt (std::chrono::seconds interrupt_timeout ) {
171
- Lock lock (*this , interrupt_timeout );
147
+ bool GDBRemoteClientBase::Interrupt () {
148
+ Lock lock (*this , true );
172
149
if (!lock.DidInterrupt ())
173
150
return false ;
174
151
m_should_stop = true ;
175
152
return true ;
176
153
}
177
-
178
154
GDBRemoteCommunication::PacketResult
179
155
GDBRemoteClientBase::SendPacketAndWaitForResponse (
180
156
llvm::StringRef payload, StringExtractorGDBRemote &response,
181
- std::chrono::seconds interrupt_timeout ) {
182
- Lock lock (*this , interrupt_timeout );
157
+ bool send_async ) {
158
+ Lock lock (*this , send_async );
183
159
if (!lock) {
184
160
if (Log *log =
185
161
ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS))
186
162
LLDB_LOGF (log,
187
163
" GDBRemoteClientBase::%s failed to get mutex, not sending "
188
- " packet '%.*s'" ,
189
- __FUNCTION__, int (payload.size ()), payload.data ());
164
+ " packet '%.*s' (send_async=%d) " ,
165
+ __FUNCTION__, int (payload.size ()), payload.data (), send_async );
190
166
return PacketResult::ErrorSendFailed;
191
167
}
192
168
@@ -196,16 +172,16 @@ GDBRemoteClientBase::SendPacketAndWaitForResponse(
196
172
GDBRemoteCommunication::PacketResult
197
173
GDBRemoteClientBase::SendPacketAndReceiveResponseWithOutputSupport (
198
174
llvm::StringRef payload, StringExtractorGDBRemote &response,
199
- std::chrono::seconds interrupt_timeout ,
175
+ bool send_async ,
200
176
llvm::function_ref<void (llvm::StringRef)> output_callback) {
201
- Lock lock (*this , interrupt_timeout );
177
+ Lock lock (*this , send_async );
202
178
if (!lock) {
203
179
if (Log *log =
204
180
ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS))
205
181
LLDB_LOGF (log,
206
182
" GDBRemoteClientBase::%s failed to get mutex, not sending "
207
- " packet '%.*s'" ,
208
- __FUNCTION__, int (payload.size ()), payload.data ());
183
+ " packet '%.*s' (send_async=%d) " ,
184
+ __FUNCTION__, int (payload.size ()), payload.data (), send_async );
209
185
return PacketResult::ErrorSendFailed;
210
186
}
211
187
@@ -246,14 +222,13 @@ GDBRemoteClientBase::SendPacketAndWaitForResponseNoLock(
246
222
return packet_result;
247
223
}
248
224
249
- bool GDBRemoteClientBase::SendvContPacket (
250
- llvm::StringRef payload, std::chrono::seconds interrupt_timeout,
251
- StringExtractorGDBRemote &response) {
225
+ bool GDBRemoteClientBase::SendvContPacket (llvm::StringRef payload,
226
+ StringExtractorGDBRemote &response) {
252
227
Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS));
253
228
LLDB_LOGF (log, " GDBRemoteCommunicationClient::%s ()" , __FUNCTION__);
254
229
255
230
// we want to lock down packet sending while we continue
256
- Lock lock (*this , interrupt_timeout );
231
+ Lock lock (*this , true );
257
232
258
233
LLDB_LOGF (log,
259
234
" GDBRemoteCommunicationClient::%s () sending vCont packet: %.*s" ,
@@ -361,20 +336,18 @@ GDBRemoteClientBase::ContinueLock::lock() {
361
336
// GDBRemoteClientBase::Lock //
362
337
// /////////////////////////////
363
338
364
- GDBRemoteClientBase::Lock::Lock (GDBRemoteClientBase &comm,
365
- std::chrono::seconds interrupt_timeout)
339
+ GDBRemoteClientBase::Lock::Lock (GDBRemoteClientBase &comm, bool interrupt)
366
340
: m_async_lock(comm.m_async_mutex, std::defer_lock), m_comm(comm),
367
- m_interrupt_timeout(interrupt_timeout), m_acquired(false ),
368
- m_did_interrupt(false ) {
369
- SyncWithContinueThread ();
341
+ m_acquired(false ), m_did_interrupt(false ) {
342
+ SyncWithContinueThread (interrupt);
370
343
if (m_acquired)
371
344
m_async_lock.lock ();
372
345
}
373
346
374
- void GDBRemoteClientBase::Lock::SyncWithContinueThread () {
347
+ void GDBRemoteClientBase::Lock::SyncWithContinueThread (bool interrupt ) {
375
348
Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS));
376
349
std::unique_lock<std::mutex> lock (m_comm.m_mutex );
377
- if (m_comm.m_is_running && m_interrupt_timeout == std::chrono::seconds ( 0 ) )
350
+ if (m_comm.m_is_running && !interrupt )
378
351
return ; // We were asked to avoid interrupting the sender. Lock is not
379
352
// acquired.
380
353
@@ -392,9 +365,9 @@ void GDBRemoteClientBase::Lock::SyncWithContinueThread() {
392
365
" interrupt packet" );
393
366
return ;
394
367
}
395
- m_comm.m_interrupt_endpoint = steady_clock::now () + m_interrupt_timeout;
396
368
if (log)
397
369
log->PutCString (" GDBRemoteClientBase::Lock::Lock sent packet: \\ x03" );
370
+ m_comm.m_interrupt_time = steady_clock::now ();
398
371
}
399
372
m_comm.m_cv .wait (lock, [this ] { return !m_comm.m_is_running ; });
400
373
m_did_interrupt = true ;
0 commit comments