@@ -2460,11 +2460,7 @@ NativeProcessLinux::MonitorSIGTRAP(const siginfo_t *info, lldb::pid_t pid)
2460
2460
assert (main_thread_sp && " exec called during ptraced process but no main thread metadata tracked" );
2461
2461
2462
2462
// Let the process know we're stopped.
2463
- CallAfterRunningThreadsStop (pid,
2464
- [=] (lldb::tid_t signaling_tid)
2465
- {
2466
- SetState (StateType::eStateStopped, true );
2467
- });
2463
+ StopRunningThreads (pid);
2468
2464
2469
2465
break ;
2470
2466
}
@@ -2584,11 +2580,7 @@ NativeProcessLinux::MonitorTrace(lldb::pid_t pid, NativeThreadProtocolSP thread_
2584
2580
// once all running threads have checked in as stopped.
2585
2581
SetCurrentThreadID (pid);
2586
2582
// Tell the process we have a stop (from software breakpoint).
2587
- CallAfterRunningThreadsStop (pid,
2588
- [=](lldb::tid_t signaling_tid)
2589
- {
2590
- SetState (StateType::eStateStopped, true );
2591
- });
2583
+ StopRunningThreads (pid);
2592
2584
}
2593
2585
2594
2586
void
@@ -2633,13 +2625,7 @@ NativeProcessLinux::MonitorBreakpoint(lldb::pid_t pid, NativeThreadProtocolSP th
2633
2625
2634
2626
2635
2627
// We need to tell all other running threads before we notify the delegate about this stop.
2636
- CallAfterRunningThreadsStop (pid,
2637
- [=](lldb::tid_t deferred_notification_tid)
2638
- {
2639
- SetCurrentThreadID (deferred_notification_tid);
2640
- // Tell the process we have a stop (from software breakpoint).
2641
- SetState (StateType::eStateStopped, true );
2642
- });
2628
+ StopRunningThreads (pid);
2643
2629
}
2644
2630
2645
2631
void
@@ -2660,13 +2646,7 @@ NativeProcessLinux::MonitorWatchpoint(lldb::pid_t pid, NativeThreadProtocolSP th
2660
2646
std::static_pointer_cast<NativeThreadLinux>(thread_sp)->SetStoppedByWatchpoint (wp_index);
2661
2647
2662
2648
// We need to tell all other running threads before we notify the delegate about this stop.
2663
- CallAfterRunningThreadsStop (pid,
2664
- [=](lldb::tid_t deferred_notification_tid)
2665
- {
2666
- SetCurrentThreadID (deferred_notification_tid);
2667
- // Tell the process we have a stop (from watchpoint).
2668
- SetState (StateType::eStateStopped, true );
2669
- });
2649
+ StopRunningThreads (pid);
2670
2650
}
2671
2651
2672
2652
void
@@ -2759,10 +2739,18 @@ NativeProcessLinux::MonitorSignal(const siginfo_t *info, lldb::pid_t pid, bool e
2759
2739
const StateType thread_state = linux_thread_sp->GetState ();
2760
2740
if (!StateIsStoppedState (thread_state, false ))
2761
2741
{
2762
- // An inferior thread just stopped, but was not the primary cause of the process stop.
2763
- // Instead, something else (like a breakpoint or step) caused the stop. Mark the
2764
- // stop signal as 0 to let lldb know this isn't the important stop.
2765
- linux_thread_sp->SetStoppedBySignal (0 );
2742
+ // An inferior thread has stopped because of a SIGSTOP we have sent it.
2743
+ // Generally, these are not important stops and we don't want to report them as
2744
+ // they are just used to stop other threads when one thread (the one with the
2745
+ // *real* stop reason) hits a breakpoint (watchpoint, etc...). However, in the
2746
+ // case of an asynchronous Interrupt(), this *is* the real stop reason, so we
2747
+ // leave the signal intact if this is the thread that was chosen as the
2748
+ // triggering thread.
2749
+ if (m_pending_notification_up && m_pending_notification_up->triggering_tid == pid)
2750
+ linux_thread_sp->SetStoppedBySignal (SIGSTOP);
2751
+ else
2752
+ linux_thread_sp->SetStoppedBySignal (0 );
2753
+
2766
2754
SetCurrentThreadID (thread_sp->GetID ());
2767
2755
NotifyThreadStop (thread_sp->GetID (), true , CoordinatorErrorHandler);
2768
2756
}
@@ -2840,12 +2828,7 @@ NativeProcessLinux::MonitorSignal(const siginfo_t *info, lldb::pid_t pid, bool e
2840
2828
}
2841
2829
2842
2830
// Send a stop to the debugger after we get all other threads to stop.
2843
- CallAfterRunningThreadsStop (pid,
2844
- [=] (lldb::tid_t signaling_tid)
2845
- {
2846
- SetCurrentThreadID (signaling_tid);
2847
- SetState (StateType::eStateStopped, true );
2848
- });
2831
+ StopRunningThreads (pid);
2849
2832
}
2850
2833
2851
2834
namespace {
@@ -3154,21 +3137,7 @@ NativeProcessLinux::Resume (const ResumeActionList &resume_actions)
3154
3137
// after all other running threads have stopped.
3155
3138
// If there is a stepping thread involved we'll be eventually stopped by SIGTRAP trace signal.
3156
3139
if (deferred_signal_tid != LLDB_INVALID_THREAD_ID && !stepping)
3157
- {
3158
- CallAfterRunningThreadsStopWithSkipTID (deferred_signal_tid,
3159
- deferred_signal_skip_tid,
3160
- [=](lldb::tid_t deferred_notification_tid)
3161
- {
3162
- // Set the signal thread to the current thread.
3163
- SetCurrentThreadID (deferred_notification_tid);
3164
-
3165
- // Set the thread state as stopped by the deferred signo.
3166
- std::static_pointer_cast<NativeThreadLinux> (deferred_signal_thread_sp)->SetStoppedBySignal (deferred_signo);
3167
-
3168
- // Tell the process delegate that the process is in a stopped state.
3169
- SetState (StateType::eStateStopped, true );
3170
- });
3171
- }
3140
+ StopRunningThreadsWithSkipTID (deferred_signal_tid, deferred_signal_skip_tid);
3172
3141
3173
3142
return Error ();
3174
3143
}
@@ -3272,18 +3241,7 @@ NativeProcessLinux::Interrupt ()
3272
3241
running_thread_sp ? " running" : " stopped" ,
3273
3242
deferred_signal_thread_sp->GetID ());
3274
3243
3275
- CallAfterRunningThreadsStop (deferred_signal_thread_sp->GetID (),
3276
- [=](lldb::tid_t deferred_notification_tid)
3277
- {
3278
- // Set the signal thread to the current thread.
3279
- SetCurrentThreadID (deferred_notification_tid);
3280
-
3281
- // Set the thread state as stopped by the deferred signo.
3282
- std::static_pointer_cast<NativeThreadLinux> (deferred_signal_thread_sp)->SetStoppedBySignal (SIGSTOP);
3283
-
3284
- // Tell the process delegate that the process is in a stopped state.
3285
- SetState (StateType::eStateStopped, true );
3286
- });
3244
+ StopRunningThreads (deferred_signal_thread_sp->GetID ());
3287
3245
3288
3246
return Error ();
3289
3247
}
@@ -4260,37 +4218,30 @@ NativeProcessLinux::NotifyThreadStop (lldb::tid_t tid)
4260
4218
}
4261
4219
4262
4220
void
4263
- NativeProcessLinux::CallAfterRunningThreadsStop (lldb::tid_t tid,
4264
- const std::function<void (lldb::tid_t tid)> &call_after_function)
4221
+ NativeProcessLinux::StopRunningThreads (lldb::tid_t trigerring_tid)
4265
4222
{
4266
4223
Log *const log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
4267
4224
if (log )
4268
- log ->Printf (" NativeProcessLinux::%s tid %" PRIu64, __FUNCTION__, tid );
4225
+ log ->Printf (" NativeProcessLinux::%s tid %" PRIu64, __FUNCTION__, trigerring_tid );
4269
4226
4270
4227
const lldb::pid_t pid = GetID ();
4271
- CallAfterRunningThreadsStop (tid,
4272
- [=](lldb::tid_t request_stop_tid)
4273
- {
4274
- return RequestThreadStop (pid, request_stop_tid);
4275
- },
4276
- call_after_function,
4277
- CoordinatorErrorHandler);
4228
+ StopRunningThreads (trigerring_tid,
4229
+ [=](lldb::tid_t request_stop_tid) { return RequestThreadStop (pid, request_stop_tid); },
4230
+ CoordinatorErrorHandler);
4278
4231
}
4279
4232
4280
4233
void
4281
- NativeProcessLinux::CallAfterRunningThreadsStopWithSkipTID (lldb::tid_t deferred_signal_tid,
4282
- lldb::tid_t skip_stop_request_tid,
4283
- const std::function<void (lldb::tid_t tid)> &call_after_function)
4234
+ NativeProcessLinux::StopRunningThreadsWithSkipTID (lldb::tid_t deferred_signal_tid,
4235
+ lldb::tid_t skip_stop_request_tid)
4284
4236
{
4285
4237
Log *const log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
4286
4238
if (log )
4287
4239
log ->Printf (" NativeProcessLinux::%s deferred_signal_tid %" PRIu64 " , skip_stop_request_tid %" PRIu64, __FUNCTION__, deferred_signal_tid, skip_stop_request_tid);
4288
4240
4289
4241
const lldb::pid_t pid = GetID ();
4290
- CallAfterRunningThreadsStopWithSkipTIDs (deferred_signal_tid,
4242
+ StopRunningThreadsWithSkipTID (deferred_signal_tid,
4291
4243
skip_stop_request_tid != LLDB_INVALID_THREAD_ID ? NativeProcessLinux::ThreadIDSet {skip_stop_request_tid} : NativeProcessLinux::ThreadIDSet (),
4292
4244
[=](lldb::tid_t request_stop_tid) { return RequestThreadStop (pid, request_stop_tid); },
4293
- call_after_function,
4294
4245
CoordinatorErrorHandler);
4295
4246
}
4296
4247
@@ -4442,10 +4393,9 @@ NativeProcessLinux::DoResume(
4442
4393
// ===----------------------------------------------------------------------===//
4443
4394
4444
4395
void
4445
- NativeProcessLinux::CallAfterThreadsStop (const lldb::tid_t triggering_tid,
4396
+ NativeProcessLinux::StopThreads (const lldb::tid_t triggering_tid,
4446
4397
const ThreadIDSet &wait_for_stop_tids,
4447
4398
const StopThreadFunction &request_thread_stop_function,
4448
- const ThreadIDFunction &call_after_function,
4449
4399
const ErrorFunction &error_function)
4450
4400
{
4451
4401
std::lock_guard<std::mutex> lock (m_event_mutex);
@@ -4456,9 +4406,8 @@ NativeProcessLinux::CallAfterThreadsStop (const lldb::tid_t triggering_tid,
4456
4406
__FUNCTION__, triggering_tid, wait_for_stop_tids.size ());
4457
4407
}
4458
4408
4459
- DoCallAfterThreadsStop (PendingNotificationUP (new PendingNotification (
4460
- triggering_tid, wait_for_stop_tids, request_thread_stop_function,
4461
- call_after_function, error_function)));
4409
+ DoStopThreads (PendingNotificationUP (new PendingNotification (
4410
+ triggering_tid, wait_for_stop_tids, request_thread_stop_function, error_function)));
4462
4411
4463
4412
if (m_log_event_processing)
4464
4413
{
@@ -4467,9 +4416,8 @@ NativeProcessLinux::CallAfterThreadsStop (const lldb::tid_t triggering_tid,
4467
4416
}
4468
4417
4469
4418
void
4470
- NativeProcessLinux::CallAfterRunningThreadsStop (const lldb::tid_t triggering_tid,
4419
+ NativeProcessLinux::StopRunningThreads (const lldb::tid_t triggering_tid,
4471
4420
const StopThreadFunction &request_thread_stop_function,
4472
- const ThreadIDFunction &call_after_function,
4473
4421
const ErrorFunction &error_function)
4474
4422
{
4475
4423
std::lock_guard<std::mutex> lock (m_event_mutex);
@@ -4480,10 +4428,9 @@ NativeProcessLinux::CallAfterRunningThreadsStop (const lldb::tid_t triggering_ti
4480
4428
__FUNCTION__, triggering_tid);
4481
4429
}
4482
4430
4483
- DoCallAfterThreadsStop (PendingNotificationUP (new PendingNotification (
4431
+ DoStopThreads (PendingNotificationUP (new PendingNotification (
4484
4432
triggering_tid,
4485
4433
request_thread_stop_function,
4486
- call_after_function,
4487
4434
error_function)));
4488
4435
4489
4436
if (m_log_event_processing)
@@ -4493,10 +4440,9 @@ NativeProcessLinux::CallAfterRunningThreadsStop (const lldb::tid_t triggering_ti
4493
4440
}
4494
4441
4495
4442
void
4496
- NativeProcessLinux::CallAfterRunningThreadsStopWithSkipTIDs (lldb::tid_t triggering_tid,
4443
+ NativeProcessLinux::StopRunningThreadsWithSkipTID (lldb::tid_t triggering_tid,
4497
4444
const ThreadIDSet &skip_stop_request_tids,
4498
4445
const StopThreadFunction &request_thread_stop_function,
4499
- const ThreadIDFunction &call_after_function,
4500
4446
const ErrorFunction &error_function)
4501
4447
{
4502
4448
std::lock_guard<std::mutex> lock (m_event_mutex);
@@ -4507,10 +4453,9 @@ NativeProcessLinux::CallAfterRunningThreadsStopWithSkipTIDs (lldb::tid_t trigger
4507
4453
__FUNCTION__, triggering_tid, skip_stop_request_tids.size ());
4508
4454
}
4509
4455
4510
- DoCallAfterThreadsStop (PendingNotificationUP (new PendingNotification (
4456
+ DoStopThreads (PendingNotificationUP (new PendingNotification (
4511
4457
triggering_tid,
4512
4458
request_thread_stop_function,
4513
- call_after_function,
4514
4459
skip_stop_request_tids,
4515
4460
error_function)));
4516
4461
@@ -4525,7 +4470,8 @@ NativeProcessLinux::SignalIfRequirementsSatisfied()
4525
4470
{
4526
4471
if (m_pending_notification_up && m_pending_notification_up->wait_for_stop_tids .empty ())
4527
4472
{
4528
- m_pending_notification_up->call_after_function (m_pending_notification_up->triggering_tid );
4473
+ SetCurrentThreadID (m_pending_notification_up->triggering_tid );
4474
+ SetState (StateType::eStateStopped, true );
4529
4475
m_pending_notification_up.reset ();
4530
4476
}
4531
4477
}
@@ -4664,7 +4610,7 @@ NativeProcessLinux::ThreadDidStop (lldb::tid_t tid, bool initiated_by_llgs, cons
4664
4610
}
4665
4611
4666
4612
void
4667
- NativeProcessLinux::DoCallAfterThreadsStop (PendingNotificationUP &¬ification_up)
4613
+ NativeProcessLinux::DoStopThreads (PendingNotificationUP &¬ification_up)
4668
4614
{
4669
4615
// Validate we know about the deferred trigger thread.
4670
4616
if (!IsKnownThread (notification_up->triggering_tid ))
@@ -4697,12 +4643,7 @@ NativeProcessLinux::DoCallAfterThreadsStop(PendingNotificationUP &¬ification_
4697
4643
return ;
4698
4644
}
4699
4645
4700
- if (m_pending_notification_up->wait_for_stop_tids .empty ())
4701
- {
4702
- // We're not waiting for any threads. Fire off the deferred signal delivery event.
4703
- m_pending_notification_up->call_after_function (m_pending_notification_up->triggering_tid );
4704
- m_pending_notification_up.reset ();
4705
- }
4646
+ SignalIfRequirementsSatisfied ();
4706
4647
}
4707
4648
4708
4649
void
0 commit comments