Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@@ -0,0 +1,21 @@
include_directories(.)
include_directories(../POSIX)
include_directories(../Utility)
add_lldb_library(lldbPluginProcessNetBSD PLUGIN
NativeProcessNetBSD.cpp
NativeRegisterContextNetBSD.cpp
NativeRegisterContextNetBSD_x86_64.cpp
NativeThreadNetBSD.cpp
LINK_LIBS
lldbCore
lldbHost
lldbSymbol
lldbTarget
lldbUtility
lldbPluginProcessPOSIX
lldbPluginProcessUtility
LINK_COMPONENTS
Support
)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,140 @@
//===-- NativeProcessNetBSD.h --------------------------------- -*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_NativeProcessNetBSD_H_
#define liblldb_NativeProcessNetBSD_H_
#include "lldb/Target/MemoryRegionInfo.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/FileSpec.h"
#include "NativeThreadNetBSD.h"
#include "lldb/Host/common/NativeProcessProtocol.h"
namespace lldb_private {
namespace process_netbsd {
/// @class NativeProcessNetBSD
/// @brief Manages communication with the inferior (debugee) process.
///
/// Upon construction, this class prepares and launches an inferior process for
/// debugging.
///
/// Changes in the inferior process state are broadcasted.
class NativeProcessNetBSD : public NativeProcessProtocol {
public:
class Factory : public NativeProcessProtocol::Factory {
public:
llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
Launch(ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate,
MainLoop &mainloop) const override;
llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
Attach(lldb::pid_t pid, NativeDelegate &native_delegate,
MainLoop &mainloop) const override;
};
// ---------------------------------------------------------------------
// NativeProcessProtocol Interface
// ---------------------------------------------------------------------
Status Resume(const ResumeActionList &resume_actions) override;
Status Halt() override;
Status Detach() override;
Status Signal(int signo) override;
Status Kill() override;
Status GetMemoryRegionInfo(lldb::addr_t load_addr,
MemoryRegionInfo &range_info) override;
Status ReadMemory(lldb::addr_t addr, void *buf, size_t size,
size_t &bytes_read) override;
Status ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf, size_t size,
size_t &bytes_read) override;
Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size,
size_t &bytes_written) override;
Status AllocateMemory(size_t size, uint32_t permissions,
lldb::addr_t &addr) override;
Status DeallocateMemory(lldb::addr_t addr) override;
lldb::addr_t GetSharedLibraryInfoAddress() override;
size_t UpdateThreads() override;
const ArchSpec &GetArchitecture() const override { return m_arch; }
Status SetBreakpoint(lldb::addr_t addr, uint32_t size,
bool hardware) override;
Status GetLoadedModuleFileSpec(const char *module_path,
FileSpec &file_spec) override;
Status GetFileLoadAddress(const llvm::StringRef &file_name,
lldb::addr_t &load_addr) override;
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
GetAuxvData() const override;
// ---------------------------------------------------------------------
// Interface used by NativeRegisterContext-derived classes.
// ---------------------------------------------------------------------
static Status PtraceWrapper(int req, lldb::pid_t pid, void *addr = nullptr,
int data = 0, int *result = nullptr);
protected:
// ---------------------------------------------------------------------
// NativeProcessProtocol protected interface
// ---------------------------------------------------------------------
Status
GetSoftwareBreakpointTrapOpcode(size_t trap_opcode_size_hint,
size_t &actual_opcode_size,
const uint8_t *&trap_opcode_bytes) override;
private:
MainLoop::SignalHandleUP m_sigchld_handle;
ArchSpec m_arch;
LazyBool m_supports_mem_region = eLazyBoolCalculate;
std::vector<std::pair<MemoryRegionInfo, FileSpec>> m_mem_region_cache;
// ---------------------------------------------------------------------
// Private Instance Methods
// ---------------------------------------------------------------------
NativeProcessNetBSD(::pid_t pid, int terminal_fd, NativeDelegate &delegate,
const ArchSpec &arch, MainLoop &mainloop);
bool HasThreadNoLock(lldb::tid_t thread_id);
NativeThreadNetBSD &AddThread(lldb::tid_t thread_id);
void MonitorCallback(lldb::pid_t pid, int signal);
void MonitorExited(lldb::pid_t pid, WaitStatus status);
void MonitorSIGSTOP(lldb::pid_t pid);
void MonitorSIGTRAP(lldb::pid_t pid);
void MonitorSignal(lldb::pid_t pid, int signal);
Status GetSoftwareBreakpointPCOffset(uint32_t &actual_opcode_size);
Status FixupBreakpointPCAsNeeded(NativeThreadNetBSD &thread);
Status PopulateMemoryRegionCache();
void SigchldHandler();
Status Attach();
Status ReinitializeThreads();
};
} // namespace process_netbsd
} // namespace lldb_private
#endif // #ifndef liblldb_NativeProcessNetBSD_H_

View File

@@ -0,0 +1,112 @@
//===-- NativeRegisterContextNetBSD.cpp -------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "NativeRegisterContextNetBSD.h"
#include "lldb/Host/common/NativeProcessProtocol.h"
using namespace lldb_private;
using namespace lldb_private::process_netbsd;
// clang-format off
#include <sys/types.h>
#include <sys/ptrace.h>
// clang-format on
NativeRegisterContextNetBSD::NativeRegisterContextNetBSD(
NativeThreadProtocol &native_thread,
RegisterInfoInterface *reg_info_interface_p)
: NativeRegisterContextRegisterInfo(native_thread,
reg_info_interface_p) {}
Status NativeRegisterContextNetBSD::ReadGPR() {
void *buf = GetGPRBuffer();
if (!buf)
return Status("GPR buffer is NULL");
return DoReadGPR(buf);
}
Status NativeRegisterContextNetBSD::WriteGPR() {
void *buf = GetGPRBuffer();
if (!buf)
return Status("GPR buffer is NULL");
return DoWriteGPR(buf);
}
Status NativeRegisterContextNetBSD::ReadFPR() {
void *buf = GetFPRBuffer();
if (!buf)
return Status("FPR buffer is NULL");
return DoReadFPR(buf);
}
Status NativeRegisterContextNetBSD::WriteFPR() {
void *buf = GetFPRBuffer();
if (!buf)
return Status("FPR buffer is NULL");
return DoWriteFPR(buf);
}
Status NativeRegisterContextNetBSD::ReadDBR() {
void *buf = GetDBRBuffer();
if (!buf)
return Status("DBR buffer is NULL");
return DoReadDBR(buf);
}
Status NativeRegisterContextNetBSD::WriteDBR() {
void *buf = GetDBRBuffer();
if (!buf)
return Status("DBR buffer is NULL");
return DoWriteDBR(buf);
}
Status NativeRegisterContextNetBSD::DoReadGPR(void *buf) {
return NativeProcessNetBSD::PtraceWrapper(PT_GETREGS, GetProcessPid(), buf,
m_thread.GetID());
}
Status NativeRegisterContextNetBSD::DoWriteGPR(void *buf) {
return NativeProcessNetBSD::PtraceWrapper(PT_SETREGS, GetProcessPid(), buf,
m_thread.GetID());
}
Status NativeRegisterContextNetBSD::DoReadFPR(void *buf) {
return NativeProcessNetBSD::PtraceWrapper(PT_GETFPREGS, GetProcessPid(), buf,
m_thread.GetID());
}
Status NativeRegisterContextNetBSD::DoWriteFPR(void *buf) {
return NativeProcessNetBSD::PtraceWrapper(PT_SETFPREGS, GetProcessPid(), buf,
m_thread.GetID());
}
Status NativeRegisterContextNetBSD::DoReadDBR(void *buf) {
return NativeProcessNetBSD::PtraceWrapper(PT_GETDBREGS, GetProcessPid(), buf,
m_thread.GetID());
}
Status NativeRegisterContextNetBSD::DoWriteDBR(void *buf) {
return NativeProcessNetBSD::PtraceWrapper(PT_SETDBREGS, GetProcessPid(), buf,
m_thread.GetID());
}
NativeProcessNetBSD &NativeRegisterContextNetBSD::GetProcess() {
return static_cast<NativeProcessNetBSD &>(m_thread.GetProcess());
}
::pid_t NativeRegisterContextNetBSD::GetProcessPid() {
return GetProcess().GetID();
}

View File

@@ -0,0 +1,72 @@
//===-- NativeRegisterContextNetBSD.h ---------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef lldb_NativeRegisterContextNetBSD_h
#define lldb_NativeRegisterContextNetBSD_h
#include "lldb/Host/common/NativeThreadProtocol.h"
#include "Plugins/Process/NetBSD/NativeProcessNetBSD.h"
#include "Plugins/Process/Utility/NativeRegisterContextRegisterInfo.h"
namespace lldb_private {
namespace process_netbsd {
class NativeRegisterContextNetBSD : public NativeRegisterContextRegisterInfo {
public:
NativeRegisterContextNetBSD(NativeThreadProtocol &native_thread,
RegisterInfoInterface *reg_info_interface_p);
// This function is implemented in the NativeRegisterContextNetBSD_*
// subclasses to create a new instance of the host specific
// NativeRegisterContextNetBSD. The implementations can't collide as only one
// NativeRegisterContextNetBSD_* variant should be compiled into the final
// executable.
static NativeRegisterContextNetBSD *
CreateHostNativeRegisterContextNetBSD(const ArchSpec &target_arch,
NativeThreadProtocol &native_thread);
protected:
virtual Status ReadGPR();
virtual Status WriteGPR();
virtual Status ReadFPR();
virtual Status WriteFPR();
virtual Status ReadDBR();
virtual Status WriteDBR();
virtual void *GetGPRBuffer() { return nullptr; }
virtual size_t GetGPRSize() {
return GetRegisterInfoInterface().GetGPRSize();
}
virtual void *GetFPRBuffer() { return nullptr; }
virtual size_t GetFPRSize() { return 0; }
virtual void *GetDBRBuffer() { return nullptr; }
virtual size_t GetDBRSize() { return 0; }
virtual Status DoReadGPR(void *buf);
virtual Status DoWriteGPR(void *buf);
virtual Status DoReadFPR(void *buf);
virtual Status DoWriteFPR(void *buf);
virtual Status DoReadDBR(void *buf);
virtual Status DoWriteDBR(void *buf);
virtual NativeProcessNetBSD &GetProcess();
virtual ::pid_t GetProcessPid();
};
} // namespace process_netbsd
} // namespace lldb_private
#endif // #ifndef lldb_NativeRegisterContextNetBSD_h

View File

@@ -0,0 +1,95 @@
//===-- NativeRegisterContextNetBSD_x86_64.h --------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#if defined(__x86_64__)
#ifndef lldb_NativeRegisterContextNetBSD_x86_64_h
#define lldb_NativeRegisterContextNetBSD_x86_64_h
// clang-format off
#include <sys/param.h>
#include <sys/types.h>
#include <machine/reg.h>
// clang-format on
#include "Plugins/Process/NetBSD/NativeRegisterContextNetBSD.h"
#include "Plugins/Process/Utility/RegisterContext_x86.h"
#include "Plugins/Process/Utility/lldb-x86-register-enums.h"
namespace lldb_private {
namespace process_netbsd {
class NativeProcessNetBSD;
class NativeRegisterContextNetBSD_x86_64 : public NativeRegisterContextNetBSD {
public:
NativeRegisterContextNetBSD_x86_64(const ArchSpec &target_arch,
NativeThreadProtocol &native_thread);
uint32_t GetRegisterSetCount() const override;
const RegisterSet *GetRegisterSet(uint32_t set_index) const override;
Status ReadRegister(const RegisterInfo *reg_info,
RegisterValue &reg_value) override;
Status WriteRegister(const RegisterInfo *reg_info,
const RegisterValue &reg_value) override;
Status ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override;
Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override;
Status IsWatchpointHit(uint32_t wp_index, bool &is_hit) override;
Status GetWatchpointHitIndex(uint32_t &wp_index,
lldb::addr_t trap_addr) override;
Status IsWatchpointVacant(uint32_t wp_index, bool &is_vacant) override;
bool ClearHardwareWatchpoint(uint32_t wp_index) override;
Status ClearAllHardwareWatchpoints() override;
Status SetHardwareWatchpointWithIndex(lldb::addr_t addr, size_t size,
uint32_t watch_flags,
uint32_t wp_index);
uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
uint32_t watch_flags) override;
lldb::addr_t GetWatchpointAddress(uint32_t wp_index) override;
uint32_t NumSupportedHardwareWatchpoints() override;
protected:
void *GetGPRBuffer() override { return &m_gpr_x86_64; }
void *GetFPRBuffer() override { return &m_fpr_x86_64; }
void *GetDBRBuffer() override { return &m_dbr_x86_64; }
private:
// Private member types.
enum { GPRegSet, FPRegSet, DBRegSet };
// Private member variables.
struct reg m_gpr_x86_64;
struct fpreg m_fpr_x86_64;
struct dbreg m_dbr_x86_64;
int GetSetForNativeRegNum(int reg_num) const;
int ReadRegisterSet(uint32_t set);
int WriteRegisterSet(uint32_t set);
};
} // namespace process_netbsd
} // namespace lldb_private
#endif // #ifndef lldb_NativeRegisterContextNetBSD_x86_64_h
#endif // defined(__x86_64__)

View File

@@ -0,0 +1,206 @@
//===-- NativeThreadNetBSD.cpp -------------------------------- -*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "NativeThreadNetBSD.h"
#include "NativeRegisterContextNetBSD.h"
#include "NativeProcessNetBSD.h"
#include "Plugins/Process/POSIX/CrashReason.h"
#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
#include "lldb/Core/RegisterValue.h"
#include "lldb/Core/State.h"
#include "lldb/Utility/LLDBAssert.h"
#include <sstream>
using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::process_netbsd;
NativeThreadNetBSD::NativeThreadNetBSD(NativeProcessNetBSD &process,
lldb::tid_t tid)
: NativeThreadProtocol(process, tid), m_state(StateType::eStateInvalid),
m_stop_info(), m_reg_context_up(
NativeRegisterContextNetBSD::CreateHostNativeRegisterContextNetBSD(process.GetArchitecture(), *this)
), m_stop_description() {}
void NativeThreadNetBSD::SetStoppedBySignal(uint32_t signo,
const siginfo_t *info) {
Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
LLDB_LOG(log, "tid = {0} in called with signal {1}", GetID(), signo);
SetStopped();
m_stop_info.reason = StopReason::eStopReasonSignal;
m_stop_info.details.signal.signo = signo;
m_stop_description.clear();
if (info) {
switch (signo) {
case SIGSEGV:
case SIGBUS:
case SIGFPE:
case SIGILL:
const auto reason = GetCrashReason(*info);
m_stop_description = GetCrashReasonString(reason, *info);
break;
}
}
}
void NativeThreadNetBSD::SetStoppedByBreakpoint() {
SetStopped();
m_stop_info.reason = StopReason::eStopReasonBreakpoint;
m_stop_info.details.signal.signo = SIGTRAP;
}
void NativeThreadNetBSD::SetStoppedByTrace() {
SetStopped();
m_stop_info.reason = StopReason::eStopReasonTrace;
m_stop_info.details.signal.signo = SIGTRAP;
}
void NativeThreadNetBSD::SetStoppedByExec() {
SetStopped();
m_stop_info.reason = StopReason::eStopReasonExec;
m_stop_info.details.signal.signo = SIGTRAP;
}
void NativeThreadNetBSD::SetStoppedByWatchpoint(uint32_t wp_index) {
SetStopped();
lldbassert(wp_index != LLDB_INVALID_INDEX32 && "wp_index cannot be invalid");
std::ostringstream ostr;
ostr << GetRegisterContext().GetWatchpointAddress(wp_index) << " ";
ostr << wp_index;
ostr << " " << GetRegisterContext().GetWatchpointHitAddress(wp_index);
m_stop_description = ostr.str();
m_stop_info.reason = StopReason::eStopReasonWatchpoint;
m_stop_info.details.signal.signo = SIGTRAP;
}
void NativeThreadNetBSD::SetStopped() {
const StateType new_state = StateType::eStateStopped;
m_state = new_state;
m_stop_description.clear();
}
void NativeThreadNetBSD::SetRunning() {
m_state = StateType::eStateRunning;
m_stop_info.reason = StopReason::eStopReasonNone;
}
void NativeThreadNetBSD::SetStepping() {
m_state = StateType::eStateStepping;
m_stop_info.reason = StopReason::eStopReasonNone;
}
std::string NativeThreadNetBSD::GetName() { return std::string(""); }
lldb::StateType NativeThreadNetBSD::GetState() { return m_state; }
bool NativeThreadNetBSD::GetStopReason(ThreadStopInfo &stop_info,
std::string &description) {
Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_THREAD));
description.clear();
switch (m_state) {
case eStateStopped:
case eStateCrashed:
case eStateExited:
case eStateSuspended:
case eStateUnloaded:
stop_info = m_stop_info;
description = m_stop_description;
return true;
case eStateInvalid:
case eStateConnected:
case eStateAttaching:
case eStateLaunching:
case eStateRunning:
case eStateStepping:
case eStateDetached:
LLDB_LOG(log, "tid = {0} in state {1} cannot answer stop reason", GetID(),
StateAsCString(m_state));
return false;
}
llvm_unreachable("unhandled StateType!");
}
NativeRegisterContext& NativeThreadNetBSD::GetRegisterContext() {
assert(m_reg_context_up);
return *m_reg_context_up;
}
Status NativeThreadNetBSD::SetWatchpoint(lldb::addr_t addr, size_t size,
uint32_t watch_flags, bool hardware) {
if (!hardware)
return Status("not implemented");
if (m_state == eStateLaunching)
return Status();
Status error = RemoveWatchpoint(addr);
if (error.Fail())
return error;
uint32_t wp_index = GetRegisterContext().SetHardwareWatchpoint(addr, size, watch_flags);
if (wp_index == LLDB_INVALID_INDEX32)
return Status("Setting hardware watchpoint failed.");
m_watchpoint_index_map.insert({addr, wp_index});
return Status();
}
Status NativeThreadNetBSD::RemoveWatchpoint(lldb::addr_t addr) {
auto wp = m_watchpoint_index_map.find(addr);
if (wp == m_watchpoint_index_map.end())
return Status();
uint32_t wp_index = wp->second;
m_watchpoint_index_map.erase(wp);
if (GetRegisterContext().ClearHardwareWatchpoint(wp_index))
return Status();
return Status("Clearing hardware watchpoint failed.");
}
Status NativeThreadNetBSD::SetHardwareBreakpoint(lldb::addr_t addr,
size_t size) {
if (m_state == eStateLaunching)
return Status();
Status error = RemoveHardwareBreakpoint(addr);
if (error.Fail())
return error;
uint32_t bp_index = GetRegisterContext().SetHardwareBreakpoint(addr, size);
if (bp_index == LLDB_INVALID_INDEX32)
return Status("Setting hardware breakpoint failed.");
m_hw_break_index_map.insert({addr, bp_index});
return Status();
}
Status NativeThreadNetBSD::RemoveHardwareBreakpoint(lldb::addr_t addr) {
auto bp = m_hw_break_index_map.find(addr);
if (bp == m_hw_break_index_map.end())
return Status();
uint32_t bp_index = bp->second;
if (GetRegisterContext().ClearHardwareBreakpoint(bp_index)) {
m_hw_break_index_map.erase(bp);
return Status();
}
return Status("Clearing hardware breakpoint failed.");
}

View File

@@ -0,0 +1,81 @@
//===-- NativeThreadNetBSD.h ---------------------------------- -*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef liblldb_NativeThreadNetBSD_H_
#define liblldb_NativeThreadNetBSD_H_
#include "lldb/Host/common/NativeThreadProtocol.h"
#include <csignal>
#include <map>
#include <string>
namespace lldb_private {
namespace process_netbsd {
class NativeProcessNetBSD;
class NativeThreadNetBSD : public NativeThreadProtocol {
friend class NativeProcessNetBSD;
public:
NativeThreadNetBSD(NativeProcessNetBSD &process, lldb::tid_t tid);
// ---------------------------------------------------------------------
// NativeThreadProtocol Interface
// ---------------------------------------------------------------------
std::string GetName() override;
lldb::StateType GetState() override;
bool GetStopReason(ThreadStopInfo &stop_info,
std::string &description) override;
NativeRegisterContext& GetRegisterContext() override;
Status SetWatchpoint(lldb::addr_t addr, size_t size, uint32_t watch_flags,
bool hardware) override;
Status RemoveWatchpoint(lldb::addr_t addr) override;
Status SetHardwareBreakpoint(lldb::addr_t addr, size_t size) override;
Status RemoveHardwareBreakpoint(lldb::addr_t addr) override;
private:
// ---------------------------------------------------------------------
// Interface for friend classes
// ---------------------------------------------------------------------
void SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr);
void SetStoppedByBreakpoint();
void SetStoppedByTrace();
void SetStoppedByExec();
void SetStoppedByWatchpoint(uint32_t wp_index);
void SetStopped();
void SetRunning();
void SetStepping();
// ---------------------------------------------------------------------
// Member Variables
// ---------------------------------------------------------------------
lldb::StateType m_state;
ThreadStopInfo m_stop_info;
std::unique_ptr<NativeRegisterContext> m_reg_context_up;
std::string m_stop_description;
using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>;
WatchpointIndexMap m_watchpoint_index_map;
WatchpointIndexMap m_hw_break_index_map;
};
typedef std::shared_ptr<NativeThreadNetBSD> NativeThreadNetBSDSP;
} // namespace process_netbsd
} // namespace lldb_private
#endif // #ifndef liblldb_NativeThreadNetBSD_H_