LLDB mainline
FormatEntity.h
Go to the documentation of this file.
1//===-- FormatEntity.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_CORE_FORMATENTITY_H
10#define LLDB_CORE_FORMATENTITY_H
11
13#include "lldb/lldb-types.h"
14#include "llvm/ADT/SmallVector.h"
15#include <algorithm>
16#include <cstddef>
17#include <cstdint>
18#include <string>
19#include <vector>
20
21namespace lldb_private {
22class Address;
25class FileSpec;
26class Status;
27class Stream;
28class StringList;
29class SymbolContext;
30class ValueObject;
31}
32
33namespace llvm {
34class StringRef;
35}
36
37namespace lldb_private {
38namespace FormatEntity {
39struct Entry {
40 enum class Type {
120 };
121
122 struct Definition {
123 /// The name/string placeholder that corresponds to this definition.
124 const char *name;
125 /// Insert this exact string into the output
126 const char *string = nullptr;
127 /// Entry::Type corresponding to this definition.
129 /// Data that is returned as the value of the format string.
130 const uint64_t data = 0;
131 /// The number of children of this node in the tree of format strings.
132 const uint32_t num_children = 0;
133 /// An array of "num_children" Definition entries.
134 const Definition *children = nullptr;
135 /// Whether the separator is kept during parsing or not. It's used
136 /// for entries with parameters.
137 const bool keep_separator = false;
138
139 constexpr Definition(const char *name, const FormatEntity::Entry::Type t)
140 : name(name), type(t) {}
141
142 constexpr Definition(const char *name, const char *string)
144
145 constexpr Definition(const char *name, const FormatEntity::Entry::Type t,
146 const uint64_t data)
147 : name(name), type(t), data(data) {}
148
149 constexpr Definition(const char *name, const FormatEntity::Entry::Type t,
150 const uint64_t num_children,
151 const Definition *children,
152 const bool keep_separator = false)
155 };
156
157 template <size_t N>
158 static constexpr Definition
160 const Definition (&children)[N],
161 bool keep_separator = false) {
162 return Definition(name, t, N, children, keep_separator);
163 }
164
165 Entry(Type t = Type::Invalid, const char *s = nullptr,
166 const char *f = nullptr);
167 Entry(llvm::StringRef s);
168 Entry(char ch);
169
170 void AppendChar(char ch);
171
172 void AppendText(const llvm::StringRef &s);
173
174 void AppendText(const char *cstr);
175
176 void AppendEntry(const Entry &&entry);
177
178 void StartAlternative();
179
180 void Clear() {
181 string.clear();
182 printf_format.clear();
183 children_stack.clear();
184 children_stack.emplace_back();
187 number = 0;
188 level = 0;
189 deref = false;
190 }
191
192 static const char *TypeToCString(Type t);
193
194 void Dump(Stream &s, int depth = 0) const;
195
196 bool operator==(const Entry &rhs) const {
197 if (string != rhs.string)
198 return false;
199 if (printf_format != rhs.printf_format)
200 return false;
202 return false;
203 if (type != rhs.type)
204 return false;
205 if (fmt != rhs.fmt)
206 return false;
207 if (deref != rhs.deref)
208 return false;
209 return true;
210 }
211
212 operator bool() const { return type != Type::Invalid; }
213
214 std::vector<Entry> &GetChildren();
215
216 std::string string;
217 std::string printf_format;
218
219 /// A stack of children entries, used by Scope entries to provide alterantive
220 /// children. All other entries have a stack of size 1.
221 /// @{
222 llvm::SmallVector<std::vector<Entry>, 1> children_stack;
223 size_t level = 0;
224 /// @}
225
229 bool deref = false;
230};
231
232bool Format(const Entry &entry, Stream &s, const SymbolContext *sc,
233 const ExecutionContext *exe_ctx, const Address *addr,
234 ValueObject *valobj, bool function_changed, bool initial_function);
235
236bool FormatStringRef(const llvm::StringRef &format, Stream &s,
237 const SymbolContext *sc, const ExecutionContext *exe_ctx,
238 const Address *addr, ValueObject *valobj,
239 bool function_changed, bool initial_function);
240
241Status Parse(const llvm::StringRef &format, Entry &entry);
242
243Status ExtractVariableInfo(llvm::StringRef &format_str,
244 llvm::StringRef &variable_name,
245 llvm::StringRef &variable_format);
246
248
249// Format the current elements into the stream \a s.
250//
251// The root element will be stripped off and the format str passed in will be
252// either an empty string (print a description of this object), or contain a
253// `.`-separated series like a domain name that identifies further
254// sub-elements to display.
255bool FormatFileSpec(const FileSpec &file, Stream &s, llvm::StringRef elements,
256 llvm::StringRef element_format);
257
258/// For each variable in 'args' this function writes the variable
259/// name and it's pretty-printed value representation to 'out_stream'
260/// in following format:
261///
262/// \verbatim
263/// name_1=repr_1, name_2=repr_2 ...
264/// \endverbatim
265void PrettyPrintFunctionArguments(Stream &out_stream, VariableList const &args,
266 ExecutionContextScope *exe_scope);
267} // namespace FormatEntity
268} // namespace lldb_private
269
270#endif // LLDB_CORE_FORMATENTITY_H
lldb_private::FormatEntity::Entry::Definition Definition
FormatEntity::Entry Entry
A section + offset based address class.
Definition Address.h:62
"lldb/Utility/ArgCompletionRequest.h"
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A file utility class.
Definition FileSpec.h:57
An error handling class.
Definition Status.h:118
A stream class that can stream formatted output to a file.
Definition Stream.h:28
Defines a symbol context baton that can be handed other debug core functions.
bool FormatFileSpec(const FileSpec &file, Stream &s, llvm::StringRef elements, llvm::StringRef element_format)
Status Parse(const llvm::StringRef &format, Entry &entry)
bool Format(const Entry &entry, Stream &s, const SymbolContext *sc, const ExecutionContext *exe_ctx, const Address *addr, ValueObject *valobj, bool function_changed, bool initial_function)
Status ExtractVariableInfo(llvm::StringRef &format_str, llvm::StringRef &variable_name, llvm::StringRef &variable_format)
bool FormatStringRef(const llvm::StringRef &format, Stream &s, const SymbolContext *sc, const ExecutionContext *exe_ctx, const Address *addr, ValueObject *valobj, bool function_changed, bool initial_function)
void PrettyPrintFunctionArguments(Stream &out_stream, VariableList const &args, ExecutionContextScope *exe_scope)
For each variable in 'args' this function writes the variable name and it's pretty-printed value repr...
void AutoComplete(lldb_private::CompletionRequest &request)
A class that represents a running process on the host machine.
Format
Display format definitions.
uint64_t addr_t
Definition lldb-types.h:80
const char * name
The name/string placeholder that corresponds to this definition.
constexpr Definition(const char *name, const FormatEntity::Entry::Type t, const uint64_t data)
const Definition * children
An array of "num_children" Definition entries.
constexpr Definition(const char *name, const FormatEntity::Entry::Type t, const uint64_t num_children, const Definition *children, const bool keep_separator=false)
const bool keep_separator
Whether the separator is kept during parsing or not.
const char * string
Insert this exact string into the output.
const uint64_t data
Data that is returned as the value of the format string.
constexpr Definition(const char *name, const FormatEntity::Entry::Type t)
const uint32_t num_children
The number of children of this node in the tree of format strings.
const Entry::Type type
Entry::Type corresponding to this definition.
constexpr Definition(const char *name, const char *string)
void Dump(Stream &s, int depth=0) const
Entry(Type t=Type::Invalid, const char *s=nullptr, const char *f=nullptr)
void AppendText(const llvm::StringRef &s)
static constexpr Definition DefinitionWithChildren(const char *name, const FormatEntity::Entry::Type t, const Definition(&children)[N], bool keep_separator=false)
llvm::SmallVector< std::vector< Entry >, 1 > children_stack
A stack of children entries, used by Scope entries to provide alterantive children.
bool operator==(const Entry &rhs) const
std::vector< Entry > & GetChildren()
static const char * TypeToCString(Type t)
void AppendEntry(const Entry &&entry)