Skip to content

Commit 337f3eb

Browse files
committedMay 8, 2015
[NativeProcessLinux] Remove the stop callback
Summary: The stop callback is a remnant of the ThreadStateCoordinator. We don't need it now that TSC is gone, as we know exactly which function to call when threads stop. This also removes some stop-related functions, which were just forwarding calls to one another. Test Plan: ninja check-lldb continues to pass Reviewers: chaoren, ovyalov Subscribers: lldb-commits Differential Revision: http://reviews.llvm.org/D9531 llvm-svn: 236814
1 parent 7325aee commit 337f3eb

File tree

2 files changed

+71
-157
lines changed

2 files changed

+71
-157
lines changed
 

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

Lines changed: 38 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,7 +1978,7 @@ NativeProcessLinux::Launch(LaunchArgs *args, Error &error)
19781978

19791979
thread_sp = AddThread (pid);
19801980
assert (thread_sp && "AddThread() returned a nullptr thread");
1981-
NotifyThreadCreateStopped (pid);
1981+
NotifyThreadCreate (pid, ThreadState::Stopped);
19821982
std::static_pointer_cast<NativeThreadLinux> (thread_sp)->SetStoppedBySignal (SIGSTOP);
19831983

19841984
// Let our process instance know the thread has stopped.
@@ -2074,7 +2074,7 @@ NativeProcessLinux::Attach(lldb::pid_t pid, Error &error)
20742074
assert (thread_sp && "AddThread() returned a nullptr");
20752075

20762076
// This will notify this is a new thread and tell the system it is stopped.
2077-
NotifyThreadCreateStopped (tid);
2077+
NotifyThreadCreate (tid, ThreadState::Stopped);
20782078
std::static_pointer_cast<NativeThreadLinux> (thread_sp)->SetStoppedBySignal (SIGSTOP);
20792079
SetCurrentThreadID (thread_sp->GetID ());
20802080
}
@@ -2331,7 +2331,7 @@ NativeProcessLinux::WaitForNewThread(::pid_t tid)
23312331
new_thread_sp = AddThread(tid);
23322332
std::static_pointer_cast<NativeThreadLinux> (new_thread_sp)->SetRunning ();
23332333
Resume (tid, LLDB_INVALID_SIGNAL_NUMBER);
2334-
NotifyThreadCreate (tid, false);
2334+
NotifyThreadCreate (tid, ThreadState::Running);
23352335
}
23362336

23372337
void
@@ -2427,7 +2427,7 @@ NativeProcessLinux::MonitorSIGTRAP(const siginfo_t *info, lldb::pid_t pid)
24272427

24282428
// Tell coordinator about about the "new" (since exec) stopped main thread.
24292429
const lldb::tid_t main_thread_tid = GetID ();
2430-
NotifyThreadCreateStopped (main_thread_tid);
2430+
NotifyThreadCreate (main_thread_tid, ThreadState::Stopped);
24312431

24322432
// NOTE: ideally these next statements would execute at the same time as the coordinator thread create was executed.
24332433
// 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
26862686
// We can now resume the newly created thread.
26872687
std::static_pointer_cast<NativeThreadLinux> (thread_sp)->SetRunning ();
26882688
Resume (pid, LLDB_INVALID_SIGNAL_NUMBER);
2689-
NotifyThreadCreate (pid, false);
2689+
NotifyThreadCreate (pid, ThreadState::Running);
26902690
// Done handling.
26912691
return;
26922692
}
@@ -4175,58 +4175,6 @@ NativeProcessLinux::FixupBreakpointPCAsNeeded (NativeThreadProtocolSP &thread_sp
41754175
return error;
41764176
}
41774177

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-
42304178
Error
42314179
NativeProcessLinux::GetLoadedModuleFileSpec(const char* module_path, FileSpec& file_spec)
42324180
{
@@ -4342,8 +4290,7 @@ NativeProcessLinux::DoResume(
43424290

43434291
void
43444292
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)
43474294
{
43484295
Log *const log = GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD);
43494296
std::lock_guard<std::mutex> lock(m_event_mutex);
@@ -4355,7 +4302,7 @@ NativeProcessLinux::StopThreads(const lldb::tid_t triggering_tid,
43554302
}
43564303

43574304
DoStopThreads(PendingNotificationUP(new PendingNotification(
4358-
triggering_tid, wait_for_stop_tids, request_thread_stop_function)));
4305+
triggering_tid, wait_for_stop_tids, ThreadIDSet())));
43594306

43604307
if (log)
43614308
{
@@ -4364,8 +4311,7 @@ NativeProcessLinux::StopThreads(const lldb::tid_t triggering_tid,
43644311
}
43654312

43664313
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)
43694315
{
43704316
Log *const log = GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD);
43714317
std::lock_guard<std::mutex> lock(m_event_mutex);
@@ -4376,9 +4322,7 @@ NativeProcessLinux::StopRunningThreads(const lldb::tid_t triggering_tid,
43764322
__FUNCTION__, triggering_tid);
43774323
}
43784324

4379-
DoStopThreads(PendingNotificationUP(new PendingNotification(
4380-
triggering_tid,
4381-
request_thread_stop_function)));
4325+
DoStopThreads(PendingNotificationUP(new PendingNotification(triggering_tid)));
43824326

43834327
if (log)
43844328
{
@@ -4388,22 +4332,21 @@ NativeProcessLinux::StopRunningThreads(const lldb::tid_t triggering_tid,
43884332

43894333
void
43904334
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)
43934336
{
43944337
Log *const log = GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD);
43954338
std::lock_guard<std::mutex> lock(m_event_mutex);
43964339

43974340
if (log)
43984341
{
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);
44014344
}
44024345

44034346
DoStopThreads(PendingNotificationUP(new PendingNotification(
44044347
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 ())));
44074350

44084351
if (log)
44094352
{
@@ -4485,19 +4428,28 @@ NativeProcessLinux::RequestStopOnAllRunningThreads()
44854428
m_pending_notification_up->wait_for_stop_tids.swap (sent_tids);
44864429
}
44874430

4488-
void
4431+
Error
44894432
NativeProcessLinux::RequestThreadStop (lldb::tid_t tid, ThreadContext& context)
44904433
{
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)
44954444
{
4496-
Log *const log = GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD);
4445+
err.SetErrorToErrno ();
44974446
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 ());
45004448
}
4449+
else
4450+
context.m_stop_requested = true;
4451+
4452+
return err;
45014453
}
45024454

45034455

@@ -4576,22 +4528,20 @@ NativeProcessLinux::DoStopThreads(PendingNotificationUP &&notification_up)
45764528
}
45774529

45784530
void
4579-
NativeProcessLinux::ThreadWasCreated (lldb::tid_t tid, bool is_stopped)
4531+
NativeProcessLinux::ThreadWasCreated (lldb::tid_t tid, ThreadState state)
45804532
{
45814533
// Ensure we don't already know about the thread.
45824534
lldbassert(m_tid_map.find(tid) == m_tid_map.end());
45834535

45844536
// 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;
45884538

4589-
if (m_pending_notification_up && !is_stopped)
4539+
if (m_pending_notification_up && state == ThreadState::Running)
45904540
{
45914541
// We will need to wait for this new thread to stop as well before firing the
45924542
// notification.
45934543
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);
45954545
}
45964546
}
45974547

@@ -4684,19 +4634,18 @@ NativeProcessLinux::RequestThreadResumeAsNeeded (lldb::tid_t tid,
46844634
}
46854635

46864636
void
4687-
NativeProcessLinux::NotifyThreadCreate (lldb::tid_t tid,
4688-
bool is_stopped)
4637+
NativeProcessLinux::NotifyThreadCreate (lldb::tid_t tid, ThreadState state)
46894638
{
46904639
Log *const log = GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD);
46914640
std::lock_guard<std::mutex> lock(m_event_mutex);
46924641

46934642
if (log)
46944643
{
46954644
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 ");
46974646
}
46984647

4699-
ThreadWasCreated (tid, is_stopped);
4648+
ThreadWasCreated (tid, state);
47004649

47014650
if (log)
47024651
{

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

Lines changed: 33 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -346,69 +346,52 @@ namespace process_linux {
346346
SingleStep(lldb::tid_t tid, uint32_t signo);
347347

348348
// ThreadStateCoordinator helper methods.
349-
void
350-
NotifyThreadCreateStopped (lldb::tid_t tid);
351-
352-
void
353-
NotifyThreadCreateRunning (lldb::tid_t tid);
354-
355349
void
356350
NotifyThreadDeath (lldb::tid_t tid);
357351

358-
void
359-
StopRunningThreads (lldb::tid_t triggering_tid);
360-
361-
void
362-
StopRunningThreadsWithSkipTID (lldb::tid_t deferred_signal_tid,
363-
lldb::tid_t skip_stop_request_tid);
364-
365352
Error
366353
Detach(lldb::tid_t tid);
367354

368-
Error
369-
RequestThreadStop (const lldb::pid_t pid, const lldb::tid_t tid);
370-
371355

372356
public:
373357
// Typedefs.
374358
typedef std::unordered_set<lldb::tid_t> ThreadIDSet;
375359

376360
// Callback/block definitions.
377-
typedef std::function<Error (lldb::tid_t tid)> StopThreadFunction;
378361
typedef std::function<Error (lldb::tid_t tid, bool supress_signal)> ResumeThreadFunction;
379362

380363
private:
381-
// Notify the coordinator when a thread is created and/or starting to be
382-
// tracked. is_stopped should be true if the thread is currently stopped;
383-
// otherwise, it should be set false if it is already running. Will
384-
// call the error function if the thread id is already tracked.
364+
enum class ThreadState
365+
{
366+
Running,
367+
Stopped
368+
};
369+
370+
// Notify that a thread is created and/or starting to be
371+
// tracked. The state parameter should reflect whether the thread is created in a running
372+
// or stopped state.
385373
void
386-
NotifyThreadCreate(lldb::tid_t tid, bool is_stopped);
374+
NotifyThreadCreate(lldb::tid_t tid, ThreadState state);
387375

388376

389377
// Notify the delegate after a given set of threads stops. The triggering_tid will be set
390378
// as the current thread. The error_function will be fired if either the triggering tid
391379
// or any of the wait_for_stop_tids are unknown.
392380
void
393-
StopThreads(lldb::tid_t triggering_tid,
394-
const ThreadIDSet &wait_for_stop_tids,
395-
const StopThreadFunction &request_thread_stop_function);
381+
StopThreads(lldb::tid_t triggering_tid, const ThreadIDSet &wait_for_stop_tids);
396382

397383
// Notify the delegate after all non-stopped threads stop. The triggering_tid will be set
398384
// as the current thread. The error_function will be fired if the triggering tid
399385
// is unknown.
400386
void
401-
StopRunningThreads(lldb::tid_t triggering_tid,
402-
const StopThreadFunction &request_thread_stop_function);
387+
StopRunningThreads(lldb::tid_t triggering_tid);
403388

404389
// Notify the delegate after all non-stopped threads stop. The triggering_tid will be set
405390
// as the current thread. The error_function will be fired if either the triggering tid
406391
// or any of the wait_for_stop_tids are unknown. This variant will send stop requests to
407-
// all non-stopped threads except for any contained in skip_stop_request_tids.
392+
// all non-stopped threads except skip_stop_request_tid.
408393
void
409-
StopRunningThreadsWithSkipTID(lldb::tid_t triggering_tid,
410-
const ThreadIDSet &skip_stop_request_tids,
411-
const StopThreadFunction &request_thread_stop_function);
394+
StopRunningThreadsWithSkipTID(lldb::tid_t triggering_tid, lldb::tid_t skip_stop_request_tid);
412395

413396
// Notify the thread stopped. Will trigger error at time of execution if we
414397
// already think it is stopped.
@@ -436,61 +419,43 @@ namespace process_linux {
436419

437420
private:
438421

439-
enum class ThreadState
440-
{
441-
Running,
442-
Stopped
443-
};
444-
445422
struct ThreadContext
446423
{
447424
ThreadState m_state;
448425
bool m_stop_requested = false;
449426
ResumeThreadFunction m_request_resume_function;
427+
428+
explicit ThreadContext(ThreadState state)
429+
: m_state(state)
430+
{}
450431
};
451432
typedef std::unordered_map<lldb::tid_t, ThreadContext> TIDContextMap;
452433

453434
struct PendingNotification
454435
{
455436
PendingNotification (lldb::tid_t triggering_tid,
456-
const ThreadIDSet &wait_for_stop_tids,
457-
const StopThreadFunction &request_thread_stop_function):
458-
triggering_tid (triggering_tid),
459-
wait_for_stop_tids (wait_for_stop_tids),
460-
original_wait_for_stop_tids (wait_for_stop_tids),
461-
request_thread_stop_function (request_thread_stop_function),
462-
request_stop_on_all_unstopped_threads (false),
463-
skip_stop_request_tids ()
437+
const ThreadIDSet &wait_for_stop_tids,
438+
const ThreadIDSet &skip_stop_request_tids):
439+
triggering_tid (triggering_tid),
440+
wait_for_stop_tids (wait_for_stop_tids),
441+
original_wait_for_stop_tids (wait_for_stop_tids),
442+
request_stop_on_all_unstopped_threads (false),
443+
skip_stop_request_tids (skip_stop_request_tids)
464444
{
465445
}
466446

467-
PendingNotification (lldb::tid_t triggering_tid,
468-
const StopThreadFunction &request_thread_stop_function):
469-
triggering_tid (triggering_tid),
470-
wait_for_stop_tids (),
471-
original_wait_for_stop_tids (),
472-
request_thread_stop_function (request_thread_stop_function),
473-
request_stop_on_all_unstopped_threads (true),
474-
skip_stop_request_tids ()
475-
{
476-
}
477-
478-
PendingNotification (lldb::tid_t triggering_tid,
479-
const StopThreadFunction &request_thread_stop_function,
480-
const ThreadIDSet &skip_stop_request_tids):
481-
triggering_tid (triggering_tid),
482-
wait_for_stop_tids (),
483-
original_wait_for_stop_tids (),
484-
request_thread_stop_function (request_thread_stop_function),
485-
request_stop_on_all_unstopped_threads (true),
486-
skip_stop_request_tids (skip_stop_request_tids)
447+
PendingNotification (lldb::tid_t triggering_tid):
448+
triggering_tid (triggering_tid),
449+
wait_for_stop_tids (),
450+
original_wait_for_stop_tids (),
451+
request_stop_on_all_unstopped_threads (true),
452+
skip_stop_request_tids ()
487453
{
488454
}
489455

490456
const lldb::tid_t triggering_tid;
491457
ThreadIDSet wait_for_stop_tids;
492458
const ThreadIDSet original_wait_for_stop_tids;
493-
StopThreadFunction request_thread_stop_function;
494459
const bool request_stop_on_all_unstopped_threads;
495460
ThreadIDSet skip_stop_request_tids;
496461
};
@@ -505,7 +470,7 @@ namespace process_linux {
505470
void
506471
RequestStopOnAllRunningThreads();
507472

508-
void
473+
Error
509474
RequestThreadStop (lldb::tid_t tid, ThreadContext& context);
510475

511476
std::mutex m_event_mutex; // Serializes execution of ProcessEvent. XXX
@@ -521,7 +486,7 @@ namespace process_linux {
521486
DoStopThreads(PendingNotificationUP &&notification_up);
522487

523488
void
524-
ThreadWasCreated (lldb::tid_t tid, bool is_stopped);
489+
ThreadWasCreated (lldb::tid_t tid, ThreadState state);
525490

526491
void
527492
ThreadDidDie (lldb::tid_t tid);

0 commit comments

Comments
 (0)
Please sign in to comment.