Skip to content

Commit ed89c7f

Browse files
committedMay 6, 2015
[NativeProcessLinux] Remove the post-stop lambda
Summary: The lambda was always calling SetState(eStateStopped) with small variations, so I have inlined the code. Given that we don't have the TSC anymore, I believe we don't need to be so generic. The only major change here is the way we choose a stop reason thread when we're interrupting a program on client request. Previously, we were setting a null stop reason for all threads and then fixing up the reason for one victim thread in the lambda. Now, I make sure the stop reason is set for the victim thread correctly in the first place. I also take the opportunity to rename CallAfter* functions into something more appropriate. Test Plan: All tests continue to pass. Reviewers: chaoren, vharron Subscribers: lldb-commits Differential Revision: http://reviews.llvm.org/D9321 llvm-svn: 236595
1 parent 24a8f55 commit ed89c7f

File tree

2 files changed

+55
-132
lines changed

2 files changed

+55
-132
lines changed
 

‎lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp

Lines changed: 38 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,11 +2460,7 @@ NativeProcessLinux::MonitorSIGTRAP(const siginfo_t *info, lldb::pid_t pid)
24602460
assert (main_thread_sp && "exec called during ptraced process but no main thread metadata tracked");
24612461

24622462
// 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);
24682464

24692465
break;
24702466
}
@@ -2584,11 +2580,7 @@ NativeProcessLinux::MonitorTrace(lldb::pid_t pid, NativeThreadProtocolSP thread_
25842580
// once all running threads have checked in as stopped.
25852581
SetCurrentThreadID(pid);
25862582
// 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);
25922584
}
25932585

25942586
void
@@ -2633,13 +2625,7 @@ NativeProcessLinux::MonitorBreakpoint(lldb::pid_t pid, NativeThreadProtocolSP th
26332625

26342626

26352627
// 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);
26432629
}
26442630

26452631
void
@@ -2660,13 +2646,7 @@ NativeProcessLinux::MonitorWatchpoint(lldb::pid_t pid, NativeThreadProtocolSP th
26602646
std::static_pointer_cast<NativeThreadLinux>(thread_sp)->SetStoppedByWatchpoint(wp_index);
26612647

26622648
// 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);
26702650
}
26712651

26722652
void
@@ -2759,10 +2739,18 @@ NativeProcessLinux::MonitorSignal(const siginfo_t *info, lldb::pid_t pid, bool e
27592739
const StateType thread_state = linux_thread_sp->GetState ();
27602740
if (!StateIsStoppedState (thread_state, false))
27612741
{
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+
27662754
SetCurrentThreadID (thread_sp->GetID ());
27672755
NotifyThreadStop (thread_sp->GetID (), true, CoordinatorErrorHandler);
27682756
}
@@ -2840,12 +2828,7 @@ NativeProcessLinux::MonitorSignal(const siginfo_t *info, lldb::pid_t pid, bool e
28402828
}
28412829

28422830
// 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);
28492832
}
28502833

28512834
namespace {
@@ -3154,21 +3137,7 @@ NativeProcessLinux::Resume (const ResumeActionList &resume_actions)
31543137
// after all other running threads have stopped.
31553138
// If there is a stepping thread involved we'll be eventually stopped by SIGTRAP trace signal.
31563139
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);
31723141

31733142
return Error();
31743143
}
@@ -3272,18 +3241,7 @@ NativeProcessLinux::Interrupt ()
32723241
running_thread_sp ? "running" : "stopped",
32733242
deferred_signal_thread_sp->GetID ());
32743243

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());
32873245

32883246
return Error();
32893247
}
@@ -4260,37 +4218,30 @@ NativeProcessLinux::NotifyThreadStop (lldb::tid_t tid)
42604218
}
42614219

42624220
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)
42654222
{
42664223
Log *const log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
42674224
if (log)
4268-
log->Printf("NativeProcessLinux::%s tid %" PRIu64, __FUNCTION__, tid);
4225+
log->Printf("NativeProcessLinux::%s tid %" PRIu64, __FUNCTION__, trigerring_tid);
42694226

42704227
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);
42784231
}
42794232

42804233
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)
42844236
{
42854237
Log *const log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
42864238
if (log)
42874239
log->Printf("NativeProcessLinux::%s deferred_signal_tid %" PRIu64 ", skip_stop_request_tid %" PRIu64, __FUNCTION__, deferred_signal_tid, skip_stop_request_tid);
42884240

42894241
const lldb::pid_t pid = GetID ();
4290-
CallAfterRunningThreadsStopWithSkipTIDs (deferred_signal_tid,
4242+
StopRunningThreadsWithSkipTID(deferred_signal_tid,
42914243
skip_stop_request_tid != LLDB_INVALID_THREAD_ID ? NativeProcessLinux::ThreadIDSet {skip_stop_request_tid} : NativeProcessLinux::ThreadIDSet (),
42924244
[=](lldb::tid_t request_stop_tid) { return RequestThreadStop(pid, request_stop_tid); },
4293-
call_after_function,
42944245
CoordinatorErrorHandler);
42954246
}
42964247

@@ -4442,10 +4393,9 @@ NativeProcessLinux::DoResume(
44424393
//===----------------------------------------------------------------------===//
44434394

44444395
void
4445-
NativeProcessLinux::CallAfterThreadsStop (const lldb::tid_t triggering_tid,
4396+
NativeProcessLinux::StopThreads(const lldb::tid_t triggering_tid,
44464397
const ThreadIDSet &wait_for_stop_tids,
44474398
const StopThreadFunction &request_thread_stop_function,
4448-
const ThreadIDFunction &call_after_function,
44494399
const ErrorFunction &error_function)
44504400
{
44514401
std::lock_guard<std::mutex> lock(m_event_mutex);
@@ -4456,9 +4406,8 @@ NativeProcessLinux::CallAfterThreadsStop (const lldb::tid_t triggering_tid,
44564406
__FUNCTION__, triggering_tid, wait_for_stop_tids.size());
44574407
}
44584408

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)));
44624411

44634412
if (m_log_event_processing)
44644413
{
@@ -4467,9 +4416,8 @@ NativeProcessLinux::CallAfterThreadsStop (const lldb::tid_t triggering_tid,
44674416
}
44684417

44694418
void
4470-
NativeProcessLinux::CallAfterRunningThreadsStop (const lldb::tid_t triggering_tid,
4419+
NativeProcessLinux::StopRunningThreads(const lldb::tid_t triggering_tid,
44714420
const StopThreadFunction &request_thread_stop_function,
4472-
const ThreadIDFunction &call_after_function,
44734421
const ErrorFunction &error_function)
44744422
{
44754423
std::lock_guard<std::mutex> lock(m_event_mutex);
@@ -4480,10 +4428,9 @@ NativeProcessLinux::CallAfterRunningThreadsStop (const lldb::tid_t triggering_ti
44804428
__FUNCTION__, triggering_tid);
44814429
}
44824430

4483-
DoCallAfterThreadsStop(PendingNotificationUP(new PendingNotification(
4431+
DoStopThreads(PendingNotificationUP(new PendingNotification(
44844432
triggering_tid,
44854433
request_thread_stop_function,
4486-
call_after_function,
44874434
error_function)));
44884435

44894436
if (m_log_event_processing)
@@ -4493,10 +4440,9 @@ NativeProcessLinux::CallAfterRunningThreadsStop (const lldb::tid_t triggering_ti
44934440
}
44944441

44954442
void
4496-
NativeProcessLinux::CallAfterRunningThreadsStopWithSkipTIDs (lldb::tid_t triggering_tid,
4443+
NativeProcessLinux::StopRunningThreadsWithSkipTID(lldb::tid_t triggering_tid,
44974444
const ThreadIDSet &skip_stop_request_tids,
44984445
const StopThreadFunction &request_thread_stop_function,
4499-
const ThreadIDFunction &call_after_function,
45004446
const ErrorFunction &error_function)
45014447
{
45024448
std::lock_guard<std::mutex> lock(m_event_mutex);
@@ -4507,10 +4453,9 @@ NativeProcessLinux::CallAfterRunningThreadsStopWithSkipTIDs (lldb::tid_t trigger
45074453
__FUNCTION__, triggering_tid, skip_stop_request_tids.size());
45084454
}
45094455

4510-
DoCallAfterThreadsStop(PendingNotificationUP(new PendingNotification(
4456+
DoStopThreads(PendingNotificationUP(new PendingNotification(
45114457
triggering_tid,
45124458
request_thread_stop_function,
4513-
call_after_function,
45144459
skip_stop_request_tids,
45154460
error_function)));
45164461

@@ -4525,7 +4470,8 @@ NativeProcessLinux::SignalIfRequirementsSatisfied()
45254470
{
45264471
if (m_pending_notification_up && m_pending_notification_up->wait_for_stop_tids.empty ())
45274472
{
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);
45294475
m_pending_notification_up.reset();
45304476
}
45314477
}
@@ -4664,7 +4610,7 @@ NativeProcessLinux::ThreadDidStop (lldb::tid_t tid, bool initiated_by_llgs, cons
46644610
}
46654611

46664612
void
4667-
NativeProcessLinux::DoCallAfterThreadsStop(PendingNotificationUP &&notification_up)
4613+
NativeProcessLinux::DoStopThreads(PendingNotificationUP &&notification_up)
46684614
{
46694615
// Validate we know about the deferred trigger thread.
46704616
if (!IsKnownThread (notification_up->triggering_tid))
@@ -4697,12 +4643,7 @@ NativeProcessLinux::DoCallAfterThreadsStop(PendingNotificationUP &&notification_
46974643
return;
46984644
}
46994645

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();
47064647
}
47074648

47084649
void

0 commit comments

Comments
 (0)
Please sign in to comment.