LLDB mainline
FormattersHelpers.h
Go to the documentation of this file.
1//===-- FormattersHelpers.h -------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_DATAFORMATTERS_FORMATTERSHELPERS_H
10#define LLDB_DATAFORMATTERS_FORMATTERSHELPERS_H
11
13#include "lldb/lldb-forward.h"
14
19
20namespace lldb_private {
21namespace formatters {
23 llvm::StringRef type_name, TypeFormatImpl::Flags flags,
24 bool regex = false);
25
27 lldb::TypeSummaryImplSP summary_sp, llvm::StringRef type_name,
28 bool regex = false);
29
31 const char *string, llvm::StringRef type_name,
32 TypeSummaryImpl::Flags flags, bool regex = false);
33
35 llvm::StringRef type_name, TypeSummaryImpl::Flags flags,
36 bool regex = false);
37
38/// Add a summary that is implemented by a C++ callback.
41 const char *description, llvm::StringRef type_name,
42 TypeSummaryImpl::Flags flags, bool regex = false);
43
44/// Add a synthetic that is implemented by a C++ callback.
47 const char *description, llvm::StringRef type_name,
48 ScriptedSyntheticChildren::Flags flags,
49 bool regex = false);
50
52 std::vector<std::string> children, const char *description,
53 llvm::StringRef type_name,
54 ScriptedSyntheticChildren::Flags flags, bool regex = false);
55
56std::optional<size_t> ExtractIndexFromString(const char *item_name);
57
58/// Prints the summary for the pointer value of a C++
59/// std::unique_ptr/std::shared_ptr/std::weak_ptr.
60void DumpCxxSmartPtrPointerSummary(Stream &stream, ValueObject &ptr,
61 const TypeSummaryOptions &options);
62
63bool ContainerSizeSummaryProvider(ValueObject &valobj, Stream &stream,
64 const TypeSummaryOptions &options);
65
66Address GetArrayAddressOrPointerValue(ValueObject &valobj);
67
68time_t GetOSXEpoch();
69
71
73 if (ptr_size == 4)
75 else
77 }
78
80 ptr_size = word.ptr_size;
81 if (ptr_size == 4)
83 else
85 return *this;
86 }
87
88 InferiorSizedWord(uint64_t val, Process &process)
89 : ptr_size(process.GetAddressByteSize()) {
90 if (ptr_size == 4)
91 thirty_two = (uint32_t)val;
92 else if (ptr_size == 8)
93 sixty_four = val;
94 else
95 assert(false && "new pointer size is unknown");
96 }
97
98 bool IsNegative() const {
99 if (ptr_size == 4)
100 return ((int32_t)thirty_two) < 0;
101 else
102 return ((int64_t)sixty_four) < 0;
103 }
104
105 bool IsZero() const {
106 if (ptr_size == 4)
107 return thirty_two == 0;
108 else
109 return sixty_four == 0;
110 }
111
113 if (process.GetAddressByteSize() == 4)
114 return InferiorSizedWord(UINT32_MAX, 4);
115 else
116 return InferiorSizedWord(UINT64_MAX, 8);
117 }
118
120 if (ptr_size == 4)
121 return InferiorSizedWord(thirty_two >> rhs, 4);
122 return InferiorSizedWord(sixty_four >> rhs, 8);
123 }
124
126 if (ptr_size == 4)
127 return InferiorSizedWord(thirty_two << rhs, 4);
128 return InferiorSizedWord(sixty_four << rhs, 8);
129 }
130
132 if (ptr_size != word.ptr_size)
133 return InferiorSizedWord(0, ptr_size);
134 if (ptr_size == 4)
135 return InferiorSizedWord(thirty_two & word.thirty_two, 4);
136 return InferiorSizedWord(sixty_four & word.sixty_four, 8);
137 }
138
140 if (ptr_size == 4)
141 return InferiorSizedWord(thirty_two & x, 4);
142 return InferiorSizedWord(sixty_four & x, 8);
143 }
144
145 size_t GetBitSize() const { return ptr_size << 3; }
146
147 size_t GetByteSize() const { return ptr_size; }
148
149 uint64_t GetValue() const {
150 if (ptr_size == 4)
151 return (uint64_t)thirty_two;
152 return sixty_four;
153 }
154
156 if (ptr_size == 4)
157 return InferiorSizedWord((int32_t)thirty_two, 4);
158 return InferiorSizedWord((int64_t)sixty_four, 8);
159 }
160
161 uint8_t *CopyToBuffer(uint8_t *buffer) const {
162 if (ptr_size == 4) {
163 memcpy(buffer, &thirty_two, 4);
164 return buffer + 4;
165 } else {
166 memcpy(buffer, &sixty_four, 8);
167 return buffer + 8;
168 }
169 }
170
173 if (ptr_size == 4)
174 return DataExtractor(&thirty_two, 4, byte_order, 4);
175 else
176 return DataExtractor(&sixty_four, 8, byte_order, 8);
177 }
178
179private:
180 InferiorSizedWord(uint64_t val, size_t psz) : ptr_size(psz) {
181 if (ptr_size == 4)
182 thirty_two = (uint32_t)val;
183 else
184 sixty_four = val;
185 }
186
187 size_t ptr_size;
188 union {
189 uint32_t thirty_two;
190 uint64_t sixty_four;
191 };
192};
193} // namespace formatters
194} // namespace lldb_private
195
196#endif // LLDB_DATAFORMATTERS_FORMATTERSHELPERS_H
std::function< SyntheticChildrenFrontEnd *(CXXSyntheticChildren *, lldb::ValueObjectSP)> CreateFrontEndCallback
An data extractor class.
A plug-in interface definition class for debugging a process.
Definition Process.h:357
uint32_t GetAddressByteSize() const
Definition Process.cpp:3620
std::shared_ptr< TypeCategoryImpl > SharedPointer
#define UINT64_MAX
#define UINT32_MAX
std::optional< size_t > ExtractIndexFromString(const char *item_name)
void AddOneLineSummary(TypeCategoryImpl::SharedPointer category_sp, llvm::StringRef type_name, TypeSummaryImpl::Flags flags, bool regex=false)
void AddCXXSummary(TypeCategoryImpl::SharedPointer category_sp, CXXFunctionSummaryFormat::Callback funct, const char *description, llvm::StringRef type_name, TypeSummaryImpl::Flags flags, bool regex=false)
Add a summary that is implemented by a C++ callback.
void AddStringSummary(TypeCategoryImpl::SharedPointer category_sp, const char *string, llvm::StringRef type_name, TypeSummaryImpl::Flags flags, bool regex=false)
void AddCXXSynthetic(TypeCategoryImpl::SharedPointer category_sp, CXXSyntheticChildren::CreateFrontEndCallback generator, const char *description, llvm::StringRef type_name, ScriptedSyntheticChildren::Flags flags, bool regex=false)
Add a synthetic that is implemented by a C++ callback.
void AddFilter(TypeCategoryImpl::SharedPointer category_sp, std::vector< std::string > children, const char *description, llvm::StringRef type_name, ScriptedSyntheticChildren::Flags flags, bool regex=false)
void AddFormat(TypeCategoryImpl::SharedPointer category_sp, lldb::Format format, llvm::StringRef type_name, TypeFormatImpl::Flags flags, bool regex=false)
bool ContainerSizeSummaryProvider(ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options)
Address GetArrayAddressOrPointerValue(ValueObject &valobj)
void AddSummary(TypeCategoryImpl::SharedPointer category_sp, lldb::TypeSummaryImplSP summary_sp, llvm::StringRef type_name, bool regex=false)
void DumpCxxSmartPtrPointerSummary(Stream &stream, ValueObject &ptr, const TypeSummaryOptions &options)
Prints the summary for the pointer value of a C++ std::unique_ptr/stdshared_ptr/stdweak_ptr.
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::TypeSummaryImpl > TypeSummaryImplSP
Format
Display format definitions.
ByteOrder
Byte ordering definitions.
std::function< bool(ValueObject &, Stream &, const TypeSummaryOptions &)> Callback
InferiorSizedWord operator&(const InferiorSizedWord &word) const
uint8_t * CopyToBuffer(uint8_t *buffer) const
static InferiorSizedWord GetMaximum(Process &process)
DataExtractor GetAsData(lldb::ByteOrder byte_order=lldb::eByteOrderInvalid) const
InferiorSizedWord operator>>(int rhs) const
InferiorSizedWord(uint64_t val, Process &process)
InferiorSizedWord operator<<(int rhs) const
InferiorSizedWord operator=(const InferiorSizedWord &word)
InferiorSizedWord(const InferiorSizedWord &word)