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 //===---------------------------------------------------------------------===//
11 #include "RegisterContextPOSIX_x86.h"
12 #include "RegisterContextLinux_i386.h"
13 #include "RegisterContextLinux_x86_64.h"
15 using namespace lldb_private;
55 GPR gpr; // General purpose registers.
56 int32_t fpvalid; // True if FPU is being used.
58 FXSAVE fpr; // General purpose floating point registers (see FPR for extended 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.
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.
77 #define DR_OFFSET(reg_index) \
78 (LLVM_EXTENSION offsetof(UserArea, dbg) + \
79 LLVM_EXTENSION offsetof(DBG, dr[reg_index]))
81 //---------------------------------------------------------------------------
82 // Include RegisterInfos_x86_64 to declare our g_register_infos_x86_64 structure.
83 //---------------------------------------------------------------------------
84 #define DECLARE_REGISTER_INFOS_X86_64_STRUCT
85 #include "RegisterInfos_x86_64.h"
86 #undef DECLARE_REGISTER_INFOS_X86_64_STRUCT
88 static std::vector<lldb_private::RegisterInfo>&
89 GetPrivateRegisterInfoVector ()
91 static std::vector<lldb_private::RegisterInfo> g_register_infos;
92 return g_register_infos;
95 static const RegisterInfo *
96 GetRegisterInfo_i386(const lldb_private::ArchSpec &arch)
98 std::vector<lldb_private::RegisterInfo> &g_register_infos = GetPrivateRegisterInfoVector ();
100 // Allocate RegisterInfo only once
101 if (g_register_infos.empty())
103 // Copy the register information from base class
104 std::unique_ptr<RegisterContextLinux_i386> reg_interface(new RegisterContextLinux_i386 (arch));
105 const RegisterInfo *base_info = reg_interface->GetRegisterInfo();
106 g_register_infos.insert(g_register_infos.end(), &base_info[0], &base_info[k_num_registers_i386]);
108 //---------------------------------------------------------------------------
109 // Include RegisterInfos_x86_64 to update the g_register_infos structure
110 // with x86_64 offsets.
111 //---------------------------------------------------------------------------
112 #define UPDATE_REGISTER_INFOS_I386_STRUCT_WITH_X86_64_OFFSETS
113 #include "RegisterInfos_x86_64.h"
114 #undef UPDATE_REGISTER_INFOS_I386_STRUCT_WITH_X86_64_OFFSETS
117 return &g_register_infos[0];
120 static const RegisterInfo *
121 GetRegisterInfoPtr (const ArchSpec &target_arch)
123 switch (target_arch.GetMachine())
125 case llvm::Triple::x86:
126 return GetRegisterInfo_i386 (target_arch);
127 case llvm::Triple::x86_64:
128 return g_register_infos_x86_64;
130 assert(false && "Unhandled target architecture.");
136 GetRegisterInfoCount (const ArchSpec &target_arch)
138 switch (target_arch.GetMachine())
140 case llvm::Triple::x86:
142 assert (!GetPrivateRegisterInfoVector ().empty () && "i386 register info not yet filled.");
143 return static_cast<uint32_t> (GetPrivateRegisterInfoVector ().size ());
145 case llvm::Triple::x86_64:
146 return static_cast<uint32_t> (sizeof (g_register_infos_x86_64) / sizeof (g_register_infos_x86_64 [0]));
148 assert(false && "Unhandled target architecture.");
154 GetUserRegisterInfoCount (const ArchSpec &target_arch)
156 switch (target_arch.GetMachine())
158 case llvm::Triple::x86:
159 return static_cast<uint32_t> (k_num_user_registers_i386);
160 case llvm::Triple::x86_64:
161 return static_cast<uint32_t> (k_num_user_registers_x86_64);
163 assert(false && "Unhandled target architecture.");
168 RegisterContextLinux_x86_64::RegisterContextLinux_x86_64(const ArchSpec &target_arch) :
169 lldb_private::RegisterInfoInterface(target_arch),
170 m_register_info_p (GetRegisterInfoPtr (target_arch)),
171 m_register_info_count (GetRegisterInfoCount (target_arch)),
172 m_user_register_count (GetUserRegisterInfoCount (target_arch))
177 RegisterContextLinux_x86_64::GetGPRSize() const
183 RegisterContextLinux_x86_64::GetRegisterInfo() const
185 return m_register_info_p;
189 RegisterContextLinux_x86_64::GetRegisterCount () const
191 return m_register_info_count;
195 RegisterContextLinux_x86_64::GetUserRegisterCount () const
197 return m_user_register_count;