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 
14 using namespace lldb_private;
15 using namespace lldb;
16 
17 // http://svnweb.freebsd.org/base/head/sys/x86/include/reg.h
18 typedef 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;
40  uint64_t rip;
41  uint64_t cs;
42  uint64_t rflags;
43  uint64_t rsp;
44  uint64_t ss;
45 } GPR;
46 
47 struct 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 
56 struct 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
69 #include "RegisterInfos_x86_64.h"
70 #undef DECLARE_REGISTER_INFOS_X86_64_STRUCT
71 
72 static std::vector<lldb_private::RegisterInfo> &GetSharedRegisterInfoVector() {
73  static std::vector<lldb_private::RegisterInfo> register_infos;
74  return register_infos;
75 }
76 
77 static 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(
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]);
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
94 #include "RegisterInfos_x86_64.h"
95 #undef UPDATE_REGISTER_INFOS_I386_STRUCT_WITH_X86_64_OFFSETS
96  }
97 
98  return &g_register_infos[0];
99 }
100 
101 static 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 
114 static 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 
137 size_t RegisterContextFreeBSD_x86_64::GetGPRSize() const { return sizeof(GPR); }
138 
140  return m_register_info_p;
141 }
142 
144  return m_register_count;
145 }
DBG
Definition: RegisterContextFreeBSD_i386.cpp:38
r12
@ r12
Definition: CompactUnwindInfo.cpp:705
RegisterContextFreeBSD_x86_64::GetRegisterCount
uint32_t GetRegisterCount() const override
Definition: RegisterContextFreeBSD_x86_64.cpp:143
lldb_private::ArchSpec
Definition: ArchSpec.h:33
RegisterContextFreeBSD_x86_64::GetGPRSize
size_t GetGPRSize() const override
Definition: RegisterContextFreeBSD_x86_64.cpp:137
lldb_private::ArchSpec::GetMachine
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition: ArchSpec.cpp:667
_GPR::rip
uint64_t rip
Definition: RegisterContextFreeBSD_x86_64.cpp:40
r10
@ r10
Definition: CompactUnwindInfo.cpp:703
lldb_private::RegisterInfoInterface
Definition: RegisterInfoInterface.h:21
_GPR::rbp
uint64_t rbp
Definition: RegisterContextFreeBSD_x86_64.cpp:29
RegisterInfos_x86_64.h
_GPR::rbx
uint64_t rbx
Definition: RegisterContextFreeBSD_x86_64.cpp:30
g_register_infos
static const RegisterInfo g_register_infos[]
Definition: ABIMacOSX_arm.cpp:37
_GPR::ds
uint16_t ds
Definition: RegisterContextFreeBSD_x86_64.cpp:39
UserArea::fpr
FPR fpr
Definition: RegisterContextFreeBSD_x86_64.cpp:58
RegisterContextFreeBSD_x86_64::m_register_info_p
const lldb_private::RegisterInfo * m_register_info_p
Definition: RegisterContextFreeBSD_x86_64.h:26
GetSharedRegisterInfoVector
static std::vector< lldb_private::RegisterInfo > & GetSharedRegisterInfoVector()
Definition: RegisterContextFreeBSD_x86_64.cpp:72
UserArea
Definition: RegisterContext_mips.h:368
RegisterContextFreeBSD_x86_64::RegisterContextFreeBSD_x86_64
RegisterContextFreeBSD_x86_64(const lldb_private::ArchSpec &target_arch)
Definition: RegisterContextFreeBSD_x86_64.cpp:131
PrivateGetRegisterInfoPtr
static const RegisterInfo * PrivateGetRegisterInfoPtr(const lldb_private::ArchSpec &target_arch)
Definition: RegisterContextFreeBSD_x86_64.cpp:102
_GPR::ss
uint64_t ss
Definition: RegisterContextFreeBSD_x86_64.cpp:44
_GPR::rdi
uint64_t rdi
Definition: RegisterContextFreeBSD_x86_64.cpp:27
RegisterContextPOSIX_x86.h
r8
@ r8
Definition: CompactUnwindInfo.cpp:701
GPR
struct _GPR GPR
_GPR::rsi
uint64_t rsi
Definition: RegisterContextFreeBSD_x86_64.cpp:28
_GPR::es
uint16_t es
Definition: RegisterContextFreeBSD_x86_64.cpp:38
PrivateGetRegisterCount
static uint32_t PrivateGetRegisterCount(const lldb_private::ArchSpec &target_arch)
Definition: RegisterContextFreeBSD_x86_64.cpp:115
_GPR::err
uint32_t err
Definition: RegisterContextFreeBSD_x86_64.cpp:37
GetRegisterInfo_i386
static const RegisterInfo * GetRegisterInfo_i386(const lldb_private::ArchSpec &arch)
Definition: RegisterContextFreeBSD_x86_64.cpp:78
r11
@ r11
Definition: CompactUnwindInfo.cpp:704
r14
@ r14
Definition: CompactUnwindInfo.cpp:707
RegisterContextFreeBSD_x86_64::GetRegisterInfo
const lldb_private::RegisterInfo * GetRegisterInfo() const override
Definition: RegisterContextFreeBSD_x86_64.cpp:139
_GPR::cs
uint64_t cs
Definition: RegisterContextFreeBSD_x86_64.cpp:41
_GPR::rcx
uint64_t rcx
Definition: RegisterContextFreeBSD_x86_64.cpp:32
_GPR::rsp
uint64_t rsp
Definition: RegisterContextFreeBSD_x86_64.cpp:43
lldb_private::FPR
Definition: RegisterContext_x86.h:363
_GPR::fs
uint16_t fs
Definition: RegisterContextFreeBSD_x86_64.cpp:35
_GPR::gs
uint16_t gs
Definition: RegisterContextFreeBSD_x86_64.cpp:36
RegisterContextFreeBSD_x86_64.h
GPR
Definition: RegisterContextFreeBSD_i386.cpp:16
lldb_private::k_num_registers_i386
@ k_num_registers_i386
Definition: lldb-x86-register-enums.h:127
uint32_t
_GPR::rflags
uint64_t rflags
Definition: RegisterContextFreeBSD_x86_64.cpp:42
RegisterContextFreeBSD_i386.h
RegisterContextFreeBSD_x86_64::m_register_count
const uint32_t m_register_count
Definition: RegisterContextFreeBSD_x86_64.h:27
uint16_t
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
r15
@ r15
Definition: CompactUnwindInfo.cpp:708
_GPR::rdx
uint64_t rdx
Definition: RegisterContextFreeBSD_x86_64.cpp:31
RegisterContextFreeBSD_i386
Definition: RegisterContextFreeBSD_i386.h:14
_GPR::trapno
uint32_t trapno
Definition: RegisterContextFreeBSD_x86_64.cpp:34
_GPR::rax
uint64_t rax
Definition: RegisterContextFreeBSD_x86_64.cpp:33
r9
@ r9
Definition: CompactUnwindInfo.cpp:702
lldb
Definition: SBAddress.h:15
r13
@ r13
Definition: CompactUnwindInfo.cpp:706