LLDB  mainline
RegisterContextPOSIX_mips64.cpp
Go to the documentation of this file.
1 //===-- RegisterContextPOSIX_mips64.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 
27 
28 using namespace lldb_private;
29 using namespace lldb;
30 
32  return reg < m_registers_count[gpr_registers_count]; // GPR's come first.
33 }
34 
36  int set = GetRegisterSetCount();
37  if (set > 1)
38  return reg < (m_registers_count[fpr_registers_count]
39  + m_registers_count[gpr_registers_count]);
40  return false;
41 }
42 
44  Thread &thread, uint32_t concrete_frame_idx,
45  RegisterInfoInterface *register_info)
46  : RegisterContext(thread, concrete_frame_idx) {
47  m_register_info_up.reset(register_info);
49  int set = GetRegisterSetCount();
50 
51  const RegisterSet *reg_set_ptr;
52  for(int i = 0; i < set; ++i) {
53  reg_set_ptr = GetRegisterSet(i);
54  m_registers_count[i] = reg_set_ptr->num_registers;
55  }
56 
57  assert(m_num_registers ==
58  static_cast<uint32_t>(m_registers_count[gpr_registers_count] +
61 }
62 
64 
66 
68 
70  assert(reg < m_num_registers && "Invalid register number.");
71  return GetRegisterInfo()[reg].byte_offset;
72 }
73 
75  assert(reg < m_num_registers && "Invalid register number.");
76  return GetRegisterInfo()[reg].byte_size;
77 }
78 
80  return m_register_info_up->GetRegisterCount();
81 }
82 
84  return m_register_info_up->GetGPRSize();
85 }
86 
88  // Commonly, this method is overridden and g_register_infos is copied and
89  // specialized. So, use GetRegisterInfo() rather than g_register_infos in
90  // this scope.
91  return m_register_info_up->GetRegisterInfo();
92 }
93 
94 const RegisterInfo *
96  if (reg < m_num_registers)
97  return &GetRegisterInfo()[reg];
98  else
99  return NULL;
100 }
101 
103  ArchSpec target_arch = m_register_info_up->GetTargetArchitecture();
104  switch (target_arch.GetTriple().getOS()) {
105  case llvm::Triple::Linux: {
106  if ((target_arch.GetMachine() == llvm::Triple::mipsel) ||
107  (target_arch.GetMachine() == llvm::Triple::mips)) {
108  const auto *context = static_cast<const RegisterContextLinux_mips *>(
109  m_register_info_up.get());
110  return context->GetRegisterSetCount();
111  }
112  const auto *context = static_cast<const RegisterContextLinux_mips64 *>(
113  m_register_info_up.get());
114  return context->GetRegisterSetCount();
115  }
116  default: {
117  const auto *context = static_cast<const RegisterContextFreeBSD_mips64 *>(
118  m_register_info_up.get());
119  return context->GetRegisterSetCount();
120  }
121 
122  }
123 }
124 
125 const RegisterSet *RegisterContextPOSIX_mips64::GetRegisterSet(size_t set) {
126  ArchSpec target_arch = m_register_info_up->GetTargetArchitecture();
127  switch (target_arch.GetTriple().getOS()) {
128  case llvm::Triple::Linux: {
129  if ((target_arch.GetMachine() == llvm::Triple::mipsel) ||
130  (target_arch.GetMachine() == llvm::Triple::mips)) {
131  const auto *context = static_cast<const RegisterContextLinux_mips *>(
132  m_register_info_up.get());
133  return context->GetRegisterSet(set);
134  }
135  const auto *context = static_cast<const RegisterContextLinux_mips64 *>(
136  m_register_info_up.get());
137  return context->GetRegisterSet(set);
138  }
139  default: {
140  const auto *context = static_cast<const RegisterContextFreeBSD_mips64 *>(
141  m_register_info_up.get());
142  return context->GetRegisterSet(set);
143  }
144  }
145 }
146 
148  assert(reg < m_num_registers && "Invalid register offset.");
149  return GetRegisterInfo()[reg].name;
150 }
151 
153  // Get the target process whose privileged thread was used for the register
154  // read.
155  lldb::ByteOrder byte_order = eByteOrderInvalid;
156  Process *process = CalculateProcess().get();
157 
158  if (process)
159  byte_order = process->GetByteOrder();
160  return byte_order;
161 }
162 
164  size_t num_sets = GetRegisterSetCount();
165 
166  return (set_index < num_sets);
167 }
168 
169 // Used when parsing DWARF and EH frame information and any other object file
170 // sections that contain register numbers in them.
172  lldb::RegisterKind kind, uint32_t num) {
173  const uint32_t num_regs = m_num_registers;
174 
175  assert(kind < kNumRegisterKinds);
176  for (uint32_t reg_idx = 0; reg_idx < num_regs; ++reg_idx) {
177  const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg_idx);
178 
179  if (reg_info->kinds[kind] == num)
180  return reg_idx;
181  }
182 
183  return LLDB_INVALID_REGNUM;
184 }
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
const lldb_private::RegisterSet * GetRegisterSet(size_t set) const
virtual bool IsRegisterSetAvailable(size_t set_index)
RegisterInfo interface to patch RegisterInfo structure for archs.
std::unique_ptr< lldb_private::RegisterInfoInterface > m_register_info_up
uint8_t m_registers_count[register_set_count]
const char * GetRegisterName(unsigned reg)
An architecture specification class.
Definition: ArchSpec.h:32
uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind, uint32_t num) override
Convert from a given register numbering scheme to the lldb register numbering scheme.
lldb::ByteOrder GetByteOrder() const
Definition: Process.cpp:3366
virtual const lldb_private::RegisterInfo * GetRegisterInfo()
RegisterContextPOSIX_mips64(lldb_private::Thread &thread, uint32_t concrete_frame_idx, lldb_private::RegisterInfoInterface *register_info)
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:431
const lldb_private::RegisterSet * GetRegisterSet(size_t set) override
A plug-in interface definition class for debugging a process.
Definition: Process.h:353
const lldb_private::RegisterSet * GetRegisterSet(size_t set) const
virtual unsigned GetRegisterSize(unsigned reg)
Definition: SBAddress.h:15
lldb::ProcessSP CalculateProcess() override
const lldb_private::RegisterSet * GetRegisterSet(size_t set) const
const lldb_private::RegisterInfo * GetRegisterInfoAtIndex(size_t reg) override
virtual unsigned GetRegisterOffset(unsigned reg)
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition: ArchSpec.cpp:726
#define LLDB_INVALID_REGNUM
Definition: lldb-defines.h:90