7
7
// ===----------------------------------------------------------------------===//
8
8
9
9
#include " RegisterContextNetBSD_x86_64.h"
10
+ #include " RegisterContextNetBSD_i386.h"
10
11
#include " RegisterContextPOSIX_x86.h"
11
12
#include " llvm/ADT/Triple.h"
12
13
#include " llvm/Support/Compiler.h"
@@ -83,9 +84,40 @@ struct UserArea {
83
84
#include " RegisterInfos_x86_64.h"
84
85
#undef DECLARE_REGISTER_INFOS_X86_64_STRUCT
85
86
87
+ static std::vector<lldb_private::RegisterInfo> &GetPrivateRegisterInfoVector () {
88
+ static std::vector<lldb_private::RegisterInfo> g_register_infos;
89
+ return g_register_infos;
90
+ }
91
+
92
+ static const RegisterInfo *
93
+ GetRegisterInfo_i386 (const lldb_private::ArchSpec &arch) {
94
+ std::vector<lldb_private::RegisterInfo> &g_register_infos =
95
+ GetPrivateRegisterInfoVector ();
96
+
97
+ // Allocate RegisterInfo only once
98
+ if (g_register_infos.empty ()) {
99
+ // Copy the register information from base class
100
+ std::unique_ptr<RegisterContextNetBSD_i386> reg_interface (
101
+ new RegisterContextNetBSD_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]);
105
+
106
+ // Include RegisterInfos_x86_64 to update the g_register_infos structure
107
+ // with x86_64 offsets.
108
+ #define UPDATE_REGISTER_INFOS_I386_STRUCT_WITH_X86_64_OFFSETS
109
+ #include " RegisterInfos_x86_64.h"
110
+ #undef UPDATE_REGISTER_INFOS_I386_STRUCT_WITH_X86_64_OFFSETS
111
+ }
112
+
113
+ return &g_register_infos[0 ];
114
+ }
115
+
86
116
static const RegisterInfo *
87
117
PrivateGetRegisterInfoPtr (const lldb_private::ArchSpec &target_arch) {
88
118
switch (target_arch.GetMachine ()) {
119
+ case llvm::Triple::x86:
120
+ return GetRegisterInfo_i386 (target_arch);
89
121
case llvm::Triple::x86_64:
90
122
return g_register_infos_x86_64;
91
123
default :
@@ -97,6 +129,11 @@ PrivateGetRegisterInfoPtr(const lldb_private::ArchSpec &target_arch) {
97
129
static uint32_t
98
130
PrivateGetRegisterCount (const lldb_private::ArchSpec &target_arch) {
99
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 ());
136
+ }
100
137
case llvm::Triple::x86_64:
101
138
return static_cast <uint32_t >(sizeof (g_register_infos_x86_64) /
102
139
sizeof (g_register_infos_x86_64[0 ]));
@@ -106,11 +143,25 @@ PrivateGetRegisterCount(const lldb_private::ArchSpec &target_arch) {
106
143
}
107
144
}
108
145
146
+ static uint32_t
147
+ PrivateGetUserRegisterCount (const lldb_private::ArchSpec &target_arch) {
148
+ switch (target_arch.GetMachine ()) {
149
+ case llvm::Triple::x86:
150
+ return static_cast <uint32_t >(k_num_user_registers_i386);
151
+ case llvm::Triple::x86_64:
152
+ return static_cast <uint32_t >(k_num_user_registers_x86_64);
153
+ default :
154
+ assert (false && " Unhandled target architecture." );
155
+ return 0 ;
156
+ }
157
+ }
158
+
109
159
RegisterContextNetBSD_x86_64::RegisterContextNetBSD_x86_64 (
110
160
const ArchSpec &target_arch)
111
161
: lldb_private::RegisterInfoInterface(target_arch),
112
162
m_register_info_p(PrivateGetRegisterInfoPtr(target_arch)),
113
- m_register_count(PrivateGetRegisterCount(target_arch)) {}
163
+ m_register_count(PrivateGetRegisterCount(target_arch)),
164
+ m_user_register_count(PrivateGetUserRegisterCount(target_arch)) {}
114
165
115
166
size_t RegisterContextNetBSD_x86_64::GetGPRSize () const { return sizeof (GPR); }
116
167
@@ -121,3 +172,7 @@ const RegisterInfo *RegisterContextNetBSD_x86_64::GetRegisterInfo() const {
121
172
uint32_t RegisterContextNetBSD_x86_64::GetRegisterCount () const {
122
173
return m_register_count;
123
174
}
175
+
176
+ uint32_t RegisterContextNetBSD_x86_64::GetUserRegisterCount () const {
177
+ return m_user_register_count;
178
+ }
0 commit comments