File indexing completed on 2026-05-10 08:42:45
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLDB_CORE_FORMATENTITY_H
0010 #define LLDB_CORE_FORMATENTITY_H
0011
0012 #include "lldb/lldb-enumerations.h"
0013 #include "lldb/lldb-types.h"
0014 #include <algorithm>
0015 #include <cstddef>
0016 #include <cstdint>
0017
0018 #include <string>
0019 #include <vector>
0020
0021 namespace lldb_private {
0022 class Address;
0023 class CompletionRequest;
0024 class ExecutionContext;
0025 class FileSpec;
0026 class Status;
0027 class Stream;
0028 class StringList;
0029 class SymbolContext;
0030 class ValueObject;
0031 }
0032
0033 namespace llvm {
0034 class StringRef;
0035 }
0036
0037 namespace lldb_private {
0038 namespace FormatEntity {
0039 struct Entry {
0040 enum class Type {
0041 Invalid,
0042 ParentNumber,
0043 ParentString,
0044 EscapeCode,
0045 Root,
0046 String,
0047 Scope,
0048 Variable,
0049 VariableSynthetic,
0050 ScriptVariable,
0051 ScriptVariableSynthetic,
0052 AddressLoad,
0053 AddressFile,
0054 AddressLoadOrFile,
0055 ProcessID,
0056 ProcessFile,
0057 ScriptProcess,
0058 ThreadID,
0059 ThreadProtocolID,
0060 ThreadIndexID,
0061 ThreadName,
0062 ThreadQueue,
0063 ThreadStopReason,
0064 ThreadStopReasonRaw,
0065 ThreadReturnValue,
0066 ThreadCompletedExpression,
0067 ScriptThread,
0068 ThreadInfo,
0069 TargetArch,
0070 TargetFile,
0071 ScriptTarget,
0072 ModuleFile,
0073 File,
0074 Lang,
0075 FrameIndex,
0076 FrameNoDebug,
0077 FrameRegisterPC,
0078 FrameRegisterSP,
0079 FrameRegisterFP,
0080 FrameRegisterFlags,
0081 FrameRegisterByName,
0082 FrameIsArtificial,
0083 ScriptFrame,
0084 FunctionID,
0085 FunctionDidChange,
0086 FunctionInitialFunction,
0087 FunctionName,
0088 FunctionNameWithArgs,
0089 FunctionNameNoArgs,
0090 FunctionMangledName,
0091 FunctionAddrOffset,
0092 FunctionAddrOffsetConcrete,
0093 FunctionLineOffset,
0094 FunctionPCOffset,
0095 FunctionInitial,
0096 FunctionChanged,
0097 FunctionIsOptimized,
0098 LineEntryFile,
0099 LineEntryLineNumber,
0100 LineEntryColumn,
0101 LineEntryStartAddress,
0102 LineEntryEndAddress,
0103 CurrentPCArrow
0104 };
0105
0106 struct Definition {
0107
0108 const char *name;
0109
0110 const char *string = nullptr;
0111
0112 const Entry::Type type;
0113
0114 const uint64_t data = 0;
0115
0116 const uint32_t num_children = 0;
0117
0118 const Definition *children = nullptr;
0119
0120
0121 const bool keep_separator = false;
0122
0123 constexpr Definition(const char *name, const FormatEntity::Entry::Type t)
0124 : name(name), type(t) {}
0125
0126 constexpr Definition(const char *name, const char *string)
0127 : name(name), string(string), type(Entry::Type::EscapeCode) {}
0128
0129 constexpr Definition(const char *name, const FormatEntity::Entry::Type t,
0130 const uint64_t data)
0131 : name(name), type(t), data(data) {}
0132
0133 constexpr Definition(const char *name, const FormatEntity::Entry::Type t,
0134 const uint64_t num_children,
0135 const Definition *children,
0136 const bool keep_separator = false)
0137 : name(name), type(t), num_children(num_children), children(children),
0138 keep_separator(keep_separator) {}
0139 };
0140
0141 template <size_t N>
0142 static constexpr Definition
0143 DefinitionWithChildren(const char *name, const FormatEntity::Entry::Type t,
0144 const Definition (&children)[N],
0145 bool keep_separator = false) {
0146 return Definition(name, t, N, children, keep_separator);
0147 }
0148
0149 Entry(Type t = Type::Invalid, const char *s = nullptr,
0150 const char *f = nullptr)
0151 : string(s ? s : ""), printf_format(f ? f : ""), type(t) {}
0152
0153 Entry(llvm::StringRef s);
0154 Entry(char ch);
0155
0156 void AppendChar(char ch);
0157
0158 void AppendText(const llvm::StringRef &s);
0159
0160 void AppendText(const char *cstr);
0161
0162 void AppendEntry(const Entry &&entry) { children.push_back(entry); }
0163
0164 void Clear() {
0165 string.clear();
0166 printf_format.clear();
0167 children.clear();
0168 type = Type::Invalid;
0169 fmt = lldb::eFormatDefault;
0170 number = 0;
0171 deref = false;
0172 }
0173
0174 static const char *TypeToCString(Type t);
0175
0176 void Dump(Stream &s, int depth = 0) const;
0177
0178 bool operator==(const Entry &rhs) const {
0179 if (string != rhs.string)
0180 return false;
0181 if (printf_format != rhs.printf_format)
0182 return false;
0183 const size_t n = children.size();
0184 const size_t m = rhs.children.size();
0185 for (size_t i = 0; i < std::min<size_t>(n, m); ++i) {
0186 if (!(children[i] == rhs.children[i]))
0187 return false;
0188 }
0189 if (children != rhs.children)
0190 return false;
0191 if (type != rhs.type)
0192 return false;
0193 if (fmt != rhs.fmt)
0194 return false;
0195 if (deref != rhs.deref)
0196 return false;
0197 return true;
0198 }
0199
0200 std::string string;
0201 std::string printf_format;
0202 std::vector<Entry> children;
0203 Type type;
0204 lldb::Format fmt = lldb::eFormatDefault;
0205 lldb::addr_t number = 0;
0206 bool deref = false;
0207 };
0208
0209 bool Format(const Entry &entry, Stream &s, const SymbolContext *sc,
0210 const ExecutionContext *exe_ctx, const Address *addr,
0211 ValueObject *valobj, bool function_changed, bool initial_function);
0212
0213 bool FormatStringRef(const llvm::StringRef &format, Stream &s,
0214 const SymbolContext *sc, const ExecutionContext *exe_ctx,
0215 const Address *addr, ValueObject *valobj,
0216 bool function_changed, bool initial_function);
0217
0218 bool FormatCString(const char *format, Stream &s, const SymbolContext *sc,
0219 const ExecutionContext *exe_ctx, const Address *addr,
0220 ValueObject *valobj, bool function_changed,
0221 bool initial_function);
0222
0223 Status Parse(const llvm::StringRef &format, Entry &entry);
0224
0225 Status ExtractVariableInfo(llvm::StringRef &format_str,
0226 llvm::StringRef &variable_name,
0227 llvm::StringRef &variable_format);
0228
0229 void AutoComplete(lldb_private::CompletionRequest &request);
0230
0231
0232
0233
0234
0235
0236
0237 bool FormatFileSpec(const FileSpec &file, Stream &s, llvm::StringRef elements,
0238 llvm::StringRef element_format);
0239
0240
0241
0242
0243
0244
0245
0246
0247 void PrettyPrintFunctionArguments(Stream &out_stream, VariableList const &args,
0248 ExecutionContextScope *exe_scope);
0249 }
0250 }
0251
0252 #endif