]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/lldb/Core/RegisterValue.h
Vendor import of lldb release_39 branch r276489:
[FreeBSD/FreeBSD.git] / 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/lldb-public.h"
22 #include "lldb/lldb-private.h"
23 #include "lldb/Host/Endian.h"
24 #include "lldb/Core/Scalar.h"
25
26 namespace lldb_private {
27
28     class RegisterValue
29     {
30     public:
31         enum
32         {
33             kMaxRegisterByteSize = 32u
34         };
35
36         enum Type
37         {
38             eTypeInvalid,
39             eTypeUInt8,
40             eTypeUInt16,
41             eTypeUInt32,
42             eTypeUInt64,
43             eTypeUInt128,
44             eTypeFloat,
45             eTypeDouble,
46             eTypeLongDouble,
47             eTypeBytes
48         };
49         
50         RegisterValue () : 
51             m_type (eTypeInvalid),
52             m_scalar ((unsigned long)0)
53         {
54         }
55
56         explicit 
57         RegisterValue (uint8_t inst) : 
58             m_type (eTypeUInt8)
59         {
60             m_scalar = inst;
61         }
62
63         explicit 
64         RegisterValue (uint16_t inst) : 
65             m_type (eTypeUInt16)
66         {
67             m_scalar = inst;
68         }
69
70         explicit 
71         RegisterValue (uint32_t inst) : 
72             m_type (eTypeUInt32)
73         {
74             m_scalar = inst;
75         }
76
77         explicit 
78         RegisterValue (uint64_t inst) : 
79             m_type (eTypeUInt64)
80         {
81             m_scalar = inst;
82         }
83
84         explicit 
85         RegisterValue (llvm::APInt inst) :
86             m_type (eTypeUInt128)
87         {
88             m_scalar = llvm::APInt(inst);
89         }
90
91         explicit 
92         RegisterValue (float value) : 
93             m_type (eTypeFloat)
94         {
95             m_scalar = value;
96         }
97
98         explicit 
99         RegisterValue (double value) : 
100             m_type (eTypeDouble)
101         {
102             m_scalar = value;
103         }
104
105         explicit 
106         RegisterValue (long double value) : 
107             m_type (eTypeLongDouble)
108         {
109             m_scalar = value;
110         }
111
112         explicit 
113         RegisterValue (uint8_t *bytes, size_t length, lldb::ByteOrder byte_order)
114         {
115             SetBytes (bytes, length, byte_order);
116         }
117
118         RegisterValue::Type
119         GetType () const
120         {
121             return m_type;
122         }
123
124         bool
125         CopyValue (const RegisterValue &rhs);
126
127         void
128         SetType (RegisterValue::Type type)
129         {
130             m_type = type;
131         }
132
133         RegisterValue::Type
134         SetType (const RegisterInfo *reg_info);
135         
136         bool
137         GetData (DataExtractor &data) const;
138         
139         // Copy the register value from this object into a buffer in "dst"
140         // and obey the "dst_byte_order" when copying the data. Also watch out
141         // in case "dst_len" is longer or shorter than the register value 
142         // described by "reg_info" and only copy the least significant bytes 
143         // of the register value, or pad the destination with zeroes if the
144         // register byte size is shorter that "dst_len" (all while correctly
145         // abiding the "dst_byte_order"). Returns the number of bytes copied
146         // into "dst".
147         uint32_t
148         GetAsMemoryData (const RegisterInfo *reg_info,
149                          void *dst, 
150                          uint32_t dst_len, 
151                          lldb::ByteOrder dst_byte_order,
152                          Error &error) const;
153
154         uint32_t
155         SetFromMemoryData (const RegisterInfo *reg_info,
156                            const void *src,
157                            uint32_t src_len,
158                            lldb::ByteOrder src_byte_order,
159                            Error &error);
160                            
161         bool
162         GetScalarValue (Scalar &scalar) const;
163
164         uint8_t
165         GetAsUInt8(uint8_t fail_value = UINT8_MAX, bool *success_ptr = nullptr) const
166         {
167             if (m_type == eTypeUInt8)
168             {
169                 if (success_ptr)
170                     *success_ptr = true;                
171                 return m_scalar.UChar(fail_value);
172             }
173             if (success_ptr)
174                 *success_ptr = true;
175             return fail_value;
176         }
177
178         uint16_t
179         GetAsUInt16(uint16_t fail_value = UINT16_MAX, bool *success_ptr = nullptr) const;
180
181         uint32_t
182         GetAsUInt32(uint32_t fail_value = UINT32_MAX, bool *success_ptr = nullptr) const;
183
184         uint64_t
185         GetAsUInt64(uint64_t fail_value = UINT64_MAX, bool *success_ptr = nullptr) const;
186
187         llvm::APInt
188         GetAsUInt128(const llvm::APInt& fail_value, bool *success_ptr = nullptr) const;
189
190         float
191         GetAsFloat(float fail_value = 0.0f, bool *success_ptr = nullptr) const;
192
193         double
194         GetAsDouble(double fail_value = 0.0, bool *success_ptr = nullptr) const;
195
196         long double
197         GetAsLongDouble(long double fail_value = 0.0, bool *success_ptr = nullptr) const;
198
199         void
200         SetValueToInvalid ()
201         {
202             m_type = eTypeInvalid;
203         }
204
205         bool
206         ClearBit (uint32_t bit);
207
208         bool
209         SetBit (uint32_t bit);
210
211         bool
212         operator == (const RegisterValue &rhs) const;
213
214         bool
215         operator != (const RegisterValue &rhs) const;
216
217         void
218         operator = (uint8_t uint)
219         {
220             m_type = eTypeUInt8;
221             m_scalar = uint;
222         }
223
224         void
225         operator = (uint16_t uint)
226         {
227             m_type = eTypeUInt16;
228             m_scalar = uint;
229         }
230
231         void
232         operator = (uint32_t uint)
233         {
234             m_type = eTypeUInt32;
235             m_scalar = uint;
236         }
237
238         void
239         operator = (uint64_t uint)
240         {
241             m_type = eTypeUInt64;
242             m_scalar = uint;
243         }
244
245         void
246         operator = (llvm::APInt uint)
247         {
248             m_type = eTypeUInt128;
249             m_scalar = llvm::APInt(uint);
250         }
251
252         void
253         operator = (float f)
254         {
255             m_type = eTypeFloat;
256             m_scalar = f;
257         }
258
259         void
260         operator = (double f)
261         {
262             m_type = eTypeDouble;
263             m_scalar = f;
264         }
265
266         void
267         operator = (long double f)
268         {
269             m_type = eTypeLongDouble;
270             m_scalar = f;
271         }
272
273         void
274         SetUInt8 (uint8_t uint)
275         {
276             m_type = eTypeUInt8;
277             m_scalar = uint;
278         }
279
280         void
281         SetUInt16 (uint16_t uint)
282         {
283             m_type = eTypeUInt16;
284             m_scalar = uint;
285         }
286
287         void
288         SetUInt32 (uint32_t uint, Type t = eTypeUInt32)
289         {
290             m_type = t;
291             m_scalar = uint;
292         }
293
294         void
295         SetUInt64 (uint64_t uint, Type t = eTypeUInt64)
296         {
297             m_type = t;
298             m_scalar = uint;
299         }
300
301         void
302         SetUInt128 (llvm::APInt uint)
303         {
304             m_type = eTypeUInt128;
305             m_scalar = uint;
306         }
307
308         bool
309         SetUInt (uint64_t uint, uint32_t byte_size);
310     
311         void
312         SetFloat (float f)
313         {
314             m_type = eTypeFloat;
315             m_scalar = f;
316         }
317
318         void
319         SetDouble (double f)
320         {
321             m_type = eTypeDouble;
322             m_scalar = f;
323         }
324
325         void
326         SetLongDouble (long double f)
327         {
328             m_type = eTypeLongDouble;
329             m_scalar = f;
330         }
331
332         void
333         SetBytes (const void *bytes, size_t length, lldb::ByteOrder byte_order);
334
335         bool
336         SignExtend (uint32_t sign_bitpos);
337
338         Error
339         SetValueFromCString (const RegisterInfo *reg_info, 
340                              const char *value_str);
341
342         Error
343         SetValueFromData (const RegisterInfo *reg_info, 
344                           DataExtractor &data, 
345                           lldb::offset_t offset,
346                           bool partial_data_ok);
347
348         // The default value of 0 for reg_name_right_align_at means no alignment at all.
349         bool
350         Dump (Stream *s, 
351               const RegisterInfo *reg_info, 
352               bool prefix_with_name,
353               bool prefix_with_alt_name,
354               lldb::Format format,
355               uint32_t reg_name_right_align_at = 0) const;
356
357         const void *
358         GetBytes () const;
359
360         lldb::ByteOrder
361         GetByteOrder () const
362         {
363             if (m_type == eTypeBytes)
364                 return buffer.byte_order;
365             return endian::InlHostByteOrder();
366         }
367         
368         uint32_t
369         GetByteSize () const;
370
371         static uint32_t
372         GetMaxByteSize ()
373         {
374             return kMaxRegisterByteSize;
375         }
376
377         void
378         Clear();
379
380     protected:
381         RegisterValue::Type m_type;
382         Scalar m_scalar;
383
384         struct
385         {
386             uint8_t bytes[kMaxRegisterByteSize]; // This must be big enough to hold any register for any supported target.
387             uint8_t length;
388             lldb::ByteOrder byte_order;
389         } buffer;
390     };
391
392 } // namespace lldb_private
393
394 #endif // lldb_RegisterValue_h