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:
34
35 RegisterTypeKind getKind() const { return m_kind; }
36
37 RegisterType(RegisterTypeKind kind, std::string id);
38 RegisterType(const RegisterType &) = delete;
42
43 /// Output XML that describes this type, to be inserted into a target XML
44 /// file. Reserved characters like "<" are replaced with their XML safe
45 /// equivalents like "&lt;".
46 virtual void ToXML(Stream &strm,
47 std::unordered_set<std::string> &previously_emitted,
48 const RegisterType *user = nullptr) const;
49
50 /// Print a string escaped for use as an XML attribute value.
51 static void PrintXMLAttributeValue(Stream &strm, llvm::StringRef value);
52
53 virtual ~RegisterType() = default;
54
55 /// Output the register type as an XML element. That is, "<foo ...>" until the
56 /// closing </foo>, including any child types in between. For example the
57 /// flags in a register flag set.
58 virtual void ToXMLElement(Stream &strm,
59 const RegisterType *user = nullptr) const = 0;
60
61 const std::string &GetID() const { return m_id; }
62
63 /// Return an identifier unique among all RegisterType instances constructed
64 /// during the lifetime of the LLDB host process. The identifier is not
65 /// reused after this instance is destroyed.
66 uint64_t GetUID() const { return m_uid; }
67
68 /// Return this type's fixed size in bytes, if it has one. No byte size means
69 /// it depends on the target.
70 virtual std::optional<uint64_t> GetByteSize() const { return std::nullopt; }
71
72 void SetDependencies(std::vector<const RegisterType *> dependencies) {
73 m_dependencies = dependencies;
74 }
75
76private:
78 const std::string m_id;
79 const uint64_t m_uid;
80 std::vector<const RegisterType *> m_dependencies;
81};
82
83/// A predefined GDB target-description type. Builtin types are referenced by
84/// name and are not emitted as XML definitions.
86public:
87 /// A missing byte size means the size depends on the target.
88 RegisterTypeBuiltin(std::string id, lldb::Encoding encoding,
89 lldb::Format format, std::optional<uint64_t> byte_size);
90
92 lldb::Format GetFormat() const { return m_format; }
93 std::optional<uint64_t> GetByteSize() const override { return m_byte_size; }
94
95 void ToXML(Stream &strm, std::unordered_set<std::string> &previously_emitted,
96 const RegisterType *user = nullptr) const override;
97 void ToXMLElement(Stream &strm,
98 const RegisterType *user = nullptr) const override;
99
100 static bool classof(const RegisterType *type) {
101 return type->getKind() == eRegisterTypeKindBuiltin;
102 }
103
104private:
107 const std::optional<uint64_t> m_byte_size;
108};
109
110/// A GDB target-description vector type. The element type must outlive it.
112public:
113 RegisterTypeVector(std::string id, const RegisterType *element_type,
114 uint32_t count);
115
116 const RegisterType *GetElementType() const { return m_element_type; }
117 uint32_t GetCount() const { return m_count; }
118 std::optional<uint64_t> GetByteSize() const override;
119 bool IsByteSizeCompatible(uint64_t byte_size) const;
120
121 void DumpToLog(Log *log) const;
122
123 void ToXMLElement(Stream &strm,
124 const RegisterType *user = nullptr) const override;
125
126 static bool classof(const RegisterType *type) {
127 return type->getKind() == eRegisterTypeKindVector;
128 }
129
130private:
132 const uint32_t m_count;
133};
134
135} // namespace lldb_private
136
137#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.
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.