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