[Lldb-commits] [lldb] r109930 - in /lldb/trunk/tools/debugserver/source: MacOSX/MachProcess.cpp MacOSX/MachProcess.h MacOSX/MachTask.cpp debugserver.cpp
Greg Clayton
gclayton at apple.com
Fri Jul 30 16:14:42 PDT 2010
Author: gclayton
Date: Fri Jul 30 18:14:42 2010
New Revision: 109930
URL: http://llvm.org/viewvc/llvm-project?rev=109930&view=rev
Log:
Fixed debugserver to not exit when we are able to spawn the process, yet not
launch it due to not being able to get the task port. A SIGHUP was killing us
and also an error string wasn't properly being passed along. Got rid of a
class error variable that can only lead to multi-threaded crashes.
Modified:
lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp
lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h
lldb/trunk/tools/debugserver/source/MacOSX/MachTask.cpp
lldb/trunk/tools/debugserver/source/debugserver.cpp
Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp?rev=109930&r1=109929&r2=109930&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp Fri Jul 30 18:14:42 2010
@@ -101,7 +101,6 @@
m_threadList (),
m_exception_messages (),
m_exception_messages_mutex (PTHREAD_MUTEX_RECURSIVE),
- m_err (KERN_SUCCESS),
m_state (eStateUnloaded),
m_state_mutex (PTHREAD_MUTEX_RECURSIVE),
m_events (0, kAllEventsMask),
@@ -276,8 +275,6 @@
PTHREAD_MUTEX_LOCKER(locker, m_exception_messages_mutex);
m_exception_messages.clear();
}
- m_err.Clear();
-
}
@@ -286,8 +283,7 @@
{
DNBLogThreadedIf(LOG_PROCESS, "MachProcess::%s ( )", __FUNCTION__);
// Create the thread that watches for the child STDIO
- m_err = ::pthread_create (&m_stdio_thread, NULL, MachProcess::STDIOThread, this);
- return m_err.Success();
+ return ::pthread_create (&m_stdio_thread, NULL, MachProcess::STDIOThread, this) == 0;
}
@@ -308,19 +304,15 @@
if (CanResume(state))
{
PrivateResume(thread_actions);
+ return true;
}
else if (state == eStateRunning)
{
DNBLogThreadedIf(LOG_PROCESS, "Resume() - task 0x%x is running, ignoring...", m_task.TaskPort());
- m_err.Clear();
-
- }
- else
- {
- DNBLogThreadedIf(LOG_PROCESS, "Resume() - task 0x%x can't continue, ignoring...", m_task.TaskPort());
- m_err.SetError(UINT_MAX, DNBError::Generic);
+ return true;
}
- return m_err.Success();
+ DNBLogThreadedIf(LOG_PROCESS, "Resume() - task 0x%x can't continue, ignoring...", m_task.TaskPort());
+ return false;
}
bool
@@ -331,8 +323,9 @@
DNBLogThreadedIf(LOG_PROCESS, "MachProcess::Kill() DoSIGSTOP() state = %s", DNBStateAsString(state));
errno = 0;
::ptrace (PT_KILL, m_pid, 0, 0);
- m_err.SetErrorToErrno();
- DNBLogThreadedIf(LOG_PROCESS, "MachProcess::Kill() DoSIGSTOP() ::ptrace (PT_KILL, pid=%u, 0, 0) => 0x%8.8x (%s)", m_err.Error(), m_err.AsString());
+ DNBError err;
+ err.SetErrorToErrno();
+ DNBLogThreadedIf(LOG_PROCESS, "MachProcess::Kill() DoSIGSTOP() ::ptrace (PT_KILL, pid=%u, 0, 0) => 0x%8.8x (%s)", err.Error(), err.AsString());
PrivateResume (DNBThreadResumeActions (eStateRunning, 0));
return true;
}
@@ -344,7 +337,6 @@
nub_state_t state = GetState();
if (::kill (ProcessID(), signal) == 0)
{
- m_err.Clear();
// If we were running and we have a timeout, wait for the signal to stop
if (IsRunning(state) && timeout_abstime)
{
@@ -355,13 +347,11 @@
return !IsRunning (state);
}
DNBLogThreadedIf(LOG_PROCESS, "MachProcess::Signal (signal = %d, timeout = %p) not waiting...", signal, timeout_abstime);
+ return true;
}
- else
- {
- m_err.SetError(errno, DNBError::POSIX);
- m_err.LogThreadedIfError("kill (pid = %d, signo = %i)", ProcessID(), signal);
- }
- return m_err.Success();
+ DNBError err(errno, DNBError::POSIX);
+ err.LogThreadedIfError("kill (pid = %d, signo = %i)", ProcessID(), signal);
+ return false;
}
@@ -423,9 +413,9 @@
errno = 0;
nub_process_t pid = m_pid;
::ptrace (PT_DETACH, pid, (caddr_t)1, 0);
- m_err.SetError (errno, DNBError::POSIX);
- if (DNBLogCheckLogBit(LOG_PROCESS) || m_err.Fail())
- m_err.LogThreaded("::ptrace (PT_DETACH, %u, (caddr_t)1, 0)", pid);
+ DNBError err(errno, DNBError::POSIX);
+ if (DNBLogCheckLogBit(LOG_PROCESS) || err.Fail())
+ err.LogThreaded("::ptrace (PT_DETACH, %u, (caddr_t)1, 0)", pid);
// Resume our task
m_task.Resume();
@@ -590,9 +580,9 @@
thread_actions.SetSignalHandledForThread (pos->state.thread_port);
}
- m_err = pos->Reply(this, thread_reply_signal);
+ DNBError err (pos->Reply(this, thread_reply_signal));
if (DNBLogCheckLogBit(LOG_EXCEPTIONS))
- m_err.LogThreadedIfError("Error replying to exception");
+ err.LogThreadedIfError("Error replying to exception");
}
// Erase all exception message as we should have used and replied
@@ -620,8 +610,7 @@
SetState (eStateRunning);
// Now resume our task.
- m_err = m_task.Resume();
-
+ m_task.Resume();
}
nub_break_t
@@ -1138,7 +1127,8 @@
nub_addr_t
MachProcess::GetDYLDAllImageInfosAddress ()
{
- return m_task.GetDYLDAllImageInfosAddress(m_err);
+ DNBError err;
+ return m_task.GetDYLDAllImageInfosAddress(err);
}
size_t
@@ -1279,11 +1269,12 @@
Clear();
if (pid != 0)
{
+ DNBError err;
// Make sure the process exists...
if (::getpgid (pid) < 0)
{
- m_err.SetErrorToErrno();
- const char *err_cstr = m_err.AsString();
+ err.SetErrorToErrno();
+ const char *err_cstr = err.AsString();
::snprintf (err_str, err_len, "%s", err_cstr ? err_cstr : "No such process");
return INVALID_NUB_PROCESS;
}
@@ -1295,9 +1286,9 @@
if (IsSBProcess(pid))
m_flags |= eMachProcessFlagsUsingSBS;
#endif
- if (!m_task.StartExceptionThread(m_err))
+ if (!m_task.StartExceptionThread(err))
{
- const char *err_cstr = m_err.AsString();
+ const char *err_cstr = err.AsString();
::snprintf (err_str, err_len, "%s", err_cstr ? err_cstr : "unable to start the exception thread");
DNBLogThreadedIf(LOG_PROCESS, "error: failed to attach to pid %d", pid);
m_pid = INVALID_NUB_PROCESS;
@@ -1305,14 +1296,12 @@
}
errno = 0;
- int err = ptrace (PT_ATTACHEXC, pid, 0, 0);
-
- if (err < 0)
- m_err.SetError(errno);
+ if (::ptrace (PT_ATTACHEXC, pid, 0, 0))
+ err.SetError(errno);
else
- m_err.Clear();
+ err.Clear();
- if (m_err.Success())
+ if (err.Success())
{
m_flags |= eMachProcessFlagsAttached;
// Sleep a bit to let the exception get received and set our process status
@@ -1323,7 +1312,7 @@
}
else
{
- ::snprintf (err_str, err_len, "%s", m_err.AsString());
+ ::snprintf (err_str, err_len, "%s", err.AsString());
DNBLogThreadedIf(LOG_PROCESS, "error: failed to attach to pid %d", pid);
}
}
@@ -1525,11 +1514,11 @@
for (i=0; (arg = argv[i]) != NULL; i++)
m_args.push_back(arg);
- m_task.StartExceptionThread(m_err);
- if (m_err.Fail())
+ m_task.StartExceptionThread(launch_err);
+ if (launch_err.Fail())
{
- if (m_err.AsString() == NULL)
- m_err.SetErrorString("unable to start the exception thread");
+ if (launch_err.AsString() == NULL)
+ launch_err.SetErrorString("unable to start the exception thread");
::ptrace (PT_KILL, m_pid, 0, 0);
m_pid = INVALID_NUB_PROCESS;
return INVALID_NUB_PROCESS;
Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h?rev=109930&r1=109929&r2=109930&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h Fri Jul 30 18:14:42 2010
@@ -161,8 +161,6 @@
return state == eStateStopped;
}
- const DNBError& GetLastError () const { return m_err; }
-
bool GetExitStatus(int* status)
{
if (GetState() == eStateExited)
@@ -246,7 +244,6 @@
PThreadMutex m_exception_messages_mutex; // Multithreaded protection for m_exception_messages
MachThreadList m_threadList; // A list of threads that is maintained/updated after each stop
- DNBError m_err; // The last error for any transaction
nub_state_t m_state; // The state of our process
PThreadMutex m_state_mutex; // Multithreaded protection for m_state
PThreadEvent m_events; // Process related events in the child processes lifetime can be waited upon
Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachTask.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachTask.cpp?rev=109930&r1=109929&r2=109930&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachTask.cpp (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachTask.cpp Fri Jul 30 18:14:42 2010
@@ -226,13 +226,10 @@
char str[1024];
::snprintf (str,
sizeof(str),
- "::task_for_pid ( task_self, pid = %d, task => TASK_NULL (0x%4.4x) ) uid=%u, euid=%u gid=%u egid=%u (%s)",
+ "::task_for_pid ( target_tport = 0x%4.4x, pid = %d, &task ) => err = 0x%8.8x (%s)",
+ task_self,
pid,
- task,
- getuid(),
- geteuid(),
- getgid(),
- getegid(),
+ err.Error(),
err.AsString() ? err.AsString() : "success");
if (err.Fail())
err.SetErrorString(str);
Modified: lldb/trunk/tools/debugserver/source/debugserver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/debugserver.cpp?rev=109930&r1=109929&r2=109930&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/debugserver.cpp (original)
+++ lldb/trunk/tools/debugserver/source/debugserver.cpp Fri Jul 30 18:14:42 2010
@@ -216,7 +216,7 @@
if (pid == INVALID_NUB_PROCESS && strlen(launch_err_str) > 0)
{
- DNBLogThreaded ("%s DNBProcessLaunch() returned error: '%s'", __FUNCTION__);
+ DNBLogThreaded ("%s DNBProcessLaunch() returned error: '%s'", __FUNCTION__, launch_err_str);
ctx.LaunchStatus().SetError(-1, DNBError::Generic);
ctx.LaunchStatus().SetErrorString(launch_err_str);
}
@@ -676,6 +676,7 @@
// signal (SIGINT, signal_handler);
signal (SIGPIPE, signal_handler);
+ signal (SIGHUP, signal_handler);
int i;
int attach_pid = INVALID_NUB_PROCESS;
More information about the lldb-commits
mailing list