1 //===-- RegisterContextFreeBSD_x86_64.cpp ---------------------------------===//
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
7 //===---------------------------------------------------------------------===//
9 #include "RegisterContextFreeBSD_x86_64.h"
10 #include "RegisterContextFreeBSD_i386.h"
11 #include "RegisterContextPOSIX_x86.h"
14 using namespace lldb_private
;
17 // http://svnweb.freebsd.org/base/head/sys/x86/include/reg.h
48 uint64_t dr
[16]; /* debug registers */
49 /* Index 0-3: debug address registers */
50 /* Index 4-5: reserved */
51 /* Index 6: debug status */
52 /* Index 7: debug control */
53 /* Index 8-15: reserved */
62 #define DR_OFFSET(reg_index) \
63 (LLVM_EXTENSION offsetof(UserArea, dbg) + \
64 LLVM_EXTENSION offsetof(DBG, dr[reg_index]))
66 // Include RegisterInfos_x86_64 to declare our g_register_infos_x86_64
68 #define DECLARE_REGISTER_INFOS_X86_64_STRUCT
69 #include "RegisterInfos_x86_64.h"
70 #undef DECLARE_REGISTER_INFOS_X86_64_STRUCT
72 static std::vector
<lldb_private::RegisterInfo
> &GetSharedRegisterInfoVector() {
73 static std::vector
<lldb_private::RegisterInfo
> register_infos
;
74 return register_infos
;
77 static const RegisterInfo
*
78 GetRegisterInfo_i386(const lldb_private::ArchSpec
&arch
) {
79 static std::vector
<lldb_private::RegisterInfo
> g_register_infos(
80 GetSharedRegisterInfoVector());
82 // Allocate RegisterInfo only once
83 if (g_register_infos
.empty()) {
84 // Copy the register information from base class
85 std::unique_ptr
<RegisterContextFreeBSD_i386
> reg_interface(
86 new RegisterContextFreeBSD_i386(arch
));
87 const RegisterInfo
*base_info
= reg_interface
->GetRegisterInfo();
88 g_register_infos
.insert(g_register_infos
.end(), &base_info
[0],
89 &base_info
[k_num_registers_i386
]);
91 // Include RegisterInfos_x86_64 to update the g_register_infos structure
92 // with x86_64 offsets.
93 #define UPDATE_REGISTER_INFOS_I386_STRUCT_WITH_X86_64_OFFSETS
94 #include "RegisterInfos_x86_64.h"
95 #undef UPDATE_REGISTER_INFOS_I386_STRUCT_WITH_X86_64_OFFSETS
98 return &g_register_infos
[0];
101 static const RegisterInfo
*
102 PrivateGetRegisterInfoPtr(const lldb_private::ArchSpec
&target_arch
) {
103 switch (target_arch
.GetMachine()) {
104 case llvm::Triple::x86
:
105 return GetRegisterInfo_i386(target_arch
);
106 case llvm::Triple::x86_64
:
107 return g_register_infos_x86_64
;
109 assert(false && "Unhandled target architecture.");
115 PrivateGetRegisterCount(const lldb_private::ArchSpec
&target_arch
) {
116 switch (target_arch
.GetMachine()) {
117 case llvm::Triple::x86
:
118 // This vector should have already been filled.
119 assert(!GetSharedRegisterInfoVector().empty() &&
120 "i386 register info vector not filled.");
121 return static_cast<uint32_t>(GetSharedRegisterInfoVector().size());
122 case llvm::Triple::x86_64
:
123 return static_cast<uint32_t>(sizeof(g_register_infos_x86_64
) /
124 sizeof(g_register_infos_x86_64
[0]));
126 assert(false && "Unhandled target architecture.");
131 RegisterContextFreeBSD_x86_64::RegisterContextFreeBSD_x86_64(
132 const ArchSpec
&target_arch
)
133 : lldb_private::RegisterInfoInterface(target_arch
),
134 m_register_info_p(PrivateGetRegisterInfoPtr(target_arch
)),
135 m_register_count(PrivateGetRegisterCount(target_arch
)) {}
137 size_t RegisterContextFreeBSD_x86_64::GetGPRSize() const { return sizeof(GPR
); }
139 const RegisterInfo
*RegisterContextFreeBSD_x86_64::GetRegisterInfo() const {
140 return m_register_info_p
;
143 uint32_t RegisterContextFreeBSD_x86_64::GetRegisterCount() const {
144 return m_register_count
;