summaryrefslogtreecommitdiff
path: root/source/Plugins/Process/Linux
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-07-19 07:03:07 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-07-19 07:03:07 +0000
commita884e649599e13d58ce6d2b2a0ce8091ceb48dac (patch)
treef527514e113dd4f771eef3d39e5a5d2da36b8552 /source/Plugins/Process/Linux
parente75e363cb71a7339552b9d943e78ac62b737379b (diff)
Notes
Diffstat (limited to 'source/Plugins/Process/Linux')
-rw-r--r--source/Plugins/Process/Linux/NativeProcessLinux.cpp24
-rw-r--r--source/Plugins/Process/Linux/NativeProcessLinux.h11
-rw-r--r--source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp6
-rw-r--r--source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp4
-rw-r--r--source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.cpp4
-rw-r--r--source/Plugins/Process/Linux/NativeThreadLinux.cpp24
-rw-r--r--source/Plugins/Process/Linux/NativeThreadLinux.h3
-rw-r--r--source/Plugins/Process/Linux/ProcessorTrace.h1
8 files changed, 28 insertions, 49 deletions
diff --git a/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/source/Plugins/Process/Linux/NativeProcessLinux.cpp
index d988ee93a2bc..170d3b100064 100644
--- a/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ b/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -214,7 +214,7 @@ static Status EnsureFDFlags(int fd, int flags) {
// Public Static Methods
// -----------------------------------------------------------------------------
-llvm::Expected<NativeProcessProtocolSP>
+llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
NativeProcessLinux::Factory::Launch(ProcessLaunchInfo &launch_info,
NativeDelegate &native_delegate,
MainLoop &mainloop) const {
@@ -259,14 +259,13 @@ NativeProcessLinux::Factory::Launch(ProcessLaunchInfo &launch_info,
return status.ToError();
}
- std::shared_ptr<NativeProcessLinux> process_sp(new NativeProcessLinux(
+ return std::unique_ptr<NativeProcessLinux>(new NativeProcessLinux(
pid, launch_info.GetPTY().ReleaseMasterFileDescriptor(), native_delegate,
- arch, mainloop));
- process_sp->InitializeThreads({pid});
- return process_sp;
+ arch, mainloop, {pid}));
}
-llvm::Expected<NativeProcessProtocolSP> NativeProcessLinux::Factory::Attach(
+llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
+NativeProcessLinux::Factory::Attach(
lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate,
MainLoop &mainloop) const {
Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
@@ -282,10 +281,8 @@ llvm::Expected<NativeProcessProtocolSP> NativeProcessLinux::Factory::Attach(
if (!tids_or)
return tids_or.takeError();
- std::shared_ptr<NativeProcessLinux> process_sp(
- new NativeProcessLinux(pid, -1, native_delegate, arch, mainloop));
- process_sp->InitializeThreads(*tids_or);
- return process_sp;
+ return std::unique_ptr<NativeProcessLinux>(new NativeProcessLinux(
+ pid, -1, native_delegate, arch, mainloop, *tids_or));
}
// -----------------------------------------------------------------------------
@@ -294,7 +291,8 @@ llvm::Expected<NativeProcessProtocolSP> NativeProcessLinux::Factory::Attach(
NativeProcessLinux::NativeProcessLinux(::pid_t pid, int terminal_fd,
NativeDelegate &delegate,
- const ArchSpec &arch, MainLoop &mainloop)
+ const ArchSpec &arch, MainLoop &mainloop,
+ llvm::ArrayRef<::pid_t> tids)
: NativeProcessProtocol(pid, terminal_fd, delegate), m_arch(arch) {
if (m_terminal_fd != -1) {
Status status = EnsureFDFlags(m_terminal_fd, O_NONBLOCK);
@@ -305,9 +303,7 @@ NativeProcessLinux::NativeProcessLinux(::pid_t pid, int terminal_fd,
m_sigchld_handle = mainloop.RegisterSignal(
SIGCHLD, [this](MainLoopBase &) { SigchldHandler(); }, status);
assert(m_sigchld_handle && status.Success());
-}
-void NativeProcessLinux::InitializeThreads(llvm::ArrayRef<::pid_t> tids) {
for (const auto &tid : tids) {
NativeThreadLinuxSP thread_sp = AddThread(tid);
assert(thread_sp && "AddThread() returned a nullptr thread");
@@ -2009,7 +2005,7 @@ NativeThreadLinuxSP NativeProcessLinux::AddThread(lldb::tid_t thread_id) {
if (m_threads.empty())
SetCurrentThreadID(thread_id);
- auto thread_sp = std::make_shared<NativeThreadLinux>(this, thread_id);
+ auto thread_sp = std::make_shared<NativeThreadLinux>(*this, thread_id);
m_threads.push_back(thread_sp);
if (m_pt_proces_trace_id != LLDB_INVALID_UID) {
diff --git a/source/Plugins/Process/Linux/NativeProcessLinux.h b/source/Plugins/Process/Linux/NativeProcessLinux.h
index 9584713d3654..c9ec002760f8 100644
--- a/source/Plugins/Process/Linux/NativeProcessLinux.h
+++ b/source/Plugins/Process/Linux/NativeProcessLinux.h
@@ -10,7 +10,7 @@
#ifndef liblldb_NativeProcessLinux_H_
#define liblldb_NativeProcessLinux_H_
-// C++ Includes
+#include <csignal>
#include <unordered_set>
// Other libraries and framework includes
@@ -42,11 +42,11 @@ class NativeProcessLinux : public NativeProcessProtocol {
public:
class Factory : public NativeProcessProtocol::Factory {
public:
- llvm::Expected<NativeProcessProtocolSP>
+ llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
Launch(ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate,
MainLoop &mainloop) const override;
- llvm::Expected<NativeProcessProtocolSP>
+ llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
Attach(lldb::pid_t pid, NativeDelegate &native_delegate,
MainLoop &mainloop) const override;
};
@@ -160,15 +160,14 @@ private:
// Private Instance Methods
// ---------------------------------------------------------------------
NativeProcessLinux(::pid_t pid, int terminal_fd, NativeDelegate &delegate,
- const ArchSpec &arch, MainLoop &mainloop);
+ const ArchSpec &arch, MainLoop &mainloop,
+ llvm::ArrayRef<::pid_t> tids);
// Returns a list of process threads that we have attached to.
static llvm::Expected<std::vector<::pid_t>> Attach(::pid_t pid);
static Status SetDefaultPtraceOpts(const lldb::pid_t);
- void InitializeThreads(llvm::ArrayRef<::pid_t> tids);
-
void MonitorCallback(lldb::pid_t pid, bool exited, WaitStatus status);
void WaitForNewThread(::pid_t tid);
diff --git a/source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp b/source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp
index 43253f388019..30f09f0c3a3f 100644
--- a/source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp
+++ b/source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp
@@ -30,11 +30,7 @@ lldb::ByteOrder NativeRegisterContextLinux::GetByteOrder() const {
// read.
lldb::ByteOrder byte_order = lldb::eByteOrderInvalid;
- NativeProcessProtocolSP process_sp(m_thread.GetProcess());
- if (!process_sp)
- return byte_order;
-
- if (!process_sp->GetByteOrder(byte_order)) {
+ if (!m_thread.GetProcess().GetByteOrder(byte_order)) {
// FIXME log here
}
diff --git a/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp b/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
index 1a5b304ac697..7aad062e3f93 100644
--- a/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
+++ b/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp
@@ -873,7 +873,7 @@ Status NativeRegisterContextLinux_arm64::DoReadRegisterValue(
PTRACE_GETREGSET, m_thread.GetID(), &regset, &ioVec, sizeof regs);
if (error.Success()) {
ArchSpec arch;
- if (m_thread.GetProcess()->GetArchitecture(arch))
+ if (m_thread.GetProcess().GetArchitecture(arch))
value.SetBytes((void *)(((unsigned char *)(&regs)) + offset), 16,
arch.GetByteOrder());
else
@@ -890,7 +890,7 @@ Status NativeRegisterContextLinux_arm64::DoReadRegisterValue(
PTRACE_GETREGSET, m_thread.GetID(), &regset, &ioVec, sizeof regs);
if (error.Success()) {
ArchSpec arch;
- if (m_thread.GetProcess()->GetArchitecture(arch))
+ if (m_thread.GetProcess().GetArchitecture(arch))
value.SetBytes((void *)(((unsigned char *)(regs)) + offset), 8,
arch.GetByteOrder());
else
diff --git a/source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.cpp b/source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.cpp
index dee2c064a346..f35ff2be0d94 100644
--- a/source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.cpp
+++ b/source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.cpp
@@ -953,7 +953,7 @@ NativeRegisterContextLinux_mips64::GetWatchpointHitAddress(uint32_t wp_index) {
return LLDB_INVALID_ADDRESS;
EmulatorBaton baton(
- static_cast<NativeProcessLinux *>(m_thread.GetProcess().get()), this);
+ static_cast<NativeProcessLinux *>(&m_thread.GetProcess()), this);
emulator_ap->SetBaton(&baton);
emulator_ap->SetReadMemCallback(&ReadMemoryCallback);
emulator_ap->SetReadRegCallback(&ReadRegisterCallback);
@@ -1034,7 +1034,7 @@ Status NativeRegisterContextLinux_mips64::Read_SR_Config(uint32_t offset,
PTRACE_GETREGS, m_thread.GetID(), NULL, &regs, sizeof regs);
if (error.Success()) {
lldb_private::ArchSpec arch;
- if (m_thread.GetProcess()->GetArchitecture(arch)) {
+ if (m_thread.GetProcess().GetArchitecture(arch)) {
void *target_address = ((uint8_t *)&regs) + offset +
4 * (arch.GetMachine() == llvm::Triple::mips);
value.SetUInt(*(uint32_t *)target_address, size);
diff --git a/source/Plugins/Process/Linux/NativeThreadLinux.cpp b/source/Plugins/Process/Linux/NativeThreadLinux.cpp
index b1d13668f327..5cd40941dcf8 100644
--- a/source/Plugins/Process/Linux/NativeThreadLinux.cpp
+++ b/source/Plugins/Process/Linux/NativeThreadLinux.cpp
@@ -85,7 +85,7 @@ void LogThreadStopInfo(Log &log, const ThreadStopInfo &stop_info,
}
}
-NativeThreadLinux::NativeThreadLinux(NativeProcessLinux *process,
+NativeThreadLinux::NativeThreadLinux(NativeProcessLinux &process,
lldb::tid_t tid)
: NativeThreadProtocol(process, tid), m_state(StateType::eStateInvalid),
m_stop_info(), m_reg_context_sp(), m_stop_description() {}
@@ -144,12 +144,8 @@ NativeRegisterContextSP NativeThreadLinux::GetRegisterContext() {
if (m_reg_context_sp)
return m_reg_context_sp;
- NativeProcessProtocolSP m_process_sp = m_process_wp.lock();
- if (!m_process_sp)
- return NativeRegisterContextSP();
-
ArchSpec target_arch;
- if (!m_process_sp->GetArchitecture(target_arch))
+ if (!m_process.GetArchitecture(target_arch))
return NativeRegisterContextSP();
const uint32_t concrete_frame_idx = 0;
@@ -460,20 +456,10 @@ void NativeThreadLinux::MaybeLogStateChange(lldb::StateType new_state) {
if (new_state == old_state)
return;
- NativeProcessProtocolSP m_process_sp = m_process_wp.lock();
- lldb::pid_t pid =
- m_process_sp ? m_process_sp->GetID() : LLDB_INVALID_PROCESS_ID;
-
- // Log it.
- log->Printf("NativeThreadLinux: thread (pid=%" PRIu64 ", tid=%" PRIu64
- ") changing from state %s to %s",
- pid, GetID(), StateAsCString(old_state),
- StateAsCString(new_state));
+ LLDB_LOG(log, "pid={0}, tid={1}: changing from state {2} to {3}",
+ m_process.GetID(), GetID(), old_state, new_state);
}
NativeProcessLinux &NativeThreadLinux::GetProcess() {
- auto process_sp = std::static_pointer_cast<NativeProcessLinux>(
- NativeThreadProtocol::GetProcess());
- assert(process_sp);
- return *process_sp;
+ return static_cast<NativeProcessLinux &>(m_process);
}
diff --git a/source/Plugins/Process/Linux/NativeThreadLinux.h b/source/Plugins/Process/Linux/NativeThreadLinux.h
index b9126b3752a0..6ae87feffcda 100644
--- a/source/Plugins/Process/Linux/NativeThreadLinux.h
+++ b/source/Plugins/Process/Linux/NativeThreadLinux.h
@@ -14,6 +14,7 @@
#include "lldb/Host/common/NativeThreadProtocol.h"
#include "lldb/lldb-private-forward.h"
+#include <csignal>
#include <map>
#include <memory>
#include <string>
@@ -27,7 +28,7 @@ class NativeThreadLinux : public NativeThreadProtocol {
friend class NativeProcessLinux;
public:
- NativeThreadLinux(NativeProcessLinux *process, lldb::tid_t tid);
+ NativeThreadLinux(NativeProcessLinux &process, lldb::tid_t tid);
// ---------------------------------------------------------------------
// NativeThreadProtocol Interface
diff --git a/source/Plugins/Process/Linux/ProcessorTrace.h b/source/Plugins/Process/Linux/ProcessorTrace.h
index ddcaf0f842b5..6603c7d60478 100644
--- a/source/Plugins/Process/Linux/ProcessorTrace.h
+++ b/source/Plugins/Process/Linux/ProcessorTrace.h
@@ -18,6 +18,7 @@
#include <linux/perf_event.h>
#include <sys/mman.h>
+#include <unistd.h>
namespace lldb_private {