@@ -1978,7 +1978,7 @@ NativeProcessLinux::Launch(LaunchArgs *args, Error &error)
1978
1978
1979
1979
thread_sp = AddThread (pid);
1980
1980
assert (thread_sp && " AddThread() returned a nullptr thread" );
1981
- NotifyThreadCreateStopped (pid);
1981
+ NotifyThreadCreate (pid, ThreadState::Stopped );
1982
1982
std::static_pointer_cast<NativeThreadLinux> (thread_sp)->SetStoppedBySignal (SIGSTOP);
1983
1983
1984
1984
// Let our process instance know the thread has stopped.
@@ -2074,7 +2074,7 @@ NativeProcessLinux::Attach(lldb::pid_t pid, Error &error)
2074
2074
assert (thread_sp && " AddThread() returned a nullptr" );
2075
2075
2076
2076
// This will notify this is a new thread and tell the system it is stopped.
2077
- NotifyThreadCreateStopped (tid);
2077
+ NotifyThreadCreate (tid, ThreadState::Stopped );
2078
2078
std::static_pointer_cast<NativeThreadLinux> (thread_sp)->SetStoppedBySignal (SIGSTOP);
2079
2079
SetCurrentThreadID (thread_sp->GetID ());
2080
2080
}
@@ -2331,7 +2331,7 @@ NativeProcessLinux::WaitForNewThread(::pid_t tid)
2331
2331
new_thread_sp = AddThread (tid);
2332
2332
std::static_pointer_cast<NativeThreadLinux> (new_thread_sp)->SetRunning ();
2333
2333
Resume (tid, LLDB_INVALID_SIGNAL_NUMBER);
2334
- NotifyThreadCreate (tid, false );
2334
+ NotifyThreadCreate (tid, ThreadState::Running );
2335
2335
}
2336
2336
2337
2337
void
@@ -2427,7 +2427,7 @@ NativeProcessLinux::MonitorSIGTRAP(const siginfo_t *info, lldb::pid_t pid)
2427
2427
2428
2428
// Tell coordinator about about the "new" (since exec) stopped main thread.
2429
2429
const lldb::tid_t main_thread_tid = GetID ();
2430
- NotifyThreadCreateStopped (main_thread_tid);
2430
+ NotifyThreadCreate (main_thread_tid, ThreadState::Stopped );
2431
2431
2432
2432
// NOTE: ideally these next statements would execute at the same time as the coordinator thread create was executed.
2433
2433
// Consider a handler that can execute when that happens.
@@ -2686,7 +2686,7 @@ NativeProcessLinux::MonitorSignal(const siginfo_t *info, lldb::pid_t pid, bool e
2686
2686
// We can now resume the newly created thread.
2687
2687
std::static_pointer_cast<NativeThreadLinux> (thread_sp)->SetRunning ();
2688
2688
Resume (pid, LLDB_INVALID_SIGNAL_NUMBER);
2689
- NotifyThreadCreate (pid, false );
2689
+ NotifyThreadCreate (pid, ThreadState::Running );
2690
2690
// Done handling.
2691
2691
return ;
2692
2692
}
@@ -4175,58 +4175,6 @@ NativeProcessLinux::FixupBreakpointPCAsNeeded (NativeThreadProtocolSP &thread_sp
4175
4175
return error;
4176
4176
}
4177
4177
4178
- void
4179
- NativeProcessLinux::NotifyThreadCreateStopped (lldb::tid_t tid)
4180
- {
4181
- const bool is_stopped = true ;
4182
- NotifyThreadCreate (tid, is_stopped);
4183
- }
4184
-
4185
- void
4186
- NativeProcessLinux::StopRunningThreads (lldb::tid_t trigerring_tid)
4187
- {
4188
- Log *const log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
4189
- if (log )
4190
- log ->Printf (" NativeProcessLinux::%s tid %" PRIu64, __FUNCTION__, trigerring_tid);
4191
-
4192
- const lldb::pid_t pid = GetID ();
4193
- StopRunningThreads (trigerring_tid,
4194
- [=](lldb::tid_t request_stop_tid) { return RequestThreadStop (pid, request_stop_tid); });
4195
- }
4196
-
4197
- void
4198
- NativeProcessLinux::StopRunningThreadsWithSkipTID (lldb::tid_t deferred_signal_tid,
4199
- lldb::tid_t skip_stop_request_tid)
4200
- {
4201
- Log *const log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
4202
- if (log )
4203
- log ->Printf (" NativeProcessLinux::%s deferred_signal_tid %" PRIu64 " , skip_stop_request_tid %" PRIu64, __FUNCTION__, deferred_signal_tid, skip_stop_request_tid);
4204
-
4205
- const lldb::pid_t pid = GetID ();
4206
- StopRunningThreadsWithSkipTID (deferred_signal_tid,
4207
- skip_stop_request_tid != LLDB_INVALID_THREAD_ID ? NativeProcessLinux::ThreadIDSet {skip_stop_request_tid} : NativeProcessLinux::ThreadIDSet (),
4208
- [=](lldb::tid_t request_stop_tid) { return RequestThreadStop (pid, request_stop_tid); });
4209
- }
4210
-
4211
- Error
4212
- NativeProcessLinux::RequestThreadStop (const lldb::pid_t pid, const lldb::tid_t tid)
4213
- {
4214
- Log* log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
4215
- if (log )
4216
- log ->Printf (" NativeProcessLinux::%s requesting thread stop(pid: %" PRIu64 " , tid: %" PRIu64 " )" , __FUNCTION__, pid, tid);
4217
-
4218
- Error err;
4219
- errno = 0 ;
4220
- if (::tgkill (pid, tid, SIGSTOP) != 0 )
4221
- {
4222
- err.SetErrorToErrno ();
4223
- if (log )
4224
- log ->Printf (" NativeProcessLinux::%s tgkill(%" PRIu64 " , %" PRIu64 " , SIGSTOP) failed: %s" , __FUNCTION__, pid, tid, err.AsCString ());
4225
- }
4226
-
4227
- return err;
4228
- }
4229
-
4230
4178
Error
4231
4179
NativeProcessLinux::GetLoadedModuleFileSpec (const char * module_path, FileSpec& file_spec)
4232
4180
{
@@ -4342,8 +4290,7 @@ NativeProcessLinux::DoResume(
4342
4290
4343
4291
void
4344
4292
NativeProcessLinux::StopThreads (const lldb::tid_t triggering_tid,
4345
- const ThreadIDSet &wait_for_stop_tids,
4346
- const StopThreadFunction &request_thread_stop_function)
4293
+ const ThreadIDSet &wait_for_stop_tids)
4347
4294
{
4348
4295
Log *const log = GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD);
4349
4296
std::lock_guard<std::mutex> lock (m_event_mutex);
@@ -4355,7 +4302,7 @@ NativeProcessLinux::StopThreads(const lldb::tid_t triggering_tid,
4355
4302
}
4356
4303
4357
4304
DoStopThreads (PendingNotificationUP (new PendingNotification (
4358
- triggering_tid, wait_for_stop_tids, request_thread_stop_function )));
4305
+ triggering_tid, wait_for_stop_tids, ThreadIDSet () )));
4359
4306
4360
4307
if (log )
4361
4308
{
@@ -4364,8 +4311,7 @@ NativeProcessLinux::StopThreads(const lldb::tid_t triggering_tid,
4364
4311
}
4365
4312
4366
4313
void
4367
- NativeProcessLinux::StopRunningThreads (const lldb::tid_t triggering_tid,
4368
- const StopThreadFunction &request_thread_stop_function)
4314
+ NativeProcessLinux::StopRunningThreads (const lldb::tid_t triggering_tid)
4369
4315
{
4370
4316
Log *const log = GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD);
4371
4317
std::lock_guard<std::mutex> lock (m_event_mutex);
@@ -4376,9 +4322,7 @@ NativeProcessLinux::StopRunningThreads(const lldb::tid_t triggering_tid,
4376
4322
__FUNCTION__, triggering_tid);
4377
4323
}
4378
4324
4379
- DoStopThreads (PendingNotificationUP (new PendingNotification (
4380
- triggering_tid,
4381
- request_thread_stop_function)));
4325
+ DoStopThreads (PendingNotificationUP (new PendingNotification (triggering_tid)));
4382
4326
4383
4327
if (log )
4384
4328
{
@@ -4388,22 +4332,21 @@ NativeProcessLinux::StopRunningThreads(const lldb::tid_t triggering_tid,
4388
4332
4389
4333
void
4390
4334
NativeProcessLinux::StopRunningThreadsWithSkipTID (lldb::tid_t triggering_tid,
4391
- const ThreadIDSet &skip_stop_request_tids,
4392
- const StopThreadFunction &request_thread_stop_function)
4335
+ lldb::tid_t skip_stop_request_tid)
4393
4336
{
4394
4337
Log *const log = GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD);
4395
4338
std::lock_guard<std::mutex> lock (m_event_mutex);
4396
4339
4397
4340
if (log )
4398
4341
{
4399
- log ->Printf (" NativeProcessLinux::%s about to process event: (triggering_tid: %" PRIu64 " , skip_stop_request_tids.size() : %zd )" ,
4400
- __FUNCTION__, triggering_tid, skip_stop_request_tids. size () );
4342
+ log ->Printf (" NativeProcessLinux::%s about to process event: (triggering_tid: %" PRIu64 " , skip_stop_request_tid : %" PRIu64 " )" ,
4343
+ __FUNCTION__, triggering_tid, skip_stop_request_tid );
4401
4344
}
4402
4345
4403
4346
DoStopThreads (PendingNotificationUP (new PendingNotification (
4404
4347
triggering_tid,
4405
- request_thread_stop_function ,
4406
- skip_stop_request_tids )));
4348
+ ThreadIDSet () ,
4349
+ skip_stop_request_tid != LLDB_INVALID_THREAD_ID ? NativeProcessLinux::ThreadIDSet {skip_stop_request_tid} : ThreadIDSet () )));
4407
4350
4408
4351
if (log )
4409
4352
{
@@ -4485,19 +4428,28 @@ NativeProcessLinux::RequestStopOnAllRunningThreads()
4485
4428
m_pending_notification_up->wait_for_stop_tids .swap (sent_tids);
4486
4429
}
4487
4430
4488
- void
4431
+ Error
4489
4432
NativeProcessLinux::RequestThreadStop (lldb::tid_t tid, ThreadContext& context)
4490
4433
{
4491
- const auto error = m_pending_notification_up->request_thread_stop_function (tid);
4492
- if (error.Success ())
4493
- context.m_stop_requested = true ;
4494
- else
4434
+ Log* log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
4435
+
4436
+ lldb::pid_t pid = GetID ();
4437
+
4438
+ if (log )
4439
+ log ->Printf (" NativeProcessLinux::%s requesting thread stop(pid: %" PRIu64 " , tid: %" PRIu64 " )" , __FUNCTION__, pid, tid);
4440
+
4441
+ Error err;
4442
+ errno = 0 ;
4443
+ if (::tgkill (pid, tid, SIGSTOP) != 0 )
4495
4444
{
4496
- Log * const log = GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD );
4445
+ err. SetErrorToErrno ( );
4497
4446
if (log )
4498
- log ->Printf (" NativeProcessLinux::%s failed to request thread stop tid %" PRIu64 " : %s" ,
4499
- __FUNCTION__, tid, error.AsCString ());
4447
+ log ->Printf (" NativeProcessLinux::%s tgkill(%" PRIu64 " , %" PRIu64 " , SIGSTOP) failed: %s" , __FUNCTION__, pid, tid, err.AsCString ());
4500
4448
}
4449
+ else
4450
+ context.m_stop_requested = true ;
4451
+
4452
+ return err;
4501
4453
}
4502
4454
4503
4455
@@ -4576,22 +4528,20 @@ NativeProcessLinux::DoStopThreads(PendingNotificationUP &¬ification_up)
4576
4528
}
4577
4529
4578
4530
void
4579
- NativeProcessLinux::ThreadWasCreated (lldb::tid_t tid, bool is_stopped )
4531
+ NativeProcessLinux::ThreadWasCreated (lldb::tid_t tid, ThreadState state )
4580
4532
{
4581
4533
// Ensure we don't already know about the thread.
4582
4534
lldbassert (m_tid_map.find (tid) == m_tid_map.end ());
4583
4535
4584
4536
// Add the new thread to the stop map.
4585
- ThreadContext ctx;
4586
- ctx.m_state = (is_stopped) ? ThreadState::Stopped : ThreadState::Running;
4587
- m_tid_map[tid] = std::move (ctx);
4537
+ auto tid_it = m_tid_map.emplace (tid, ThreadContext (state)).first ;
4588
4538
4589
- if (m_pending_notification_up && !is_stopped )
4539
+ if (m_pending_notification_up && state == ThreadState::Running )
4590
4540
{
4591
4541
// We will need to wait for this new thread to stop as well before firing the
4592
4542
// notification.
4593
4543
m_pending_notification_up->wait_for_stop_tids .insert (tid);
4594
- m_pending_notification_up-> request_thread_stop_function (tid);
4544
+ RequestThreadStop (tid, tid_it-> second );
4595
4545
}
4596
4546
}
4597
4547
@@ -4684,19 +4634,18 @@ NativeProcessLinux::RequestThreadResumeAsNeeded (lldb::tid_t tid,
4684
4634
}
4685
4635
4686
4636
void
4687
- NativeProcessLinux::NotifyThreadCreate (lldb::tid_t tid,
4688
- bool is_stopped)
4637
+ NativeProcessLinux::NotifyThreadCreate (lldb::tid_t tid, ThreadState state)
4689
4638
{
4690
4639
Log *const log = GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD);
4691
4640
std::lock_guard<std::mutex> lock (m_event_mutex);
4692
4641
4693
4642
if (log )
4694
4643
{
4695
4644
log ->Printf (" NativeProcessLinux::%s about to process event: (tid: %" PRIu64 " , is %sstopped)" ,
4696
- __FUNCTION__, tid, is_stopped ?" " :" not " );
4645
+ __FUNCTION__, tid, state==ThreadState::Stopped ?" " :" not " );
4697
4646
}
4698
4647
4699
- ThreadWasCreated (tid, is_stopped );
4648
+ ThreadWasCreated (tid, state );
4700
4649
4701
4650
if (log )
4702
4651
{
0 commit comments