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 12 #include "Plugins/Process/Utility/NativeRegisterContextRegisterInfo.h" 13 #include "lldb/Host/common/NativeThreadProtocol.h" 14 15 namespace lldb_private { 16 namespace process_linux { 17 18 class NativeRegisterContextLinux : public NativeRegisterContextRegisterInfo { 19 public: 20 NativeRegisterContextLinux(NativeThreadProtocol &native_thread, 21 RegisterInfoInterface *reg_info_interface_p); 22 23 // This function is implemented in the NativeRegisterContextLinux_* subclasses 24 // to create a new instance of the host specific NativeRegisterContextLinux. 25 // The implementations can't collide as only one NativeRegisterContextLinux_* 26 // variant should be compiled into the final executable. 27 static std::unique_ptr<NativeRegisterContextLinux> 28 CreateHostNativeRegisterContextLinux(const ArchSpec &target_arch, 29 NativeThreadProtocol &native_thread); 30 31 // Invalidates cached values in register context data structures 32 virtual void InvalidateAllRegisters(){} 33 34 struct SyscallData { 35 /// The syscall instruction. If the architecture uses software 36 /// single-stepping, the instruction should also be followed by a trap to 37 /// ensure the process is stopped after the syscall. 38 llvm::ArrayRef<uint8_t> Insn; 39 40 /// Registers used for syscall arguments. The first register is used to 41 /// store the syscall number. 42 llvm::ArrayRef<uint32_t> Args; 43 44 uint32_t Result; ///< Register containing the syscall result. 45 }; 46 /// Return architecture-specific data needed to make inferior syscalls, if 47 /// they are supported. 48 virtual llvm::Optional<SyscallData> GetSyscallData() { return llvm::None; } 49 50 struct MmapData { 51 // Syscall numbers can be found (e.g.) in /usr/include/asm/unistd.h for the 52 // relevant architecture. 53 unsigned SysMmap; ///< mmap syscall number. 54 unsigned SysMunmap; ///< munmap syscall number 55 }; 56 /// Return the architecture-specific data needed to make mmap syscalls, if 57 /// they are supported. 58 virtual llvm::Optional<MmapData> GetMmapData() { return llvm::None; } 59 60 protected: 61 lldb::ByteOrder GetByteOrder() const; 62 63 virtual Status ReadRegisterRaw(uint32_t reg_index, RegisterValue ®_value); 64 65 virtual Status WriteRegisterRaw(uint32_t reg_index, 66 const RegisterValue ®_value); 67 68 virtual Status ReadRegisterSet(void *buf, size_t buf_size, 69 unsigned int regset); 70 71 virtual Status WriteRegisterSet(void *buf, size_t buf_size, 72 unsigned int regset); 73 74 virtual Status ReadGPR(); 75 76 virtual Status WriteGPR(); 77 78 virtual Status ReadFPR(); 79 80 virtual Status WriteFPR(); 81 82 virtual void *GetGPRBuffer() = 0; 83 84 virtual size_t GetGPRSize() const { 85 return GetRegisterInfoInterface().GetGPRSize(); 86 } 87 88 virtual void *GetFPRBuffer() = 0; 89 90 virtual size_t GetFPRSize() = 0; 91 92 virtual uint32_t GetPtraceOffset(uint32_t reg_index) { 93 return GetRegisterInfoAtIndex(reg_index)->byte_offset; 94 } 95 96 // The Do*** functions are executed on the privileged thread and can perform 97 // ptrace 98 // operations directly. 99 virtual Status DoReadRegisterValue(uint32_t offset, const char *reg_name, 100 uint32_t size, RegisterValue &value); 101 102 virtual Status DoWriteRegisterValue(uint32_t offset, const char *reg_name, 103 const RegisterValue &value); 104 }; 105 106 } // namespace process_linux 107 } // namespace lldb_private 108 109 #endif // #ifndef lldb_NativeRegisterContextLinux_h 110