LLDB mainline
RegisterInfoLinux_x86_64.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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
11#include "RegisterContext_x86.h"
13#include "lldb/lldb-defines.h"
14#include <vector>
15
16using namespace lldb_private;
17using namespace lldb;
19typedef struct _GPR {
20 uint64_t r15;
21 uint64_t r14;
22 uint64_t r13;
23 uint64_t r12;
24 uint64_t rbp;
25 uint64_t rbx;
26 uint64_t r11;
27 uint64_t r10;
28 uint64_t r9;
29 uint64_t r8;
30 uint64_t rax;
31 uint64_t rcx;
32 uint64_t rdx;
33 uint64_t rsi;
34 uint64_t rdi;
35 uint64_t orig_rax;
36 uint64_t rip;
37 uint64_t cs;
38 uint64_t rflags;
39 uint64_t rsp;
40 uint64_t ss;
41 uint64_t fs_base;
42 uint64_t gs_base;
43 uint64_t ds;
44 uint64_t es;
45 uint64_t fs;
46 uint64_t gs;
48
49struct DBG {
50 uint64_t dr[8];
51};
52
53struct UserArea {
54 GPR gpr; // General purpose registers.
55 int32_t fpvalid; // True if FPU is being used.
56 int32_t pad0;
57 FXSAVE fpr; // General purpose floating point registers (see FPR for extended
58 // register sets).
59 uint64_t tsize; // Text segment size.
60 uint64_t dsize; // Data segment size.
61 uint64_t ssize; // Stack segment size.
62 uint64_t start_code; // VM address of text.
63 uint64_t start_stack; // VM address of stack bottom (top in rsp).
64 int64_t signal; // Signal causing core dump.
65 int32_t reserved; // Unused.
66 int32_t pad1;
67 uint64_t ar0; // Location of GPR's.
68 FXSAVE *fpstate; // Location of FPR's.
69 uint64_t magic; // Identifier for core dumps.
70 char u_comm[32]; // Command causing core dump.
71 DBG dbg; // Debug registers.
72 uint64_t error_code; // CPU error code.
73 uint64_t fault_address; // Control register CR3.
74};
75
76#define DR_OFFSET(reg_index) \
77 (LLVM_EXTENSION offsetof(UserArea, dbg) + \
78 LLVM_EXTENSION offsetof(DBG, dr[reg_index]))
79
80// Include RegisterInfos_x86_64 to declare our g_register_infos_x86_64_with_base
81// structure.
82#define DECLARE_REGISTER_INFOS_X86_64_STRUCT
84#undef DECLARE_REGISTER_INFOS_X86_64_STRUCT
85
86static std::vector<lldb_private::RegisterInfo> &GetPrivateRegisterInfoVector() {
87 static std::vector<lldb_private::RegisterInfo> g_register_infos;
88 return g_register_infos;
89}
90
91static const RegisterInfo *
93 std::vector<lldb_private::RegisterInfo> &g_register_infos =
95
96 // Allocate RegisterInfo only once
97 if (g_register_infos.empty()) {
98 // Copy the register information from base class
99 std::unique_ptr<RegisterInfoLinux_i386> reg_interface(
100 new RegisterInfoLinux_i386(arch));
101 const RegisterInfo *base_info = reg_interface->GetRegisterInfo();
102 g_register_infos.insert(g_register_infos.end(), &base_info[0],
103 &base_info[k_num_registers_i386]);
104
105// Include RegisterInfos_x86_64 to update the g_register_infos structure
106// with x86_64 offsets.
107#define UPDATE_REGISTER_INFOS_I386_STRUCT_WITH_X86_64_OFFSETS
109#undef UPDATE_REGISTER_INFOS_I386_STRUCT_WITH_X86_64_OFFSETS
110 }
111
112 return &g_register_infos[0];
113}
114
115static const RegisterInfo *GetRegisterInfoPtr(const ArchSpec &target_arch) {
116 switch (target_arch.GetMachine()) {
117 case llvm::Triple::x86:
118 return GetRegisterInfo_i386(target_arch);
119 case llvm::Triple::x86_64:
120 return g_register_infos_x86_64_with_base;
121 default:
122 assert(false && "Unhandled target architecture.");
123 return nullptr;
124 }
125}
126
127static uint32_t GetRegisterInfoCount(const ArchSpec &target_arch) {
128 switch (target_arch.GetMachine()) {
129 case llvm::Triple::x86: {
130 assert(!GetPrivateRegisterInfoVector().empty() &&
131 "i386 register info not yet filled.");
132 return static_cast<uint32_t>(GetPrivateRegisterInfoVector().size());
133 }
134 case llvm::Triple::x86_64:
135 return static_cast<uint32_t>(sizeof(g_register_infos_x86_64_with_base) /
136 sizeof(g_register_infos_x86_64_with_base[0]));
137 default:
138 assert(false && "Unhandled target architecture.");
139 return 0;
140 }
141}
142
143static uint32_t GetUserRegisterInfoCount(const ArchSpec &target_arch) {
144 switch (target_arch.GetMachine()) {
145 case llvm::Triple::x86:
146 return static_cast<uint32_t>(k_num_user_registers_i386);
147 case llvm::Triple::x86_64:
148 return static_cast<uint32_t>(x86_64_with_base::k_num_user_registers);
149 default:
150 assert(false && "Unhandled target architecture.");
151 return 0;
152 }
153}
154
156 const ArchSpec &target_arch)
158 target_arch,
159 {"orig_rax",
160 nullptr,
161 sizeof(((GPR *)nullptr)->orig_rax),
162 (LLVM_EXTENSION offsetof(GPR, orig_rax)),
167 nullptr,
168 nullptr,
169 nullptr}),
170 m_register_info_p(GetRegisterInfoPtr(target_arch)),
171 m_register_info_count(GetRegisterInfoCount(target_arch)),
172 m_user_register_count(GetUserRegisterInfoCount(target_arch)) {}
173
175
179
183
static const RegisterInfo g_register_infos[]
#define GPR(r16)
Definition ABIX86.cpp:145
static const RegisterInfo * GetRegisterInfoPtr(const ArchSpec &target_arch)
static uint32_t GetUserRegisterInfoCount(const ArchSpec &target_arch)
static std::vector< lldb_private::RegisterInfo > & GetPrivateRegisterInfoVector()
static uint32_t GetRegisterInfoCount(const ArchSpec &target_arch)
static const RegisterInfo * GetRegisterInfo_i386(const lldb_private::ArchSpec &arch)
struct _GPR GPR
const lldb_private::RegisterInfo * m_register_info_p
uint32_t GetUserRegisterCount() const override
uint32_t GetRegisterCount() const override
RegisterInfoLinux_x86_64(const lldb_private::ArchSpec &target_arch)
const lldb_private::RegisterInfo * GetRegisterInfo() const override
An architecture specification class.
Definition ArchSpec.h:32
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition ArchSpec.cpp:886
RegisterInfoLinux_x86(const ArchSpec &target_arch, RegisterInfo orig_ax_info)
#define LLDB_INVALID_REGNUM
A class that represents a running process on the host machine.
@ eEncodingUint
unsigned integer
GPR_linux_mips gpr
FPR_linux_mips fpr
Every register is described in detail including its name, alternate name (optional),...