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 liblldb_FormatEntity_h_
10 #define liblldb_FormatEntity_h_
11 
13 #include "lldb/Utility/FileSpec.h"
14 #include "lldb/Utility/Status.h"
15 #include "lldb/lldb-enumerations.h"
16 #include "lldb/lldb-types.h"
17 #include <algorithm>
18 #include <stddef.h>
19 #include <stdint.h>
20 
21 #include <string>
22 #include <vector>
23 
24 namespace lldb_private {
25 class Address;
26 }
27 namespace lldb_private {
28 class ExecutionContext;
29 }
30 namespace lldb_private {
31 class Stream;
32 }
33 namespace lldb_private {
34 class StringList;
35 }
36 namespace lldb_private {
37 class SymbolContext;
38 }
39 namespace lldb_private {
40 class ValueObject;
41 }
42 namespace llvm {
43 class StringRef;
44 }
45 
46 namespace lldb_private {
47 class FormatEntity {
48 public:
49  struct Entry {
50  enum class Type {
51  Invalid,
52  ParentNumber,
53  ParentString,
54  InsertString,
55  Root,
56  String,
57  Scope,
58  Variable,
59  VariableSynthetic,
60  ScriptVariable,
61  ScriptVariableSynthetic,
62  AddressLoad,
63  AddressFile,
64  AddressLoadOrFile,
65  ProcessID,
66  ProcessFile,
67  ScriptProcess,
68  ThreadID,
69  ThreadProtocolID,
70  ThreadIndexID,
71  ThreadName,
72  ThreadQueue,
73  ThreadStopReason,
74  ThreadReturnValue,
75  ThreadCompletedExpression,
76  ScriptThread,
77  ThreadInfo,
78  TargetArch,
79  ScriptTarget,
80  ModuleFile,
81  File,
82  Lang,
83  FrameIndex,
84  FrameNoDebug,
85  FrameRegisterPC,
86  FrameRegisterSP,
87  FrameRegisterFP,
88  FrameRegisterFlags,
89  FrameRegisterByName,
90  FrameIsArtificial,
91  ScriptFrame,
92  FunctionID,
93  FunctionDidChange,
94  FunctionInitialFunction,
95  FunctionName,
96  FunctionNameWithArgs,
97  FunctionNameNoArgs,
98  FunctionAddrOffset,
99  FunctionAddrOffsetConcrete,
100  FunctionLineOffset,
101  FunctionPCOffset,
102  FunctionInitial,
103  FunctionChanged,
104  FunctionIsOptimized,
105  LineEntryFile,
106  LineEntryLineNumber,
107  LineEntryColumn,
108  LineEntryStartAddress,
109  LineEntryEndAddress,
110  CurrentPCArrow
111  };
112 
113  struct Definition {
114  const char *name;
115  const char *string; // Insert this exact string into the output
117  uint64_t data;
119  Definition *children; // An array of "num_children" Definition entries,
121  };
122 
123  Entry(Type t = Type::Invalid, const char *s = nullptr,
124  const char *f = nullptr)
125  : string(s ? s : ""), printf_format(f ? f : ""), children(),
126  definition(nullptr), type(t), fmt(lldb::eFormatDefault), number(0),
127  deref(false) {}
128 
129  Entry(llvm::StringRef s);
130  Entry(char ch);
131 
132  void AppendChar(char ch);
133 
134  void AppendText(const llvm::StringRef &s);
135 
136  void AppendText(const char *cstr);
137 
138  void AppendEntry(const Entry &&entry) { children.push_back(entry); }
139 
140  void Clear() {
141  string.clear();
142  printf_format.clear();
143  children.clear();
144  definition = nullptr;
145  type = Type::Invalid;
146  fmt = lldb::eFormatDefault;
147  number = 0;
148  deref = false;
149  }
150 
151  static const char *TypeToCString(Type t);
152 
153  void Dump(Stream &s, int depth = 0) const;
154 
155  bool operator==(const Entry &rhs) const {
156  if (string != rhs.string)
157  return false;
158  if (printf_format != rhs.printf_format)
159  return false;
160  const size_t n = children.size();
161  const size_t m = rhs.children.size();
162  for (size_t i = 0; i < std::min<size_t>(n, m); ++i) {
163  if (!(children[i] == rhs.children[i]))
164  return false;
165  }
166  if (children != rhs.children)
167  return false;
168  if (definition != rhs.definition)
169  return false;
170  if (type != rhs.type)
171  return false;
172  if (fmt != rhs.fmt)
173  return false;
174  if (deref != rhs.deref)
175  return false;
176  return true;
177  }
178 
179  std::string string;
180  std::string printf_format;
181  std::vector<Entry> children;
186  bool deref;
187  };
188 
189  static bool Format(const Entry &entry, Stream &s, const SymbolContext *sc,
190  const ExecutionContext *exe_ctx, const Address *addr,
191  ValueObject *valobj, bool function_changed,
192  bool initial_function);
193 
194  static bool FormatStringRef(const llvm::StringRef &format, Stream &s,
195  const SymbolContext *sc,
196  const ExecutionContext *exe_ctx,
197  const Address *addr, ValueObject *valobj,
198  bool function_changed, bool initial_function);
199 
200  static bool FormatCString(const char *format, Stream &s,
201  const SymbolContext *sc,
202  const ExecutionContext *exe_ctx,
203  const Address *addr, ValueObject *valobj,
204  bool function_changed, bool initial_function);
205 
206  static Status Parse(const llvm::StringRef &format, Entry &entry);
207 
208  static Status ExtractVariableInfo(llvm::StringRef &format_str,
209  llvm::StringRef &variable_name,
210  llvm::StringRef &variable_format);
211 
212  static size_t AutoComplete(lldb_private::CompletionRequest &request);
213 
214  // Format the current elements into the stream \a s.
215  //
216  // The root element will be stripped off and the format str passed in will be
217  // either an empty string (print a description of this object), or contain a
218  // `.`-separated series like a domain name that identifies further
219  // sub-elements to display.
220  static bool FormatFileSpec(const FileSpec &file, Stream &s,
221  llvm::StringRef elements,
222  llvm::StringRef element_format);
223 
224 protected:
225  static Status ParseInternal(llvm::StringRef &format, Entry &parent_entry,
226  uint32_t depth);
227 };
228 } // namespace lldb_private
229 
230 #endif // liblldb_FormatEntity_h_
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
Definition: Debugger.h:71
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:33
A file utility class.
Definition: FileSpec.h:55
bool operator==(const Entry &rhs) const
Definition: FormatEntity.h:155
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
std::vector< Entry > children
Definition: FormatEntity.h:181
"lldb/Utility/ArgCompletionRequest.h"
Node * Parse(llvm::StringRef expr, llvm::BumpPtrAllocator &alloc)
Parse the given postfix expression.
Entry(Type t=Type::Invalid, const char *s=nullptr, const char *f=nullptr)
Definition: FormatEntity.h:123
A section + offset based address class.
Definition: Address.h:80
void AppendEntry(const Entry &&entry)
Definition: FormatEntity.h:138
uint64_t addr_t
Definition: lldb-types.h:83
Definition: SBAddress.h:15
An error handling class.
Definition: Status.h:44