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 "llvm/Support/Threading.h"
13#include <vector>
14
15using namespace lldb_private;
16using namespace lldb;
17
18// http://svnweb.freebsd.org/base/head/sys/x86/include/reg.h
19typedef struct _GPR {
20 uint64_t r15;
21 uint64_t r14;
22 uint64_t r13;
23 uint64_t r12;
24 uint64_t r11;
25 uint64_t r10;
26 uint64_t r9;
27 uint64_t r8;
28 uint64_t rdi;
29 uint64_t rsi;
30 uint64_t rbp;
31 uint64_t rbx;
32 uint64_t rdx;
33 uint64_t rcx;
34 uint64_t rax;
35 uint32_t trapno;
36 uint16_t fs;
37 uint16_t gs;
38 uint32_t err;
39 uint16_t es;
40 uint16_t ds;
41 uint64_t rip;
42 uint64_t cs;
43 uint64_t rflags;
44 uint64_t rsp;
45 uint64_t ss;
47
48struct DBG {
49 uint64_t dr[16]; /* debug registers */
50 /* Index 0-3: debug address registers */
51 /* Index 4-5: reserved */
52 /* Index 6: debug status */
53 /* Index 7: debug control */
54 /* Index 8-15: reserved */
55};
56
57struct UserArea {
58 GPR gpr;
60 DBG dbg;
61};
62
63#define DR_OFFSET(reg_index) \
64 (LLVM_EXTENSION offsetof(UserArea, dbg) + \
65 LLVM_EXTENSION offsetof(DBG, dr[reg_index]))
66
67// Include RegisterInfos_x86_64 to declare our g_register_infos_x86_64
68// structure.
69#define DECLARE_REGISTER_INFOS_X86_64_STRUCT
71#undef DECLARE_REGISTER_INFOS_X86_64_STRUCT
72
73static std::vector<lldb_private::RegisterInfo> &
75 static std::vector<lldb_private::RegisterInfo> g_register_infos;
76 static llvm::once_flag g_initialized;
77 llvm::call_once(g_initialized, [&]() {
78 if (g_register_infos.empty()) {
79 // Copy the register information from base class
80 std::unique_ptr<RegisterContextFreeBSD_i386> reg_interface(
82 const RegisterInfo *base_info = reg_interface->GetRegisterInfo();
83 g_register_infos.insert(g_register_infos.end(), &base_info[0],
84 &base_info[k_num_registers_i386]);
85
86// Include RegisterInfos_x86_64 to update the g_register_infos structure
87// with x86_64 offsets.
88#define UPDATE_REGISTER_INFOS_I386_STRUCT_WITH_X86_64_OFFSETS
90#undef UPDATE_REGISTER_INFOS_I386_STRUCT_WITH_X86_64_OFFSETS
91 }
92 });
93 return g_register_infos;
94}
95
96static const RegisterInfo *
98 switch (target_arch.GetMachine()) {
99 case llvm::Triple::x86:
100 return &GetSharedRegisterInfoVector_i386(target_arch)[0];
101 case llvm::Triple::x86_64:
102 return g_register_infos_x86_64;
103 default:
104 assert(false && "Unhandled target architecture.");
105 return nullptr;
106 }
107}
108
109static uint32_t
111 switch (target_arch.GetMachine()) {
112 case llvm::Triple::x86:
113 // This vector should have already been filled.
114 assert(!GetSharedRegisterInfoVector_i386(target_arch).empty() &&
115 "i386 register info vector not filled.");
116 return static_cast<uint32_t>(
117 GetSharedRegisterInfoVector_i386(target_arch).size());
118 case llvm::Triple::x86_64:
119 return static_cast<uint32_t>(sizeof(g_register_infos_x86_64) /
120 sizeof(g_register_infos_x86_64[0]));
121 default:
122 assert(false && "Unhandled target architecture.");
123 return 0;
124 }
125}
126
132
133size_t RegisterContextFreeBSD_x86_64::GetGPRSize() const { return sizeof(GPR); }
134
138
static const RegisterInfo g_register_infos[]
#define GPR(r16)
Definition ABIX86.cpp:145
static bool g_initialized
static const RegisterInfo * PrivateGetRegisterInfoPtr(const lldb_private::ArchSpec &target_arch)
static uint32_t PrivateGetRegisterCount(const lldb_private::ArchSpec &target_arch)
static std::vector< lldb_private::RegisterInfo > & GetSharedRegisterInfoVector_i386(const lldb_private::ArchSpec &arch)
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:677
RegisterInfoInterface(const lldb_private::ArchSpec &target_arch)
A class that represents a running process on the host machine.
GPR_linux_mips gpr
FPR_linux_mips fpr
Every register is described in detail including its name, alternate name (optional),...