LLDB  mainline
RegisterNumber.cpp
Go to the documentation of this file.
1 //===-- RegisterNumber.cpp ------------------------------------------------===//
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 
29 RegisterNumber::RegisterNumber() : m_reg_ctx_sp(), m_kind_regnum_map() {}
30 
32  uint32_t num) {
34  m_regnum = num;
35  m_kind = kind;
36  if (m_reg_ctx_sp.get()) {
37  const lldb_private::RegisterInfo *reginfo =
38  m_reg_ctx_sp->GetRegisterInfoAtIndex(
40  if (reginfo && reginfo->name) {
41  m_name = reginfo->name;
42  }
43  }
44 }
45 
48  m_regnum = rhs.m_regnum;
49  m_kind = rhs.m_kind;
50  for (auto it : rhs.m_kind_regnum_map)
51  m_kind_regnum_map[it.first] = it.second;
52  m_name = rhs.m_name;
53  return *this;
54 }
55 
57  if (IsValid() != rhs.IsValid())
58  return false;
59 
60  if (m_kind == rhs.m_kind) {
61  return m_regnum == rhs.m_regnum;
62  }
63 
64  uint32_t rhs_regnum = rhs.GetAsKind(m_kind);
65  if (rhs_regnum != LLDB_INVALID_REGNUM) {
66  return m_regnum == rhs_regnum;
67  }
68  uint32_t lhs_regnum = GetAsKind(rhs.m_kind);
69  { return lhs_regnum == rhs.m_regnum; }
70  return false;
71 }
72 
73 bool RegisterNumber::operator!=(RegisterNumber &rhs) { return !(*this == rhs); }
74 
76  return m_reg_ctx_sp.get() && m_kind != lldb::kNumRegisterKinds &&
78 }
79 
82  return LLDB_INVALID_REGNUM;
83 
84  if (kind == m_kind)
85  return m_regnum;
86 
87  Collection::iterator iter = m_kind_regnum_map.find(kind);
88  if (iter != m_kind_regnum_map.end()) {
89  return iter->second;
90  }
91  uint32_t output_regnum = LLDB_INVALID_REGNUM;
92  if (m_reg_ctx_sp &&
93  m_reg_ctx_sp->ConvertBetweenRegisterKinds(m_kind, m_regnum, kind,
94  output_regnum) &&
95  output_regnum != LLDB_INVALID_REGNUM) {
96  m_kind_regnum_map[kind] = output_regnum;
97  }
98  return output_regnum;
99 }
100 
102 
104 
105 const char *RegisterNumber::GetName() { return m_name; }
LLDB_INVALID_REGNUM
#define LLDB_INVALID_REGNUM
Definition: lldb-defines.h:91
lldb::kNumRegisterKinds
@ kNumRegisterKinds
Definition: lldb-enumerations.h:235
RegisterNumber::GetRegisterNumber
uint32_t GetRegisterNumber() const
Definition: RegisterNumber.cpp:101
RegisterNumber::operator=
const RegisterNumber & operator=(const RegisterNumber &rhs)
Definition: RegisterNumber.cpp:46
RegisterNumber::operator!=
bool operator!=(RegisterNumber &rhs)
Definition: RegisterNumber.cpp:73
RegisterNumber::init
void init(lldb_private::Thread &thread, lldb::RegisterKind kind, uint32_t num)
Definition: RegisterNumber.cpp:31
RegisterNumber
A class to represent register numbers, and able to convert between different register numbering schem...
Definition: RegisterNumber.h:19
lldb::eRegisterKindLLDB
@ eRegisterKindLLDB
lldb's internal register numbers
Definition: lldb-enumerations.h:234
lldb_private::Thread
Definition: Thread.h:60
RegisterNumber::operator==
bool operator==(RegisterNumber &rhs)
Definition: RegisterNumber.cpp:56
RegisterNumber::m_name
const char * m_name
Definition: RegisterNumber.h:56
RegisterNumber::m_kind
lldb::RegisterKind m_kind
Definition: RegisterNumber.h:54
RegisterNumber::GetAsKind
uint32_t GetAsKind(lldb::RegisterKind kind)
Definition: RegisterNumber.cpp:80
Thread.h
RegisterNumber::GetName
const char * GetName()
Definition: RegisterNumber.cpp:105
RegisterNumber::RegisterNumber
RegisterNumber()
Definition: RegisterNumber.cpp:29
lldb::RegisterKind
RegisterKind
Register numbering types.
Definition: lldb-enumerations.h:227
uint32_t
RegisterNumber::m_regnum
uint32_t m_regnum
Definition: RegisterNumber.h:53
RegisterNumber::IsValid
bool IsValid() const
Definition: RegisterNumber.cpp:75
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
RegisterNumber::GetRegisterKind
lldb::RegisterKind GetRegisterKind() const
Definition: RegisterNumber.cpp:103
RegisterNumber::m_kind_regnum_map
Collection m_kind_regnum_map
Definition: RegisterNumber.h:55
RegisterNumber.h
RegisterNumber::m_reg_ctx_sp
lldb::RegisterContextSP m_reg_ctx_sp
Definition: RegisterNumber.h:52
lldb_private::Thread::GetRegisterContext
virtual lldb::RegisterContextSP GetRegisterContext()=0
RegisterContext.h