LLDB mainline
RegisterInfoFreeBSD_x86_64.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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
11#include "RegisterContext_x86.h"
13#include "lldb/lldb-defines.h"
14#include "llvm/Support/Threading.h"
15#include <vector>
16
17using namespace lldb_private;
18using namespace lldb;
19
20// https://cgit.freebsd.org/src/tree/sys/x86/include/reg.h
21typedef struct _GPR {
22 uint64_t r15;
23 uint64_t r14;
24 uint64_t r13;
25 uint64_t r12;
26 uint64_t r11;
27 uint64_t r10;
28 uint64_t r9;
29 uint64_t r8;
30 uint64_t rdi;
31 uint64_t rsi;
32 uint64_t rbp;
33 uint64_t rbx;
34 uint64_t rdx;
35 uint64_t rcx;
36 uint64_t rax;
37 uint32_t trapno;
38 uint16_t fs;
39 uint16_t gs;
40 uint32_t err;
41 uint16_t es;
42 uint16_t ds;
43 uint64_t rip;
44 uint64_t cs;
45 uint64_t rflags;
46 uint64_t rsp;
47 uint64_t ss;
49
50struct DBG {
51 uint64_t dr[16]; /* debug registers */
52 /* Index 0-3: debug address registers */
53 /* Index 4-5: reserved */
54 /* Index 6: debug status */
55 /* Index 7: debug control */
56 /* Index 8-15: reserved */
57};
58
59struct UserArea {
60 GPR gpr;
62 DBG dbg;
63};
64
65#define DR_OFFSET(reg_index) \
66 (LLVM_EXTENSION offsetof(UserArea, dbg) + \
67 LLVM_EXTENSION offsetof(DBG, dr[reg_index]))
68
69// Include RegisterInfos_x86_64 to declare our g_register_infos_x86_64
70// structure.
71#define DECLARE_REGISTER_INFOS_X86_64_STRUCT
73#undef DECLARE_REGISTER_INFOS_X86_64_STRUCT
74
75static std::vector<lldb_private::RegisterInfo> &
77 static std::vector<lldb_private::RegisterInfo> g_register_infos;
78 static llvm::once_flag g_initialized;
79 llvm::call_once(g_initialized, [&]() {
80 if (g_register_infos.empty()) {
81 // Copy the register information from base class
82 std::unique_ptr<RegisterInfoFreeBSD_i386> reg_interface(
83 new RegisterInfoFreeBSD_i386(arch));
84 const RegisterInfo *base_info = reg_interface->GetRegisterInfo();
85 g_register_infos.insert(g_register_infos.end(), &base_info[0],
86 &base_info[k_num_registers_i386]);
87
88// Include RegisterInfos_x86_64 to update the g_register_infos structure
89// with x86_64 offsets.
90#define UPDATE_REGISTER_INFOS_I386_STRUCT_WITH_X86_64_OFFSETS
92#undef UPDATE_REGISTER_INFOS_I386_STRUCT_WITH_X86_64_OFFSETS
93 }
94 });
95 return g_register_infos;
96}
97
98static const RegisterInfo *
100 switch (target_arch.GetMachine()) {
101 case llvm::Triple::x86:
102 return &GetSharedRegisterInfoVector_i386(target_arch)[0];
103 case llvm::Triple::x86_64:
104 return g_register_infos_x86_64;
105 default:
106 assert(false && "Unhandled target architecture.");
107 return nullptr;
108 }
109}
110
111static uint32_t
113 switch (target_arch.GetMachine()) {
114 case llvm::Triple::x86:
115 // This vector should have already been filled.
116 assert(!GetSharedRegisterInfoVector_i386(target_arch).empty() &&
117 "i386 register info vector not filled.");
118 return static_cast<uint32_t>(
119 GetSharedRegisterInfoVector_i386(target_arch).size());
120 case llvm::Triple::x86_64:
121 return static_cast<uint32_t>(sizeof(g_register_infos_x86_64) /
122 sizeof(g_register_infos_x86_64[0]));
123 default:
124 assert(false && "Unhandled target architecture.");
125 return 0;
126 }
127}
128
134
135size_t RegisterInfoFreeBSD_x86_64::GetGPRSize() const { return sizeof(GPR); }
136
140
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)
uint32_t GetRegisterCount() const override
const lldb_private::RegisterInfo * m_register_info_p
const lldb_private::RegisterInfo * GetRegisterInfo() const override
RegisterInfoFreeBSD_x86_64(const lldb_private::ArchSpec &target_arch)
An architecture specification class.
Definition ArchSpec.h:32
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition ArchSpec.cpp:886
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),...