]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/Plugins/Process/Utility/RegisterContextLinux_arm.cpp
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / source / Plugins / Process / Utility / RegisterContextLinux_arm.cpp
1 //===-- RegisterContextLinux_arm.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 <cassert>
11 #include <stddef.h>
12 #include <vector>
13
14 #include "lldb/lldb-defines.h"
15 #include "llvm/Support/Compiler.h"
16
17 #include "RegisterContextLinux_arm.h"
18
19 using namespace lldb;
20 using namespace lldb_private;
21
22 // Based on RegisterContextDarwin_arm.cpp
23 #define GPR_OFFSET(idx) ((idx)*4)
24 #define FPU_OFFSET(idx) ((idx)*4 + sizeof(RegisterContextLinux_arm::GPR))
25 #define FPSCR_OFFSET                                                           \
26   (LLVM_EXTENSION offsetof(RegisterContextLinux_arm::FPU, fpscr) +             \
27    sizeof(RegisterContextLinux_arm::GPR))
28 #define EXC_OFFSET(idx)                                                        \
29   ((idx)*4 + sizeof(RegisterContextLinux_arm::GPR) +                           \
30    sizeof(RegisterContextLinux_arm::FPU))
31 #define DBG_OFFSET(reg)                                                        \
32   ((LLVM_EXTENSION offsetof(RegisterContextLinux_arm::DBG, reg) +              \
33     sizeof(RegisterContextLinux_arm::GPR) +                                    \
34     sizeof(RegisterContextLinux_arm::FPU) +                                    \
35     sizeof(RegisterContextLinux_arm::EXC)))
36
37 #define DEFINE_DBG(reg, i)                                                     \
38   #reg, NULL, sizeof(((RegisterContextLinux_arm::DBG *) NULL)->reg[i]),        \
39                       DBG_OFFSET(reg[i]), eEncodingUint, eFormatHex,           \
40                                  {LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,    \
41                                   LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM,    \
42                                   dbg_##reg##i },                              \
43                                   NULL, NULL, NULL, 0
44 #define REG_CONTEXT_SIZE                                                       \
45   (sizeof(RegisterContextLinux_arm::GPR) +                                     \
46    sizeof(RegisterContextLinux_arm::FPU) +                                     \
47    sizeof(RegisterContextLinux_arm::EXC))
48
49 //-----------------------------------------------------------------------------
50 // Include RegisterInfos_arm to declare our g_register_infos_arm structure.
51 //-----------------------------------------------------------------------------
52 #define DECLARE_REGISTER_INFOS_ARM_STRUCT
53 #include "RegisterInfos_arm.h"
54 #undef DECLARE_REGISTER_INFOS_ARM_STRUCT
55
56 static const lldb_private::RegisterInfo *
57 GetRegisterInfoPtr(const lldb_private::ArchSpec &target_arch) {
58   switch (target_arch.GetMachine()) {
59   case llvm::Triple::arm:
60     return g_register_infos_arm;
61   default:
62     assert(false && "Unhandled target architecture.");
63     return NULL;
64   }
65 }
66
67 static uint32_t
68 GetRegisterInfoCount(const lldb_private::ArchSpec &target_arch) {
69   switch (target_arch.GetMachine()) {
70   case llvm::Triple::arm:
71     return static_cast<uint32_t>(sizeof(g_register_infos_arm) /
72                                  sizeof(g_register_infos_arm[0]));
73   default:
74     assert(false && "Unhandled target architecture.");
75     return 0;
76   }
77 }
78
79 RegisterContextLinux_arm::RegisterContextLinux_arm(
80     const lldb_private::ArchSpec &target_arch)
81     : lldb_private::RegisterInfoInterface(target_arch),
82       m_register_info_p(GetRegisterInfoPtr(target_arch)),
83       m_register_info_count(GetRegisterInfoCount(target_arch)) {}
84
85 size_t RegisterContextLinux_arm::GetGPRSize() const {
86   return sizeof(struct RegisterContextLinux_arm::GPR);
87 }
88
89 const lldb_private::RegisterInfo *
90 RegisterContextLinux_arm::GetRegisterInfo() const {
91   return m_register_info_p;
92 }
93
94 uint32_t RegisterContextLinux_arm::GetRegisterCount() const {
95   return m_register_info_count;
96 }