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
56size_t ExtractIndexFromString(const char *item_name);
57
58Address GetArrayAddressOrPointerValue(ValueObject &valobj);
59
60time_t GetOSXEpoch();
61
63
65 if (ptr_size == 4)
67 else
69 }
70
72 ptr_size = word.ptr_size;
73 if (ptr_size == 4)
75 else
77 return *this;
78 }
79
80 InferiorSizedWord(uint64_t val, Process &process)
81 : ptr_size(process.GetAddressByteSize()) {
82 if (ptr_size == 4)
83 thirty_two = (uint32_t)val;
84 else if (ptr_size == 8)
85 sixty_four = val;
86 else
87 assert(false && "new pointer size is unknown");
88 }
89
90 bool IsNegative() const {
91 if (ptr_size == 4)
92 return ((int32_t)thirty_two) < 0;
93 else
94 return ((int64_t)sixty_four) < 0;
95 }
96
97 bool IsZero() const {
98 if (ptr_size == 4)
99 return thirty_two == 0;
100 else
101 return sixty_four == 0;
102 }
103
105 if (process.GetAddressByteSize() == 4)
106 return InferiorSizedWord(UINT32_MAX, 4);
107 else
108 return InferiorSizedWord(UINT64_MAX, 8);
109 }
110
112 if (ptr_size == 4)
113 return InferiorSizedWord(thirty_two >> rhs, 4);
114 return InferiorSizedWord(sixty_four >> rhs, 8);
115 }
116
118 if (ptr_size == 4)
119 return InferiorSizedWord(thirty_two << rhs, 4);
120 return InferiorSizedWord(sixty_four << rhs, 8);
121 }
122
124 if (ptr_size != word.ptr_size)
125 return InferiorSizedWord(0, ptr_size);
126 if (ptr_size == 4)
127 return InferiorSizedWord(thirty_two & word.thirty_two, 4);
128 return InferiorSizedWord(sixty_four & word.sixty_four, 8);
129 }
130
132 if (ptr_size == 4)
133 return InferiorSizedWord(thirty_two & x, 4);
134 return InferiorSizedWord(sixty_four & x, 8);
135 }
136
137 size_t GetBitSize() const { return ptr_size << 3; }
138
139 size_t GetByteSize() const { return ptr_size; }
140
141 uint64_t GetValue() const {
142 if (ptr_size == 4)
143 return (uint64_t)thirty_two;
144 return sixty_four;
145 }
146
148 if (ptr_size == 4)
149 return InferiorSizedWord((int32_t)thirty_two, 4);
150 return InferiorSizedWord((int64_t)sixty_four, 8);
151 }
152
153 uint8_t *CopyToBuffer(uint8_t *buffer) const {
154 if (ptr_size == 4) {
155 memcpy(buffer, &thirty_two, 4);
156 return buffer + 4;
157 } else {
158 memcpy(buffer, &sixty_four, 8);
159 return buffer + 8;
160 }
161 }
162
165 if (ptr_size == 4)
166 return DataExtractor(&thirty_two, 4, byte_order, 4);
167 else
168 return DataExtractor(&sixty_four, 8, byte_order, 8);
169 }
170
171private:
172 InferiorSizedWord(uint64_t val, size_t psz) : ptr_size(psz) {
173 if (ptr_size == 4)
174 thirty_two = (uint32_t)val;
175 else
176 sixty_four = val;
177 }
178
179 size_t ptr_size;
180 union {
181 uint32_t thirty_two;
182 uint64_t sixty_four;
183 };
184};
185} // namespace formatters
186} // namespace lldb_private
187
188#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:343
uint32_t GetAddressByteSize() const
Definition: Process.cpp:3615
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.
std::shared_ptr< lldb_private::TypeSummaryImpl > TypeSummaryImplSP
Definition: lldb-forward.h:475
Format
Display format definitions.
ByteOrder
Byte ordering definitions.
@ eByteOrderInvalid
std::function< bool(ValueObject &, Stream &, const TypeSummaryOptions &)> Callback
Definition: TypeSummary.h:325
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)