1 //===-- RegisterContextLinux_x86_64.cpp ------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===---------------------------------------------------------------------===//
10 #include "RegisterContextLinux_x86_64.h"
11 #include "RegisterContextLinux_i386.h"
12 #include "RegisterContextPOSIX_x86.h"
15 using namespace lldb_private;
53 GPR gpr; // General purpose registers.
54 int32_t fpvalid; // True if FPU is being used.
56 FXSAVE fpr; // General purpose floating point registers (see FPR for extended
58 uint64_t tsize; // Text segment size.
59 uint64_t dsize; // Data segment size.
60 uint64_t ssize; // Stack segment size.
61 uint64_t start_code; // VM address of text.
62 uint64_t start_stack; // VM address of stack bottom (top in rsp).
63 int64_t signal; // Signal causing core dump.
64 int32_t reserved; // Unused.
66 uint64_t ar0; // Location of GPR's.
67 FXSAVE *fpstate; // Location of FPR's.
68 uint64_t magic; // Identifier for core dumps.
69 char u_comm[32]; // Command causing core dump.
70 DBG dbg; // Debug registers.
71 uint64_t error_code; // CPU error code.
72 uint64_t fault_address; // Control register CR3.
75 #define DR_OFFSET(reg_index) \
76 (LLVM_EXTENSION offsetof(UserArea, dbg) + \
77 LLVM_EXTENSION offsetof(DBG, dr[reg_index]))
79 //---------------------------------------------------------------------------
80 // Include RegisterInfos_x86_64 to declare our g_register_infos_x86_64
82 //---------------------------------------------------------------------------
83 #define DECLARE_REGISTER_INFOS_X86_64_STRUCT
84 #include "RegisterInfos_x86_64.h"
85 #undef DECLARE_REGISTER_INFOS_X86_64_STRUCT
87 static std::vector<lldb_private::RegisterInfo> &GetPrivateRegisterInfoVector() {
88 static std::vector<lldb_private::RegisterInfo> g_register_infos;
89 return g_register_infos;
92 static const RegisterInfo *
93 GetRegisterInfo_i386(const lldb_private::ArchSpec &arch) {
94 std::vector<lldb_private::RegisterInfo> &g_register_infos =
95 GetPrivateRegisterInfoVector();
97 // Allocate RegisterInfo only once
98 if (g_register_infos.empty()) {
99 // Copy the register information from base class
100 std::unique_ptr<RegisterContextLinux_i386> reg_interface(
101 new RegisterContextLinux_i386(arch));
102 const RegisterInfo *base_info = reg_interface->GetRegisterInfo();
103 g_register_infos.insert(g_register_infos.end(), &base_info[0],
104 &base_info[k_num_registers_i386]);
106 //---------------------------------------------------------------------------
107 // Include RegisterInfos_x86_64 to update the g_register_infos structure
108 // with x86_64 offsets.
109 //---------------------------------------------------------------------------
110 #define UPDATE_REGISTER_INFOS_I386_STRUCT_WITH_X86_64_OFFSETS
111 #include "RegisterInfos_x86_64.h"
112 #undef UPDATE_REGISTER_INFOS_I386_STRUCT_WITH_X86_64_OFFSETS
115 return &g_register_infos[0];
118 static const RegisterInfo *GetRegisterInfoPtr(const ArchSpec &target_arch) {
119 switch (target_arch.GetMachine()) {
120 case llvm::Triple::x86:
121 return GetRegisterInfo_i386(target_arch);
122 case llvm::Triple::x86_64:
123 return g_register_infos_x86_64;
125 assert(false && "Unhandled target architecture.");
130 static uint32_t GetRegisterInfoCount(const ArchSpec &target_arch) {
131 switch (target_arch.GetMachine()) {
132 case llvm::Triple::x86: {
133 assert(!GetPrivateRegisterInfoVector().empty() &&
134 "i386 register info not yet filled.");
135 return static_cast<uint32_t>(GetPrivateRegisterInfoVector().size());
137 case llvm::Triple::x86_64:
138 return static_cast<uint32_t>(sizeof(g_register_infos_x86_64) /
139 sizeof(g_register_infos_x86_64[0]));
141 assert(false && "Unhandled target architecture.");
146 static uint32_t GetUserRegisterInfoCount(const ArchSpec &target_arch) {
147 switch (target_arch.GetMachine()) {
148 case llvm::Triple::x86:
149 return static_cast<uint32_t>(k_num_user_registers_i386);
150 case llvm::Triple::x86_64:
151 return static_cast<uint32_t>(k_num_user_registers_x86_64);
153 assert(false && "Unhandled target architecture.");
158 RegisterContextLinux_x86_64::RegisterContextLinux_x86_64(
159 const ArchSpec &target_arch)
160 : lldb_private::RegisterInfoInterface(target_arch),
161 m_register_info_p(GetRegisterInfoPtr(target_arch)),
162 m_register_info_count(GetRegisterInfoCount(target_arch)),
163 m_user_register_count(GetUserRegisterInfoCount(target_arch)) {
164 RegisterInfo orig_ax = {"orig_rax",
166 sizeof(((GPR *)NULL)->orig_rax),
167 (LLVM_EXTENSION offsetof(GPR, orig_rax)),
170 {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
171 LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,
172 LLDB_INVALID_REGNUM},
177 d_register_infos.push_back(orig_ax);
180 size_t RegisterContextLinux_x86_64::GetGPRSize() const { return sizeof(GPR); }
182 const std::vector<lldb_private::RegisterInfo> *
183 RegisterContextLinux_x86_64::GetDynamicRegisterInfoP() const {
184 return &d_register_infos;
187 const RegisterInfo *RegisterContextLinux_x86_64::GetRegisterInfo() const {
188 return m_register_info_p;
191 uint32_t RegisterContextLinux_x86_64::GetRegisterCount() const {
192 return m_register_info_count;
195 uint32_t RegisterContextLinux_x86_64::GetUserRegisterCount() const {
196 return m_user_register_count;