]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/RegisterValue.h
MFV r314565,314567,314570:
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Core / RegisterValue.h
1 //===-- RegisterValue.h -----------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef lldb_RegisterValue_h
11 #define lldb_RegisterValue_h
12
13 // C Includes
14 #include <string.h>
15
16 // C++ Includes
17 // Other libraries and framework includes
18 #include "llvm/ADT/APInt.h"
19
20 // Project includes
21 #include "lldb/Core/Scalar.h"
22 #include "lldb/Host/Endian.h"
23 #include "lldb/lldb-private.h"
24 #include "lldb/lldb-public.h"
25
26 namespace lldb_private {
27
28 class RegisterValue {
29 public:
30   enum { kMaxRegisterByteSize = 32u };
31
32   enum Type {
33     eTypeInvalid,
34     eTypeUInt8,
35     eTypeUInt16,
36     eTypeUInt32,
37     eTypeUInt64,
38     eTypeUInt128,
39     eTypeFloat,
40     eTypeDouble,
41     eTypeLongDouble,
42     eTypeBytes
43   };
44
45   RegisterValue() : m_type(eTypeInvalid), m_scalar((unsigned long)0) {}
46
47   explicit RegisterValue(uint8_t inst) : m_type(eTypeUInt8) { m_scalar = inst; }
48
49   explicit RegisterValue(uint16_t inst) : m_type(eTypeUInt16) {
50     m_scalar = inst;
51   }
52
53   explicit RegisterValue(uint32_t inst) : m_type(eTypeUInt32) {
54     m_scalar = inst;
55   }
56
57   explicit RegisterValue(uint64_t inst) : m_type(eTypeUInt64) {
58     m_scalar = inst;
59   }
60
61   explicit RegisterValue(llvm::APInt inst) : m_type(eTypeUInt128) {
62     m_scalar = llvm::APInt(inst);
63   }
64
65   explicit RegisterValue(float value) : m_type(eTypeFloat) { m_scalar = value; }
66
67   explicit RegisterValue(double value) : m_type(eTypeDouble) {
68     m_scalar = value;
69   }
70
71   explicit RegisterValue(long double value) : m_type(eTypeLongDouble) {
72     m_scalar = value;
73   }
74
75   explicit RegisterValue(uint8_t *bytes, size_t length,
76                          lldb::ByteOrder byte_order) {
77     SetBytes(bytes, length, byte_order);
78   }
79
80   RegisterValue::Type GetType() const { return m_type; }
81
82   bool CopyValue(const RegisterValue &rhs);
83
84   void SetType(RegisterValue::Type type) { m_type = type; }
85
86   RegisterValue::Type SetType(const RegisterInfo *reg_info);
87
88   bool GetData(DataExtractor &data) const;
89
90   // Copy the register value from this object into a buffer in "dst"
91   // and obey the "dst_byte_order" when copying the data. Also watch out
92   // in case "dst_len" is longer or shorter than the register value
93   // described by "reg_info" and only copy the least significant bytes
94   // of the register value, or pad the destination with zeroes if the
95   // register byte size is shorter that "dst_len" (all while correctly
96   // abiding the "dst_byte_order"). Returns the number of bytes copied
97   // into "dst".
98   uint32_t GetAsMemoryData(const RegisterInfo *reg_info, void *dst,
99                            uint32_t dst_len, lldb::ByteOrder dst_byte_order,
100                            Error &error) const;
101
102   uint32_t SetFromMemoryData(const RegisterInfo *reg_info, const void *src,
103                              uint32_t src_len, lldb::ByteOrder src_byte_order,
104                              Error &error);
105
106   bool GetScalarValue(Scalar &scalar) const;
107
108   uint8_t GetAsUInt8(uint8_t fail_value = UINT8_MAX,
109                      bool *success_ptr = nullptr) const {
110     if (m_type == eTypeUInt8) {
111       if (success_ptr)
112         *success_ptr = true;
113       return m_scalar.UChar(fail_value);
114     }
115     if (success_ptr)
116       *success_ptr = true;
117     return fail_value;
118   }
119
120   uint16_t GetAsUInt16(uint16_t fail_value = UINT16_MAX,
121                        bool *success_ptr = nullptr) const;
122
123   uint32_t GetAsUInt32(uint32_t fail_value = UINT32_MAX,
124                        bool *success_ptr = nullptr) const;
125
126   uint64_t GetAsUInt64(uint64_t fail_value = UINT64_MAX,
127                        bool *success_ptr = nullptr) const;
128
129   llvm::APInt GetAsUInt128(const llvm::APInt &fail_value,
130                            bool *success_ptr = nullptr) const;
131
132   float GetAsFloat(float fail_value = 0.0f, bool *success_ptr = nullptr) const;
133
134   double GetAsDouble(double fail_value = 0.0,
135                      bool *success_ptr = nullptr) const;
136
137   long double GetAsLongDouble(long double fail_value = 0.0,
138                               bool *success_ptr = nullptr) const;
139
140   void SetValueToInvalid() { m_type = eTypeInvalid; }
141
142   bool ClearBit(uint32_t bit);
143
144   bool SetBit(uint32_t bit);
145
146   bool operator==(const RegisterValue &rhs) const;
147
148   bool operator!=(const RegisterValue &rhs) const;
149
150   void operator=(uint8_t uint) {
151     m_type = eTypeUInt8;
152     m_scalar = uint;
153   }
154
155   void operator=(uint16_t uint) {
156     m_type = eTypeUInt16;
157     m_scalar = uint;
158   }
159
160   void operator=(uint32_t uint) {
161     m_type = eTypeUInt32;
162     m_scalar = uint;
163   }
164
165   void operator=(uint64_t uint) {
166     m_type = eTypeUInt64;
167     m_scalar = uint;
168   }
169
170   void operator=(llvm::APInt uint) {
171     m_type = eTypeUInt128;
172     m_scalar = llvm::APInt(uint);
173   }
174
175   void operator=(float f) {
176     m_type = eTypeFloat;
177     m_scalar = f;
178   }
179
180   void operator=(double f) {
181     m_type = eTypeDouble;
182     m_scalar = f;
183   }
184
185   void operator=(long double f) {
186     m_type = eTypeLongDouble;
187     m_scalar = f;
188   }
189
190   void SetUInt8(uint8_t uint) {
191     m_type = eTypeUInt8;
192     m_scalar = uint;
193   }
194
195   void SetUInt16(uint16_t uint) {
196     m_type = eTypeUInt16;
197     m_scalar = uint;
198   }
199
200   void SetUInt32(uint32_t uint, Type t = eTypeUInt32) {
201     m_type = t;
202     m_scalar = uint;
203   }
204
205   void SetUInt64(uint64_t uint, Type t = eTypeUInt64) {
206     m_type = t;
207     m_scalar = uint;
208   }
209
210   void SetUInt128(llvm::APInt uint) {
211     m_type = eTypeUInt128;
212     m_scalar = uint;
213   }
214
215   bool SetUInt(uint64_t uint, uint32_t byte_size);
216
217   void SetFloat(float f) {
218     m_type = eTypeFloat;
219     m_scalar = f;
220   }
221
222   void SetDouble(double f) {
223     m_type = eTypeDouble;
224     m_scalar = f;
225   }
226
227   void SetLongDouble(long double f) {
228     m_type = eTypeLongDouble;
229     m_scalar = f;
230   }
231
232   void SetBytes(const void *bytes, size_t length, lldb::ByteOrder byte_order);
233
234   bool SignExtend(uint32_t sign_bitpos);
235
236   Error SetValueFromString(const RegisterInfo *reg_info,
237                            llvm::StringRef value_str);
238   Error SetValueFromString(const RegisterInfo *reg_info,
239                            const char *value_str) = delete;
240
241   Error SetValueFromData(const RegisterInfo *reg_info, DataExtractor &data,
242                          lldb::offset_t offset, bool partial_data_ok);
243
244   // The default value of 0 for reg_name_right_align_at means no alignment at
245   // all.
246   bool Dump(Stream *s, const RegisterInfo *reg_info, bool prefix_with_name,
247             bool prefix_with_alt_name, lldb::Format format,
248             uint32_t reg_name_right_align_at = 0) const;
249
250   const void *GetBytes() const;
251
252   lldb::ByteOrder GetByteOrder() const {
253     if (m_type == eTypeBytes)
254       return buffer.byte_order;
255     return endian::InlHostByteOrder();
256   }
257
258   uint32_t GetByteSize() const;
259
260   static uint32_t GetMaxByteSize() { return kMaxRegisterByteSize; }
261
262   void Clear();
263
264 protected:
265   RegisterValue::Type m_type;
266   Scalar m_scalar;
267
268   struct {
269     uint8_t bytes[kMaxRegisterByteSize]; // This must be big enough to hold any
270                                          // register for any supported target.
271     uint8_t length;
272     lldb::ByteOrder byte_order;
273   } buffer;
274 };
275
276 } // namespace lldb_private
277
278 #endif // lldb_RegisterValue_h