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
13using 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
29RegisterNumber::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
73bool RegisterNumber::operator!=(RegisterNumber &rhs) { return !(*this == rhs); }
74
76 return m_reg_ctx_sp.get() && m_kind != lldb::kNumRegisterKinds &&
78}
79
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
101uint32_t RegisterNumber::GetRegisterNumber() const { return m_regnum; }
102
104
105const char *RegisterNumber::GetName() { return m_name; }
A class to represent register numbers, and able to convert between different register numbering schem...
lldb::RegisterContextSP m_reg_ctx_sp
bool operator==(RegisterNumber &rhs)
bool IsValid() const
uint32_t GetAsKind(lldb::RegisterKind kind)
lldb::RegisterKind GetRegisterKind() const
const RegisterNumber & operator=(const RegisterNumber &rhs)
const char * m_name
uint32_t m_regnum
uint32_t GetRegisterNumber() const
bool operator!=(RegisterNumber &rhs)
lldb::RegisterKind m_kind
void init(lldb_private::Thread &thread, lldb::RegisterKind kind, uint32_t num)
const char * GetName()
Collection m_kind_regnum_map
virtual lldb::RegisterContextSP GetRegisterContext()=0
#define LLDB_INVALID_REGNUM
Definition: lldb-defines.h:87
A class that represents a running process on the host machine.
RegisterKind
Register numbering types.
@ kNumRegisterKinds
@ eRegisterKindLLDB
lldb's internal register numbers
Every register is described in detail including its name, alternate name (optional),...
const char * name
Name of this register, can't be NULL.