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 Lang, 65 FrameIndex, 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 LineEntryFile, 85 LineEntryLineNumber, 86 LineEntryStartAddress, 87 LineEntryEndAddress, 88 CurrentPCArrow 89 }; 90 91 enum FormatType 92 { 93 None, 94 UInt32, 95 UInt64, 96 CString 97 }; 98 99 struct Definition 100 { 101 const char *name; 102 const char *string; // Insert this exact string into the output 103 Entry::Type type; 104 FormatType format_type; // uint32_t, uint64_t, cstr, or anything that can be formatted by printf or lldb::Format 105 uint64_t data; 106 uint32_t num_children; 107 Definition *children; // An array of "num_children" Definition entries, 108 bool keep_separator; 109 }; 110 111 Entry (Type t = Type::Invalid, 112 const char *s = NULL, 113 const char *f = NULL) : 114 string (s ? s : ""), 115 printf_format (f ? f : ""), 116 children (), 117 definition (NULL), 118 type (t), 119 fmt (lldb::eFormatDefault), 120 number (0), 121 deref (false) 122 { 123 } 124 125 Entry (llvm::StringRef s); 126 Entry (char ch); 127 128 void 129 AppendChar (char ch); 130 131 void 132 AppendText (const llvm::StringRef &s); 133 134 void 135 AppendText (const char *cstr); 136 137 void AppendEntryEntry138 AppendEntry (const Entry &&entry) 139 { 140 children.push_back(entry); 141 } 142 143 void ClearEntry144 Clear () 145 { 146 string.clear(); 147 printf_format.clear(); 148 children.clear(); 149 definition = NULL; 150 type = Type::Invalid; 151 fmt = lldb::eFormatDefault; 152 number = 0; 153 deref = false; 154 } 155 156 static const char * 157 TypeToCString (Type t); 158 159 void 160 Dump (Stream &s, int depth = 0) const; 161 162 bool 163 operator == (const Entry &rhs) const 164 { 165 if (string != rhs.string) 166 return false; 167 if (printf_format != rhs.printf_format) 168 return false; 169 const size_t n = children.size(); 170 const size_t m = rhs.children.size(); 171 for (size_t i=0; i < std::min<size_t>(n, m); ++i) 172 { 173 if (!(children[i] == rhs.children[i])) 174 return false; 175 } 176 if (children != rhs.children) 177 return false; 178 if (definition != rhs.definition) 179 return false; 180 if (type != rhs.type) 181 return false; 182 if (fmt != rhs.fmt) 183 return false; 184 if (deref != rhs.deref) 185 return false; 186 return true; 187 } 188 189 std::string string; 190 std::string printf_format; 191 std::vector<Entry> children; 192 Definition *definition; 193 Type type; 194 lldb::Format fmt; 195 lldb::addr_t number; 196 bool deref; 197 }; 198 199 static bool 200 Format (const Entry &entry, 201 Stream &s, 202 const SymbolContext *sc, 203 const ExecutionContext *exe_ctx, 204 const Address *addr, 205 ValueObject* valobj, 206 bool function_changed, 207 bool initial_function); 208 209 static bool 210 FormatStringRef (const llvm::StringRef &format, 211 Stream &s, 212 const SymbolContext *sc, 213 const ExecutionContext *exe_ctx, 214 const Address *addr, 215 ValueObject* valobj, 216 bool function_changed, 217 bool initial_function); 218 219 static bool 220 FormatCString (const char *format, 221 Stream &s, 222 const SymbolContext *sc, 223 const ExecutionContext *exe_ctx, 224 const Address *addr, 225 ValueObject* valobj, 226 bool function_changed, 227 bool initial_function); 228 229 static Error 230 Parse (const llvm::StringRef &format, Entry &entry); 231 232 static Error 233 ExtractVariableInfo (llvm::StringRef &format_str, 234 llvm::StringRef &variable_name, 235 llvm::StringRef &variable_format); 236 237 static size_t 238 AutoComplete (const char *s, 239 int match_start_point, 240 int max_return_elements, 241 bool &word_complete, 242 StringList &matches); 243 244 //---------------------------------------------------------------------- 245 // Format the current elements into the stream \a s. 246 // 247 // The root element will be stripped off and the format str passed in 248 // will be either an empty string (print a description of this object), 249 // or contain a . separated series like a domain name that identifies 250 // further sub elements to display. 251 //---------------------------------------------------------------------- 252 static bool 253 FormatFileSpec (const FileSpec &file, Stream &s, llvm::StringRef elements, llvm::StringRef element_format); 254 protected: 255 256 static Error 257 ParseInternal (llvm::StringRef &format, Entry &parent_entry, uint32_t depth); 258 259 }; 260 261 } 262 #endif // #if defined(__cplusplus) 263 #endif // liblldb_FormatEntity_h_ 264