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