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 <algorithm>
15#include <cstddef>
16#include <cstdint>
17
18#include <string>
19#include <vector>
20
21namespace lldb_private {
22class Address;
23class CompletionRequest;
24class ExecutionContext;
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 {
41 Invalid,
45 Root,
46 String,
47 Scope,
73 File,
74 Lang,
104 };
105
106 struct Definition {
107 /// The name/string placeholder that corresponds to this definition.
108 const char *name;
109 /// Insert this exact string into the output
110 const char *string = nullptr;
111 /// Entry::Type corresponding to this definition.
113 /// Data that is returned as the value of the format string.
114 const uint64_t data = 0;
115 /// The number of children of this node in the tree of format strings.
116 const uint32_t num_children = 0;
117 /// An array of "num_children" Definition entries.
118 const Definition *children = nullptr;
119 /// Whether the separator is kept during parsing or not. It's used
120 /// for entries with parameters.
121 const bool keep_separator = false;
122
123 constexpr Definition(const char *name, const FormatEntity::Entry::Type t)
124 : name(name), type(t) {}
125
126 constexpr Definition(const char *name, const char *string)
128
129 constexpr Definition(const char *name, const FormatEntity::Entry::Type t,
130 const uint64_t data)
131 : name(name), type(t), data(data) {}
132
133 constexpr Definition(const char *name, const FormatEntity::Entry::Type t,
134 const uint64_t num_children,
135 const Definition *children,
136 const bool keep_separator = false)
139 };
140
141 template <size_t N>
142 static constexpr Definition
144 const Definition (&children)[N],
145 bool keep_separator = false) {
146 return Definition(name, t, N, children, keep_separator);
147 }
148
149 Entry(Type t = Type::Invalid, const char *s = nullptr,
150 const char *f = nullptr)
151 : string(s ? s : ""), printf_format(f ? f : ""), type(t) {}
152
153 Entry(llvm::StringRef s);
154 Entry(char ch);
155
156 void AppendChar(char ch);
157
158 void AppendText(const llvm::StringRef &s);
159
160 void AppendText(const char *cstr);
161
162 void AppendEntry(const Entry &&entry) { children.push_back(entry); }
163
164 void Clear() {
165 string.clear();
166 printf_format.clear();
167 children.clear();
170 number = 0;
171 deref = false;
172 }
173
174 static const char *TypeToCString(Type t);
175
176 void Dump(Stream &s, int depth = 0) const;
177
178 bool operator==(const Entry &rhs) const {
179 if (string != rhs.string)
180 return false;
181 if (printf_format != rhs.printf_format)
182 return false;
183 const size_t n = children.size();
184 const size_t m = rhs.children.size();
185 for (size_t i = 0; i < std::min<size_t>(n, m); ++i) {
186 if (!(children[i] == rhs.children[i]))
187 return false;
188 }
189 if (children != rhs.children)
190 return false;
191 if (type != rhs.type)
192 return false;
193 if (fmt != rhs.fmt)
194 return false;
195 if (deref != rhs.deref)
196 return false;
197 return true;
198 }
199
200 std::string string;
201 std::string printf_format;
202 std::vector<Entry> children;
206 bool deref = false;
207};
208
209bool Format(const Entry &entry, Stream &s, const SymbolContext *sc,
210 const ExecutionContext *exe_ctx, const Address *addr,
211 ValueObject *valobj, bool function_changed, bool initial_function);
212
213bool FormatStringRef(const llvm::StringRef &format, Stream &s,
214 const SymbolContext *sc, const ExecutionContext *exe_ctx,
215 const Address *addr, ValueObject *valobj,
216 bool function_changed, bool initial_function);
217
218bool FormatCString(const char *format, Stream &s, const SymbolContext *sc,
219 const ExecutionContext *exe_ctx, const Address *addr,
220 ValueObject *valobj, bool function_changed,
221 bool initial_function);
222
223Status Parse(const llvm::StringRef &format, Entry &entry);
224
225Status ExtractVariableInfo(llvm::StringRef &format_str,
226 llvm::StringRef &variable_name,
227 llvm::StringRef &variable_format);
228
230
231// Format the current elements into the stream \a s.
232//
233// The root element will be stripped off and the format str passed in will be
234// either an empty string (print a description of this object), or contain a
235// `.`-separated series like a domain name that identifies further
236// sub-elements to display.
237bool FormatFileSpec(const FileSpec &file, Stream &s, llvm::StringRef elements,
238 llvm::StringRef element_format);
239
240/// For each variable in 'args' this function writes the variable
241/// name and it's pretty-printed value representation to 'out_stream'
242/// in following format:
243///
244/// \verbatim
245/// name_1=repr_1, name_2=repr_2 ...
246/// \endverbatim
247void PrettyPrintFunctionArguments(Stream &out_stream, VariableList const &args,
248 ExecutionContextScope *exe_scope);
249} // namespace FormatEntity
250} // namespace lldb_private
251
252#endif // LLDB_CORE_FORMATENTITY_H
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:56
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.
Definition: SymbolContext.h:34
bool FormatFileSpec(const FileSpec &file, Stream &s, llvm::StringRef elements, llvm::StringRef element_format)
Status Parse(const llvm::StringRef &format, Entry &entry)
bool FormatCString(const char *format, 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
Definition: Debugger.h:54
const char * name
The name/string placeholder that corresponds to this definition.
Definition: FormatEntity.h:108
constexpr Definition(const char *name, const FormatEntity::Entry::Type t, const uint64_t data)
Definition: FormatEntity.h:129
const Definition * children
An array of "num_children" Definition entries.
Definition: FormatEntity.h:118
constexpr Definition(const char *name, const FormatEntity::Entry::Type t, const uint64_t num_children, const Definition *children, const bool keep_separator=false)
Definition: FormatEntity.h:133
const bool keep_separator
Whether the separator is kept during parsing or not.
Definition: FormatEntity.h:121
const char * string
Insert this exact string into the output.
Definition: FormatEntity.h:110
const uint64_t data
Data that is returned as the value of the format string.
Definition: FormatEntity.h:114
constexpr Definition(const char *name, const FormatEntity::Entry::Type t)
Definition: FormatEntity.h:123
const uint32_t num_children
The number of children of this node in the tree of format strings.
Definition: FormatEntity.h:116
const Entry::Type type
Entry::Type corresponding to this definition.
Definition: FormatEntity.h:112
constexpr Definition(const char *name, const char *string)
Definition: FormatEntity.h:126
void Dump(Stream &s, int depth=0) const
std::vector< Entry > children
Definition: FormatEntity.h:202
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)
Definition: FormatEntity.h:143
bool operator==(const Entry &rhs) const
Definition: FormatEntity.h:178
void AppendEntry(const Entry &&entry)
Definition: FormatEntity.h:162
static const char * TypeToCString(Type t)
Entry(Type t=Type::Invalid, const char *s=nullptr, const char *f=nullptr)
Definition: FormatEntity.h:149