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