]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/FormatEntity.h
Merge ^/head r295601 through r295844.
[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 // C Includes
14 // C++ Includes
15 #include <string>
16 #include <vector>
17
18 // Other libraries and framework includes
19 // Project includes
20 #include "lldb/lldb-private.h"
21 #include "lldb/Core/Error.h"
22
23 namespace llvm
24 {
25     class StringRef;
26 } // namespace llvm
27
28 namespace lldb_private
29 {
30     class FormatEntity
31     {
32     public:
33         struct Entry
34         {
35             enum class Type {
36                 Invalid,
37                 ParentNumber,
38                 ParentString,
39                 InsertString,
40                 Root,
41                 String,
42                 Scope,
43                 Variable,
44                 VariableSynthetic,
45                 ScriptVariable,
46                 ScriptVariableSynthetic,
47                 AddressLoad,
48                 AddressFile,
49                 AddressLoadOrFile,
50                 ProcessID,
51                 ProcessFile,
52                 ScriptProcess,
53                 ThreadID,
54                 ThreadProtocolID,
55                 ThreadIndexID,
56                 ThreadName,
57                 ThreadQueue,
58                 ThreadStopReason,
59                 ThreadReturnValue,
60                 ThreadCompletedExpression,
61                 ScriptThread,
62                 ThreadInfo,
63                 TargetArch,
64                 ScriptTarget,
65                 ModuleFile,
66                 File,
67                 Lang,
68                 FrameIndex,
69                 FrameRegisterPC,
70                 FrameRegisterSP,
71                 FrameRegisterFP,
72                 FrameRegisterFlags,
73                 FrameRegisterByName,
74                 ScriptFrame,
75                 FunctionID,
76                 FunctionDidChange,
77                 FunctionInitialFunction,
78                 FunctionName,
79                 FunctionNameWithArgs,
80                 FunctionNameNoArgs,
81                 FunctionAddrOffset,
82                 FunctionAddrOffsetConcrete,
83                 FunctionLineOffset,
84                 FunctionPCOffset,
85                 FunctionInitial,
86                 FunctionChanged,
87                 FunctionIsOptimized,
88                 LineEntryFile,
89                 LineEntryLineNumber,
90                 LineEntryStartAddress,
91                 LineEntryEndAddress,
92                 CurrentPCArrow
93             };
94
95             enum FormatType
96             {
97                 None,
98                 UInt32,
99                 UInt64,
100                 CString
101             };
102             
103             struct Definition
104             {
105                 const char *name;
106                 const char *string; // Insert this exact string into the output
107                 Entry::Type type;
108                 FormatType  format_type; // uint32_t, uint64_t, cstr, or anything that can be formatted by printf or lldb::Format
109                 uint64_t data;
110                 uint32_t num_children;
111                 Definition *children; // An array of "num_children" Definition entries,
112                 bool keep_separator;
113             };
114
115             Entry(Type t = Type::Invalid,
116                   const char *s = nullptr,
117                   const char *f = nullptr) :
118                 string (s ? s : ""),
119                 printf_format (f ? f : ""),
120                 children (),
121                 definition (nullptr),
122                 type (t),
123                 fmt (lldb::eFormatDefault),
124                 number (0),
125                 deref (false)
126             {
127             }
128
129             Entry (llvm::StringRef s);
130             Entry (char ch);
131
132             void
133             AppendChar (char ch);
134
135             void
136             AppendText (const llvm::StringRef &s);
137
138             void
139             AppendText (const char *cstr);
140
141             void
142             AppendEntry (const Entry &&entry)
143             {
144                 children.push_back(entry);
145             }
146
147             void
148             Clear ()
149             {
150                 string.clear();
151                 printf_format.clear();
152                 children.clear();
153                 definition = nullptr;
154                 type = Type::Invalid;
155                 fmt = lldb::eFormatDefault;
156                 number = 0;
157                 deref = false;
158             }
159             
160             static const char *
161             TypeToCString (Type t);
162
163             void
164             Dump (Stream &s, int depth = 0) const;
165             
166             bool
167             operator == (const Entry &rhs) const
168             {
169                 if (string != rhs.string)
170                     return false;
171                 if (printf_format != rhs.printf_format)
172                     return false;
173                 const size_t n = children.size();
174                 const size_t m = rhs.children.size();
175                 for (size_t i=0; i < std::min<size_t>(n, m); ++i)
176                 {
177                     if (!(children[i] == rhs.children[i]))
178                         return false;
179                 }
180                 if (children != rhs.children)
181                     return false;
182                 if (definition != rhs.definition)
183                     return false;
184                 if (type != rhs.type)
185                     return false;
186                 if (fmt != rhs.fmt)
187                     return false;
188                 if (deref != rhs.deref)
189                     return false;
190                 return true;
191             }
192
193             std::string string;
194             std::string printf_format;
195             std::vector<Entry> children;
196             Definition *definition;
197             Type type;
198             lldb::Format fmt;
199             lldb::addr_t number;
200             bool deref;
201         };
202
203         static bool
204         Format (const Entry &entry,
205                 Stream &s,
206                 const SymbolContext *sc,
207                 const ExecutionContext *exe_ctx,
208                 const Address *addr,
209                 ValueObject* valobj,
210                 bool function_changed,
211                 bool initial_function);
212
213         static bool
214         FormatStringRef (const llvm::StringRef &format,
215                          Stream &s,
216                          const SymbolContext *sc,
217                          const ExecutionContext *exe_ctx,
218                          const Address *addr,
219                          ValueObject* valobj,
220                          bool function_changed,
221                          bool initial_function);
222
223         static bool
224         FormatCString (const char *format,
225                        Stream &s,
226                        const SymbolContext *sc,
227                        const ExecutionContext *exe_ctx,
228                        const Address *addr,
229                        ValueObject* valobj,
230                        bool function_changed,
231                        bool initial_function);
232
233         static Error
234         Parse (const llvm::StringRef &format, Entry &entry);
235
236         static Error
237         ExtractVariableInfo (llvm::StringRef &format_str,
238                              llvm::StringRef &variable_name,
239                              llvm::StringRef &variable_format);
240
241         static size_t
242         AutoComplete (const char *s,
243                       int match_start_point,
244                       int max_return_elements,
245                       bool &word_complete,
246                       StringList &matches);
247
248         //----------------------------------------------------------------------
249         // Format the current elements into the stream \a s.
250         //
251         // The root element will be stripped off and the format str passed in
252         // will be either an empty string (print a description of this object),
253         // or contain a . separated series like a domain name that identifies
254         // further sub elements to display.
255         //----------------------------------------------------------------------
256         static bool
257         FormatFileSpec (const FileSpec &file, Stream &s, llvm::StringRef elements, llvm::StringRef element_format);
258     protected:
259         static Error
260         ParseInternal (llvm::StringRef &format, Entry &parent_entry, uint32_t depth);
261
262     };
263 } // namespace lldb_private
264
265 #endif // liblldb_FormatEntity_h_