aboutsummaryrefslogtreecommitdiff
path: root/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/Plugins/Process/FreeBSD/ProcessMonitor.cpp')
-rw-r--r--source/Plugins/Process/FreeBSD/ProcessMonitor.cpp66
1 files changed, 30 insertions, 36 deletions
diff --git a/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp b/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
index 63439b155111..84e35ba22644 100644
--- a/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
+++ b/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
@@ -25,6 +25,7 @@
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/Scalar.h"
#include "lldb/Host/Host.h"
+#include "lldb/Host/ThreadLauncher.h"
#include "lldb/Target/Thread.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Utility/PseudoTerminal.h"
@@ -112,6 +113,7 @@ PtraceWrapper(int req, lldb::pid_t pid, void *addr, int data,
log->Printf("PT_GETREGS: ax=0x%lx", r->r_rax);
}
#endif
+#ifndef __powerpc__
if (req == PT_GETDBREGS || req == PT_SETDBREGS) {
struct dbreg *r = (struct dbreg *) addr;
char setget = (req == PT_GETDBREGS) ? 'G' : 'S';
@@ -119,6 +121,7 @@ PtraceWrapper(int req, lldb::pid_t pid, void *addr, int data,
for (int i = 0; i <= 7; i++)
log->Printf("PT_%cETDBREGS: dr[%d]=0x%lx", setget, i, r->dr[i]);
}
+#endif
}
return result;
@@ -309,9 +312,14 @@ ReadRegOperation::Execute(ProcessMonitor *monitor)
if ((rc = PTRACE(PT_GETREGS, m_tid, (caddr_t)&regs, 0)) < 0) {
m_result = false;
} else {
- if (m_size == sizeof(uintptr_t))
- m_value = *(uintptr_t *)(((caddr_t)&regs) + m_offset);
- else
+ // 'struct reg' contains only 32- or 64-bit register values. Punt on
+ // others. Also, not all entries may be uintptr_t sized, such as 32-bit
+ // processes on powerpc64 (probably the same for i386 on amd64)
+ if (m_size == sizeof(uint32_t))
+ m_value = *(uint32_t *)(((caddr_t)&regs) + m_offset);
+ else if (m_size == sizeof(uint64_t))
+ m_value = *(uint64_t *)(((caddr_t)&regs) + m_offset);
+ else
memcpy(&m_value, (((caddr_t)&regs) + m_offset), m_size);
m_result = true;
}
@@ -810,8 +818,6 @@ ProcessMonitor::ProcessMonitor(ProcessPOSIX *process,
const lldb_private::ProcessLaunchInfo & /* launch_info */,
lldb_private::Error &error)
: m_process(static_cast<ProcessFreeBSD *>(process)),
- m_operation_thread(LLDB_INVALID_HOST_THREAD),
- m_monitor_thread(LLDB_INVALID_HOST_THREAD),
m_pid(LLDB_INVALID_PROCESS_ID),
m_terminal_fd(-1),
m_operation(0)
@@ -852,7 +858,7 @@ WAIT_AGAIN:
// Finally, start monitoring the child process for change in state.
m_monitor_thread = Host::StartMonitoringChildProcess(
ProcessMonitor::MonitorCallback, this, GetPID(), true);
- if (!IS_VALID_LLDB_HOST_THREAD(m_monitor_thread))
+ if (!m_monitor_thread.IsJoinable())
{
error.SetErrorToGenericError();
error.SetErrorString("Process launch failed.");
@@ -864,8 +870,6 @@ ProcessMonitor::ProcessMonitor(ProcessPOSIX *process,
lldb::pid_t pid,
lldb_private::Error &error)
: m_process(static_cast<ProcessFreeBSD *>(process)),
- m_operation_thread(LLDB_INVALID_HOST_THREAD),
- m_monitor_thread(LLDB_INVALID_HOST_THREAD),
m_pid(pid),
m_terminal_fd(-1),
m_operation(0)
@@ -904,7 +908,7 @@ WAIT_AGAIN:
// Finally, start monitoring the child process for change in state.
m_monitor_thread = Host::StartMonitoringChildProcess(
ProcessMonitor::MonitorCallback, this, GetPID(), true);
- if (!IS_VALID_LLDB_HOST_THREAD(m_monitor_thread))
+ if (!m_monitor_thread.IsJoinable())
{
error.SetErrorToGenericError();
error.SetErrorString("Process attach failed.");
@@ -924,11 +928,10 @@ ProcessMonitor::StartLaunchOpThread(LaunchArgs *args, Error &error)
{
static const char *g_thread_name = "lldb.process.freebsd.operation";
- if (IS_VALID_LLDB_HOST_THREAD(m_operation_thread))
+ if (m_operation_thread.IsJoinable())
return;
- m_operation_thread =
- Host::ThreadCreate(g_thread_name, LaunchOpThread, args, &error);
+ m_operation_thread = ThreadLauncher::LaunchThread(g_thread_name, LaunchOpThread, args, &error);
}
void *
@@ -1101,11 +1104,10 @@ ProcessMonitor::StartAttachOpThread(AttachArgs *args, lldb_private::Error &error
{
static const char *g_thread_name = "lldb.process.freebsd.operation";
- if (IS_VALID_LLDB_HOST_THREAD(m_operation_thread))
+ if (m_operation_thread.IsJoinable())
return;
- m_operation_thread =
- Host::ThreadCreate(g_thread_name, AttachOpThread, args, &error);
+ m_operation_thread = ThreadLauncher::LaunchThread(g_thread_name, AttachOpThread, args, &error);
}
void *
@@ -1113,14 +1115,13 @@ ProcessMonitor::AttachOpThread(void *arg)
{
AttachArgs *args = static_cast<AttachArgs*>(arg);
- if (!Attach(args))
- return NULL;
+ Attach(args);
ServeOperation(args);
return NULL;
}
-bool
+void
ProcessMonitor::Attach(AttachArgs *args)
{
lldb::pid_t pid = args->m_pid;
@@ -1132,27 +1133,24 @@ ProcessMonitor::Attach(AttachArgs *args)
{
args->m_error.SetErrorToGenericError();
args->m_error.SetErrorString("Attaching to process 1 is not allowed.");
- goto FINISH;
+ return;
}
// Attach to the requested process.
if (PTRACE(PT_ATTACH, pid, NULL, 0) < 0)
{
args->m_error.SetErrorToErrno();
- goto FINISH;
+ return;
}
int status;
if ((status = waitpid(pid, NULL, 0)) < 0)
{
args->m_error.SetErrorToErrno();
- goto FINISH;
+ return;
}
process.SendMessage(ProcessMessage::Attach(pid));
-
-FINISH:
- return args->m_error.Success();
}
size_t
@@ -1714,13 +1712,11 @@ ProcessMonitor::DupDescriptor(const char *path, int fd, int flags)
void
ProcessMonitor::StopMonitoringChildProcess()
{
- lldb::thread_result_t thread_result;
-
- if (IS_VALID_LLDB_HOST_THREAD(m_monitor_thread))
+ if (m_monitor_thread.IsJoinable())
{
- Host::ThreadCancel(m_monitor_thread, NULL);
- Host::ThreadJoin(m_monitor_thread, &thread_result, NULL);
- m_monitor_thread = LLDB_INVALID_HOST_THREAD;
+ m_monitor_thread.Cancel();
+ m_monitor_thread.Join(nullptr);
+ m_monitor_thread.Reset();
}
}
@@ -1764,12 +1760,10 @@ ProcessMonitor::WaitForInitialTIDStop(lldb::tid_t tid)
void
ProcessMonitor::StopOpThread()
{
- lldb::thread_result_t result;
-
- if (!IS_VALID_LLDB_HOST_THREAD(m_operation_thread))
+ if (!m_operation_thread.IsJoinable())
return;
- Host::ThreadCancel(m_operation_thread, NULL);
- Host::ThreadJoin(m_operation_thread, &result, NULL);
- m_operation_thread = LLDB_INVALID_HOST_THREAD;
+ m_operation_thread.Cancel();
+ m_operation_thread.Join(nullptr);
+ m_operation_thread.Reset();
}