]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/DataFormatters/FormattersHelpers.h
MFV r330973: 9164 assert: newds == os->os_dsl_dataset
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / DataFormatters / FormattersHelpers.h
1 //===-- FormattersHelpers.h --------------------------------------*- C++
2 //-*-===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #ifndef lldb_FormattersHelpers_h_
12 #define lldb_FormattersHelpers_h_
13
14 // C Includes
15 // C++ Includes
16 // Other libraries and framework includes
17 // Project includes
18 #include "lldb/lldb-enumerations.h"
19 #include "lldb/lldb-forward.h"
20
21 #include "lldb/DataFormatters/TypeCategory.h"
22 #include "lldb/DataFormatters/TypeFormat.h"
23 #include "lldb/DataFormatters/TypeSummary.h"
24 #include "lldb/DataFormatters/TypeSynthetic.h"
25
26 namespace lldb_private {
27 namespace formatters {
28 void AddFormat(TypeCategoryImpl::SharedPointer category_sp, lldb::Format format,
29                ConstString type_name, TypeFormatImpl::Flags flags,
30                bool regex = false);
31
32 void AddSummary(TypeCategoryImpl::SharedPointer category_sp,
33                 lldb::TypeSummaryImplSP summary_sp, ConstString type_name,
34                 bool regex = false);
35
36 void AddStringSummary(TypeCategoryImpl::SharedPointer category_sp,
37                       const char *string, ConstString type_name,
38                       TypeSummaryImpl::Flags flags, bool regex = false);
39
40 void AddOneLineSummary(TypeCategoryImpl::SharedPointer category_sp,
41                        ConstString type_name, TypeSummaryImpl::Flags flags,
42                        bool regex = false);
43
44 #ifndef LLDB_DISABLE_PYTHON
45 void AddCXXSummary(TypeCategoryImpl::SharedPointer category_sp,
46                    CXXFunctionSummaryFormat::Callback funct,
47                    const char *description, ConstString type_name,
48                    TypeSummaryImpl::Flags flags, bool regex = false);
49
50 void AddCXXSynthetic(TypeCategoryImpl::SharedPointer category_sp,
51                      CXXSyntheticChildren::CreateFrontEndCallback generator,
52                      const char *description, ConstString type_name,
53                      ScriptedSyntheticChildren::Flags flags,
54                      bool regex = false);
55
56 void AddFilter(TypeCategoryImpl::SharedPointer category_sp,
57                std::vector<std::string> children, const char *description,
58                ConstString type_name, ScriptedSyntheticChildren::Flags flags,
59                bool regex = false);
60 #endif
61
62 size_t ExtractIndexFromString(const char *item_name);
63
64 lldb::addr_t GetArrayAddressOrPointerValue(ValueObject &valobj);
65
66 time_t GetOSXEpoch();
67
68 struct InferiorSizedWord {
69
70   InferiorSizedWord(const InferiorSizedWord &word) : ptr_size(word.ptr_size) {
71     if (ptr_size == 4)
72       thirty_two = word.thirty_two;
73     else
74       sixty_four = word.sixty_four;
75   }
76
77   InferiorSizedWord operator=(const InferiorSizedWord &word) {
78     ptr_size = word.ptr_size;
79     if (ptr_size == 4)
80       thirty_two = word.thirty_two;
81     else
82       sixty_four = word.sixty_four;
83     return *this;
84   }
85
86   InferiorSizedWord(uint64_t val, Process &process)
87       : ptr_size(process.GetAddressByteSize()) {
88     if (ptr_size == 4)
89       thirty_two = (uint32_t)val;
90     else if (ptr_size == 8)
91       sixty_four = val;
92     else
93       assert(false && "new pointer size is unknown");
94   }
95
96   bool IsNegative() const {
97     if (ptr_size == 4)
98       return ((int32_t)thirty_two) < 0;
99     else
100       return ((int64_t)sixty_four) < 0;
101   }
102
103   bool IsZero() const {
104     if (ptr_size == 4)
105       return thirty_two == 0;
106     else
107       return sixty_four == 0;
108   }
109
110   static InferiorSizedWord GetMaximum(Process &process) {
111     if (process.GetAddressByteSize() == 4)
112       return InferiorSizedWord(UINT32_MAX, 4);
113     else
114       return InferiorSizedWord(UINT64_MAX, 8);
115   }
116
117   InferiorSizedWord operator>>(int rhs) const {
118     if (ptr_size == 4)
119       return InferiorSizedWord(thirty_two >> rhs, 4);
120     return InferiorSizedWord(sixty_four >> rhs, 8);
121   }
122
123   InferiorSizedWord operator<<(int rhs) const {
124     if (ptr_size == 4)
125       return InferiorSizedWord(thirty_two << rhs, 4);
126     return InferiorSizedWord(sixty_four << rhs, 8);
127   }
128
129   InferiorSizedWord operator&(const InferiorSizedWord &word) const {
130     if (ptr_size != word.ptr_size)
131       return InferiorSizedWord(0, ptr_size);
132     if (ptr_size == 4)
133       return InferiorSizedWord(thirty_two & word.thirty_two, 4);
134     return InferiorSizedWord(sixty_four & word.sixty_four, 8);
135   }
136
137   InferiorSizedWord operator&(int x) const {
138     if (ptr_size == 4)
139       return InferiorSizedWord(thirty_two & x, 4);
140     return InferiorSizedWord(sixty_four & x, 8);
141   }
142
143   size_t GetBitSize() const { return ptr_size << 3; }
144
145   size_t GetByteSize() const { return ptr_size; }
146
147   uint64_t GetValue() const {
148     if (ptr_size == 4)
149       return (uint64_t)thirty_two;
150     return sixty_four;
151   }
152
153   InferiorSizedWord SignExtend() const {
154     if (ptr_size == 4)
155       return InferiorSizedWord((int32_t)thirty_two, 4);
156     return InferiorSizedWord((int64_t)sixty_four, 8);
157   }
158
159   uint8_t *CopyToBuffer(uint8_t *buffer) const {
160     if (ptr_size == 4) {
161       memcpy(buffer, &thirty_two, 4);
162       return buffer + 4;
163     } else {
164       memcpy(buffer, &sixty_four, 8);
165       return buffer + 8;
166     }
167   }
168
169   DataExtractor
170   GetAsData(lldb::ByteOrder byte_order = lldb::eByteOrderInvalid) const {
171     if (ptr_size == 4)
172       return DataExtractor(&thirty_two, 4, byte_order, 4);
173     else
174       return DataExtractor(&sixty_four, 8, byte_order, 8);
175   }
176
177 private:
178   InferiorSizedWord(uint64_t val, size_t psz) : ptr_size(psz) {
179     if (ptr_size == 4)
180       thirty_two = (uint32_t)val;
181     else
182       sixty_four = val;
183   }
184
185   size_t ptr_size;
186   union {
187     uint32_t thirty_two;
188     uint64_t sixty_four;
189   };
190 };
191 } // namespace formatters
192 } // namespace lldb_private
193
194 #endif // lldb_FormattersHelpers_h_