Summary: This patch is a stripped down from features a NetBSD process code (patch is kept under 2k LOC). This code has assumption that there is only one thread within a debugged process. The only debugger trap supported is software breakpoint (TRAP_BRKPT). The generic platform code requires to add dummy function for watchpoints etc. These functions are currently empty. This code is not the final platform support as is and it's treated as a base to extend, refactor and address issues afterwards. Supported features: - handle software breakpoints, - correctly attach to a tracee, - support NetBSD specific ptrace(2), - monitor process termination, - monitor SIGTRAP events, - monitor SIGSTOP events, - monitor other signals events, - resume the whole process, - get memory region info perms, - read memory from tracee, - write memory to tracee, - read ELF AUXV, - x86_64 GPR read and write code For the generic framework include: - halt, - detach, - signal, - kill, - allocatememory, - deallocatememory, - update threads, - getarchitecture, - getfileloadaddress, - and others. This code has preliminary AddThread code. Out of interest in this patch: - exec() traps, - hardware debug register traps, - single step trap, - thread creation/termination trap, - process fork(2), vfork(2) and vfork(2) done traps, - syscall entry and exit trap, - threads, - FPR registers, - retrieving tracee's thread name, - non x86_64 support. This code can be used to start a hello world application and trace it. This code can be used by other BSD systems as a starting point to get similar capabilities. Sponsored by <The NetBSD Foundation> Reviewers: emaste, joerg, kettenis, labath Subscribers: mgorny, #lldb Tags: #lldb Differential Revision: https://reviews.llvm.org/D31374 llvm-svn: 298953
140 lines
4.9 KiB
C++
140 lines
4.9 KiB
C++
//===-- 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_
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
#include "lldb/Core/ArchSpec.h"
|
|
#include "lldb/Target/MemoryRegionInfo.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 {
|
|
friend Error NativeProcessProtocol::Launch(
|
|
ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate,
|
|
MainLoop &mainloop, NativeProcessProtocolSP &process_sp);
|
|
|
|
friend Error NativeProcessProtocol::Attach(
|
|
lldb::pid_t pid, NativeProcessProtocol::NativeDelegate &native_delegate,
|
|
MainLoop &mainloop, NativeProcessProtocolSP &process_sp);
|
|
|
|
public:
|
|
// ---------------------------------------------------------------------
|
|
// NativeProcessProtocol Interface
|
|
// ---------------------------------------------------------------------
|
|
Error Resume(const ResumeActionList &resume_actions) override;
|
|
|
|
Error Halt() override;
|
|
|
|
Error Detach() override;
|
|
|
|
Error Signal(int signo) override;
|
|
|
|
Error Kill() override;
|
|
|
|
Error GetMemoryRegionInfo(lldb::addr_t load_addr,
|
|
MemoryRegionInfo &range_info) override;
|
|
|
|
Error ReadMemory(lldb::addr_t addr, void *buf, size_t size,
|
|
size_t &bytes_read) override;
|
|
|
|
Error ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf, size_t size,
|
|
size_t &bytes_read) override;
|
|
|
|
Error WriteMemory(lldb::addr_t addr, const void *buf, size_t size,
|
|
size_t &bytes_written) override;
|
|
|
|
Error AllocateMemory(size_t size, uint32_t permissions,
|
|
lldb::addr_t &addr) override;
|
|
|
|
Error DeallocateMemory(lldb::addr_t addr) override;
|
|
|
|
lldb::addr_t GetSharedLibraryInfoAddress() override;
|
|
|
|
size_t UpdateThreads() override;
|
|
|
|
bool GetArchitecture(ArchSpec &arch) const override;
|
|
|
|
Error SetBreakpoint(lldb::addr_t addr, uint32_t size, bool hardware) override;
|
|
|
|
Error GetLoadedModuleFileSpec(const char *module_path,
|
|
FileSpec &file_spec) override;
|
|
|
|
Error 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 Error PtraceWrapper(int req, lldb::pid_t pid, void *addr = nullptr,
|
|
int data = 0, int *result = nullptr);
|
|
|
|
protected:
|
|
// ---------------------------------------------------------------------
|
|
// NativeProcessProtocol protected interface
|
|
// ---------------------------------------------------------------------
|
|
|
|
Error
|
|
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;
|
|
std::vector<std::pair<MemoryRegionInfo, FileSpec>> m_mem_region_cache;
|
|
|
|
// ---------------------------------------------------------------------
|
|
// Private Instance Methods
|
|
// ---------------------------------------------------------------------
|
|
NativeProcessNetBSD();
|
|
|
|
NativeThreadNetBSDSP AddThread(lldb::tid_t thread_id);
|
|
|
|
Error LaunchInferior(MainLoop &mainloop, ProcessLaunchInfo &launch_info);
|
|
void AttachToInferior(MainLoop &mainloop, lldb::pid_t pid, Error &error);
|
|
|
|
void MonitorCallback(lldb::pid_t pid, int signal);
|
|
void MonitorExited(lldb::pid_t pid, int signal, int status);
|
|
void MonitorSIGSTOP(lldb::pid_t pid);
|
|
void MonitorSIGTRAP(lldb::pid_t pid);
|
|
void MonitorSignal(lldb::pid_t pid, int signal);
|
|
|
|
Error GetSoftwareBreakpointPCOffset(uint32_t &actual_opcode_size);
|
|
Error FixupBreakpointPCAsNeeded(NativeThreadNetBSD &thread);
|
|
Error PopulateMemoryRegionCache();
|
|
void SigchldHandler();
|
|
|
|
::pid_t Attach(lldb::pid_t pid, Error &error);
|
|
};
|
|
|
|
} // namespace process_netbsd
|
|
} // namespace lldb_private
|
|
|
|
#endif // #ifndef liblldb_NativeProcessNetBSD_H_
|