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 
12 #include "lldb/lldb-enumerations.h"
13 #include "lldb/lldb-types.h"
14 #include <algorithm>
15 #include <cstddef>
16 #include <cstdint>
17 
18 #include <string>
19 #include <vector>
20 
21 namespace lldb_private {
22 class Address;
23 class CompletionRequest;
24 class ExecutionContext;
25 class FileSpec;
26 class Status;
27 class Stream;
28 class StringList;
29 class SymbolContext;
30 class ValueObject;
31 }
32 
33 namespace llvm {
34 class StringRef;
35 }
36 
37 namespace lldb_private {
38 class FormatEntity {
39 public:
40  struct Entry {
41  enum class Type {
42  Invalid,
45  EscapeCode,
46  Root,
47  String,
48  Scope,
49  Variable,
56  ProcessID,
59  ThreadID,
62  ThreadName,
69  ThreadInfo,
70  TargetArch,
72  ModuleFile,
73  File,
74  Lang,
75  FrameIndex,
84  FunctionID,
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.
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)
127  : name(name), string(string), type(Entry::Type::EscapeCode) {}
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 : ""), children(), 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 
202  std::vector<Entry> children;
206  bool deref = false;
207  };
208 
209  static bool Format(const Entry &entry, Stream &s, const SymbolContext *sc,
210  const ExecutionContext *exe_ctx, const Address *addr,
211  ValueObject *valobj, bool function_changed,
212  bool initial_function);
213 
214  static bool FormatStringRef(const llvm::StringRef &format, Stream &s,
215  const SymbolContext *sc,
216  const ExecutionContext *exe_ctx,
217  const Address *addr, ValueObject *valobj,
218  bool function_changed, bool initial_function);
219 
220  static bool FormatCString(const char *format, Stream &s,
221  const SymbolContext *sc,
222  const ExecutionContext *exe_ctx,
223  const Address *addr, ValueObject *valobj,
224  bool function_changed, bool initial_function);
225 
226  static Status Parse(const llvm::StringRef &format, Entry &entry);
227 
228  static Status ExtractVariableInfo(llvm::StringRef &format_str,
229  llvm::StringRef &variable_name,
230  llvm::StringRef &variable_format);
231 
232  static void AutoComplete(lldb_private::CompletionRequest &request);
233 
234  // Format the current elements into the stream \a s.
235  //
236  // The root element will be stripped off and the format str passed in will be
237  // either an empty string (print a description of this object), or contain a
238  // `.`-separated series like a domain name that identifies further
239  // sub-elements to display.
240  static bool FormatFileSpec(const FileSpec &file, Stream &s,
241  llvm::StringRef elements,
242  llvm::StringRef element_format);
243 
244 protected:
245  static Status ParseInternal(llvm::StringRef &format, Entry &parent_entry,
246  uint32_t depth);
247 };
248 } // namespace lldb_private
249 
250 #endif // LLDB_CORE_FORMATENTITY_H
lldb_private::FormatEntity::Entry::Type::FrameRegisterFP
@ FrameRegisterFP
lldb_private::FormatEntity::FormatCString
static 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)
Definition: FormatEntity.cpp:1063
lldb_private::FormatEntity::Entry::Type::FunctionInitial
@ FunctionInitial
lldb_private::FormatEntity::Entry::Type::FrameIsArtificial
@ FrameIsArtificial
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb_private::FormatEntity::FormatStringRef
static 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)
Definition: FormatEntity.cpp:1046
llvm
Definition: Debugger.h:49
lldb_private::FormatEntity::Entry::Type::FrameNoDebug
@ FrameNoDebug
lldb_private::FormatEntity::Entry::Type::Variable
@ Variable
lldb_private::FormatEntity::Entry::Definition::data
const uint64_t data
Data that is returned as the value of the format string.
Definition: FormatEntity.h:114
lldb_private::FormatEntity::Entry::Type::FunctionChanged
@ FunctionChanged
lldb_private::FormatEntity::Entry::Type::FunctionAddrOffset
@ FunctionAddrOffset
lldb_private::FormatEntity::Entry::Type::ThreadReturnValue
@ ThreadReturnValue
lldb_private::FormatEntity::Entry::Type::LineEntryColumn
@ LineEntryColumn
lldb_private::FormatEntity::Entry::Type::AddressFile
@ AddressFile
lldb::Format
Format
Display format definitions.
Definition: lldb-enumerations.h:155
lldb_private::FormatEntity::Entry::Type::FunctionInitialFunction
@ FunctionInitialFunction
lldb_private::FormatEntity::Entry::Type::FrameRegisterSP
@ FrameRegisterSP
lldb_private::FormatEntity::Entry::type
Type type
Definition: FormatEntity.h:203
lldb_private::FormatEntity::Entry::Type::ThreadProtocolID
@ ThreadProtocolID
lldb_private::FormatEntity::Entry::Type::CurrentPCArrow
@ CurrentPCArrow
lldb_private::FormatEntity::Entry::TypeToCString
static const char * TypeToCString(Type t)
Definition: FormatEntity.cpp:301
lldb_private::FormatEntity::Entry::number
lldb::addr_t number
Definition: FormatEntity.h:205
lldb_private::FormatEntity::Entry::Type::FrameIndex
@ FrameIndex
lldb_private::FormatEntity::Entry::Type::ProcessFile
@ ProcessFile
lldb_private::FormatEntity::Entry::Type::FrameRegisterByName
@ FrameRegisterByName
lldb_private::FormatEntity::Entry::deref
bool deref
Definition: FormatEntity.h:206
lldb_private::FormatEntity::Entry::Type::LineEntryEndAddress
@ LineEntryEndAddress
lldb_private::FormatEntity::Entry::Type::ModuleFile
@ ModuleFile
lldb_private::FormatEntity::Entry::Type::LineEntryStartAddress
@ LineEntryStartAddress
lldb_private::FormatEntity::Entry::Type::ThreadID
@ ThreadID
lldb_private::FormatEntity::Entry::Type::FunctionName
@ FunctionName
lldb_private::FormatEntity::Entry::AppendText
void AppendText(const llvm::StringRef &s)
Definition: FormatEntity.cpp:279
lldb_private::FormatEntity::Entry::Definition::Definition
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
lldb_private::FormatEntity::Entry::Definition::type
const Entry::Type type
Entry::Type corresponding to this definition.
Definition: FormatEntity.h:112
lldb_private::FormatEntity::Entry::Type::ThreadQueue
@ ThreadQueue
lldb_private::FormatEntity::Entry::Type::ProcessID
@ ProcessID
lldb_private::Stream
Definition: Stream.h:28
lldb_private::FormatEntity::Entry::Type::File
@ File
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::FormatEntity::Entry::fmt
lldb::Format fmt
Definition: FormatEntity.h:204
lldb_private::FormatEntity::Entry::Type::FunctionPCOffset
@ FunctionPCOffset
lldb_private::FormatEntity::Entry::Type::Invalid
@ Invalid
lldb_private::SymbolContext
Definition: SymbolContext.h:33
lldb_private::FormatEntity::Entry::Type::TargetArch
@ TargetArch
lldb_private::FormatEntity::Entry::children
std::vector< Entry > children
Definition: FormatEntity.h:202
lldb_private::FormatEntity::Entry::Definition::string
const char * string
Insert this exact string into the output.
Definition: FormatEntity.h:110
lldb_private::FormatEntity::Entry::Type::FunctionIsOptimized
@ FunctionIsOptimized
lldb_private::FormatEntity::Entry::Definition::num_children
const uint32_t num_children
The number of children of this node in the tree of format strings.
Definition: FormatEntity.h:116
lldb_private::FormatEntity::Entry::Type::FunctionMangledName
@ FunctionMangledName
lldb_private::FormatEntity::Entry::Type::FrameRegisterFlags
@ FrameRegisterFlags
lldb_private::FileSpec
Definition: FileSpec.h:56
lldb_private::FormatEntity::Entry::Type::FunctionNameNoArgs
@ FunctionNameNoArgs
lldb_private::FormatEntity::Entry::Type::FunctionAddrOffsetConcrete
@ FunctionAddrOffsetConcrete
lldb_private::FormatEntity::Entry::Type::FunctionID
@ FunctionID
lldb_private::FormatEntity::Entry::Type::ParentString
@ ParentString
lldb_private::FormatEntity::ParseInternal
static Status ParseInternal(llvm::StringRef &format, Entry &parent_entry, uint32_t depth)
Definition: FormatEntity.cpp:2030
lldb_private::FormatEntity::Entry::Type::ScriptVariable
@ ScriptVariable
lldb_private::FormatEntity::Entry::Definition::keep_separator
const bool keep_separator
Whether the separator is kept during parsing or not.
Definition: FormatEntity.h:121
lldb_private::FormatEntity::Entry::Type::Scope
@ Scope
lldb_private::FormatEntity::Entry::Type::AddressLoadOrFile
@ AddressLoadOrFile
lldb_private::FormatEntity::Entry::Type::ParentNumber
@ ParentNumber
lldb_private::FormatEntity::Entry::Definition::Definition
constexpr Definition(const char *name, const char *string)
Definition: FormatEntity.h:126
lldb_private::FormatEntity::Entry::Type::ThreadInfo
@ ThreadInfo
lldb_private::FormatEntity::Entry::Type::FunctionDidChange
@ FunctionDidChange
lldb-enumerations.h
lldb_private::FormatEntity::Entry::Type::VariableSynthetic
@ VariableSynthetic
lldb_private::FormatEntity::Entry::Type::FunctionNameWithArgs
@ FunctionNameWithArgs
lldb_private::FormatEntity::Entry::Definition::Definition
constexpr Definition(const char *name, const FormatEntity::Entry::Type t)
Definition: FormatEntity.h:123
lldb_private::FormatEntity::Entry::Type::ThreadIndexID
@ ThreadIndexID
lldb_private::FormatEntity::Entry::Type::ThreadCompletedExpression
@ ThreadCompletedExpression
lldb_private::FormatEntity::Entry::Definition
Definition: FormatEntity.h:106
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:39
lldb_private::FormatEntity::Entry::Type::ScriptVariableSynthetic
@ ScriptVariableSynthetic
lldb_private::FormatEntity::Entry::AppendChar
void AppendChar(char ch)
Definition: FormatEntity.cpp:272
lldb_private::FormatEntity::Entry::Definition::Definition
constexpr Definition(const char *name, const FormatEntity::Entry::Type t, const uint64_t data)
Definition: FormatEntity.h:129
lldb_private::FormatEntity::Parse
static Status Parse(const llvm::StringRef &format, Entry &entry)
Definition: FormatEntity.cpp:290
lldb_private::FormatEntity::Entry::Type::AddressLoad
@ AddressLoad
lldb_private::FormatEntity::Format
static 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)
Definition: FormatEntity.cpp:1080
lldb_private::FormatEntity::Entry::DefinitionWithChildren
static constexpr Definition DefinitionWithChildren(const char *name, const FormatEntity::Entry::Type t, const Definition(&children)[N], bool keep_separator=false)
Definition: FormatEntity.h:143
lldb-types.h
lldb_private::FormatEntity::Entry::AppendEntry
void AppendEntry(const Entry &&entry)
Definition: FormatEntity.h:162
lldb_private::FormatEntity::AutoComplete
static void AutoComplete(lldb_private::CompletionRequest &request)
Definition: FormatEntity.cpp:2389
lldb_private::FormatEntity::Entry::Type::FrameRegisterPC
@ FrameRegisterPC
lldb_private::FormatEntity::ExtractVariableInfo
static Status ExtractVariableInfo(llvm::StringRef &format_str, llvm::StringRef &variable_name, llvm::StringRef &variable_format)
Definition: FormatEntity.cpp:2319
Definition
lldb_private::FormatEntity::Entry::Definition Definition
Definition: FormatEntity.cpp:81
lldb_private::Status
Definition: Status.h:44
lldb_private::ValueObject
ValueObject:
Definition: ValueObject.h:105
uint32_t
lldb_private::FormatEntity::Entry::Type::String
@ String
lldb_private::FormatEntity::Entry::Dump
void Dump(Stream &s, int depth=0) const
Definition: FormatEntity.cpp:371
lldb_private::Address
Definition: Address.h:59
lldb_private::FormatEntity::Entry::Type::ThreadStopReasonRaw
@ ThreadStopReasonRaw
lldb_private::Type
Definition: Type.h:66
lldb_private::FormatEntity::Entry::Type::Root
@ Root
lldb_private::FormatEntity::Entry::Type::ScriptTarget
@ ScriptTarget
lldb_private::FormatEntity::Entry::Type::EscapeCode
@ EscapeCode
lldb_private::FormatEntity::Entry::Type::LineEntryLineNumber
@ LineEntryLineNumber
lldb_private::FormatEntity::Entry
Definition: FormatEntity.h:40
lldb_private::FormatEntity::Entry::printf_format
std::string printf_format
Definition: FormatEntity.h:201
lldb_private::FormatEntity
Definition: FormatEntity.h:38
lldb_private::FormatEntity::Entry::Definition::children
const Definition * children
An array of "num_children" Definition entries.
Definition: FormatEntity.h:118
lldb_private::FormatEntity::Entry::string
std::string string
Definition: FormatEntity.h:200
lldb_private::FormatEntity::Entry::Type::LineEntryFile
@ LineEntryFile
lldb_private::FormatEntity::Entry::Type::Lang
@ Lang
lldb_private::FormatEntity::Entry::Type::FunctionLineOffset
@ FunctionLineOffset
lldb_private::FormatEntity::Entry::Type::ScriptThread
@ ScriptThread
lldb_private::FormatEntity::Entry::Type::ThreadName
@ ThreadName
lldb_private::FormatEntity::FormatFileSpec
static bool FormatFileSpec(const FileSpec &file, Stream &s, llvm::StringRef elements, llvm::StringRef element_format)
Definition: FormatEntity.cpp:2349
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::FormatEntity::Entry::Type::ThreadStopReason
@ ThreadStopReason
lldb_private::FormatEntity::Entry::operator==
bool operator==(const Entry &rhs) const
Definition: FormatEntity.h:178
lldb_private::FormatEntity::Entry::Type::ScriptProcess
@ ScriptProcess
lldb_private::FormatEntity::Entry::Entry
Entry(Type t=Type::Invalid, const char *s=nullptr, const char *f=nullptr)
Definition: FormatEntity.h:149
lldb_private::FormatEntity::Entry::Type::ScriptFrame
@ ScriptFrame
lldb_private::FormatEntity::Entry::Clear
void Clear()
Definition: FormatEntity.h:164
lldb_private::LineStatus::Status
@ Status
lldb_private::FormatEntity::Entry::Definition::name
const char * name
The name/string placeholder that corresponds to this definition.
Definition: FormatEntity.h:108
lldb::eFormatDefault
@ eFormatDefault
Definition: lldb-enumerations.h:156
lldb_private::CompletionRequest
Definition: CompletionRequest.h:100
lldb_private::FormatEntity::Entry::Type
Type
Definition: FormatEntity.h:41