LLDB  mainline
RegisterContextFreeBSD_x86_64.cpp
Go to the documentation of this file.
1 //===-- RegisterContextFreeBSD_x86_64.cpp ----------------------*- C++ -*-===//
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;
60 };
61 
62 #define DR_OFFSET(reg_index) (LLVM_EXTENSION offsetof(DBG, dr[reg_index]))
63 
64 // Include RegisterInfos_x86_64 to declare our g_register_infos_x86_64
65 // structure.
66 #define DECLARE_REGISTER_INFOS_X86_64_STRUCT
67 #include "RegisterInfos_x86_64.h"
68 #undef DECLARE_REGISTER_INFOS_X86_64_STRUCT
69 
70 static std::vector<lldb_private::RegisterInfo> &GetSharedRegisterInfoVector() {
71  static std::vector<lldb_private::RegisterInfo> register_infos;
72  return register_infos;
73 }
74 
75 static const RegisterInfo *
77  static std::vector<lldb_private::RegisterInfo> g_register_infos(
79 
80  // Allocate RegisterInfo only once
81  if (g_register_infos.empty()) {
82  // Copy the register information from base class
83  std::unique_ptr<RegisterContextFreeBSD_i386> reg_interface(
84  new RegisterContextFreeBSD_i386(arch));
85  const RegisterInfo *base_info = reg_interface->GetRegisterInfo();
86  g_register_infos.insert(g_register_infos.end(), &base_info[0],
87  &base_info[k_num_registers_i386]);
88 
89 // Include RegisterInfos_x86_64 to update the g_register_infos structure
90 // with x86_64 offsets.
91 #define UPDATE_REGISTER_INFOS_I386_STRUCT_WITH_X86_64_OFFSETS
92 #include "RegisterInfos_x86_64.h"
93 #undef UPDATE_REGISTER_INFOS_I386_STRUCT_WITH_X86_64_OFFSETS
94  }
95 
96  return &g_register_infos[0];
97 }
98 
99 static const RegisterInfo *
101  switch (target_arch.GetMachine()) {
102  case llvm::Triple::x86:
103  return GetRegisterInfo_i386(target_arch);
104  case llvm::Triple::x86_64:
105  return g_register_infos_x86_64;
106  default:
107  assert(false && "Unhandled target architecture.");
108  return nullptr;
109  }
110 }
111 
112 static uint32_t
114  switch (target_arch.GetMachine()) {
115  case llvm::Triple::x86:
116  // This vector should have already been filled.
117  assert(!GetSharedRegisterInfoVector().empty() &&
118  "i386 register info vector not filled.");
119  return static_cast<uint32_t>(GetSharedRegisterInfoVector().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 
130  const ArchSpec &target_arch)
131  : lldb_private::RegisterInfoInterface(target_arch),
132  m_register_info_p(PrivateGetRegisterInfoPtr(target_arch)),
133  m_register_count(PrivateGetRegisterCount(target_arch)) {}
134 
135 size_t RegisterContextFreeBSD_x86_64::GetGPRSize() const { return sizeof(GPR); }
136 
138  return m_register_info_p;
139 }
140 
142  return m_register_count;
143 }
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
static std::vector< lldb_private::RegisterInfo > & GetSharedRegisterInfoVector()
RegisterInfo interface to patch RegisterInfo structure for archs.
An architecture specification class.
Definition: ArchSpec.h:32
static uint32_t PrivateGetRegisterCount(const lldb_private::ArchSpec &target_arch)
struct _GPR GPR
const lldb_private::RegisterInfo * GetRegisterInfo() const override
static RegisterInfo g_register_infos[]
static const RegisterInfo * PrivateGetRegisterInfoPtr(const lldb_private::ArchSpec &target_arch)
Definition: SBAddress.h:15
RegisterContextFreeBSD_x86_64(const lldb_private::ArchSpec &target_arch)
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition: ArchSpec.cpp:726
static const RegisterInfo * GetRegisterInfo_i386(const lldb_private::ArchSpec &arch)