/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/include/lldb/DataFormatters/FormattersHelpers.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- FormattersHelpers.h --------------------------------------*- C++ |
2 | | //-*-===// |
3 | | // |
4 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
5 | | // See https://llvm.org/LICENSE.txt for license information. |
6 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | |
10 | | #ifndef LLDB_DATAFORMATTERS_FORMATTERSHELPERS_H |
11 | | #define LLDB_DATAFORMATTERS_FORMATTERSHELPERS_H |
12 | | |
13 | | #include "lldb/lldb-enumerations.h" |
14 | | #include "lldb/lldb-forward.h" |
15 | | |
16 | | #include "lldb/DataFormatters/TypeCategory.h" |
17 | | #include "lldb/DataFormatters/TypeFormat.h" |
18 | | #include "lldb/DataFormatters/TypeSummary.h" |
19 | | #include "lldb/DataFormatters/TypeSynthetic.h" |
20 | | |
21 | | namespace lldb_private { |
22 | | namespace formatters { |
23 | | void AddFormat(TypeCategoryImpl::SharedPointer category_sp, lldb::Format format, |
24 | | llvm::StringRef type_name, TypeFormatImpl::Flags flags, |
25 | | bool regex = false); |
26 | | |
27 | | void AddSummary(TypeCategoryImpl::SharedPointer category_sp, |
28 | | lldb::TypeSummaryImplSP summary_sp, llvm::StringRef type_name, |
29 | | bool regex = false); |
30 | | |
31 | | void AddStringSummary(TypeCategoryImpl::SharedPointer category_sp, |
32 | | const char *string, llvm::StringRef type_name, |
33 | | TypeSummaryImpl::Flags flags, bool regex = false); |
34 | | |
35 | | void AddOneLineSummary(TypeCategoryImpl::SharedPointer category_sp, |
36 | | llvm::StringRef type_name, TypeSummaryImpl::Flags flags, |
37 | | bool regex = false); |
38 | | |
39 | | /// Add a summary that is implemented by a C++ callback. |
40 | | void AddCXXSummary(TypeCategoryImpl::SharedPointer category_sp, |
41 | | CXXFunctionSummaryFormat::Callback funct, |
42 | | const char *description, llvm::StringRef type_name, |
43 | | TypeSummaryImpl::Flags flags, bool regex = false); |
44 | | |
45 | | /// Add a synthetic that is implemented by a C++ callback. |
46 | | void AddCXXSynthetic(TypeCategoryImpl::SharedPointer category_sp, |
47 | | CXXSyntheticChildren::CreateFrontEndCallback generator, |
48 | | const char *description, llvm::StringRef 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 | | llvm::StringRef type_name, |
55 | | ScriptedSyntheticChildren::Flags flags, bool regex = false); |
56 | | |
57 | | size_t ExtractIndexFromString(const char *item_name); |
58 | | |
59 | | Address GetArrayAddressOrPointerValue(ValueObject &valobj); |
60 | | |
61 | | time_t GetOSXEpoch(); |
62 | | |
63 | | struct InferiorSizedWord { |
64 | | |
65 | 0 | InferiorSizedWord(const InferiorSizedWord &word) : ptr_size(word.ptr_size) { |
66 | 0 | if (ptr_size == 4) |
67 | 0 | thirty_two = word.thirty_two; |
68 | 0 | else |
69 | 0 | sixty_four = word.sixty_four; |
70 | 0 | } |
71 | | |
72 | 0 | InferiorSizedWord operator=(const InferiorSizedWord &word) { |
73 | 0 | ptr_size = word.ptr_size; |
74 | 0 | if (ptr_size == 4) |
75 | 0 | thirty_two = word.thirty_two; |
76 | 0 | else |
77 | 0 | sixty_four = word.sixty_four; |
78 | 0 | return *this; |
79 | 0 | } |
80 | | |
81 | | InferiorSizedWord(uint64_t val, Process &process) |
82 | 446 | : ptr_size(process.GetAddressByteSize()) { |
83 | 446 | if (ptr_size == 4) |
84 | 0 | thirty_two = (uint32_t)val; |
85 | 446 | else if (ptr_size == 8) |
86 | 446 | sixty_four = val; |
87 | 0 | else |
88 | 0 | assert(false && "new pointer size is unknown"); |
89 | 446 | } |
90 | | |
91 | 0 | bool IsNegative() const { |
92 | 0 | if (ptr_size == 4) |
93 | 0 | return ((int32_t)thirty_two) < 0; |
94 | 0 | else |
95 | 0 | return ((int64_t)sixty_four) < 0; |
96 | 0 | } |
97 | | |
98 | 0 | bool IsZero() const { |
99 | 0 | if (ptr_size == 4) |
100 | 0 | return thirty_two == 0; |
101 | 0 | else |
102 | 0 | return sixty_four == 0; |
103 | 0 | } |
104 | | |
105 | 0 | static InferiorSizedWord GetMaximum(Process &process) { |
106 | 0 | if (process.GetAddressByteSize() == 4) |
107 | 0 | return InferiorSizedWord(UINT32_MAX, 4); |
108 | 0 | else |
109 | 0 | return InferiorSizedWord(UINT64_MAX, 8); |
110 | 0 | } |
111 | | |
112 | 0 | InferiorSizedWord operator>>(int rhs) const { |
113 | 0 | if (ptr_size == 4) |
114 | 0 | return InferiorSizedWord(thirty_two >> rhs, 4); |
115 | 0 | return InferiorSizedWord(sixty_four >> rhs, 8); |
116 | 0 | } |
117 | | |
118 | 0 | InferiorSizedWord operator<<(int rhs) const { |
119 | 0 | if (ptr_size == 4) |
120 | 0 | return InferiorSizedWord(thirty_two << rhs, 4); |
121 | 0 | return InferiorSizedWord(sixty_four << rhs, 8); |
122 | 0 | } |
123 | | |
124 | 0 | InferiorSizedWord operator&(const InferiorSizedWord &word) const { |
125 | 0 | if (ptr_size != word.ptr_size) |
126 | 0 | return InferiorSizedWord(0, ptr_size); |
127 | 0 | if (ptr_size == 4) |
128 | 0 | return InferiorSizedWord(thirty_two & word.thirty_two, 4); |
129 | 0 | return InferiorSizedWord(sixty_four & word.sixty_four, 8); |
130 | 0 | } |
131 | | |
132 | 0 | InferiorSizedWord operator&(int x) const { |
133 | 0 | if (ptr_size == 4) |
134 | 0 | return InferiorSizedWord(thirty_two & x, 4); |
135 | 0 | return InferiorSizedWord(sixty_four & x, 8); |
136 | 0 | } |
137 | | |
138 | 0 | size_t GetBitSize() const { return ptr_size << 3; } |
139 | | |
140 | 0 | size_t GetByteSize() const { return ptr_size; } |
141 | | |
142 | 0 | uint64_t GetValue() const { |
143 | 0 | if (ptr_size == 4) |
144 | 0 | return (uint64_t)thirty_two; |
145 | 0 | return sixty_four; |
146 | 0 | } |
147 | | |
148 | 0 | InferiorSizedWord SignExtend() const { |
149 | 0 | if (ptr_size == 4) |
150 | 0 | return InferiorSizedWord((int32_t)thirty_two, 4); |
151 | 0 | return InferiorSizedWord((int64_t)sixty_four, 8); |
152 | 0 | } |
153 | | |
154 | 0 | uint8_t *CopyToBuffer(uint8_t *buffer) const { |
155 | 0 | if (ptr_size == 4) { |
156 | 0 | memcpy(buffer, &thirty_two, 4); |
157 | 0 | return buffer + 4; |
158 | 0 | } else { |
159 | 0 | memcpy(buffer, &sixty_four, 8); |
160 | 0 | return buffer + 8; |
161 | 0 | } |
162 | 0 | } |
163 | | |
164 | | DataExtractor |
165 | 311 | GetAsData(lldb::ByteOrder byte_order = lldb::eByteOrderInvalid) const { |
166 | 311 | if (ptr_size == 4) |
167 | 0 | return DataExtractor(&thirty_two, 4, byte_order, 4); |
168 | 311 | else |
169 | 311 | return DataExtractor(&sixty_four, 8, byte_order, 8); |
170 | 311 | } |
171 | | |
172 | | private: |
173 | 0 | InferiorSizedWord(uint64_t val, size_t psz) : ptr_size(psz) { |
174 | 0 | if (ptr_size == 4) |
175 | 0 | thirty_two = (uint32_t)val; |
176 | 0 | else |
177 | 0 | sixty_four = val; |
178 | 0 | } |
179 | | |
180 | | size_t ptr_size; |
181 | | union { |
182 | | uint32_t thirty_two; |
183 | | uint64_t sixty_four; |
184 | | }; |
185 | | }; |
186 | | } // namespace formatters |
187 | | } // namespace lldb_private |
188 | | |
189 | | #endif // LLDB_DATAFORMATTERS_FORMATTERSHELPERS_H |