]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/FormatEntity.h
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Core / FormatEntity.h
1 //===-- FormatEntity.h ------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_FormatEntity_h_
11 #define liblldb_FormatEntity_h_
12
13 #include "lldb/Utility/CompletionRequest.h"
14 #include "lldb/Utility/FileSpec.h" // for FileSpec
15 #include "lldb/Utility/Status.h"
16 #include "lldb/lldb-enumerations.h" // for Format::eFormatDefault, Format
17 #include "lldb/lldb-types.h"        // for addr_t
18 #include <algorithm>                // for min
19 #include <stddef.h>                 // for size_t
20 #include <stdint.h>                 // for uint32_t, uint64_t
21
22 #include <string>
23 #include <vector>
24
25 namespace lldb_private {
26 class Address;
27 }
28 namespace lldb_private {
29 class ExecutionContext;
30 }
31 namespace lldb_private {
32 class Stream;
33 }
34 namespace lldb_private {
35 class StringList;
36 }
37 namespace lldb_private {
38 class SymbolContext;
39 }
40 namespace lldb_private {
41 class ValueObject;
42 }
43 namespace llvm {
44 class StringRef;
45 }
46
47 namespace lldb_private {
48 class FormatEntity {
49 public:
50   struct Entry {
51     enum class Type {
52       Invalid,
53       ParentNumber,
54       ParentString,
55       InsertString,
56       Root,
57       String,
58       Scope,
59       Variable,
60       VariableSynthetic,
61       ScriptVariable,
62       ScriptVariableSynthetic,
63       AddressLoad,
64       AddressFile,
65       AddressLoadOrFile,
66       ProcessID,
67       ProcessFile,
68       ScriptProcess,
69       ThreadID,
70       ThreadProtocolID,
71       ThreadIndexID,
72       ThreadName,
73       ThreadQueue,
74       ThreadStopReason,
75       ThreadReturnValue,
76       ThreadCompletedExpression,
77       ScriptThread,
78       ThreadInfo,
79       TargetArch,
80       ScriptTarget,
81       ModuleFile,
82       File,
83       Lang,
84       FrameIndex,
85       FrameNoDebug,
86       FrameRegisterPC,
87       FrameRegisterSP,
88       FrameRegisterFP,
89       FrameRegisterFlags,
90       FrameRegisterByName,
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       LineEntryStartAddress,
108       LineEntryEndAddress,
109       CurrentPCArrow
110     };
111
112     enum FormatType { None, UInt32, UInt64, CString };
113
114     struct Definition {
115       const char *name;
116       const char *string; // Insert this exact string into the output
117       Entry::Type type;
118       FormatType format_type; // uint32_t, uint64_t, cstr, or anything that can
119                               // be formatted by printf or lldb::Format
120       uint64_t data;
121       uint32_t num_children;
122       Definition *children; // An array of "num_children" Definition entries,
123       bool keep_separator;
124     };
125
126     Entry(Type t = Type::Invalid, const char *s = nullptr,
127           const char *f = nullptr)
128         : string(s ? s : ""), printf_format(f ? f : ""), children(),
129           definition(nullptr), type(t), fmt(lldb::eFormatDefault), number(0),
130           deref(false) {}
131
132     Entry(llvm::StringRef s);
133     Entry(char ch);
134
135     void AppendChar(char ch);
136
137     void AppendText(const llvm::StringRef &s);
138
139     void AppendText(const char *cstr);
140
141     void AppendEntry(const Entry &&entry) { children.push_back(entry); }
142
143     void Clear() {
144       string.clear();
145       printf_format.clear();
146       children.clear();
147       definition = nullptr;
148       type = Type::Invalid;
149       fmt = lldb::eFormatDefault;
150       number = 0;
151       deref = false;
152     }
153
154     static const char *TypeToCString(Type t);
155
156     void Dump(Stream &s, int depth = 0) const;
157
158     bool operator==(const Entry &rhs) const {
159       if (string != rhs.string)
160         return false;
161       if (printf_format != rhs.printf_format)
162         return false;
163       const size_t n = children.size();
164       const size_t m = rhs.children.size();
165       for (size_t i = 0; i < std::min<size_t>(n, m); ++i) {
166         if (!(children[i] == rhs.children[i]))
167           return false;
168       }
169       if (children != rhs.children)
170         return false;
171       if (definition != rhs.definition)
172         return false;
173       if (type != rhs.type)
174         return false;
175       if (fmt != rhs.fmt)
176         return false;
177       if (deref != rhs.deref)
178         return false;
179       return true;
180     }
181
182     std::string string;
183     std::string printf_format;
184     std::vector<Entry> children;
185     Definition *definition;
186     Type type;
187     lldb::Format fmt;
188     lldb::addr_t number;
189     bool deref;
190   };
191
192   static bool Format(const Entry &entry, Stream &s, const SymbolContext *sc,
193                      const ExecutionContext *exe_ctx, const Address *addr,
194                      ValueObject *valobj, bool function_changed,
195                      bool initial_function);
196
197   static bool FormatStringRef(const llvm::StringRef &format, Stream &s,
198                               const SymbolContext *sc,
199                               const ExecutionContext *exe_ctx,
200                               const Address *addr, ValueObject *valobj,
201                               bool function_changed, bool initial_function);
202
203   static bool FormatCString(const char *format, Stream &s,
204                             const SymbolContext *sc,
205                             const ExecutionContext *exe_ctx,
206                             const Address *addr, ValueObject *valobj,
207                             bool function_changed, bool initial_function);
208
209   static Status Parse(const llvm::StringRef &format, Entry &entry);
210
211   static Status ExtractVariableInfo(llvm::StringRef &format_str,
212                                     llvm::StringRef &variable_name,
213                                     llvm::StringRef &variable_format);
214
215   static size_t AutoComplete(lldb_private::CompletionRequest &request);
216
217   //----------------------------------------------------------------------
218   // Format the current elements into the stream \a s.
219   //
220   // The root element will be stripped off and the format str passed in will be
221   // either an empty string (print a description of this object), or contain a
222   // `.`-separated series like a domain name that identifies further
223   //  sub-elements to display.
224   //----------------------------------------------------------------------
225   static bool FormatFileSpec(const FileSpec &file, Stream &s,
226                              llvm::StringRef elements,
227                              llvm::StringRef element_format);
228
229 protected:
230   static Status ParseInternal(llvm::StringRef &format, Entry &parent_entry,
231                               uint32_t depth);
232 };
233 } // namespace lldb_private
234
235 #endif // liblldb_FormatEntity_h_