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 std::string 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 std::string 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 std::string m_category; 86 87 SynthAddOptions(bool sptr, 88 bool sref, 89 bool casc, 90 bool regx, 91 std::string 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 std::string 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 std::string category, 207 Error* error = NULL); 208 }; 209 210 class CommandObjectTypeSynthAdd : public CommandObject 211 { 212 213 private: 214 215 class CommandOptions : public Options 216 { 217 public: 218 219 CommandOptions (CommandInterpreter &interpreter) : 220 Options (interpreter) 221 { 222 } 223 224 virtual 225 ~CommandOptions (){} 226 227 virtual Error 228 SetOptionValue (uint32_t option_idx, const char *option_arg) 229 { 230 Error error; 231 char short_option = (char) m_getopt_table[option_idx].val; 232 bool success; 233 234 switch (short_option) 235 { 236 case 'C': 237 m_cascade = Args::StringToBoolean(option_arg, true, &success); 238 if (!success) 239 error.SetErrorStringWithFormat("Invalid value for cascade: %s.\n", option_arg); 240 break; 241 case 'P': 242 handwrite_python = true; 243 break; 244 case 'l': 245 m_class_name = std::string(option_arg); 246 is_class_based = true; 247 break; 248 case 'p': 249 m_skip_pointers = true; 250 break; 251 case 'r': 252 m_skip_references = true; 253 break; 254 case 'w': 255 m_category = std::string(option_arg); 256 break; 257 case 'x': 258 m_regex = true; 259 break; 260 default: 261 error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option); 262 break; 263 } 264 265 return error; 266 } 267 268 void 269 OptionParsingStarting () 270 { 271 m_cascade = true; 272 m_class_name = ""; 273 m_skip_pointers = false; 274 m_skip_references = false; 275 m_category = "default"; 276 is_class_based = false; 277 handwrite_python = false; 278 m_regex = false; 279 } 280 281 const OptionDefinition* 282 GetDefinitions () 283 { 284 return g_option_table; 285 } 286 287 // Options table: Required for subclasses of Options. 288 289 static OptionDefinition g_option_table[]; 290 291 // Instance variables to hold the values for command options. 292 293 bool m_cascade; 294 bool m_skip_references; 295 bool m_skip_pointers; 296 std::string m_class_name; 297 bool m_input_python; 298 std::string m_category; 299 300 bool is_class_based; 301 302 bool handwrite_python; 303 304 bool m_regex; 305 306 }; 307 308 CommandOptions m_options; 309 310 virtual Options * 311 GetOptions () 312 { 313 return &m_options; 314 } 315 316 void 317 CollectPythonScript (SynthAddOptions *options, 318 CommandReturnObject &result); 319 bool 320 Execute_HandwritePython (Args& command, CommandReturnObject &result); 321 322 bool 323 Execute_PythonClass (Args& command, CommandReturnObject &result); 324 325 bool 326 Execute (Args& command, CommandReturnObject &result); 327 328 public: 329 330 enum SynthFormatType 331 { 332 eRegularSynth, 333 eRegexSynth 334 }; 335 336 CommandObjectTypeSynthAdd (CommandInterpreter &interpreter); 337 338 ~CommandObjectTypeSynthAdd () 339 { 340 } 341 342 static bool 343 AddSynth(const ConstString& type_name, 344 lldb::SyntheticChildrenSP entry, 345 SynthFormatType type, 346 std::string category_name, 347 Error* error); 348 }; 349 350 } // namespace lldb_private 351 352 #endif // liblldb_CommandObjectType_h_ 353