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