LLDB  mainline
RegisterContextPOSIX_powerpc.cpp
Go to the documentation of this file.
1 //===-- RegisterContextPOSIX_powerpc.cpp -------------------------*- C++
2 //-*-===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include <cstring>
11 #include <errno.h>
12 #include <stdint.h>
13 
14 #include "lldb/Target/Process.h"
15 #include "lldb/Target/Target.h"
16 #include "lldb/Target/Thread.h"
19 #include "lldb/Utility/Endian.h"
21 #include "lldb/Utility/Scalar.h"
22 #include "llvm/Support/Compiler.h"
23 
25 
26 using namespace lldb_private;
27 using namespace lldb;
28 
29 static const uint32_t g_gpr_regnums[] = {
40 };
41 
42 static const uint32_t g_fpr_regnums[] = {
52 };
53 
54 static const uint32_t g_vmx_regnums[] = {
64 };
65 
66 // Number of register sets provided by this context.
67 enum { k_num_register_sets = 3 };
68 
69 static const RegisterSet g_reg_sets_powerpc[k_num_register_sets] = {
70  {"General Purpose Registers", "gpr", k_num_gpr_registers_powerpc,
71  g_gpr_regnums},
72  {"Floating Point Registers", "fpr", k_num_fpr_registers_powerpc,
73  g_fpr_regnums},
74  {"Altivec/VMX Registers", "vmx", k_num_vmx_registers_powerpc,
75  g_vmx_regnums},
76 };
77 
78 static_assert(k_first_gpr_powerpc == 0,
79  "GPRs must index starting at 0, or fix IsGPR()");
81  return (reg <= k_last_gpr_powerpc); // GPR's come first.
82 }
83 
85  return (reg >= k_first_fpr) && (reg <= k_last_fpr);
86 }
87 
89  return (reg >= k_first_vmx) && (reg <= k_last_vmx);
90 }
91 
93  Thread &thread, uint32_t concrete_frame_idx,
94  RegisterInfoInterface *register_info)
95  : RegisterContext(thread, concrete_frame_idx) {
96  m_register_info_up.reset(register_info);
97 }
98 
100 
102 
104 
106  assert(reg < k_num_registers_powerpc && "Invalid register number.");
107  return GetRegisterInfo()[reg].byte_offset;
108 }
109 
111  assert(reg < k_num_registers_powerpc && "Invalid register number.");
112  return GetRegisterInfo()[reg].byte_size;
113 }
114 
116  size_t num_registers = k_num_registers_powerpc;
117  return num_registers;
118 }
119 
121  return m_register_info_up->GetGPRSize();
122 }
123 
125  // Commonly, this method is overridden and g_register_infos is copied and
126  // specialized. So, use GetRegisterInfo() rather than g_register_infos in
127  // this scope.
128  return m_register_info_up->GetRegisterInfo();
129 }
130 
131 const RegisterInfo *
133  if (reg < k_num_registers_powerpc)
134  return &GetRegisterInfo()[reg];
135  else
136  return NULL;
137 }
138 
140  size_t sets = 0;
141  for (size_t set = 0; set < k_num_register_sets; ++set) {
142  if (IsRegisterSetAvailable(set))
143  ++sets;
144  }
145 
146  return sets;
147 }
148 
149 const RegisterSet *RegisterContextPOSIX_powerpc::GetRegisterSet(size_t set) {
150  if (IsRegisterSetAvailable(set))
151  return &g_reg_sets_powerpc[set];
152  else
153  return NULL;
154 }
155 
157  assert(reg < k_num_registers_powerpc && "Invalid register offset.");
158  return GetRegisterInfo()[reg].name;
159 }
160 
162  // Get the target process whose privileged thread was used for the register
163  // read.
164  lldb::ByteOrder byte_order = eByteOrderInvalid;
165  Process *process = CalculateProcess().get();
166 
167  if (process)
168  byte_order = process->GetByteOrder();
169  return byte_order;
170 }
171 
173  size_t num_sets = k_num_register_sets;
174 
175  return (set_index < num_sets);
176 }
177 
178 // Used when parsing DWARF and EH frame information and any other object file
179 // sections that contain register numbers in them.
181  lldb::RegisterKind kind, uint32_t num) {
182  const uint32_t num_regs = GetRegisterCount();
183 
184  assert(kind < kNumRegisterKinds);
185  for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) {
186  const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg_idx);
187 
188  if (reg_info->kinds[kind] == num)
189  return reg_idx;
190  }
191 
192  return LLDB_INVALID_REGNUM;
193 }
virtual unsigned GetRegisterOffset(unsigned reg)
static const uint32_t g_gpr_regnums[]
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind, uint32_t num) override
Convert from a given register numbering scheme to the lldb register numbering scheme.
RegisterInfo interface to patch RegisterInfo structure for archs.
lldb::ByteOrder GetByteOrder() const
Definition: Process.cpp:3366
const lldb_private::RegisterSet * GetRegisterSet(size_t set) override
static const uint32_t g_vmx_regnums[]
virtual bool IsRegisterSetAvailable(size_t set_index)
std::unique_ptr< lldb_private::RegisterInfoInterface > m_register_info_up
static const uint32_t g_fpr_regnums[]
A plug-in interface definition class for debugging a process.
Definition: Process.h:353
virtual const lldb_private::RegisterInfo * GetRegisterInfo()
virtual unsigned GetRegisterSize(unsigned reg)
Definition: SBAddress.h:15
lldb::ProcessSP CalculateProcess() override
const char * GetRegisterName(unsigned reg)
RegisterContextPOSIX_powerpc(lldb_private::Thread &thread, uint32_t concrete_frame_idx, lldb_private::RegisterInfoInterface *register_info)
static const RegisterSet g_reg_sets_powerpc[k_num_register_sets]
const lldb_private::RegisterInfo * GetRegisterInfoAtIndex(size_t reg) override
#define LLDB_INVALID_REGNUM
Definition: lldb-defines.h:90