1 //===-- CommandObjectType.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_CommandObjectType_h_ 11 #define liblldb_CommandObjectType_h_ 12 13 // C Includes 14 // C++ Includes 15 16 17 // Other libraries and framework includes 18 // Project includes 19 20 #include "lldb/lldb-types.h" 21 #include "lldb/Interpreter/CommandObjectMultiword.h" 22 #include "lldb/Interpreter/Options.h" 23 24 namespace lldb_private { 25 26 class ScriptAddOptions 27 { 28 29 public: 30 31 bool m_skip_pointers; 32 bool m_skip_references; 33 bool m_cascade; 34 StringList m_target_types; 35 StringList m_user_source; 36 37 bool m_no_children; 38 bool m_no_value; 39 bool m_one_liner; 40 bool m_regex; 41 42 ConstString* m_name; 43 44 const char* m_category; 45 46 ScriptAddOptions(bool sptr, 47 bool sref, 48 bool casc, 49 bool noch, 50 bool novl, 51 bool onel, 52 bool regx, 53 ConstString* name, 54 const char* catg) : 55 m_skip_pointers(sptr), 56 m_skip_references(sref), 57 m_cascade(casc), 58 m_target_types(), 59 m_user_source(), 60 m_no_children(noch), 61 m_no_value(novl), 62 m_one_liner(onel), 63 m_regex(regx), 64 m_name(name), 65 m_category(catg) 66 { 67 } 68 69 typedef lldb::SharedPtr<ScriptAddOptions>::Type SharedPointer; 70 71 }; 72 73 class SynthAddOptions 74 { 75 76 public: 77 78 bool m_skip_pointers; 79 bool m_skip_references; 80 bool m_cascade; 81 bool m_regex; 82 StringList m_user_source; 83 StringList m_target_types; 84 85 const char* m_category; 86 87 SynthAddOptions(bool sptr, 88 bool sref, 89 bool casc, 90 bool regx, 91 const char* catg) : 92 m_skip_pointers(sptr), 93 m_skip_references(sref), 94 m_cascade(casc), 95 m_regex(regx), 96 m_user_source(), 97 m_target_types(), 98 m_category(catg) 99 { 100 } 101 102 typedef lldb::SharedPtr<SynthAddOptions>::Type SharedPointer; 103 104 }; 105 106 107 class CommandObjectType : public CommandObjectMultiword 108 { 109 public: 110 CommandObjectType (CommandInterpreter &interpreter); 111 112 virtual 113 ~CommandObjectType (); 114 }; 115 116 class CommandObjectTypeSummaryAdd : public CommandObject 117 { 118 119 private: 120 121 class CommandOptions : public Options 122 { 123 public: 124 125 CommandOptions (CommandInterpreter &interpreter) : 126 Options (interpreter) 127 { 128 } 129 130 virtual 131 ~CommandOptions (){} 132 133 virtual Error 134 SetOptionValue (uint32_t option_idx, const char *option_arg); 135 136 void 137 OptionParsingStarting (); 138 139 const OptionDefinition* 140 GetDefinitions () 141 { 142 return g_option_table; 143 } 144 145 // Options table: Required for subclasses of Options. 146 147 static OptionDefinition g_option_table[]; 148 149 // Instance variables to hold the values for command options. 150 151 bool m_cascade; 152 bool m_no_children; 153 bool m_no_value; 154 bool m_one_liner; 155 bool m_skip_references; 156 bool m_skip_pointers; 157 bool m_regex; 158 std::string m_format_string; 159 ConstString* m_name; 160 std::string m_python_script; 161 std::string m_python_function; 162 bool m_is_add_script; 163 const char* m_category; 164 }; 165 166 CommandOptions m_options; 167 168 virtual Options * 169 GetOptions () 170 { 171 return &m_options; 172 } 173 174 void 175 CollectPythonScript(ScriptAddOptions *options, 176 CommandReturnObject &result); 177 178 bool 179 Execute_ScriptSummary (Args& command, CommandReturnObject &result); 180 181 bool 182 Execute_StringSummary (Args& command, CommandReturnObject &result); 183 184 public: 185 186 enum SummaryFormatType 187 { 188 eRegularSummary, 189 eRegexSummary, 190 eNamedSummary, 191 }; 192 193 CommandObjectTypeSummaryAdd (CommandInterpreter &interpreter); 194 195 ~CommandObjectTypeSummaryAdd () 196 { 197 } 198 199 bool 200 Execute (Args& command, CommandReturnObject &result); 201 202 static bool 203 AddSummary(const ConstString& type_name, 204 lldb::SummaryFormatSP entry, 205 SummaryFormatType type, 206 const char* category, 207 Error* error = NULL); 208 }; 209 210 class CommandObjectTypeSynthAdd : public CommandObject 211 { 212 213 private: 214 215 class CommandOptions : public Options 216 { 217 typedef std::vector<std::string> option_vector; 218 public: 219 220 CommandOptions (CommandInterpreter &interpreter) : 221 Options (interpreter) 222 { 223 } 224 225 virtual 226 ~CommandOptions (){} 227 228 virtual Error 229 SetOptionValue (uint32_t option_idx, const char *option_arg) 230 { 231 Error error; 232 char short_option = (char) m_getopt_table[option_idx].val; 233 bool success; 234 235 switch (short_option) 236 { 237 case 'C': 238 m_cascade = Args::StringToBoolean(option_arg, true, &success); 239 if (!success) 240 error.SetErrorStringWithFormat("Invalid value for cascade: %s.\n", option_arg); 241 break; 242 case 'c': 243 m_expr_paths.push_back(option_arg); 244 has_child_list = true; 245 break; 246 case 'P': 247 handwrite_python = true; 248 break; 249 case 'l': 250 m_class_name = std::string(option_arg); 251 is_class_based = true; 252 break; 253 case 'p': 254 m_skip_pointers = true; 255 break; 256 case 'r': 257 m_skip_references = true; 258 break; 259 case 'w': 260 m_category = ConstString(option_arg).GetCString(); 261 break; 262 case 'x': 263 m_regex = true; 264 break; 265 default: 266 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option); 267 break; 268 } 269 270 return error; 271 } 272 273 void 274 OptionParsingStarting () 275 { 276 m_cascade = true; 277 m_class_name = ""; 278 m_skip_pointers = false; 279 m_skip_references = false; 280 m_category = NULL; 281 m_expr_paths.clear(); 282 is_class_based = false; 283 handwrite_python = false; 284 has_child_list = false; 285 m_regex = false; 286 } 287 288 const OptionDefinition* 289 GetDefinitions () 290 { 291 return g_option_table; 292 } 293 294 // Options table: Required for subclasses of Options. 295 296 static OptionDefinition g_option_table[]; 297 298 // Instance variables to hold the values for command options. 299 300 bool m_cascade; 301 bool m_skip_references; 302 bool m_skip_pointers; 303 std::string m_class_name; 304 bool m_input_python; 305 option_vector m_expr_paths; 306 const char* m_category; 307 308 bool is_class_based; 309 310 bool handwrite_python; 311 312 bool has_child_list; 313 314 bool m_regex; 315 316 typedef option_vector::iterator ExpressionPathsIterator; 317 }; 318 319 CommandOptions m_options; 320 321 virtual Options * 322 GetOptions () 323 { 324 return &m_options; 325 } 326 327 void 328 CollectPythonScript (SynthAddOptions *options, 329 CommandReturnObject &result); 330 bool 331 Execute_HandwritePython (Args& command, CommandReturnObject &result); 332 bool 333 Execute_ChildrenList (Args& command, CommandReturnObject &result); 334 bool 335 Execute_PythonClass (Args& command, CommandReturnObject &result); 336 bool 337 Execute (Args& command, CommandReturnObject &result); 338 339 public: 340 341 enum SynthFormatType 342 { 343 eRegularSynth, 344 eRegexSynth, 345 }; 346 347 CommandObjectTypeSynthAdd (CommandInterpreter &interpreter); 348 349 ~CommandObjectTypeSynthAdd () 350 { 351 } 352 353 static bool 354 AddSynth(const ConstString& type_name, 355 lldb::SyntheticChildrenSP entry, 356 SynthFormatType type, 357 const char* category_name, 358 Error* error); 359 }; 360 361 } // namespace lldb_private 362 363 #endif // liblldb_CommandObjectType_h_ 364