LLDB  mainline
RegisterNumber.cpp
Go to the documentation of this file.
1 //===--------------------- RegisterNumber.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 
11 #include "lldb/Target/Thread.h"
12 
13 using namespace lldb_private;
14 
16  lldb::RegisterKind kind, uint32_t num)
17  : m_reg_ctx_sp(thread.GetRegisterContext()), m_regnum(num), m_kind(kind),
18  m_kind_regnum_map(), m_name("") {
19  if (m_reg_ctx_sp.get()) {
20  const lldb_private::RegisterInfo *reginfo =
21  m_reg_ctx_sp->GetRegisterInfoAtIndex(
23  if (reginfo && reginfo->name) {
24  m_name = reginfo->name;
25  }
26  }
27 }
28 
30  : m_reg_ctx_sp(), m_regnum(LLDB_INVALID_REGNUM),
31  m_kind(lldb::kNumRegisterKinds), m_kind_regnum_map(), m_name(nullptr) {}
32 
34  uint32_t num) {
35  m_reg_ctx_sp = thread.GetRegisterContext();
36  m_regnum = num;
37  m_kind = kind;
38  if (m_reg_ctx_sp.get()) {
39  const lldb_private::RegisterInfo *reginfo =
40  m_reg_ctx_sp->GetRegisterInfoAtIndex(
42  if (reginfo && reginfo->name) {
43  m_name = reginfo->name;
44  }
45  }
46 }
47 
49  m_reg_ctx_sp = rhs.m_reg_ctx_sp;
50  m_regnum = rhs.m_regnum;
51  m_kind = rhs.m_kind;
52  for (auto it : rhs.m_kind_regnum_map)
53  m_kind_regnum_map[it.first] = it.second;
54  m_name = rhs.m_name;
55  return *this;
56 }
57 
59  if (IsValid() != rhs.IsValid())
60  return false;
61 
62  if (m_kind == rhs.m_kind) {
63  return m_regnum == rhs.m_regnum;
64  }
65 
66  uint32_t rhs_regnum = rhs.GetAsKind(m_kind);
67  if (rhs_regnum != LLDB_INVALID_REGNUM) {
68  return m_regnum == rhs_regnum;
69  }
70  uint32_t lhs_regnum = GetAsKind(rhs.m_kind);
71  { return lhs_regnum == rhs.m_regnum; }
72  return false;
73 }
74 
75 bool RegisterNumber::operator!=(RegisterNumber &rhs) { return !(*this == rhs); }
76 
78  return m_reg_ctx_sp.get() && m_kind != lldb::kNumRegisterKinds &&
79  m_regnum != LLDB_INVALID_REGNUM;
80 }
81 
83  if (m_regnum == LLDB_INVALID_REGNUM)
84  return LLDB_INVALID_REGNUM;
85 
86  if (kind == m_kind)
87  return m_regnum;
88 
89  Collection::iterator iter = m_kind_regnum_map.find(kind);
90  if (iter != m_kind_regnum_map.end()) {
91  return iter->second;
92  }
93  uint32_t output_regnum = LLDB_INVALID_REGNUM;
94  if (m_reg_ctx_sp &&
95  m_reg_ctx_sp->ConvertBetweenRegisterKinds(m_kind, m_regnum, kind,
96  output_regnum) &&
97  output_regnum != LLDB_INVALID_REGNUM) {
98  m_kind_regnum_map[kind] = output_regnum;
99  }
100  return output_regnum;
101 }
102 
103 uint32_t RegisterNumber::GetRegisterNumber() const { return m_regnum; }
104 
106 
107 const char *RegisterNumber::GetName() { return m_name; }
lldb::RegisterKind GetRegisterKind() const
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
uint32_t GetRegisterNumber() const
uint32_t GetAsKind(lldb::RegisterKind kind)
bool operator==(RegisterNumber &rhs)
const RegisterNumber & operator=(const RegisterNumber &rhs)
virtual lldb::RegisterContextSP GetRegisterContext()=0
bool operator!=(RegisterNumber &rhs)
bool IsValid() const
void init(lldb_private::Thread &thread, lldb::RegisterKind kind, uint32_t num)
const char * GetName()
Definition: SBAddress.h:15
A class to represent register numbers, and able to convert between different register numbering schem...
#define LLDB_INVALID_REGNUM
Definition: lldb-defines.h:90