LLDB mainline
RegisterContextFreeBSD_x86_64.cpp
Go to the documentation of this file.
1//===-- RegisterContextFreeBSD_x86_64.cpp ---------------------------------===//
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
12#include <vector>
13
14using namespace lldb_private;
15using namespace lldb;
16
17// http://svnweb.freebsd.org/base/head/sys/x86/include/reg.h
18typedef struct _GPR {
19 uint64_t r15;
20 uint64_t r14;
21 uint64_t r13;
22 uint64_t r12;
23 uint64_t r11;
24 uint64_t r10;
25 uint64_t r9;
26 uint64_t r8;
27 uint64_t rdi;
28 uint64_t rsi;
29 uint64_t rbp;
30 uint64_t rbx;
31 uint64_t rdx;
32 uint64_t rcx;
33 uint64_t rax;
34 uint32_t trapno;
35 uint16_t fs;
36 uint16_t gs;
37 uint32_t err;
38 uint16_t es;
39 uint16_t ds;
40 uint64_t rip;
41 uint64_t cs;
42 uint64_t rflags;
43 uint64_t rsp;
44 uint64_t ss;
46
47struct DBG {
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 */
54};
55
56struct UserArea {
57 GPR gpr;
59 DBG dbg;
60};
61
62#define DR_OFFSET(reg_index) \
63 (LLVM_EXTENSION offsetof(UserArea, dbg) + \
64 LLVM_EXTENSION offsetof(DBG, dr[reg_index]))
65
66// Include RegisterInfos_x86_64 to declare our g_register_infos_x86_64
67// structure.
68#define DECLARE_REGISTER_INFOS_X86_64_STRUCT
70#undef DECLARE_REGISTER_INFOS_X86_64_STRUCT
71
72static std::vector<lldb_private::RegisterInfo> &GetSharedRegisterInfoVector() {
73 static std::vector<lldb_private::RegisterInfo> register_infos;
74 return register_infos;
75}
76
77static const RegisterInfo *
79 static std::vector<lldb_private::RegisterInfo> g_register_infos(
81
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(
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]);
90
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
95#undef UPDATE_REGISTER_INFOS_I386_STRUCT_WITH_X86_64_OFFSETS
96 }
97
98 return &g_register_infos[0];
99}
100
101static const RegisterInfo *
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;
108 default:
109 assert(false && "Unhandled target architecture.");
110 return nullptr;
111 }
112}
113
114static uint32_t
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]));
125 default:
126 assert(false && "Unhandled target architecture.");
127 return 0;
128 }
129}
130
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)) {}
136
137size_t RegisterContextFreeBSD_x86_64::GetGPRSize() const { return sizeof(GPR); }
138
140 return m_register_info_p;
141}
142
144 return m_register_count;
145}
static const RegisterInfo g_register_infos[]
static const RegisterInfo * PrivateGetRegisterInfoPtr(const lldb_private::ArchSpec &target_arch)
struct _GPR GPR
static const RegisterInfo * GetRegisterInfo_i386(const lldb_private::ArchSpec &arch)
static uint32_t PrivateGetRegisterCount(const lldb_private::ArchSpec &target_arch)
static std::vector< lldb_private::RegisterInfo > & GetSharedRegisterInfoVector()
const lldb_private::RegisterInfo * m_register_info_p
const lldb_private::RegisterInfo * GetRegisterInfo() const override
RegisterContextFreeBSD_x86_64(const lldb_private::ArchSpec &target_arch)
An architecture specification class.
Definition: ArchSpec.h:31
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition: ArchSpec.cpp:701
RegisterInfo interface to patch RegisterInfo structure for archs.
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
GPR_linux_mips gpr
Every register is described in detail including its name, alternate name (optional),...