xref: /freebsd/contrib/llvm-project/lldb/include/lldb/Target/DynamicRegisterInfo.h (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
1 //===-- DynamicRegisterInfo.h -----------------------------------*- 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 #ifndef LLDB_TARGET_DYNAMICREGISTERINFO_H
10 #define LLDB_TARGET_DYNAMICREGISTERINFO_H
11 
12 #include <map>
13 #include <vector>
14 
15 #include "lldb/Target/RegisterFlags.h"
16 #include "lldb/Utility/ConstString.h"
17 #include "lldb/Utility/StructuredData.h"
18 #include "lldb/lldb-private.h"
19 
20 namespace lldb_private {
21 
22 class DynamicRegisterInfo {
23 protected:
24   DynamicRegisterInfo(DynamicRegisterInfo &) = default;
25   DynamicRegisterInfo &operator=(DynamicRegisterInfo &) = default;
26 
27 public:
28   struct Register {
29     ConstString name;
30     ConstString alt_name;
31     ConstString set_name;
32     uint32_t byte_size = LLDB_INVALID_INDEX32;
33     uint32_t byte_offset = LLDB_INVALID_INDEX32;
34     lldb::Encoding encoding = lldb::eEncodingUint;
35     lldb::Format format = lldb::eFormatHex;
36     uint32_t regnum_dwarf = LLDB_INVALID_REGNUM;
37     uint32_t regnum_ehframe = LLDB_INVALID_REGNUM;
38     uint32_t regnum_generic = LLDB_INVALID_REGNUM;
39     uint32_t regnum_remote = LLDB_INVALID_REGNUM;
40     std::vector<uint32_t> value_regs;
41     std::vector<uint32_t> invalidate_regs;
42     uint32_t value_reg_offset = 0;
43     // Non-null if there is an XML provided type.
44     const RegisterFlags *flags_type = nullptr;
45   };
46 
47   DynamicRegisterInfo() = default;
48 
49   static std::unique_ptr<DynamicRegisterInfo>
50   Create(const StructuredData::Dictionary &dict, const ArchSpec &arch);
51 
52   virtual ~DynamicRegisterInfo() = default;
53 
54   DynamicRegisterInfo(DynamicRegisterInfo &&info);
55   DynamicRegisterInfo &operator=(DynamicRegisterInfo &&info);
56 
57   size_t SetRegisterInfo(const lldb_private::StructuredData::Dictionary &dict,
58                          const lldb_private::ArchSpec &arch);
59 
60   size_t SetRegisterInfo(std::vector<Register> &&regs,
61                          const lldb_private::ArchSpec &arch);
62 
63   size_t GetNumRegisters() const;
64 
65   size_t GetNumRegisterSets() const;
66 
67   size_t GetRegisterDataByteSize() const;
68 
69   const lldb_private::RegisterInfo *GetRegisterInfoAtIndex(uint32_t i) const;
70 
71   const lldb_private::RegisterSet *GetRegisterSet(uint32_t i) const;
72 
73   uint32_t GetRegisterSetIndexByName(const lldb_private::ConstString &set_name,
74                                      bool can_create);
75 
76   uint32_t ConvertRegisterKindToRegisterNumber(uint32_t kind,
77                                                uint32_t num) const;
78 
79   const lldb_private::RegisterInfo *GetRegisterInfo(uint32_t kind,
80                                                     uint32_t num) const;
81 
82   void Dump() const;
83 
84   void Clear();
85 
86   bool IsReconfigurable();
87 
88   const lldb_private::RegisterInfo *
89   GetRegisterInfo(llvm::StringRef reg_name) const;
90 
91   typedef std::vector<lldb_private::RegisterInfo> reg_collection;
92   typedef llvm::iterator_range<reg_collection::const_iterator>
93       reg_collection_const_range;
94   typedef llvm::iterator_range<reg_collection::iterator> reg_collection_range;
95 
96   template <typename T> T registers() = delete;
97 
98   void ConfigureOffsets();
99 
100 protected:
101   // Classes that inherit from DynamicRegisterInfo can see and modify these
102   typedef std::vector<lldb_private::RegisterSet> set_collection;
103   typedef std::vector<uint32_t> reg_num_collection;
104   typedef std::vector<reg_num_collection> set_reg_num_collection;
105   typedef std::vector<lldb_private::ConstString> name_collection;
106   typedef std::map<uint32_t, reg_num_collection> reg_to_regs_map;
107   typedef std::map<uint32_t, uint32_t> reg_offset_map;
108 
109   llvm::Expected<uint32_t> ByteOffsetFromSlice(uint32_t index,
110                                                llvm::StringRef slice_str,
111                                                lldb::ByteOrder byte_order);
112   llvm::Expected<uint32_t> ByteOffsetFromComposite(
113       uint32_t index, lldb_private::StructuredData::Array &composite_reg_list,
114       lldb::ByteOrder byte_order);
115   llvm::Expected<uint32_t> ByteOffsetFromRegInfoDict(
116       uint32_t index, lldb_private::StructuredData::Dictionary &reg_info_dict,
117       lldb::ByteOrder byte_order);
118 
119   void MoveFrom(DynamicRegisterInfo &&info);
120 
121   void Finalize(const lldb_private::ArchSpec &arch);
122 
123   reg_collection m_regs;
124   set_collection m_sets;
125   set_reg_num_collection m_set_reg_nums;
126   name_collection m_set_names;
127   reg_to_regs_map m_value_regs_map;
128   reg_to_regs_map m_invalidate_regs_map;
129   reg_offset_map m_value_reg_offset_map;
130   size_t m_reg_data_byte_size = 0u; // The number of bytes required to store
131                                     // all registers
132   bool m_finalized = false;
133   bool m_is_reconfigurable = false;
134 };
135 
136 template <>
137 inline DynamicRegisterInfo::reg_collection_const_range
138 DynamicRegisterInfo::registers() {
139   return reg_collection_const_range(m_regs);
140 }
141 
142 template <>
143 inline DynamicRegisterInfo::reg_collection_range
144 DynamicRegisterInfo::registers() {
145   return reg_collection_range(m_regs);
146 }
147 
148 void addSupplementaryRegister(std::vector<DynamicRegisterInfo::Register> &regs,
149                               DynamicRegisterInfo::Register new_reg_info);
150 
151 } // namespace lldb_private
152 
153 #endif // LLDB_TARGET_DYNAMICREGISTERINFO_H
154