LLDB  mainline
RegisterContextPOSIX_ppc64le.cpp
Go to the documentation of this file.
1 //===-- RegisterContextPOSIX_ppc64le.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 
9 #include <cstring>
10 #include <errno.h>
11 #include <stdint.h>
12 
13 #include "lldb/Target/Process.h"
14 #include "lldb/Target/Target.h"
15 #include "lldb/Target/Thread.h"
18 #include "lldb/Utility/Endian.h"
20 #include "lldb/Utility/Scalar.h"
21 #include "llvm/Support/Compiler.h"
22 
24 
25 using namespace lldb_private;
26 using namespace lldb;
27 
28 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 static const uint32_t g_vsx_regnums[] = {
83 };
84 
85 // Number of register sets provided by this context.
86 enum { k_num_register_sets = 4 };
87 
88 static const RegisterSet g_reg_sets_ppc64le[k_num_register_sets] = {
89  {"General Purpose Registers", "gpr", k_num_gpr_registers_ppc64le,
90  g_gpr_regnums},
91  {"Floating Point Registers", "fpr", k_num_fpr_registers_ppc64le,
92  g_fpr_regnums},
93  {"Altivec/VMX Registers", "vmx", k_num_vmx_registers_ppc64le,
94  g_vmx_regnums},
95  {"VSX Registers", "vsx", k_num_vsx_registers_ppc64le, g_vsx_regnums},
96 };
97 
99  return (reg <= k_last_gpr_ppc64le); // GPR's come first.
100 }
101 
103  return (reg >= k_first_fpr_ppc64le) && (reg <= k_last_fpr_ppc64le);
104 }
105 
107  return (reg >= k_first_vmx_ppc64le) && (reg <= k_last_vmx_ppc64le);
108 }
109 
111  return (reg >= k_first_vsx_ppc64le) && (reg <= k_last_vsx_ppc64le);
112 }
113 
115  Thread &thread, uint32_t concrete_frame_idx,
116  RegisterInfoInterface *register_info)
117  : RegisterContext(thread, concrete_frame_idx) {
118  m_register_info_up.reset(register_info);
119 }
120 
122 
124  assert(reg < k_num_registers_ppc64le && "Invalid register number.");
125  return GetRegisterInfo()[reg].byte_offset;
126 }
127 
129  assert(reg < k_num_registers_ppc64le && "Invalid register number.");
130  return GetRegisterInfo()[reg].byte_size;
131 }
132 
134  size_t num_registers = k_num_registers_ppc64le;
135  return num_registers;
136 }
137 
139  return m_register_info_up->GetGPRSize();
140 }
141 
143  // Commonly, this method is overridden and g_register_infos is copied and
144  // specialized. So, use GetRegisterInfo() rather than g_register_infos in
145  // this scope.
146  return m_register_info_up->GetRegisterInfo();
147 }
148 
149 const RegisterInfo *
151  if (reg < k_num_registers_ppc64le)
152  return &GetRegisterInfo()[reg];
153  else
154  return NULL;
155 }
156 
158  size_t sets = 0;
159  for (size_t set = 0; set < k_num_register_sets; ++set) {
160  if (IsRegisterSetAvailable(set))
161  ++sets;
162  }
163 
164  return sets;
165 }
166 
167 const RegisterSet *RegisterContextPOSIX_ppc64le::GetRegisterSet(size_t set) {
168  if (IsRegisterSetAvailable(set))
169  return &g_reg_sets_ppc64le[set];
170  else
171  return NULL;
172 }
173 
175  assert(reg < k_num_registers_ppc64le && "Invalid register offset.");
176  return GetRegisterInfo()[reg].name;
177 }
178 
180  // Get the target process whose privileged thread was used for the register
181  // read.
182  lldb::ByteOrder byte_order = eByteOrderInvalid;
183  Process *process = CalculateProcess().get();
184 
185  if (process)
186  byte_order = process->GetByteOrder();
187  return byte_order;
188 }
189 
191  size_t num_sets = k_num_register_sets;
192 
193  return (set_index < num_sets);
194 }
195 
196 // Used when parsing DWARF and EH frame information and any other object file
197 // sections that contain register numbers in them.
199  lldb::RegisterKind kind, uint32_t num) {
200  const uint32_t num_regs = GetRegisterCount();
201 
202  assert(kind < kNumRegisterKinds);
203  for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) {
204  const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg_idx);
205 
206  if (reg_info->kinds[kind] == num)
207  return reg_idx;
208  }
209 
210  return LLDB_INVALID_REGNUM;
211 }
const char * GetRegisterName(unsigned reg)
uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind, uint32_t num) override
Convert from a given register numbering scheme to the lldb register numbering scheme.
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
virtual unsigned GetRegisterOffset(unsigned reg)
RegisterInfo interface to patch RegisterInfo structure for archs.
virtual unsigned GetRegisterSize(unsigned reg)
lldb::ByteOrder GetByteOrder() const
Definition: Process.cpp:3366
static const uint32_t g_vsx_regnums[]
static const RegisterSet g_reg_sets_ppc64le[k_num_register_sets]
RegisterContextPOSIX_ppc64le(lldb_private::Thread &thread, uint32_t concrete_frame_idx, lldb_private::RegisterInfoInterface *register_info)
virtual bool IsRegisterSetAvailable(size_t set_index)
static const uint32_t g_vmx_regnums[]
const lldb_private::RegisterInfo * GetRegisterInfoAtIndex(size_t reg) override
static const uint32_t g_fpr_regnums[]
static const uint32_t g_gpr_regnums[]
A plug-in interface definition class for debugging a process.
Definition: Process.h:353
virtual const lldb_private::RegisterInfo * GetRegisterInfo()
Definition: SBAddress.h:15
lldb::ProcessSP CalculateProcess() override
std::unique_ptr< lldb_private::RegisterInfoInterface > m_register_info_up
const lldb_private::RegisterSet * GetRegisterSet(size_t set) override
#define LLDB_INVALID_REGNUM
Definition: lldb-defines.h:90