Clean up handling of FreeBSD thread list on Launch / Attach

Instead of directly manipulating the thread list in Launch and Attach,
just rely on RefreshStateAfterStop to populate the initial list.

Review: http://llvm-reviews.chandlerc.com/D1565
llvm-svn: 189889
This commit is contained in:
Ed Maste 2013-09-03 23:55:30 +00:00
parent cc7ee374e2
commit e544143f03
4 changed files with 16 additions and 22 deletions

View File

@ -855,7 +855,6 @@ ProcessMonitor::Launch(LaunchArgs *args)
{ {
ProcessMonitor *monitor = args->m_monitor; ProcessMonitor *monitor = args->m_monitor;
ProcessFreeBSD &process = monitor->GetProcess(); ProcessFreeBSD &process = monitor->GetProcess();
lldb::ProcessSP processSP = process.shared_from_this();
const char **argv = args->m_argv; const char **argv = args->m_argv;
const char **envp = args->m_envp; const char **envp = args->m_envp;
const char *stdin_path = args->m_stdin_path; const char *stdin_path = args->m_stdin_path;
@ -868,9 +867,6 @@ ProcessMonitor::Launch(LaunchArgs *args)
char err_str[err_len]; char err_str[err_len];
lldb::pid_t pid; lldb::pid_t pid;
lldb::ThreadSP inferior;
Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PROCESS));
// Propagate the environment if one is not supplied. // Propagate the environment if one is not supplied.
if (envp == NULL || envp[0] == NULL) if (envp == NULL || envp[0] == NULL)
envp = const_cast<const char **>(environ); envp = const_cast<const char **>(environ);
@ -1002,14 +998,7 @@ ProcessMonitor::Launch(LaunchArgs *args)
if (!EnsureFDFlags(monitor->m_terminal_fd, O_NONBLOCK, args->m_error)) if (!EnsureFDFlags(monitor->m_terminal_fd, O_NONBLOCK, args->m_error))
goto FINISH; goto FINISH;
// Update the process thread list with this new thread. process.SendMessage(ProcessMessage::Attach(pid));
inferior.reset(process.CreateNewPOSIXThread(*processSP, pid));
if (log)
log->Printf ("ProcessMonitor::%s() adding pid = %" PRIu64, __FUNCTION__, pid);
process.GetThreadList().AddThread(inferior);
// Let our process instance know the thread has stopped.
process.SendMessage(ProcessMessage::Trace(pid));
FINISH: FINISH:
return args->m_error.Success(); return args->m_error.Success();
@ -1059,9 +1048,6 @@ ProcessMonitor::Attach(AttachArgs *args)
ProcessMonitor *monitor = args->m_monitor; ProcessMonitor *monitor = args->m_monitor;
ProcessFreeBSD &process = monitor->GetProcess(); ProcessFreeBSD &process = monitor->GetProcess();
lldb::ProcessSP processSP = process.shared_from_this();
ThreadList &tl = process.GetThreadList();
lldb::ThreadSP inferior;
if (pid <= 1) if (pid <= 1)
{ {
@ -1084,14 +1070,9 @@ ProcessMonitor::Attach(AttachArgs *args)
goto FINISH; goto FINISH;
} }
// Update the process thread list with the attached thread. process.SendMessage(ProcessMessage::Attach(pid));
inferior.reset(process.CreateNewPOSIXThread(*processSP, pid));
tl.AddThread(inferior);
// Let our process instance know the thread has stopped. FINISH:
process.SendMessage(ProcessMessage::Trace(pid));
FINISH:
return args->m_error.Success(); return args->m_error.Success();
} }

View File

@ -218,6 +218,9 @@ ProcessMessage::PrintKind(Kind kind)
case eInvalidMessage: case eInvalidMessage:
str = "eInvalidMessage"; str = "eInvalidMessage";
break; break;
case eAttachMessage:
str = "eAttachMessage";
break;
case eExitMessage: case eExitMessage:
str = "eExitMessage"; str = "eExitMessage";
break; break;

View File

@ -23,6 +23,7 @@ public:
enum Kind enum Kind
{ {
eInvalidMessage, eInvalidMessage,
eAttachMessage,
eExitMessage, eExitMessage,
eLimboMessage, eLimboMessage,
eSignalMessage, eSignalMessage,
@ -79,6 +80,11 @@ public:
lldb::tid_t GetTID() const { return m_tid; } lldb::tid_t GetTID() const { return m_tid; }
/// Indicates that the process @p pid has successfully attached.
static ProcessMessage Attach(lldb::pid_t pid) {
return ProcessMessage(pid, eAttachMessage);
}
/// Indicates that the thread @p tid is about to exit with status @p status. /// Indicates that the thread @p tid is about to exit with status @p status.
static ProcessMessage Limbo(lldb::tid_t tid, int status) { static ProcessMessage Limbo(lldb::tid_t tid, int status) {
return ProcessMessage(tid, eLimboMessage, status); return ProcessMessage(tid, eLimboMessage, status);

View File

@ -367,6 +367,10 @@ ProcessPOSIX::SendMessage(const ProcessMessage &message)
case ProcessMessage::eInvalidMessage: case ProcessMessage::eInvalidMessage:
return; return;
case ProcessMessage::eAttachMessage:
SetPrivateState(eStateStopped);
return;
case ProcessMessage::eLimboMessage: case ProcessMessage::eLimboMessage:
assert(thread); assert(thread);
thread->SetState(eStateStopped); thread->SetState(eStateStopped);