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 {
119 };
120
121 struct Definition {
122 /// The name/string placeholder that corresponds to this definition.
123 const char *name;
124 /// Insert this exact string into the output
125 const char *string = nullptr;
126 /// Entry::Type corresponding to this definition.
128 /// Data that is returned as the value of the format string.
129 const uint64_t data = 0;
130 /// The number of children of this node in the tree of format strings.
131 const uint32_t num_children = 0;
132 /// An array of "num_children" Definition entries.
133 const Definition *children = nullptr;
134 /// Whether the separator is kept during parsing or not. It's used
135 /// for entries with parameters.
136 const bool keep_separator = false;
137
138 constexpr Definition(const char *name, const FormatEntity::Entry::Type t)
139 : name(name), type(t) {}
140
141 constexpr Definition(const char *name, const char *string)
143
144 constexpr Definition(const char *name, const FormatEntity::Entry::Type t,
145 const uint64_t data)
146 : name(name), type(t), data(data) {}
147
148 constexpr Definition(const char *name, const FormatEntity::Entry::Type t,
149 const uint64_t num_children,
150 const Definition *children,
151 const bool keep_separator = false)
154 };
155
156 template <size_t N>
157 static constexpr Definition
159 const Definition (&children)[N],
160 bool keep_separator = false) {
161 return Definition(name, t, N, children, keep_separator);
162 }
163
164 Entry(Type t = Type::Invalid, const char *s = nullptr,
165 const char *f = nullptr);
166 Entry(llvm::StringRef s);
167 Entry(char ch);
168
169 void AppendChar(char ch);
170
171 void AppendText(const llvm::StringRef &s);
172
173 void AppendText(const char *cstr);
174
175 void AppendEntry(const Entry &&entry);
176
177 void StartAlternative();
178
179 void Clear() {
180 string.clear();
181 printf_format.clear();
182 children_stack.clear();
183 children_stack.emplace_back();
186 number = 0;
187 level = 0;
188 deref = false;
189 }
190
191 static const char *TypeToCString(Type t);
192
193 void Dump(Stream &s, int depth = 0) const;
194
195 bool operator==(const Entry &rhs) const {
196 if (string != rhs.string)
197 return false;
198 if (printf_format != rhs.printf_format)
199 return false;
201 return false;
202 if (type != rhs.type)
203 return false;
204 if (fmt != rhs.fmt)
205 return false;
206 if (deref != rhs.deref)
207 return false;
208 return true;
209 }
210
211 operator bool() const { return type != Type::Invalid; }
212
213 std::vector<Entry> &GetChildren();
214
215 std::string string;
216 std::string printf_format;
217
218 /// A stack of children entries, used by Scope entries to provide alterantive
219 /// children. All other entries have a stack of size 1.
220 /// @{
221 llvm::SmallVector<std::vector<Entry>, 1> children_stack;
222 size_t level = 0;
223 /// @}
224
228 bool deref = false;
229};
230
231bool Format(const Entry &entry, Stream &s, const SymbolContext *sc,
232 const ExecutionContext *exe_ctx, const Address *addr,
233 ValueObject *valobj, bool function_changed, bool initial_function);
234
235bool FormatStringRef(const llvm::StringRef &format, Stream &s,
236 const SymbolContext *sc, const ExecutionContext *exe_ctx,
237 const Address *addr, ValueObject *valobj,
238 bool function_changed, bool initial_function);
239
240Status Parse(const llvm::StringRef &format, Entry &entry);
241
242Status ExtractVariableInfo(llvm::StringRef &format_str,
243 llvm::StringRef &variable_name,
244 llvm::StringRef &variable_format);
245
247
248// Format the current elements into the stream \a s.
249//
250// The root element will be stripped off and the format str passed in will be
251// either an empty string (print a description of this object), or contain a
252// `.`-separated series like a domain name that identifies further
253// sub-elements to display.
254bool FormatFileSpec(const FileSpec &file, Stream &s, llvm::StringRef elements,
255 llvm::StringRef element_format);
256
257/// For each variable in 'args' this function writes the variable
258/// name and it's pretty-printed value representation to 'out_stream'
259/// in following format:
260///
261/// \verbatim
262/// name_1=repr_1, name_2=repr_2 ...
263/// \endverbatim
264void PrettyPrintFunctionArguments(Stream &out_stream, VariableList const &args,
265 ExecutionContextScope *exe_scope);
266} // namespace FormatEntity
267} // namespace lldb_private
268
269#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)