]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.cpp
Merge from upstream at 4189ef5d from https://github.com/onetrueawk/awk.git
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / Process / Utility / RegisterContextOpenBSD_x86_64.cpp
1 //===-- RegisterContextOpenBSD_x86_64.cpp ----------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===---------------------------------------------------------------------===//
9
10 #include "RegisterContextOpenBSD_x86_64.h"
11 #include "RegisterContextPOSIX_x86.h"
12 #include <vector>
13
14 using namespace lldb_private;
15 using namespace lldb;
16
17 // /usr/include/machine/reg.h
18 typedef struct _GPR {
19   uint64_t rdi;
20   uint64_t rsi;
21   uint64_t rdx;
22   uint64_t rcx;
23   uint64_t r8;
24   uint64_t r9;
25   uint64_t r10;
26   uint64_t r11;
27   uint64_t r12;
28   uint64_t r13;
29   uint64_t r14;
30   uint64_t r15;
31   uint64_t rbp;
32   uint64_t rbx;
33   uint64_t rax;
34   uint64_t rsp;
35   uint64_t rip;
36   uint64_t rflags;
37   uint64_t cs;
38   uint64_t ss;
39   uint64_t ds;
40   uint64_t es;
41   uint64_t fs;
42   uint64_t gs;
43 } GPR;
44
45 struct DBG {
46   uint64_t dr[16]; /* debug registers */
47                    /* Index 0-3: debug address registers */
48                    /* Index 4-5: reserved */
49                    /* Index 6: debug status */
50                    /* Index 7: debug control */
51                    /* Index 8-15: reserved */
52 };
53
54 struct UserArea {
55   GPR gpr;
56   FPR fpr;
57   DBG dbg;
58 };
59
60 #define DR_OFFSET(reg_index) (LLVM_EXTENSION offsetof(DBG, dr[reg_index]))
61
62 //---------------------------------------------------------------------------
63 // Include RegisterInfos_x86_64 to declare our g_register_infos_x86_64
64 // structure.
65 //---------------------------------------------------------------------------
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 const RegisterInfo *
71 PrivateGetRegisterInfoPtr(const lldb_private::ArchSpec &target_arch) {
72   switch (target_arch.GetMachine()) {
73   case llvm::Triple::x86_64:
74     return g_register_infos_x86_64;
75   default:
76     assert(false && "Unhandled target architecture.");
77     return nullptr;
78   }
79 }
80
81 static uint32_t
82 PrivateGetRegisterCount(const lldb_private::ArchSpec &target_arch) {
83   switch (target_arch.GetMachine()) {
84   case llvm::Triple::x86_64:
85     return static_cast<uint32_t>(sizeof(g_register_infos_x86_64) /
86                                  sizeof(g_register_infos_x86_64[0]));
87   default:
88     assert(false && "Unhandled target architecture.");
89     return 0;
90   }
91 }
92
93 RegisterContextOpenBSD_x86_64::RegisterContextOpenBSD_x86_64(
94     const ArchSpec &target_arch)
95     : lldb_private::RegisterInfoInterface(target_arch),
96       m_register_info_p(PrivateGetRegisterInfoPtr(target_arch)),
97       m_register_count(PrivateGetRegisterCount(target_arch)) {}
98
99 size_t RegisterContextOpenBSD_x86_64::GetGPRSize() const { return sizeof(GPR); }
100
101 const RegisterInfo *RegisterContextOpenBSD_x86_64::GetRegisterInfo() const {
102   return m_register_info_p;
103 }
104
105 uint32_t RegisterContextOpenBSD_x86_64::GetRegisterCount() const {
106   return m_register_count;
107 }