1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
//===-- NativeRegisterContextLinux.h ----------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef lldb_NativeRegisterContextLinux_h
#define lldb_NativeRegisterContextLinux_h
#include "Plugins/Process/Utility/NativeRegisterContextRegisterInfo.h"
#include "lldb/Host/common/NativeThreadProtocol.h"
#include "lldb/Target/MemoryTagManager.h"
#include "llvm/Support/Error.h"
#include <optional>
namespace lldb_private {
namespace process_linux {
class NativeThreadLinux;
class NativeRegisterContextLinux
: public virtual NativeRegisterContextRegisterInfo {
public:
// These static methods are implemented individual
// NativeRegisterContextLinux_* subclasses. The implementations can't collide
// as only one NativeRegisterContextLinux_* variant should be compiled into
// the final executable.
// Return a NativeRegisterContextLinux instance suitable for debugging the
// given thread.
static std::unique_ptr<NativeRegisterContextLinux>
CreateHostNativeRegisterContextLinux(const ArchSpec &target_arch,
NativeThreadLinux &native_thread);
// Determine the architecture of the thread given by its ID.
static llvm::Expected<ArchSpec> DetermineArchitecture(lldb::tid_t tid);
// Invalidates cached values in register context data structures
virtual void InvalidateAllRegisters(){}
struct SyscallData {
/// The syscall instruction. If the architecture uses software
/// single-stepping, the instruction should also be followed by a trap to
/// ensure the process is stopped after the syscall.
llvm::ArrayRef<uint8_t> Insn;
/// Registers used for syscall arguments. The first register is used to
/// store the syscall number.
llvm::ArrayRef<uint32_t> Args;
uint32_t Result; ///< Register containing the syscall result.
};
/// Return architecture-specific data needed to make inferior syscalls, if
/// they are supported.
virtual std::optional<SyscallData> GetSyscallData() { return std::nullopt; }
struct MmapData {
// Syscall numbers can be found (e.g.) in /usr/include/asm/unistd.h for the
// relevant architecture.
unsigned SysMmap; ///< mmap syscall number.
unsigned SysMunmap; ///< munmap syscall number
};
/// Return the architecture-specific data needed to make mmap syscalls, if
/// they are supported.
virtual std::optional<MmapData> GetMmapData() { return std::nullopt; }
struct MemoryTaggingDetails {
/// Object with tag handling utilities. If the function below returns
/// a valid structure, you can assume that this pointer is valid.
std::unique_ptr<MemoryTagManager> manager;
int ptrace_read_req; /// ptrace operation number for memory tag read
int ptrace_write_req; /// ptrace operation number for memory tag write
};
/// Return architecture specific data needed to use memory tags,
/// if they are supported.
virtual llvm::Expected<MemoryTaggingDetails>
GetMemoryTaggingDetails(int32_t type) {
return llvm::createStringError(
llvm::inconvertibleErrorCode(),
"Architecture does not support memory tagging");
}
protected:
// NB: This constructor is here only because gcc<=6.5 requires a virtual base
// class initializer on abstract class (even though it is never used). It can
// be deleted once we move to gcc>=7.0.
NativeRegisterContextLinux(NativeThreadProtocol &thread)
: NativeRegisterContextRegisterInfo(thread, nullptr) {}
lldb::ByteOrder GetByteOrder() const;
virtual Status ReadRegisterRaw(uint32_t reg_index, RegisterValue ®_value);
virtual Status WriteRegisterRaw(uint32_t reg_index,
const RegisterValue ®_value);
virtual Status ReadRegisterSet(void *buf, size_t buf_size,
unsigned int regset);
virtual Status WriteRegisterSet(void *buf, size_t buf_size,
unsigned int regset);
virtual Status ReadGPR();
virtual Status WriteGPR();
virtual Status ReadFPR();
virtual Status WriteFPR();
virtual void *GetGPRBuffer() = 0;
virtual size_t GetGPRSize() const {
return GetRegisterInfoInterface().GetGPRSize();
}
virtual void *GetFPRBuffer() = 0;
virtual size_t GetFPRSize() = 0;
virtual uint32_t GetPtraceOffset(uint32_t reg_index) {
return GetRegisterInfoAtIndex(reg_index)->byte_offset;
}
// The Do*** functions are executed on the privileged thread and can perform
// ptrace
// operations directly.
virtual Status DoReadRegisterValue(uint32_t offset, const char *reg_name,
uint32_t size, RegisterValue &value);
virtual Status DoWriteRegisterValue(uint32_t offset, const char *reg_name,
const RegisterValue &value);
// Determine the architecture via GPR size, as reported by
// PTRACE_GETREGSET(NT_PRSTATUS).
static llvm::Expected<ArchSpec>
DetermineArchitectureViaGPR(lldb::tid_t tid, size_t gpr64_size);
};
} // namespace process_linux
} // namespace lldb_private
#endif // #ifndef lldb_NativeRegisterContextLinux_h
|