LLDB mainline
RegisterType.h
Go to the documentation of this file.
1//===------------------------------------------------------------*- 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_UTILITY_REGISTERTYPE_H
10#define LLDB_UTILITY_REGISTERTYPE_H
11
13#include "llvm/ADT/StringRef.h"
14
15#include <cstdint>
16#include <optional>
17#include <string>
18#include <unordered_set>
19#include <vector>
20
21namespace lldb_private {
22
23class Stream;
24class Log;
25
27public:
35
36 RegisterTypeKind getKind() const { return m_kind; }
37
38 RegisterType(RegisterTypeKind kind, std::string id);
39 RegisterType(const RegisterType &) = delete;
43
44 /// Output XML that describes this type, to be inserted into a target XML
45 /// file. Reserved characters like "<" are replaced with their XML safe
46 /// equivalents like "&lt;".
47 virtual void ToXML(Stream &strm,
48 std::unordered_set<std::string> &previously_emitted,
49 const RegisterType *user = nullptr) const;
50
51 /// Print a string escaped for use as an XML attribute value.
52 static void PrintXMLAttributeValue(Stream &strm, llvm::StringRef value);
53
54 virtual ~RegisterType() = default;
55
56 /// Output the register type as an XML element. That is, "<foo ...>" until the
57 /// closing </foo>, including any child types in between. For example the
58 /// flags in a register flag set.
59 virtual void ToXMLElement(Stream &strm,
60 const RegisterType *user = nullptr) const = 0;
61
62 const std::string &GetID() const { return m_id; }
63
64 /// Return an identifier unique among all RegisterType instances constructed
65 /// during the lifetime of the LLDB host process. The identifier is not
66 /// reused after this instance is destroyed.
67 uint64_t GetUID() const { return m_uid; }
68
69 /// Return this type's fixed size in bytes, if it has one. No byte size means
70 /// it depends on the target.
71 virtual std::optional<uint64_t> GetByteSize() const { return std::nullopt; }
72
73 void SetDependencies(std::vector<const RegisterType *> dependencies) {
74 m_dependencies = dependencies;
75 }
76
77private:
79 const std::string m_id;
80 const uint64_t m_uid;
81 std::vector<const RegisterType *> m_dependencies;
82};
83
84/// A predefined GDB target-description type. Builtin types are referenced by
85/// name and are not emitted as XML definitions.
87public:
88 /// A missing byte size means the size depends on the target.
89 RegisterTypeBuiltin(std::string id, lldb::Encoding encoding,
90 lldb::Format format, std::optional<uint64_t> byte_size);
91
93 lldb::Format GetFormat() const { return m_format; }
94 std::optional<uint64_t> GetByteSize() const override { return m_byte_size; }
95
96 void ToXML(Stream &strm, std::unordered_set<std::string> &previously_emitted,
97 const RegisterType *user = nullptr) const override;
98 void ToXMLElement(Stream &strm,
99 const RegisterType *user = nullptr) const override;
100
101 static bool classof(const RegisterType *type) {
102 return type->getKind() == eRegisterTypeKindBuiltin;
103 }
104
105private:
108 const std::optional<uint64_t> m_byte_size;
109};
110
111/// A GDB target-description vector type. The element type must outlive it.
113public:
114 RegisterTypeVector(std::string id, const RegisterType *element_type,
115 uint32_t count);
116
117 const RegisterType *GetElementType() const { return m_element_type; }
118 uint32_t GetCount() const { return m_count; }
119 std::optional<uint64_t> GetByteSize() const override;
120 bool IsByteSizeCompatible(uint64_t byte_size) const;
121
122 void DumpToLog(Log *log) const;
123
124 void ToXMLElement(Stream &strm,
125 const RegisterType *user = nullptr) const override;
126
127 static bool classof(const RegisterType *type) {
128 return type->getKind() == eRegisterTypeKindVector;
129 }
130
131private:
133 const uint32_t m_count;
134};
135
136/// A GDB target-description union type. Each field is an alternative view of
137/// the same register data. Referenced field types must outlive the union.
139public:
140 class Field {
141 public:
142 Field(std::string name, const RegisterType *type);
143
144 const std::string &GetName() const { return m_name; }
145 const RegisterType *GetType() const { return m_type; }
146
147 private:
148 const std::string m_name;
150 };
151
152 RegisterTypeUnion(std::string id, std::vector<Field> fields);
153
154 const std::vector<Field> &GetFields() const { return m_fields; }
155 std::optional<uint64_t> GetByteSize() const override;
156 bool IsByteSizeCompatible(uint64_t byte_size) const;
157
158 void DumpToLog(Log *log) const;
159
160 void ToXMLElement(Stream &strm,
161 const RegisterType *user = nullptr) const override;
162
163 static bool classof(const RegisterType *type) {
164 return type->getKind() == eRegisterTypeKindUnion;
165 }
166
167private:
168 const std::vector<Field> m_fields;
169};
170
171} // namespace lldb_private
172
173#endif // LLDB_UTILITY_REGISTERTYPE_H
void ToXMLElement(Stream &strm, const RegisterType *user=nullptr) const override
Output the register type as an XML element.
RegisterTypeBuiltin(std::string id, lldb::Encoding encoding, lldb::Format format, std::optional< uint64_t > byte_size)
A missing byte size means the size depends on the target.
static bool classof(const RegisterType *type)
lldb::Encoding GetEncoding() const
const lldb::Encoding m_encoding
const std::optional< uint64_t > m_byte_size
lldb::Format GetFormat() const
void ToXML(Stream &strm, std::unordered_set< std::string > &previously_emitted, const RegisterType *user=nullptr) const override
Output XML that describes this type, to be inserted into a target XML file.
std::optional< uint64_t > GetByteSize() const override
Return this type's fixed size in bytes, if it has one.
Field(std::string name, const RegisterType *type)
const RegisterType * GetType() const
const std::string & GetName() const
void ToXMLElement(Stream &strm, const RegisterType *user=nullptr) const override
Output the register type as an XML element.
std::optional< uint64_t > GetByteSize() const override
Return this type's fixed size in bytes, if it has one.
bool IsByteSizeCompatible(uint64_t byte_size) const
const std::vector< Field > m_fields
const std::vector< Field > & GetFields() const
RegisterTypeUnion(std::string id, std::vector< Field > fields)
static bool classof(const RegisterType *type)
RegisterTypeVector(std::string id, const RegisterType *element_type, uint32_t count)
const RegisterType * GetElementType() const
bool IsByteSizeCompatible(uint64_t byte_size) const
void ToXMLElement(Stream &strm, const RegisterType *user=nullptr) const override
Output the register type as an XML element.
std::optional< uint64_t > GetByteSize() const override
Return this type's fixed size in bytes, if it has one.
static bool classof(const RegisterType *type)
const RegisterType * m_element_type
RegisterType(RegisterTypeKind kind, std::string id)
RegisterType(const RegisterType &)=delete
virtual ~RegisterType()=default
RegisterTypeKind getKind() const
virtual std::optional< uint64_t > GetByteSize() const
Return this type's fixed size in bytes, if it has one.
virtual void ToXMLElement(Stream &strm, const RegisterType *user=nullptr) const =0
Output the register type as an XML element.
const std::string & GetID() const
RegisterType(RegisterType &&)=delete
const RegisterTypeKind m_kind
std::vector< const RegisterType * > m_dependencies
void SetDependencies(std::vector< const RegisterType * > dependencies)
RegisterType & operator=(RegisterType &&)=delete
const std::string m_id
static void PrintXMLAttributeValue(Stream &strm, llvm::StringRef value)
Print a string escaped for use as an XML attribute value.
virtual void ToXML(Stream &strm, std::unordered_set< std::string > &previously_emitted, const RegisterType *user=nullptr) const
Output XML that describes this type, to be inserted into a target XML file.
uint64_t GetUID() const
Return an identifier unique among all RegisterType instances constructed during the lifetime of the L...
RegisterType & operator=(const RegisterType &)=delete
A stream class that can stream formatted output to a file.
Definition Stream.h:28
A class that represents a running process on the host machine.
Format
Display format definitions.
Encoding
Register encoding definitions.