LLDB mainline
FormattersHelpers.h
Go to the documentation of this file.
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
14#include "lldb/lldb-forward.h"
15
20
21namespace lldb_private {
22namespace formatters {
24 llvm::StringRef type_name, TypeFormatImpl::Flags flags,
25 bool regex = false);
26
28 lldb::TypeSummaryImplSP summary_sp, llvm::StringRef type_name,
29 bool regex = false);
30
32 const char *string, llvm::StringRef type_name,
33 TypeSummaryImpl::Flags flags, bool regex = false);
34
36 llvm::StringRef type_name, TypeSummaryImpl::Flags flags,
37 bool regex = false);
38
39/// Add a summary that is implemented by a C++ callback.
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.
48 const char *description, llvm::StringRef type_name,
49 ScriptedSyntheticChildren::Flags flags,
50 bool regex = false);
51
53 std::vector<std::string> children, const char *description,
54 llvm::StringRef type_name,
55 ScriptedSyntheticChildren::Flags flags, bool regex = false);
56
57size_t ExtractIndexFromString(const char *item_name);
58
59Address GetArrayAddressOrPointerValue(ValueObject &valobj);
60
61time_t GetOSXEpoch();
62
64
66 if (ptr_size == 4)
68 else
70 }
71
73 ptr_size = word.ptr_size;
74 if (ptr_size == 4)
76 else
78 return *this;
79 }
80
81 InferiorSizedWord(uint64_t val, Process &process)
82 : ptr_size(process.GetAddressByteSize()) {
83 if (ptr_size == 4)
84 thirty_two = (uint32_t)val;
85 else if (ptr_size == 8)
86 sixty_four = val;
87 else
88 assert(false && "new pointer size is unknown");
89 }
90
91 bool IsNegative() const {
92 if (ptr_size == 4)
93 return ((int32_t)thirty_two) < 0;
94 else
95 return ((int64_t)sixty_four) < 0;
96 }
97
98 bool IsZero() const {
99 if (ptr_size == 4)
100 return thirty_two == 0;
101 else
102 return sixty_four == 0;
103 }
104
106 if (process.GetAddressByteSize() == 4)
107 return InferiorSizedWord(UINT32_MAX, 4);
108 else
109 return InferiorSizedWord(UINT64_MAX, 8);
110 }
111
113 if (ptr_size == 4)
114 return InferiorSizedWord(thirty_two >> rhs, 4);
115 return InferiorSizedWord(sixty_four >> rhs, 8);
116 }
117
119 if (ptr_size == 4)
120 return InferiorSizedWord(thirty_two << rhs, 4);
121 return InferiorSizedWord(sixty_four << rhs, 8);
122 }
123
125 if (ptr_size != word.ptr_size)
126 return InferiorSizedWord(0, ptr_size);
127 if (ptr_size == 4)
128 return InferiorSizedWord(thirty_two & word.thirty_two, 4);
129 return InferiorSizedWord(sixty_four & word.sixty_four, 8);
130 }
131
133 if (ptr_size == 4)
134 return InferiorSizedWord(thirty_two & x, 4);
135 return InferiorSizedWord(sixty_four & x, 8);
136 }
137
138 size_t GetBitSize() const { return ptr_size << 3; }
139
140 size_t GetByteSize() const { return ptr_size; }
141
142 uint64_t GetValue() const {
143 if (ptr_size == 4)
144 return (uint64_t)thirty_two;
145 return sixty_four;
146 }
147
149 if (ptr_size == 4)
150 return InferiorSizedWord((int32_t)thirty_two, 4);
151 return InferiorSizedWord((int64_t)sixty_four, 8);
152 }
153
154 uint8_t *CopyToBuffer(uint8_t *buffer) const {
155 if (ptr_size == 4) {
156 memcpy(buffer, &thirty_two, 4);
157 return buffer + 4;
158 } else {
159 memcpy(buffer, &sixty_four, 8);
160 return buffer + 8;
161 }
162 }
163
166 if (ptr_size == 4)
167 return DataExtractor(&thirty_two, 4, byte_order, 4);
168 else
169 return DataExtractor(&sixty_four, 8, byte_order, 8);
170 }
171
172private:
173 InferiorSizedWord(uint64_t val, size_t psz) : ptr_size(psz) {
174 if (ptr_size == 4)
175 thirty_two = (uint32_t)val;
176 else
177 sixty_four = val;
178 }
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
std::function< SyntheticChildrenFrontEnd *(CXXSyntheticChildren *, lldb::ValueObjectSP)> CreateFrontEndCallback
An data extractor class.
Definition: DataExtractor.h:48
A plug-in interface definition class for debugging a process.
Definition: Process.h:341
uint32_t GetAddressByteSize() const
Definition: Process.cpp:3404
std::shared_ptr< TypeCategoryImpl > SharedPointer
Definition: TypeCategory.h:357
#define UINT64_MAX
Definition: lldb-defines.h:23
#define UINT32_MAX
Definition: lldb-defines.h:19
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.
size_t ExtractIndexFromString(const char *item_name)
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)
Address GetArrayAddressOrPointerValue(ValueObject &valobj)
void AddSummary(TypeCategoryImpl::SharedPointer category_sp, lldb::TypeSummaryImplSP summary_sp, llvm::StringRef type_name, bool regex=false)
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
std::shared_ptr< lldb_private::TypeSummaryImpl > TypeSummaryImplSP
Definition: lldb-forward.h:463
Format
Display format definitions.
ByteOrder
Byte ordering definitions.
@ eByteOrderInvalid
std::function< bool(ValueObject &, Stream &, const TypeSummaryOptions &)> Callback
Definition: TypeSummary.h:311
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&(int x) const
InferiorSizedWord operator=(const InferiorSizedWord &word)
InferiorSizedWord(const InferiorSizedWord &word)