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