1 //===-- CommandObjectType.cpp ----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/lldb-python.h"
12 #include "CommandObjectType.h"
20 #include "llvm/ADT/StringRef.h"
22 #include "lldb/Core/ConstString.h"
23 #include "lldb/Core/Debugger.h"
24 #include "lldb/Core/IOHandler.h"
25 #include "lldb/Core/RegularExpression.h"
26 #include "lldb/Core/State.h"
27 #include "lldb/Core/StringList.h"
28 #include "lldb/DataFormatters/DataVisualization.h"
29 #include "lldb/Interpreter/CommandInterpreter.h"
30 #include "lldb/Interpreter/CommandObject.h"
31 #include "lldb/Interpreter/CommandReturnObject.h"
32 #include "lldb/Interpreter/Options.h"
33 #include "lldb/Interpreter/OptionGroupFormat.h"
36 using namespace lldb_private;
39 class ScriptAddOptions
44 TypeSummaryImpl::Flags m_flags;
46 StringList m_target_types;
52 std::string m_category;
54 ScriptAddOptions(const TypeSummaryImpl::Flags& flags,
56 const ConstString& name,
65 typedef std::shared_ptr<ScriptAddOptions> SharedPointer;
75 bool m_skip_references;
78 StringList m_target_types;
80 std::string m_category;
82 SynthAddOptions(bool sptr,
87 m_skip_pointers(sptr),
88 m_skip_references(sref),
96 typedef std::shared_ptr<SynthAddOptions> SharedPointer;
101 WarnOnPotentialUnquotedUnsignedType (Args& command, CommandReturnObject &result)
103 for (unsigned idx = 0; idx < command.GetArgumentCount(); idx++)
105 const char* arg = command.GetArgumentAtIndex(idx);
106 if (idx+1 < command.GetArgumentCount())
108 if (arg && 0 == strcmp(arg,"unsigned"))
110 const char* next = command.GetArgumentAtIndex(idx+1);
112 (0 == strcmp(next, "int") ||
113 0 == strcmp(next, "short") ||
114 0 == strcmp(next, "char") ||
115 0 == strcmp(next, "long")))
117 result.AppendWarningWithFormat("%s %s being treated as two types. if you meant the combined type name use quotes, as in \"%s %s\"\n",
127 class CommandObjectTypeSummaryAdd :
128 public CommandObjectParsed,
129 public IOHandlerDelegateMultiline
134 class CommandOptions : public Options
138 CommandOptions (CommandInterpreter &interpreter) :
139 Options (interpreter)
147 SetOptionValue (uint32_t option_idx, const char *option_arg);
150 OptionParsingStarting ();
152 const OptionDefinition*
155 return g_option_table;
158 // Options table: Required for subclasses of Options.
160 static OptionDefinition g_option_table[];
162 // Instance variables to hold the values for command options.
164 TypeSummaryImpl::Flags m_flags;
166 std::string m_format_string;
168 std::string m_python_script;
169 std::string m_python_function;
170 bool m_is_add_script;
171 std::string m_category;
174 CommandOptions m_options;
183 Execute_ScriptSummary (Args& command, CommandReturnObject &result);
186 Execute_StringSummary (Args& command, CommandReturnObject &result);
190 enum SummaryFormatType
197 CommandObjectTypeSummaryAdd (CommandInterpreter &interpreter);
199 ~CommandObjectTypeSummaryAdd ()
204 IOHandlerActivated (IOHandler &io_handler)
206 static const char *g_summary_addreader_instructions = "Enter your Python command(s). Type 'DONE' to end.\n"
207 "def function (valobj,internal_dict):\n"
208 " \"\"\"valobj: an SBValue which you want to provide a summary for\n"
209 " internal_dict: an LLDB support object not to be used\"\"\"\n";
211 StreamFileSP output_sp(io_handler.GetOutputStreamFile());
214 output_sp->PutCString(g_summary_addreader_instructions);
221 IOHandlerInputComplete (IOHandler &io_handler, std::string &data)
223 StreamFileSP error_sp = io_handler.GetErrorStreamFile();
225 #ifndef LLDB_DISABLE_PYTHON
226 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
230 lines.SplitIntoLines(data);
231 if (lines.GetSize() > 0)
233 ScriptAddOptions *options_ptr = ((ScriptAddOptions*)io_handler.GetUserData());
236 ScriptAddOptions::SharedPointer options(options_ptr); // this will ensure that we get rid of the pointer when going out of scope
238 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
241 std::string funct_name_str;
242 if (interpreter->GenerateTypeScriptFunction (lines, funct_name_str))
244 if (funct_name_str.empty())
246 error_sp->Printf ("unable to obtain a valid function name from the script interpreter.\n");
251 // now I have a valid function name, let's add this as script for every type in the list
253 TypeSummaryImplSP script_format;
254 script_format.reset(new ScriptSummaryFormat(options->m_flags,
255 funct_name_str.c_str(),
256 lines.CopyList(" ").c_str()));
260 for (size_t i = 0; i < options->m_target_types.GetSize(); i++)
262 const char *type_name = options->m_target_types.GetStringAtIndex(i);
263 CommandObjectTypeSummaryAdd::AddSummary(ConstString(type_name),
265 (options->m_regex ? CommandObjectTypeSummaryAdd::eRegexSummary : CommandObjectTypeSummaryAdd::eRegularSummary),
270 error_sp->Printf ("error: %s", error.AsCString());
277 CommandObjectTypeSummaryAdd::AddSummary (options->m_name,
279 CommandObjectTypeSummaryAdd::eNamedSummary,
284 CommandObjectTypeSummaryAdd::AddSummary (options->m_name,
286 CommandObjectTypeSummaryAdd::eNamedSummary,
291 error_sp->Printf ("error: %s", error.AsCString());
297 error_sp->Printf ("error: %s", error.AsCString());
303 if (error.AsCString())
305 error_sp->Printf ("error: %s", error.AsCString());
313 error_sp->Printf ("error: unable to generate a function.\n");
319 error_sp->Printf ("error: no script interpreter.\n");
325 error_sp->Printf ("error: internal synchronization information missing or invalid.\n");
331 error_sp->Printf ("error: empty function, didn't add python command.\n");
337 error_sp->Printf ("error: script interpreter missing, didn't add python command.\n");
340 #endif // #ifndef LLDB_DISABLE_PYTHON
341 io_handler.SetIsDone(true);
345 AddSummary(ConstString type_name,
346 lldb::TypeSummaryImplSP entry,
347 SummaryFormatType type,
348 std::string category,
349 Error* error = NULL);
352 DoExecute (Args& command, CommandReturnObject &result);
356 static const char *g_synth_addreader_instructions = "Enter your Python command(s). Type 'DONE' to end.\n"
357 "You must define a Python class with these methods:\n"
358 " def __init__(self, valobj, dict):\n"
359 " def num_children(self):\n"
360 " def get_child_at_index(self, index):\n"
361 " def get_child_index(self, name):\n"
362 " def update(self):\n"
364 "class synthProvider:\n";
366 class CommandObjectTypeSynthAdd :
367 public CommandObjectParsed,
368 public IOHandlerDelegateMultiline
373 class CommandOptions : public Options
377 CommandOptions (CommandInterpreter &interpreter) :
378 Options (interpreter)
386 SetOptionValue (uint32_t option_idx, const char *option_arg)
389 const int short_option = m_getopt_table[option_idx].val;
392 switch (short_option)
395 m_cascade = Args::StringToBoolean(option_arg, true, &success);
397 error.SetErrorStringWithFormat("invalid value for cascade: %s", option_arg);
400 handwrite_python = true;
403 m_class_name = std::string(option_arg);
404 is_class_based = true;
407 m_skip_pointers = true;
410 m_skip_references = true;
413 m_category = std::string(option_arg);
419 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
427 OptionParsingStarting ()
431 m_skip_pointers = false;
432 m_skip_references = false;
433 m_category = "default";
434 is_class_based = false;
435 handwrite_python = false;
439 const OptionDefinition*
442 return g_option_table;
445 // Options table: Required for subclasses of Options.
447 static OptionDefinition g_option_table[];
449 // Instance variables to hold the values for command options.
452 bool m_skip_references;
453 bool m_skip_pointers;
454 std::string m_class_name;
456 std::string m_category;
460 bool handwrite_python;
466 CommandOptions m_options;
475 Execute_HandwritePython (Args& command, CommandReturnObject &result);
478 Execute_PythonClass (Args& command, CommandReturnObject &result);
482 DoExecute (Args& command, CommandReturnObject &result)
484 WarnOnPotentialUnquotedUnsignedType(command, result);
486 if (m_options.handwrite_python)
487 return Execute_HandwritePython(command, result);
488 else if (m_options.is_class_based)
489 return Execute_PythonClass(command, result);
492 result.AppendError("must either provide a children list, a Python class name, or use -P and type a Python class line-by-line");
493 result.SetStatus(eReturnStatusFailed);
499 IOHandlerActivated (IOHandler &io_handler)
501 StreamFileSP output_sp(io_handler.GetOutputStreamFile());
504 output_sp->PutCString(g_synth_addreader_instructions);
511 IOHandlerInputComplete (IOHandler &io_handler, std::string &data)
513 StreamFileSP error_sp = io_handler.GetErrorStreamFile();
515 #ifndef LLDB_DISABLE_PYTHON
516 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
520 lines.SplitIntoLines(data);
521 if (lines.GetSize() > 0)
523 SynthAddOptions *options_ptr = ((SynthAddOptions*)io_handler.GetUserData());
526 SynthAddOptions::SharedPointer options(options_ptr); // this will ensure that we get rid of the pointer when going out of scope
528 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
531 std::string class_name_str;
532 if (interpreter->GenerateTypeSynthClass (lines, class_name_str))
534 if (class_name_str.empty())
536 error_sp->Printf ("error: unable to obtain a proper name for the class.\n");
541 // everything should be fine now, let's add the synth provider class
543 SyntheticChildrenSP synth_provider;
544 synth_provider.reset(new ScriptedSyntheticChildren(SyntheticChildren::Flags().SetCascades(options->m_cascade).
545 SetSkipPointers(options->m_skip_pointers).
546 SetSkipReferences(options->m_skip_references),
547 class_name_str.c_str()));
550 lldb::TypeCategoryImplSP category;
551 DataVisualization::Categories::GetCategory(ConstString(options->m_category.c_str()), category);
555 for (size_t i = 0; i < options->m_target_types.GetSize(); i++)
557 const char *type_name = options->m_target_types.GetStringAtIndex(i);
558 ConstString const_type_name(type_name);
561 if (!CommandObjectTypeSynthAdd::AddSynth(const_type_name,
563 options->m_regex ? CommandObjectTypeSynthAdd::eRegexSynth : CommandObjectTypeSynthAdd::eRegularSynth,
567 error_sp->Printf("error: %s\n", error.AsCString());
574 error_sp->Printf ("error: invalid type name.\n");
583 error_sp->Printf ("error: unable to generate a class.\n");
589 error_sp->Printf ("error: no script interpreter.\n");
595 error_sp->Printf ("error: internal synchronization data missing.\n");
601 error_sp->Printf ("error: empty function, didn't add python command.\n");
607 error_sp->Printf ("error: script interpreter missing, didn't add python command.\n");
611 #endif // #ifndef LLDB_DISABLE_PYTHON
612 io_handler.SetIsDone(true);
623 CommandObjectTypeSynthAdd (CommandInterpreter &interpreter);
625 ~CommandObjectTypeSynthAdd ()
630 AddSynth(ConstString type_name,
631 lldb::SyntheticChildrenSP entry,
632 SynthFormatType type,
633 std::string category_name,
637 //-------------------------------------------------------------------------
638 // CommandObjectTypeFormatAdd
639 //-------------------------------------------------------------------------
641 class CommandObjectTypeFormatAdd : public CommandObjectParsed
646 class CommandOptions : public OptionGroup
661 GetNumDefinitions ();
663 virtual const OptionDefinition*
666 return g_option_table;
670 OptionParsingStarting (CommandInterpreter &interpreter)
673 m_skip_pointers = false;
674 m_skip_references = false;
676 m_category.assign("default");
677 m_custom_type_name.clear();
680 SetOptionValue (CommandInterpreter &interpreter,
682 const char *option_value)
685 const int short_option = g_option_table[option_idx].short_option;
688 switch (short_option)
691 m_cascade = Args::StringToBoolean(option_value, true, &success);
693 error.SetErrorStringWithFormat("invalid value for cascade: %s", option_value);
696 m_skip_pointers = true;
699 m_category.assign(option_value);
702 m_skip_references = true;
708 m_custom_type_name.assign(option_value);
711 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
718 // Options table: Required for subclasses of Options.
720 static OptionDefinition g_option_table[];
722 // Instance variables to hold the values for command options.
725 bool m_skip_references;
726 bool m_skip_pointers;
728 std::string m_category;
729 std::string m_custom_type_name;
732 OptionGroupOptions m_option_group;
733 OptionGroupFormat m_format_options;
734 CommandOptions m_command_options;
739 return &m_option_group;
743 CommandObjectTypeFormatAdd (CommandInterpreter &interpreter) :
744 CommandObjectParsed (interpreter,
746 "Add a new formatting style for a type.",
748 m_option_group (interpreter),
749 m_format_options (eFormatInvalid),
752 CommandArgumentEntry type_arg;
753 CommandArgumentData type_style_arg;
755 type_style_arg.arg_type = eArgTypeName;
756 type_style_arg.arg_repetition = eArgRepeatPlus;
758 type_arg.push_back (type_style_arg);
760 m_arguments.push_back (type_arg);
763 "Some examples of using this command.\n"
764 "We use as reference the following snippet of code:\n"
766 "typedef int Aint;\n"
767 "typedef float Afloat;\n"
768 "typedef Aint Bint;\n"
769 "typedef Afloat Bfloat;\n"
774 "Afloat fx = 3.14;\n"
775 "BFloat fy = 3.14;\n"
778 "type format add -f hex AInt\n"
779 "frame variable iy\n"
780 "will produce an hex display of iy, because no formatter is available for Bint and the one for Aint is used instead\n"
781 "To prevent this type\n"
782 "type format add -f hex -C no AInt\n"
784 "A similar reasoning applies to\n"
785 "type format add -f hex -C no float -p\n"
786 "which now prints all floats and float&s as hexadecimal, but does not format float*s\n"
787 "and does not change the default display for Afloat and Bfloat objects.\n"
790 // Add the "--format" to all options groups
791 m_option_group.Append (&m_format_options, OptionGroupFormat::OPTION_GROUP_FORMAT, LLDB_OPT_SET_1);
792 m_option_group.Append (&m_command_options);
793 m_option_group.Finalize();
797 ~CommandObjectTypeFormatAdd ()
803 DoExecute (Args& command, CommandReturnObject &result)
805 const size_t argc = command.GetArgumentCount();
809 result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
810 result.SetStatus(eReturnStatusFailed);
814 const Format format = m_format_options.GetFormat();
815 if (format == eFormatInvalid && m_command_options.m_custom_type_name.empty())
817 result.AppendErrorWithFormat ("%s needs a valid format.\n", m_cmd_name.c_str());
818 result.SetStatus(eReturnStatusFailed);
822 TypeFormatImplSP entry;
824 if (m_command_options.m_custom_type_name.empty())
825 entry.reset(new TypeFormatImpl_Format(format,
826 TypeFormatImpl::Flags().SetCascades(m_command_options.m_cascade).
827 SetSkipPointers(m_command_options.m_skip_pointers).
828 SetSkipReferences(m_command_options.m_skip_references)));
830 entry.reset(new TypeFormatImpl_EnumType(ConstString(m_command_options.m_custom_type_name.c_str()),
831 TypeFormatImpl::Flags().SetCascades(m_command_options.m_cascade).
832 SetSkipPointers(m_command_options.m_skip_pointers).
833 SetSkipReferences(m_command_options.m_skip_references)));
835 // now I have a valid format, let's add it to every type
837 TypeCategoryImplSP category_sp;
838 DataVisualization::Categories::GetCategory(ConstString(m_command_options.m_category), category_sp);
842 WarnOnPotentialUnquotedUnsignedType(command, result);
844 for (size_t i = 0; i < argc; i++)
846 const char* typeA = command.GetArgumentAtIndex(i);
847 ConstString typeCS(typeA);
850 if (m_command_options.m_regex)
852 RegularExpressionSP typeRX(new RegularExpression());
853 if (!typeRX->Compile(typeCS.GetCString()))
855 result.AppendError("regex format error (maybe this is not really a regex?)");
856 result.SetStatus(eReturnStatusFailed);
859 category_sp->GetRegexTypeSummariesContainer()->Delete(typeCS);
860 category_sp->GetRegexTypeFormatsContainer()->Add(typeRX, entry);
863 category_sp->GetTypeFormatsContainer()->Add(typeCS, entry);
867 result.AppendError("empty typenames not allowed");
868 result.SetStatus(eReturnStatusFailed);
873 result.SetStatus(eReturnStatusSuccessFinishNoResult);
874 return result.Succeeded();
879 CommandObjectTypeFormatAdd::CommandOptions::g_option_table[] =
881 { LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Add this to the given category instead of the default one."},
882 { LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "If true, cascade through typedef chains."},
883 { LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."},
884 { LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Don't use this format for references-to-type objects."},
885 { LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Type names are actually regular expressions."},
886 { LLDB_OPT_SET_2, false, "type", 't', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Format variables as if they were of this type."},
887 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
892 CommandObjectTypeFormatAdd::CommandOptions::GetNumDefinitions ()
894 return sizeof(g_option_table) / sizeof (OptionDefinition);
898 //-------------------------------------------------------------------------
899 // CommandObjectTypeFormatDelete
900 //-------------------------------------------------------------------------
902 class CommandObjectTypeFormatDelete : public CommandObjectParsed
905 class CommandOptions : public Options
909 CommandOptions (CommandInterpreter &interpreter) :
910 Options (interpreter)
918 SetOptionValue (uint32_t option_idx, const char *option_arg)
921 const int short_option = m_getopt_table[option_idx].val;
923 switch (short_option)
929 m_category = std::string(option_arg);
932 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
940 OptionParsingStarting ()
942 m_delete_all = false;
943 m_category = "default";
946 const OptionDefinition*
949 return g_option_table;
952 // Options table: Required for subclasses of Options.
954 static OptionDefinition g_option_table[];
956 // Instance variables to hold the values for command options.
959 std::string m_category;
963 CommandOptions m_options;
972 PerCategoryCallback(void* param,
973 const lldb::TypeCategoryImplSP& category_sp)
975 ConstString *name = (ConstString*)param;
976 category_sp->Delete(*name, eFormatCategoryItemValue | eFormatCategoryItemRegexValue);
981 CommandObjectTypeFormatDelete (CommandInterpreter &interpreter) :
982 CommandObjectParsed (interpreter,
983 "type format delete",
984 "Delete an existing formatting style for a type.",
986 m_options(interpreter)
988 CommandArgumentEntry type_arg;
989 CommandArgumentData type_style_arg;
991 type_style_arg.arg_type = eArgTypeName;
992 type_style_arg.arg_repetition = eArgRepeatPlain;
994 type_arg.push_back (type_style_arg);
996 m_arguments.push_back (type_arg);
1000 ~CommandObjectTypeFormatDelete ()
1006 DoExecute (Args& command, CommandReturnObject &result)
1008 const size_t argc = command.GetArgumentCount();
1012 result.AppendErrorWithFormat ("%s takes 1 arg.\n", m_cmd_name.c_str());
1013 result.SetStatus(eReturnStatusFailed);
1017 const char* typeA = command.GetArgumentAtIndex(0);
1018 ConstString typeCS(typeA);
1022 result.AppendError("empty typenames not allowed");
1023 result.SetStatus(eReturnStatusFailed);
1027 if (m_options.m_delete_all)
1029 DataVisualization::Categories::LoopThrough(PerCategoryCallback, &typeCS);
1030 result.SetStatus(eReturnStatusSuccessFinishNoResult);
1031 return result.Succeeded();
1034 lldb::TypeCategoryImplSP category;
1035 DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
1037 bool delete_category = category->Delete(typeCS,
1038 eFormatCategoryItemValue | eFormatCategoryItemRegexValue);
1040 if (delete_category)
1042 result.SetStatus(eReturnStatusSuccessFinishNoResult);
1043 return result.Succeeded();
1047 result.AppendErrorWithFormat ("no custom format for %s.\n", typeA);
1048 result.SetStatus(eReturnStatusFailed);
1057 CommandObjectTypeFormatDelete::CommandOptions::g_option_table[] =
1059 { LLDB_OPT_SET_1, false, "all", 'a', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Delete from every category."},
1060 { LLDB_OPT_SET_2, false, "category", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Delete from given category."},
1061 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
1064 //-------------------------------------------------------------------------
1065 // CommandObjectTypeFormatClear
1066 //-------------------------------------------------------------------------
1068 class CommandObjectTypeFormatClear : public CommandObjectParsed
1072 class CommandOptions : public Options
1076 CommandOptions (CommandInterpreter &interpreter) :
1077 Options (interpreter)
1082 ~CommandOptions (){}
1085 SetOptionValue (uint32_t option_idx, const char *option_arg)
1088 const int short_option = m_getopt_table[option_idx].val;
1090 switch (short_option)
1093 m_delete_all = true;
1096 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1104 OptionParsingStarting ()
1106 m_delete_all = false;
1109 const OptionDefinition*
1112 return g_option_table;
1115 // Options table: Required for subclasses of Options.
1117 static OptionDefinition g_option_table[];
1119 // Instance variables to hold the values for command options.
1122 bool m_delete_named;
1125 CommandOptions m_options;
1134 PerCategoryCallback(void* param,
1135 const lldb::TypeCategoryImplSP& cate)
1137 cate->GetTypeFormatsContainer()->Clear();
1138 cate->GetRegexTypeFormatsContainer()->Clear();
1144 CommandObjectTypeFormatClear (CommandInterpreter &interpreter) :
1145 CommandObjectParsed (interpreter,
1146 "type format clear",
1147 "Delete all existing format styles.",
1149 m_options(interpreter)
1153 ~CommandObjectTypeFormatClear ()
1159 DoExecute (Args& command, CommandReturnObject &result)
1161 if (m_options.m_delete_all)
1162 DataVisualization::Categories::LoopThrough(PerCategoryCallback, NULL);
1166 lldb::TypeCategoryImplSP category;
1167 if (command.GetArgumentCount() > 0)
1169 const char* cat_name = command.GetArgumentAtIndex(0);
1170 ConstString cat_nameCS(cat_name);
1171 DataVisualization::Categories::GetCategory(cat_nameCS, category);
1174 DataVisualization::Categories::GetCategory(ConstString(NULL), category);
1175 category->Clear(eFormatCategoryItemValue | eFormatCategoryItemRegexValue);
1178 result.SetStatus(eReturnStatusSuccessFinishResult);
1179 return result.Succeeded();
1185 CommandObjectTypeFormatClear::CommandOptions::g_option_table[] =
1187 { LLDB_OPT_SET_ALL, false, "all", 'a', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Clear every category."},
1188 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
1191 //-------------------------------------------------------------------------
1192 // CommandObjectTypeFormatList
1193 //-------------------------------------------------------------------------
1195 bool CommandObjectTypeFormatList_LoopCallback(void* pt2self, ConstString type, const lldb::TypeFormatImplSP& entry);
1196 bool CommandObjectTypeRXFormatList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const lldb::TypeFormatImplSP& entry);
1198 class CommandObjectTypeFormatList;
1200 struct CommandObjectTypeFormatList_LoopCallbackParam {
1201 CommandObjectTypeFormatList* self;
1202 CommandReturnObject* result;
1203 RegularExpression* regex;
1204 RegularExpression* cate_regex;
1205 CommandObjectTypeFormatList_LoopCallbackParam(CommandObjectTypeFormatList* S, CommandReturnObject* R,
1206 RegularExpression* X = NULL, RegularExpression* CX = NULL) : self(S), result(R), regex(X), cate_regex(CX) {}
1209 class CommandObjectTypeFormatList : public CommandObjectParsed
1211 class CommandOptions : public Options
1215 CommandOptions (CommandInterpreter &interpreter) :
1216 Options (interpreter)
1221 ~CommandOptions (){}
1224 SetOptionValue (uint32_t option_idx, const char *option_arg)
1227 const int short_option = m_getopt_table[option_idx].val;
1229 switch (short_option)
1232 m_category_regex = std::string(option_arg);
1235 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1243 OptionParsingStarting ()
1245 m_category_regex = "";
1248 const OptionDefinition*
1251 return g_option_table;
1254 // Options table: Required for subclasses of Options.
1256 static OptionDefinition g_option_table[];
1258 // Instance variables to hold the values for command options.
1260 std::string m_category_regex;
1264 CommandOptions m_options;
1273 CommandObjectTypeFormatList (CommandInterpreter &interpreter) :
1274 CommandObjectParsed (interpreter,
1276 "Show a list of current formatting styles.",
1278 m_options(interpreter)
1280 CommandArgumentEntry type_arg;
1281 CommandArgumentData type_style_arg;
1283 type_style_arg.arg_type = eArgTypeName;
1284 type_style_arg.arg_repetition = eArgRepeatOptional;
1286 type_arg.push_back (type_style_arg);
1288 m_arguments.push_back (type_arg);
1291 ~CommandObjectTypeFormatList ()
1297 DoExecute (Args& command, CommandReturnObject &result)
1299 const size_t argc = command.GetArgumentCount();
1301 CommandObjectTypeFormatList_LoopCallbackParam *param;
1302 RegularExpression* cate_regex =
1303 m_options.m_category_regex.empty() ? NULL :
1304 new RegularExpression(m_options.m_category_regex.c_str());
1308 RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
1309 regex->Compile(command.GetArgumentAtIndex(0));
1310 param = new CommandObjectTypeFormatList_LoopCallbackParam(this,&result,regex,cate_regex);
1313 param = new CommandObjectTypeFormatList_LoopCallbackParam(this,&result,NULL,cate_regex);
1315 DataVisualization::Categories::LoopThrough(PerCategoryCallback,param);
1321 result.SetStatus(eReturnStatusSuccessFinishResult);
1322 return result.Succeeded();
1328 PerCategoryCallback(void* param_vp,
1329 const lldb::TypeCategoryImplSP& cate)
1332 CommandObjectTypeFormatList_LoopCallbackParam* param =
1333 (CommandObjectTypeFormatList_LoopCallbackParam*)param_vp;
1334 CommandReturnObject* result = param->result;
1336 const char* cate_name = cate->GetName();
1338 // if the category is disabled or empty and there is no regex, just skip it
1339 if ((cate->IsEnabled() == false || cate->GetCount(eFormatCategoryItemValue | eFormatCategoryItemRegexValue) == 0) && param->cate_regex == NULL)
1342 // if we have a regex and this category does not match it, just skip it
1343 if(param->cate_regex != NULL && strcmp(cate_name,param->cate_regex->GetText()) != 0 && param->cate_regex->Execute(cate_name) == false)
1346 result->GetOutputStream().Printf("-----------------------\nCategory: %s (%s)\n-----------------------\n",
1348 (cate->IsEnabled() ? "enabled" : "disabled"));
1350 cate->GetTypeFormatsContainer()->LoopThrough(CommandObjectTypeFormatList_LoopCallback, param_vp);
1352 if (cate->GetRegexTypeSummariesContainer()->GetCount() > 0)
1354 result->GetOutputStream().Printf("Regex-based summaries (slower):\n");
1355 cate->GetRegexTypeFormatsContainer()->LoopThrough(CommandObjectTypeRXFormatList_LoopCallback, param_vp);
1362 LoopCallback (const char* type,
1363 const lldb::TypeFormatImplSP& entry,
1364 RegularExpression* regex,
1365 CommandReturnObject *result)
1367 if (regex == NULL || strcmp(type,regex->GetText()) == 0 || regex->Execute(type))
1368 result->GetOutputStream().Printf ("%s: %s\n", type, entry->GetDescription().c_str());
1372 friend bool CommandObjectTypeFormatList_LoopCallback(void* pt2self, ConstString type, const lldb::TypeFormatImplSP& entry);
1373 friend bool CommandObjectTypeRXFormatList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const lldb::TypeFormatImplSP& entry);
1378 CommandObjectTypeFormatList_LoopCallback (
1381 const lldb::TypeFormatImplSP& entry)
1383 CommandObjectTypeFormatList_LoopCallbackParam* param = (CommandObjectTypeFormatList_LoopCallbackParam*)pt2self;
1384 return param->self->LoopCallback(type.AsCString(), entry, param->regex, param->result);
1388 CommandObjectTypeRXFormatList_LoopCallback (
1390 lldb::RegularExpressionSP regex,
1391 const lldb::TypeFormatImplSP& entry)
1393 CommandObjectTypeFormatList_LoopCallbackParam* param = (CommandObjectTypeFormatList_LoopCallbackParam*)pt2self;
1394 return param->self->LoopCallback(regex->GetText(), entry, param->regex, param->result);
1398 CommandObjectTypeFormatList::CommandOptions::g_option_table[] =
1400 { LLDB_OPT_SET_ALL, false, "category-regex", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Only show categories matching this filter."},
1401 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
1404 #ifndef LLDB_DISABLE_PYTHON
1406 //-------------------------------------------------------------------------
1407 // CommandObjectTypeSummaryAdd
1408 //-------------------------------------------------------------------------
1410 #endif // #ifndef LLDB_DISABLE_PYTHON
1413 CommandObjectTypeSummaryAdd::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
1416 const int short_option = m_getopt_table[option_idx].val;
1419 switch (short_option)
1422 m_flags.SetCascades(Args::StringToBoolean(option_arg, true, &success));
1424 error.SetErrorStringWithFormat("invalid value for cascade: %s", option_arg);
1427 m_flags.SetDontShowChildren(false);
1430 m_flags.SetDontShowValue(true);
1433 m_flags.SetShowMembersOneLiner(true);
1436 m_format_string = std::string(option_arg);
1439 m_flags.SetSkipPointers(true);
1442 m_flags.SetSkipReferences(true);
1448 m_name.SetCString(option_arg);
1451 m_python_script = std::string(option_arg);
1452 m_is_add_script = true;
1455 m_python_function = std::string(option_arg);
1456 m_is_add_script = true;
1459 m_is_add_script = true;
1462 m_category = std::string(option_arg);
1465 m_flags.SetHideItemNames(true);
1468 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1476 CommandObjectTypeSummaryAdd::CommandOptions::OptionParsingStarting ()
1478 m_flags.Clear().SetCascades().SetDontShowChildren().SetDontShowValue(false);
1479 m_flags.SetShowMembersOneLiner(false).SetSkipPointers(false).SetSkipReferences(false).SetHideItemNames(false);
1483 m_python_script = "";
1484 m_python_function = "";
1485 m_format_string = "";
1486 m_is_add_script = false;
1487 m_category = "default";
1492 #ifndef LLDB_DISABLE_PYTHON
1495 CommandObjectTypeSummaryAdd::Execute_ScriptSummary (Args& command, CommandReturnObject &result)
1497 const size_t argc = command.GetArgumentCount();
1499 if (argc < 1 && !m_options.m_name)
1501 result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
1502 result.SetStatus(eReturnStatusFailed);
1506 TypeSummaryImplSP script_format;
1508 if (!m_options.m_python_function.empty()) // we have a Python function ready to use
1510 const char *funct_name = m_options.m_python_function.c_str();
1511 if (!funct_name || !funct_name[0])
1513 result.AppendError ("function name empty.\n");
1514 result.SetStatus (eReturnStatusFailed);
1518 std::string code = (" " + m_options.m_python_function + "(valobj,internal_dict)");
1520 script_format.reset(new ScriptSummaryFormat(m_options.m_flags,
1524 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
1526 if (interpreter && interpreter->CheckObjectExists(funct_name) == false)
1527 result.AppendWarningWithFormat("The provided function \"%s\" does not exist - "
1528 "please define it before attempting to use this summary.\n",
1531 else if (!m_options.m_python_script.empty()) // we have a quick 1-line script, just use it
1533 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
1536 result.AppendError ("script interpreter missing - unable to generate function wrapper.\n");
1537 result.SetStatus (eReturnStatusFailed);
1540 StringList funct_sl;
1541 funct_sl << m_options.m_python_script.c_str();
1542 std::string funct_name_str;
1543 if (!interpreter->GenerateTypeScriptFunction (funct_sl,
1546 result.AppendError ("unable to generate function wrapper.\n");
1547 result.SetStatus (eReturnStatusFailed);
1550 if (funct_name_str.empty())
1552 result.AppendError ("script interpreter failed to generate a valid function name.\n");
1553 result.SetStatus (eReturnStatusFailed);
1557 std::string code = " " + m_options.m_python_script;
1559 script_format.reset(new ScriptSummaryFormat(m_options.m_flags,
1560 funct_name_str.c_str(),
1565 // Use an IOHandler to grab Python code from the user
1566 ScriptAddOptions *options = new ScriptAddOptions(m_options.m_flags,
1569 m_options.m_category);
1571 for (size_t i = 0; i < argc; i++)
1573 const char* typeA = command.GetArgumentAtIndex(i);
1574 if (typeA && *typeA)
1575 options->m_target_types << typeA;
1578 result.AppendError("empty typenames not allowed");
1579 result.SetStatus(eReturnStatusFailed);
1584 m_interpreter.GetPythonCommandsFromIOHandler (" ", // Prompt
1585 *this, // IOHandlerDelegate
1586 true, // Run IOHandler in async mode
1587 options); // Baton for the "io_handler" that will be passed back into our IOHandlerDelegate functions
1588 result.SetStatus(eReturnStatusSuccessFinishNoResult);
1590 return result.Succeeded();
1593 // if I am here, script_format must point to something good, so I can add that
1594 // as a script summary to all interested parties
1598 for (size_t i = 0; i < command.GetArgumentCount(); i++)
1600 const char *type_name = command.GetArgumentAtIndex(i);
1601 CommandObjectTypeSummaryAdd::AddSummary(ConstString(type_name),
1603 (m_options.m_regex ? eRegexSummary : eRegularSummary),
1604 m_options.m_category,
1608 result.AppendError(error.AsCString());
1609 result.SetStatus(eReturnStatusFailed);
1614 if (m_options.m_name)
1616 AddSummary(m_options.m_name, script_format, eNamedSummary, m_options.m_category, &error);
1619 result.AppendError(error.AsCString());
1620 result.AppendError("added to types, but not given a name");
1621 result.SetStatus(eReturnStatusFailed);
1626 return result.Succeeded();
1633 CommandObjectTypeSummaryAdd::Execute_StringSummary (Args& command, CommandReturnObject &result)
1635 const size_t argc = command.GetArgumentCount();
1637 if (argc < 1 && !m_options.m_name)
1639 result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
1640 result.SetStatus(eReturnStatusFailed);
1644 if (!m_options.m_flags.GetShowMembersOneLiner() && m_options.m_format_string.empty())
1646 result.AppendError("empty summary strings not allowed");
1647 result.SetStatus(eReturnStatusFailed);
1651 const char* format_cstr = (m_options.m_flags.GetShowMembersOneLiner() ? "" : m_options.m_format_string.c_str());
1653 // ${var%S} is an endless recursion, prevent it
1654 if (strcmp(format_cstr, "${var%S}") == 0)
1656 result.AppendError("recursive summary not allowed");
1657 result.SetStatus(eReturnStatusFailed);
1663 lldb::TypeSummaryImplSP entry(new StringSummaryFormat(m_options.m_flags,
1668 result.AppendError(error.AsCString());
1669 result.SetStatus(eReturnStatusFailed);
1673 // now I have a valid format, let's add it to every type
1675 for (size_t i = 0; i < argc; i++)
1677 const char* typeA = command.GetArgumentAtIndex(i);
1678 if (!typeA || typeA[0] == '\0')
1680 result.AppendError("empty typenames not allowed");
1681 result.SetStatus(eReturnStatusFailed);
1684 ConstString typeCS(typeA);
1688 (m_options.m_regex ? eRegexSummary : eRegularSummary),
1689 m_options.m_category,
1694 result.AppendError(error.AsCString());
1695 result.SetStatus(eReturnStatusFailed);
1700 if (m_options.m_name)
1702 AddSummary(m_options.m_name, entry, eNamedSummary, m_options.m_category, &error);
1705 result.AppendError(error.AsCString());
1706 result.AppendError("added to types, but not given a name");
1707 result.SetStatus(eReturnStatusFailed);
1712 result.SetStatus(eReturnStatusSuccessFinishNoResult);
1713 return result.Succeeded();
1716 CommandObjectTypeSummaryAdd::CommandObjectTypeSummaryAdd (CommandInterpreter &interpreter) :
1717 CommandObjectParsed (interpreter,
1719 "Add a new summary style for a type.",
1721 IOHandlerDelegateMultiline ("DONE"),
1722 m_options (interpreter)
1724 CommandArgumentEntry type_arg;
1725 CommandArgumentData type_style_arg;
1727 type_style_arg.arg_type = eArgTypeName;
1728 type_style_arg.arg_repetition = eArgRepeatPlus;
1730 type_arg.push_back (type_style_arg);
1732 m_arguments.push_back (type_arg);
1735 "Some examples of using this command.\n"
1736 "We use as reference the following snippet of code:\n"
1737 "struct JustADemo\n"
1741 "JustADemo(int p = 1, float v = 0.1) : ptr(new int(p)), value(v) {}\n"
1743 "JustADemo object(42,3.14);\n"
1744 "struct AnotherDemo : public JustADemo\n"
1747 "AnotherDemo(uint8_t b = 'E', int p = 1, float v = 0.1) : JustADemo(p,v), byte(b) {}\n"
1749 "AnotherDemo *another_object = new AnotherDemo('E',42,3.14);\n"
1751 "type summary add --summary-string \"the answer is ${*var.ptr}\" JustADemo\n"
1752 "when typing frame variable object you will get \"the answer is 42\"\n"
1753 "type summary add --summary-string \"the answer is ${*var.ptr}, and the question is ${var.value}\" JustADemo\n"
1754 "when typing frame variable object you will get \"the answer is 42 and the question is 3.14\"\n"
1756 "Alternatively, you could also say\n"
1757 "type summary add --summary-string \"${var%V} -> ${*var}\" \"int *\"\n"
1758 "and replace the above summary string with\n"
1759 "type summary add --summary-string \"the answer is ${var.ptr}, and the question is ${var.value}\" JustADemo\n"
1760 "to obtain a similar result\n"
1762 "To add a summary valid for both JustADemo and AnotherDemo you can use the scoping operator, as in:\n"
1763 "type summary add --summary-string \"${var.ptr}, ${var.value},{${var.byte}}\" JustADemo -C yes\n"
1765 "This will be used for both variables of type JustADemo and AnotherDemo. To prevent this, change the -C to read -C no\n"
1766 "If you do not want pointers to be shown using that summary, you can use the -p option, as in:\n"
1767 "type summary add --summary-string \"${var.ptr}, ${var.value},{${var.byte}}\" JustADemo -C yes -p\n"
1768 "A similar option -r exists for references.\n"
1770 "If you simply want a one-line summary of the content of your variable, without typing an explicit string to that effect\n"
1771 "you can use the -c option, without giving any summary string:\n"
1772 "type summary add -c JustADemo\n"
1773 "frame variable object\n"
1774 "the output being similar to (ptr=0xsomeaddress, value=3.14)\n"
1776 "If you want to display some summary text, but also expand the structure of your object, you can add the -e option, as in:\n"
1777 "type summary add -e --summary-string \"*ptr = ${*var.ptr}\" JustADemo\n"
1778 "Here the value of the int* is displayed, followed by the standard LLDB sequence of children objects, one per line.\n"
1779 "to get an output like:\n"
1782 " ptr = 0xsomeaddress\n"
1786 "You can also add Python summaries, in which case you will use lldb public API to gather information from your variables"
1787 "and elaborate them to a meaningful summary inside a script written in Python. The variable object will be passed to your"
1788 "script as an SBValue object. The following example might help you when starting to use the Python summaries feature:\n"
1789 "type summary add JustADemo -o \"value = valobj.GetChildMemberWithName('value'); return 'My value is ' + value.GetValue();\"\n"
1790 "If you prefer to type your scripts on multiple lines, you will use the -P option and then type your script, ending it with "
1791 "the word DONE on a line by itself to mark you're finished editing your code:\n"
1792 "(lldb)type summary add JustADemo -P\n"
1793 " value = valobj.GetChildMemberWithName('value');\n"
1794 " return 'My value is ' + value.GetValue();\n"
1796 "(lldb) <-- type further LLDB commands here\n"
1801 CommandObjectTypeSummaryAdd::DoExecute (Args& command, CommandReturnObject &result)
1803 WarnOnPotentialUnquotedUnsignedType(command, result);
1805 if (m_options.m_is_add_script)
1807 #ifndef LLDB_DISABLE_PYTHON
1808 return Execute_ScriptSummary(command, result);
1810 result.AppendError ("python is disabled");
1811 result.SetStatus(eReturnStatusFailed);
1816 return Execute_StringSummary(command, result);
1820 FixArrayTypeNameWithRegex (ConstString &type_name)
1822 llvm::StringRef type_name_ref(type_name.GetStringRef());
1824 if (type_name_ref.endswith("[]"))
1826 std::string type_name_str(type_name.GetCString());
1827 type_name_str.resize(type_name_str.length()-2);
1828 if (type_name_str.back() != ' ')
1829 type_name_str.append(" \\[[0-9]+\\]");
1831 type_name_str.append("\\[[0-9]+\\]");
1832 type_name.SetCString(type_name_str.c_str());
1839 CommandObjectTypeSummaryAdd::AddSummary(ConstString type_name,
1840 TypeSummaryImplSP entry,
1841 SummaryFormatType type,
1842 std::string category_name,
1845 lldb::TypeCategoryImplSP category;
1846 DataVisualization::Categories::GetCategory(ConstString(category_name.c_str()), category);
1848 if (type == eRegularSummary)
1850 if (FixArrayTypeNameWithRegex (type_name))
1851 type = eRegexSummary;
1854 if (type == eRegexSummary)
1856 RegularExpressionSP typeRX(new RegularExpression());
1857 if (!typeRX->Compile(type_name.GetCString()))
1860 error->SetErrorString("regex format error (maybe this is not really a regex?)");
1864 category->GetRegexTypeSummariesContainer()->Delete(type_name);
1865 category->GetRegexTypeSummariesContainer()->Add(typeRX, entry);
1869 else if (type == eNamedSummary)
1871 // system named summaries do not exist (yet?)
1872 DataVisualization::NamedSummaryFormats::Add(type_name,entry);
1877 category->GetTypeSummariesContainer()->Add(type_name, entry);
1883 CommandObjectTypeSummaryAdd::CommandOptions::g_option_table[] =
1885 { LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Add this to the given category instead of the default one."},
1886 { LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "If true, cascade through typedef chains."},
1887 { LLDB_OPT_SET_ALL, false, "no-value", 'v', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Don't show the value, just show the summary, for this type."},
1888 { LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."},
1889 { LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Don't use this format for references-to-type objects."},
1890 { LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Type names are actually regular expressions."},
1891 { LLDB_OPT_SET_1 , true, "inline-children", 'c', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "If true, inline all child values into summary string."},
1892 { LLDB_OPT_SET_1 , false, "omit-names", 'O', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "If true, omit value names in the summary display."},
1893 { LLDB_OPT_SET_2 , true, "summary-string", 's', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeSummaryString, "Summary string used to display text and object contents."},
1894 { LLDB_OPT_SET_3, false, "python-script", 'o', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePythonScript, "Give a one-liner Python script as part of the command."},
1895 { LLDB_OPT_SET_3, false, "python-function", 'F', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePythonFunction, "Give the name of a Python function to use for this type."},
1896 { LLDB_OPT_SET_3, false, "input-python", 'P', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Input Python code to use for this type manually."},
1897 { LLDB_OPT_SET_2 | LLDB_OPT_SET_3, false, "expand", 'e', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Expand aggregate data types to show children on separate lines."},
1898 { LLDB_OPT_SET_2 | LLDB_OPT_SET_3, false, "name", 'n', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "A name for this summary string."},
1899 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
1903 //-------------------------------------------------------------------------
1904 // CommandObjectTypeSummaryDelete
1905 //-------------------------------------------------------------------------
1907 class CommandObjectTypeSummaryDelete : public CommandObjectParsed
1910 class CommandOptions : public Options
1914 CommandOptions (CommandInterpreter &interpreter) :
1915 Options (interpreter)
1920 ~CommandOptions (){}
1923 SetOptionValue (uint32_t option_idx, const char *option_arg)
1926 const int short_option = m_getopt_table[option_idx].val;
1928 switch (short_option)
1931 m_delete_all = true;
1934 m_category = std::string(option_arg);
1937 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1945 OptionParsingStarting ()
1947 m_delete_all = false;
1948 m_category = "default";
1951 const OptionDefinition*
1954 return g_option_table;
1957 // Options table: Required for subclasses of Options.
1959 static OptionDefinition g_option_table[];
1961 // Instance variables to hold the values for command options.
1964 std::string m_category;
1968 CommandOptions m_options;
1977 PerCategoryCallback(void* param,
1978 const lldb::TypeCategoryImplSP& category_sp)
1980 ConstString *name = (ConstString*)param;
1981 category_sp->Delete(*name, eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
1986 CommandObjectTypeSummaryDelete (CommandInterpreter &interpreter) :
1987 CommandObjectParsed (interpreter,
1988 "type summary delete",
1989 "Delete an existing summary style for a type.",
1991 m_options(interpreter)
1993 CommandArgumentEntry type_arg;
1994 CommandArgumentData type_style_arg;
1996 type_style_arg.arg_type = eArgTypeName;
1997 type_style_arg.arg_repetition = eArgRepeatPlain;
1999 type_arg.push_back (type_style_arg);
2001 m_arguments.push_back (type_arg);
2005 ~CommandObjectTypeSummaryDelete ()
2011 DoExecute (Args& command, CommandReturnObject &result)
2013 const size_t argc = command.GetArgumentCount();
2017 result.AppendErrorWithFormat ("%s takes 1 arg.\n", m_cmd_name.c_str());
2018 result.SetStatus(eReturnStatusFailed);
2022 const char* typeA = command.GetArgumentAtIndex(0);
2023 ConstString typeCS(typeA);
2027 result.AppendError("empty typenames not allowed");
2028 result.SetStatus(eReturnStatusFailed);
2032 if (m_options.m_delete_all)
2034 DataVisualization::Categories::LoopThrough(PerCategoryCallback, &typeCS);
2035 result.SetStatus(eReturnStatusSuccessFinishNoResult);
2036 return result.Succeeded();
2039 lldb::TypeCategoryImplSP category;
2040 DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
2042 bool delete_category = category->Delete(typeCS,
2043 eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
2044 bool delete_named = DataVisualization::NamedSummaryFormats::Delete(typeCS);
2046 if (delete_category || delete_named)
2048 result.SetStatus(eReturnStatusSuccessFinishNoResult);
2049 return result.Succeeded();
2053 result.AppendErrorWithFormat ("no custom summary for %s.\n", typeA);
2054 result.SetStatus(eReturnStatusFailed);
2062 CommandObjectTypeSummaryDelete::CommandOptions::g_option_table[] =
2064 { LLDB_OPT_SET_1, false, "all", 'a', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Delete from every category."},
2065 { LLDB_OPT_SET_2, false, "category", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Delete from given category."},
2066 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
2069 class CommandObjectTypeSummaryClear : public CommandObjectParsed
2073 class CommandOptions : public Options
2077 CommandOptions (CommandInterpreter &interpreter) :
2078 Options (interpreter)
2083 ~CommandOptions (){}
2086 SetOptionValue (uint32_t option_idx, const char *option_arg)
2089 const int short_option = m_getopt_table[option_idx].val;
2091 switch (short_option)
2094 m_delete_all = true;
2097 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
2105 OptionParsingStarting ()
2107 m_delete_all = false;
2110 const OptionDefinition*
2113 return g_option_table;
2116 // Options table: Required for subclasses of Options.
2118 static OptionDefinition g_option_table[];
2120 // Instance variables to hold the values for command options.
2123 bool m_delete_named;
2126 CommandOptions m_options;
2135 PerCategoryCallback(void* param,
2136 const lldb::TypeCategoryImplSP& cate)
2138 cate->GetTypeSummariesContainer()->Clear();
2139 cate->GetRegexTypeSummariesContainer()->Clear();
2145 CommandObjectTypeSummaryClear (CommandInterpreter &interpreter) :
2146 CommandObjectParsed (interpreter,
2147 "type summary clear",
2148 "Delete all existing summary styles.",
2150 m_options(interpreter)
2154 ~CommandObjectTypeSummaryClear ()
2160 DoExecute (Args& command, CommandReturnObject &result)
2163 if (m_options.m_delete_all)
2164 DataVisualization::Categories::LoopThrough(PerCategoryCallback, NULL);
2168 lldb::TypeCategoryImplSP category;
2169 if (command.GetArgumentCount() > 0)
2171 const char* cat_name = command.GetArgumentAtIndex(0);
2172 ConstString cat_nameCS(cat_name);
2173 DataVisualization::Categories::GetCategory(cat_nameCS, category);
2176 DataVisualization::Categories::GetCategory(ConstString(NULL), category);
2177 category->Clear(eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
2180 DataVisualization::NamedSummaryFormats::Clear();
2182 result.SetStatus(eReturnStatusSuccessFinishResult);
2183 return result.Succeeded();
2189 CommandObjectTypeSummaryClear::CommandOptions::g_option_table[] =
2191 { LLDB_OPT_SET_ALL, false, "all", 'a', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Clear every category."},
2192 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
2195 //-------------------------------------------------------------------------
2196 // CommandObjectTypeSummaryList
2197 //-------------------------------------------------------------------------
2199 bool CommandObjectTypeSummaryList_LoopCallback(void* pt2self, ConstString type, const StringSummaryFormat::SharedPointer& entry);
2200 bool CommandObjectTypeRXSummaryList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const StringSummaryFormat::SharedPointer& entry);
2202 class CommandObjectTypeSummaryList;
2204 struct CommandObjectTypeSummaryList_LoopCallbackParam {
2205 CommandObjectTypeSummaryList* self;
2206 CommandReturnObject* result;
2207 RegularExpression* regex;
2208 RegularExpression* cate_regex;
2209 CommandObjectTypeSummaryList_LoopCallbackParam(CommandObjectTypeSummaryList* S, CommandReturnObject* R,
2210 RegularExpression* X = NULL,
2211 RegularExpression* CX = NULL) : self(S), result(R), regex(X), cate_regex(CX) {}
2214 class CommandObjectTypeSummaryList : public CommandObjectParsed
2217 class CommandOptions : public Options
2221 CommandOptions (CommandInterpreter &interpreter) :
2222 Options (interpreter)
2227 ~CommandOptions (){}
2230 SetOptionValue (uint32_t option_idx, const char *option_arg)
2233 const int short_option = m_getopt_table[option_idx].val;
2235 switch (short_option)
2238 m_category_regex = std::string(option_arg);
2241 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
2249 OptionParsingStarting ()
2251 m_category_regex = "";
2254 const OptionDefinition*
2257 return g_option_table;
2260 // Options table: Required for subclasses of Options.
2262 static OptionDefinition g_option_table[];
2264 // Instance variables to hold the values for command options.
2266 std::string m_category_regex;
2270 CommandOptions m_options;
2279 CommandObjectTypeSummaryList (CommandInterpreter &interpreter) :
2280 CommandObjectParsed (interpreter,
2281 "type summary list",
2282 "Show a list of current summary styles.",
2284 m_options(interpreter)
2286 CommandArgumentEntry type_arg;
2287 CommandArgumentData type_style_arg;
2289 type_style_arg.arg_type = eArgTypeName;
2290 type_style_arg.arg_repetition = eArgRepeatOptional;
2292 type_arg.push_back (type_style_arg);
2294 m_arguments.push_back (type_arg);
2297 ~CommandObjectTypeSummaryList ()
2303 DoExecute (Args& command, CommandReturnObject &result)
2305 const size_t argc = command.GetArgumentCount();
2307 CommandObjectTypeSummaryList_LoopCallbackParam *param;
2308 RegularExpression* cate_regex =
2309 m_options.m_category_regex.empty() ? NULL :
2310 new RegularExpression(m_options.m_category_regex.c_str());
2314 RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
2315 regex->Compile(command.GetArgumentAtIndex(0));
2316 param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result,regex,cate_regex);
2319 param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result,NULL,cate_regex);
2321 DataVisualization::Categories::LoopThrough(PerCategoryCallback,param);
2324 if (DataVisualization::NamedSummaryFormats::GetCount() > 0)
2326 result.GetOutputStream().Printf("Named summaries:\n");
2329 RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
2330 regex->Compile(command.GetArgumentAtIndex(0));
2331 param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result,regex);
2334 param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result);
2335 DataVisualization::NamedSummaryFormats::LoopThrough(CommandObjectTypeSummaryList_LoopCallback, param);
2342 result.SetStatus(eReturnStatusSuccessFinishResult);
2343 return result.Succeeded();
2349 PerCategoryCallback(void* param_vp,
2350 const lldb::TypeCategoryImplSP& cate)
2353 CommandObjectTypeSummaryList_LoopCallbackParam* param =
2354 (CommandObjectTypeSummaryList_LoopCallbackParam*)param_vp;
2355 CommandReturnObject* result = param->result;
2357 const char* cate_name = cate->GetName();
2359 // if the category is disabled or empty and there is no regex, just skip it
2360 if ((cate->IsEnabled() == false || cate->GetCount(eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary) == 0) && param->cate_regex == NULL)
2363 // if we have a regex and this category does not match it, just skip it
2364 if(param->cate_regex != NULL && strcmp(cate_name,param->cate_regex->GetText()) != 0 && param->cate_regex->Execute(cate_name) == false)
2367 result->GetOutputStream().Printf("-----------------------\nCategory: %s (%s)\n-----------------------\n",
2369 (cate->IsEnabled() ? "enabled" : "disabled"));
2371 cate->GetTypeSummariesContainer()->LoopThrough(CommandObjectTypeSummaryList_LoopCallback, param_vp);
2373 if (cate->GetRegexTypeSummariesContainer()->GetCount() > 0)
2375 result->GetOutputStream().Printf("Regex-based summaries (slower):\n");
2376 cate->GetRegexTypeSummariesContainer()->LoopThrough(CommandObjectTypeRXSummaryList_LoopCallback, param_vp);
2383 LoopCallback (const char* type,
2384 const lldb::TypeSummaryImplSP& entry,
2385 RegularExpression* regex,
2386 CommandReturnObject *result)
2388 if (regex == NULL || strcmp(type,regex->GetText()) == 0 || regex->Execute(type))
2389 result->GetOutputStream().Printf ("%s: %s\n", type, entry->GetDescription().c_str());
2393 friend bool CommandObjectTypeSummaryList_LoopCallback(void* pt2self, ConstString type, const lldb::TypeSummaryImplSP& entry);
2394 friend bool CommandObjectTypeRXSummaryList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const lldb::TypeSummaryImplSP& entry);
2398 CommandObjectTypeSummaryList_LoopCallback (
2401 const lldb::TypeSummaryImplSP& entry)
2403 CommandObjectTypeSummaryList_LoopCallbackParam* param = (CommandObjectTypeSummaryList_LoopCallbackParam*)pt2self;
2404 return param->self->LoopCallback(type.AsCString(), entry, param->regex, param->result);
2408 CommandObjectTypeRXSummaryList_LoopCallback (
2410 lldb::RegularExpressionSP regex,
2411 const lldb::TypeSummaryImplSP& entry)
2413 CommandObjectTypeSummaryList_LoopCallbackParam* param = (CommandObjectTypeSummaryList_LoopCallbackParam*)pt2self;
2414 return param->self->LoopCallback(regex->GetText(), entry, param->regex, param->result);
2418 CommandObjectTypeSummaryList::CommandOptions::g_option_table[] =
2420 { LLDB_OPT_SET_ALL, false, "category-regex", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Only show categories matching this filter."},
2421 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
2424 //-------------------------------------------------------------------------
2425 // CommandObjectTypeCategoryEnable
2426 //-------------------------------------------------------------------------
2428 class CommandObjectTypeCategoryEnable : public CommandObjectParsed
2431 CommandObjectTypeCategoryEnable (CommandInterpreter &interpreter) :
2432 CommandObjectParsed (interpreter,
2433 "type category enable",
2434 "Enable a category as a source of formatters.",
2437 CommandArgumentEntry type_arg;
2438 CommandArgumentData type_style_arg;
2440 type_style_arg.arg_type = eArgTypeName;
2441 type_style_arg.arg_repetition = eArgRepeatPlus;
2443 type_arg.push_back (type_style_arg);
2445 m_arguments.push_back (type_arg);
2449 ~CommandObjectTypeCategoryEnable ()
2455 DoExecute (Args& command, CommandReturnObject &result)
2457 const size_t argc = command.GetArgumentCount();
2461 result.AppendErrorWithFormat ("%s takes 1 or more args.\n", m_cmd_name.c_str());
2462 result.SetStatus(eReturnStatusFailed);
2466 if (argc == 1 && strcmp(command.GetArgumentAtIndex(0),"*") == 0)
2468 // we want to make sure to enable "system" last and "default" first
2469 DataVisualization::Categories::Enable(ConstString("default"), TypeCategoryMap::First);
2470 uint32_t num_categories = DataVisualization::Categories::GetCount();
2471 for (uint32_t i = 0; i < num_categories; i++)
2473 lldb::TypeCategoryImplSP category_sp = DataVisualization::Categories::GetCategoryAtIndex(i);
2476 if ( ::strcmp(category_sp->GetName(), "system") == 0 ||
2477 ::strcmp(category_sp->GetName(), "default") == 0 )
2480 DataVisualization::Categories::Enable(category_sp, TypeCategoryMap::Default);
2483 DataVisualization::Categories::Enable(ConstString("system"), TypeCategoryMap::Last);
2487 for (int i = argc - 1; i >= 0; i--)
2489 const char* typeA = command.GetArgumentAtIndex(i);
2490 ConstString typeCS(typeA);
2494 result.AppendError("empty category name not allowed");
2495 result.SetStatus(eReturnStatusFailed);
2498 DataVisualization::Categories::Enable(typeCS);
2499 lldb::TypeCategoryImplSP cate;
2500 if (DataVisualization::Categories::GetCategory(typeCS, cate) && cate.get())
2502 if (cate->GetCount() == 0)
2504 result.AppendWarning("empty category enabled (typo?)");
2510 result.SetStatus(eReturnStatusSuccessFinishResult);
2511 return result.Succeeded();
2516 //-------------------------------------------------------------------------
2517 // CommandObjectTypeCategoryDelete
2518 //-------------------------------------------------------------------------
2520 class CommandObjectTypeCategoryDelete : public CommandObjectParsed
2523 CommandObjectTypeCategoryDelete (CommandInterpreter &interpreter) :
2524 CommandObjectParsed (interpreter,
2525 "type category delete",
2526 "Delete a category and all associated formatters.",
2529 CommandArgumentEntry type_arg;
2530 CommandArgumentData type_style_arg;
2532 type_style_arg.arg_type = eArgTypeName;
2533 type_style_arg.arg_repetition = eArgRepeatPlus;
2535 type_arg.push_back (type_style_arg);
2537 m_arguments.push_back (type_arg);
2541 ~CommandObjectTypeCategoryDelete ()
2547 DoExecute (Args& command, CommandReturnObject &result)
2549 const size_t argc = command.GetArgumentCount();
2553 result.AppendErrorWithFormat ("%s takes 1 or more arg.\n", m_cmd_name.c_str());
2554 result.SetStatus(eReturnStatusFailed);
2558 bool success = true;
2560 // the order is not relevant here
2561 for (int i = argc - 1; i >= 0; i--)
2563 const char* typeA = command.GetArgumentAtIndex(i);
2564 ConstString typeCS(typeA);
2568 result.AppendError("empty category name not allowed");
2569 result.SetStatus(eReturnStatusFailed);
2572 if (!DataVisualization::Categories::Delete(typeCS))
2573 success = false; // keep deleting even if we hit an error
2577 result.SetStatus(eReturnStatusSuccessFinishResult);
2578 return result.Succeeded();
2582 result.AppendError("cannot delete one or more categories\n");
2583 result.SetStatus(eReturnStatusFailed);
2589 //-------------------------------------------------------------------------
2590 // CommandObjectTypeCategoryDisable
2591 //-------------------------------------------------------------------------
2593 class CommandObjectTypeCategoryDisable : public CommandObjectParsed
2596 CommandObjectTypeCategoryDisable (CommandInterpreter &interpreter) :
2597 CommandObjectParsed (interpreter,
2598 "type category disable",
2599 "Disable a category as a source of formatters.",
2602 CommandArgumentEntry type_arg;
2603 CommandArgumentData type_style_arg;
2605 type_style_arg.arg_type = eArgTypeName;
2606 type_style_arg.arg_repetition = eArgRepeatPlus;
2608 type_arg.push_back (type_style_arg);
2610 m_arguments.push_back (type_arg);
2614 ~CommandObjectTypeCategoryDisable ()
2620 DoExecute (Args& command, CommandReturnObject &result)
2622 const size_t argc = command.GetArgumentCount();
2626 result.AppendErrorWithFormat ("%s takes 1 or more args.\n", m_cmd_name.c_str());
2627 result.SetStatus(eReturnStatusFailed);
2631 if (argc == 1 && strcmp(command.GetArgumentAtIndex(0),"*") == 0)
2633 uint32_t num_categories = DataVisualization::Categories::GetCount();
2634 for (uint32_t i = 0; i < num_categories; i++)
2636 lldb::TypeCategoryImplSP category_sp = DataVisualization::Categories::GetCategoryAtIndex(i);
2637 // no need to check if the category is enabled - disabling a disabled category has no effect
2639 DataVisualization::Categories::Disable(category_sp);
2644 // the order is not relevant here
2645 for (int i = argc - 1; i >= 0; i--)
2647 const char* typeA = command.GetArgumentAtIndex(i);
2648 ConstString typeCS(typeA);
2652 result.AppendError("empty category name not allowed");
2653 result.SetStatus(eReturnStatusFailed);
2656 DataVisualization::Categories::Disable(typeCS);
2660 result.SetStatus(eReturnStatusSuccessFinishResult);
2661 return result.Succeeded();
2666 //-------------------------------------------------------------------------
2667 // CommandObjectTypeCategoryList
2668 //-------------------------------------------------------------------------
2670 class CommandObjectTypeCategoryList : public CommandObjectParsed
2674 struct CommandObjectTypeCategoryList_CallbackParam
2676 CommandReturnObject* result;
2677 RegularExpression* regex;
2679 CommandObjectTypeCategoryList_CallbackParam(CommandReturnObject* res,
2680 RegularExpression* rex = NULL) :
2689 PerCategoryCallback(void* param_vp,
2690 const lldb::TypeCategoryImplSP& cate)
2692 CommandObjectTypeCategoryList_CallbackParam* param =
2693 (CommandObjectTypeCategoryList_CallbackParam*)param_vp;
2694 CommandReturnObject* result = param->result;
2695 RegularExpression* regex = param->regex;
2697 const char* cate_name = cate->GetName();
2699 if (regex == NULL || strcmp(cate_name, regex->GetText()) == 0 || regex->Execute(cate_name))
2700 result->GetOutputStream().Printf("Category %s is%s enabled\n",
2702 (cate->IsEnabled() ? "" : " not"));
2706 CommandObjectTypeCategoryList (CommandInterpreter &interpreter) :
2707 CommandObjectParsed (interpreter,
2708 "type category list",
2709 "Provide a list of all existing categories.",
2712 CommandArgumentEntry type_arg;
2713 CommandArgumentData type_style_arg;
2715 type_style_arg.arg_type = eArgTypeName;
2716 type_style_arg.arg_repetition = eArgRepeatOptional;
2718 type_arg.push_back (type_style_arg);
2720 m_arguments.push_back (type_arg);
2723 ~CommandObjectTypeCategoryList ()
2729 DoExecute (Args& command, CommandReturnObject &result)
2731 const size_t argc = command.GetArgumentCount();
2732 RegularExpression* regex = NULL;
2737 regex = new RegularExpression(command.GetArgumentAtIndex(0));
2740 result.AppendErrorWithFormat ("%s takes 0 or one arg.\n", m_cmd_name.c_str());
2741 result.SetStatus(eReturnStatusFailed);
2745 CommandObjectTypeCategoryList_CallbackParam param(&result,
2748 DataVisualization::Categories::LoopThrough(PerCategoryCallback, ¶m);
2753 result.SetStatus(eReturnStatusSuccessFinishResult);
2754 return result.Succeeded();
2759 //-------------------------------------------------------------------------
2760 // CommandObjectTypeFilterList
2761 //-------------------------------------------------------------------------
2763 bool CommandObjectTypeFilterList_LoopCallback(void* pt2self, ConstString type, const SyntheticChildren::SharedPointer& entry);
2764 bool CommandObjectTypeFilterRXList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const SyntheticChildren::SharedPointer& entry);
2766 class CommandObjectTypeFilterList;
2768 struct CommandObjectTypeFilterList_LoopCallbackParam {
2769 CommandObjectTypeFilterList* self;
2770 CommandReturnObject* result;
2771 RegularExpression* regex;
2772 RegularExpression* cate_regex;
2773 CommandObjectTypeFilterList_LoopCallbackParam(CommandObjectTypeFilterList* S, CommandReturnObject* R,
2774 RegularExpression* X = NULL,
2775 RegularExpression* CX = NULL) : self(S), result(R), regex(X), cate_regex(CX) {}
2778 class CommandObjectTypeFilterList : public CommandObjectParsed
2781 class CommandOptions : public Options
2785 CommandOptions (CommandInterpreter &interpreter) :
2786 Options (interpreter)
2791 ~CommandOptions (){}
2794 SetOptionValue (uint32_t option_idx, const char *option_arg)
2797 const int short_option = m_getopt_table[option_idx].val;
2799 switch (short_option)
2802 m_category_regex = std::string(option_arg);
2805 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
2813 OptionParsingStarting ()
2815 m_category_regex = "";
2818 const OptionDefinition*
2821 return g_option_table;
2824 // Options table: Required for subclasses of Options.
2826 static OptionDefinition g_option_table[];
2828 // Instance variables to hold the values for command options.
2830 std::string m_category_regex;
2834 CommandOptions m_options;
2843 CommandObjectTypeFilterList (CommandInterpreter &interpreter) :
2844 CommandObjectParsed (interpreter,
2846 "Show a list of current filters.",
2848 m_options(interpreter)
2850 CommandArgumentEntry type_arg;
2851 CommandArgumentData type_style_arg;
2853 type_style_arg.arg_type = eArgTypeName;
2854 type_style_arg.arg_repetition = eArgRepeatOptional;
2856 type_arg.push_back (type_style_arg);
2858 m_arguments.push_back (type_arg);
2861 ~CommandObjectTypeFilterList ()
2867 DoExecute (Args& command, CommandReturnObject &result)
2869 const size_t argc = command.GetArgumentCount();
2871 CommandObjectTypeFilterList_LoopCallbackParam *param;
2872 RegularExpression* cate_regex =
2873 m_options.m_category_regex.empty() ? NULL :
2874 new RegularExpression(m_options.m_category_regex.c_str());
2878 RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
2879 regex->Compile(command.GetArgumentAtIndex(0));
2880 param = new CommandObjectTypeFilterList_LoopCallbackParam(this,&result,regex,cate_regex);
2883 param = new CommandObjectTypeFilterList_LoopCallbackParam(this,&result,NULL,cate_regex);
2885 DataVisualization::Categories::LoopThrough(PerCategoryCallback,param);
2891 result.SetStatus(eReturnStatusSuccessFinishResult);
2892 return result.Succeeded();
2898 PerCategoryCallback(void* param_vp,
2899 const lldb::TypeCategoryImplSP& cate)
2902 const char* cate_name = cate->GetName();
2904 CommandObjectTypeFilterList_LoopCallbackParam* param =
2905 (CommandObjectTypeFilterList_LoopCallbackParam*)param_vp;
2906 CommandReturnObject* result = param->result;
2908 // if the category is disabled or empty and there is no regex, just skip it
2909 if ((cate->IsEnabled() == false || cate->GetCount(eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter) == 0) && param->cate_regex == NULL)
2912 // if we have a regex and this category does not match it, just skip it
2913 if(param->cate_regex != NULL && strcmp(cate_name,param->cate_regex->GetText()) != 0 && param->cate_regex->Execute(cate_name) == false)
2916 result->GetOutputStream().Printf("-----------------------\nCategory: %s (%s)\n-----------------------\n",
2918 (cate->IsEnabled() ? "enabled" : "disabled"));
2920 cate->GetTypeFiltersContainer()->LoopThrough(CommandObjectTypeFilterList_LoopCallback, param_vp);
2922 if (cate->GetRegexTypeFiltersContainer()->GetCount() > 0)
2924 result->GetOutputStream().Printf("Regex-based filters (slower):\n");
2925 cate->GetRegexTypeFiltersContainer()->LoopThrough(CommandObjectTypeFilterRXList_LoopCallback, param_vp);
2932 LoopCallback (const char* type,
2933 const SyntheticChildren::SharedPointer& entry,
2934 RegularExpression* regex,
2935 CommandReturnObject *result)
2937 if (regex == NULL || regex->Execute(type))
2938 result->GetOutputStream().Printf ("%s: %s\n", type, entry->GetDescription().c_str());
2942 friend bool CommandObjectTypeFilterList_LoopCallback(void* pt2self, ConstString type, const SyntheticChildren::SharedPointer& entry);
2943 friend bool CommandObjectTypeFilterRXList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const SyntheticChildren::SharedPointer& entry);
2947 CommandObjectTypeFilterList_LoopCallback (void* pt2self,
2949 const SyntheticChildren::SharedPointer& entry)
2951 CommandObjectTypeFilterList_LoopCallbackParam* param = (CommandObjectTypeFilterList_LoopCallbackParam*)pt2self;
2952 return param->self->LoopCallback(type.AsCString(), entry, param->regex, param->result);
2956 CommandObjectTypeFilterRXList_LoopCallback (void* pt2self,
2957 lldb::RegularExpressionSP regex,
2958 const SyntheticChildren::SharedPointer& entry)
2960 CommandObjectTypeFilterList_LoopCallbackParam* param = (CommandObjectTypeFilterList_LoopCallbackParam*)pt2self;
2961 return param->self->LoopCallback(regex->GetText(), entry, param->regex, param->result);
2966 CommandObjectTypeFilterList::CommandOptions::g_option_table[] =
2968 { LLDB_OPT_SET_ALL, false, "category-regex", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Only show categories matching this filter."},
2969 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
2972 #ifndef LLDB_DISABLE_PYTHON
2974 //-------------------------------------------------------------------------
2975 // CommandObjectTypeSynthList
2976 //-------------------------------------------------------------------------
2978 bool CommandObjectTypeSynthList_LoopCallback(void* pt2self, ConstString type, const SyntheticChildren::SharedPointer& entry);
2979 bool CommandObjectTypeSynthRXList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const SyntheticChildren::SharedPointer& entry);
2981 class CommandObjectTypeSynthList;
2983 struct CommandObjectTypeSynthList_LoopCallbackParam {
2984 CommandObjectTypeSynthList* self;
2985 CommandReturnObject* result;
2986 RegularExpression* regex;
2987 RegularExpression* cate_regex;
2988 CommandObjectTypeSynthList_LoopCallbackParam(CommandObjectTypeSynthList* S, CommandReturnObject* R,
2989 RegularExpression* X = NULL,
2990 RegularExpression* CX = NULL) : self(S), result(R), regex(X), cate_regex(CX) {}
2993 class CommandObjectTypeSynthList : public CommandObjectParsed
2996 class CommandOptions : public Options
3000 CommandOptions (CommandInterpreter &interpreter) :
3001 Options (interpreter)
3006 ~CommandOptions (){}
3009 SetOptionValue (uint32_t option_idx, const char *option_arg)
3012 const int short_option = m_getopt_table[option_idx].val;
3014 switch (short_option)
3017 m_category_regex = std::string(option_arg);
3020 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
3028 OptionParsingStarting ()
3030 m_category_regex = "";
3033 const OptionDefinition*
3036 return g_option_table;
3039 // Options table: Required for subclasses of Options.
3041 static OptionDefinition g_option_table[];
3043 // Instance variables to hold the values for command options.
3045 std::string m_category_regex;
3049 CommandOptions m_options;
3058 CommandObjectTypeSynthList (CommandInterpreter &interpreter) :
3059 CommandObjectParsed (interpreter,
3060 "type synthetic list",
3061 "Show a list of current synthetic providers.",
3063 m_options(interpreter)
3065 CommandArgumentEntry type_arg;
3066 CommandArgumentData type_style_arg;
3068 type_style_arg.arg_type = eArgTypeName;
3069 type_style_arg.arg_repetition = eArgRepeatOptional;
3071 type_arg.push_back (type_style_arg);
3073 m_arguments.push_back (type_arg);
3076 ~CommandObjectTypeSynthList ()
3082 DoExecute (Args& command, CommandReturnObject &result)
3084 const size_t argc = command.GetArgumentCount();
3086 CommandObjectTypeSynthList_LoopCallbackParam *param;
3087 RegularExpression* cate_regex =
3088 m_options.m_category_regex.empty() ? NULL :
3089 new RegularExpression(m_options.m_category_regex.c_str());
3093 RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
3094 regex->Compile(command.GetArgumentAtIndex(0));
3095 param = new CommandObjectTypeSynthList_LoopCallbackParam(this,&result,regex,cate_regex);
3098 param = new CommandObjectTypeSynthList_LoopCallbackParam(this,&result,NULL,cate_regex);
3100 DataVisualization::Categories::LoopThrough(PerCategoryCallback,param);
3106 result.SetStatus(eReturnStatusSuccessFinishResult);
3107 return result.Succeeded();
3113 PerCategoryCallback(void* param_vp,
3114 const lldb::TypeCategoryImplSP& cate)
3117 CommandObjectTypeSynthList_LoopCallbackParam* param =
3118 (CommandObjectTypeSynthList_LoopCallbackParam*)param_vp;
3119 CommandReturnObject* result = param->result;
3121 const char* cate_name = cate->GetName();
3123 // if the category is disabled or empty and there is no regex, just skip it
3124 if ((cate->IsEnabled() == false || cate->GetCount(eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth) == 0) && param->cate_regex == NULL)
3127 // if we have a regex and this category does not match it, just skip it
3128 if(param->cate_regex != NULL && strcmp(cate_name,param->cate_regex->GetText()) != 0 && param->cate_regex->Execute(cate_name) == false)
3131 result->GetOutputStream().Printf("-----------------------\nCategory: %s (%s)\n-----------------------\n",
3133 (cate->IsEnabled() ? "enabled" : "disabled"));
3135 cate->GetTypeSyntheticsContainer()->LoopThrough(CommandObjectTypeSynthList_LoopCallback, param_vp);
3137 if (cate->GetRegexTypeSyntheticsContainer()->GetCount() > 0)
3139 result->GetOutputStream().Printf("Regex-based synthetic providers (slower):\n");
3140 cate->GetRegexTypeSyntheticsContainer()->LoopThrough(CommandObjectTypeSynthRXList_LoopCallback, param_vp);
3147 LoopCallback (const char* type,
3148 const SyntheticChildren::SharedPointer& entry,
3149 RegularExpression* regex,
3150 CommandReturnObject *result)
3152 if (regex == NULL || regex->Execute(type))
3153 result->GetOutputStream().Printf ("%s: %s\n", type, entry->GetDescription().c_str());
3157 friend bool CommandObjectTypeSynthList_LoopCallback(void* pt2self, ConstString type, const SyntheticChildren::SharedPointer& entry);
3158 friend bool CommandObjectTypeSynthRXList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const SyntheticChildren::SharedPointer& entry);
3162 CommandObjectTypeSynthList_LoopCallback (void* pt2self,
3164 const SyntheticChildren::SharedPointer& entry)
3166 CommandObjectTypeSynthList_LoopCallbackParam* param = (CommandObjectTypeSynthList_LoopCallbackParam*)pt2self;
3167 return param->self->LoopCallback(type.AsCString(), entry, param->regex, param->result);
3171 CommandObjectTypeSynthRXList_LoopCallback (void* pt2self,
3172 lldb::RegularExpressionSP regex,
3173 const SyntheticChildren::SharedPointer& entry)
3175 CommandObjectTypeSynthList_LoopCallbackParam* param = (CommandObjectTypeSynthList_LoopCallbackParam*)pt2self;
3176 return param->self->LoopCallback(regex->GetText(), entry, param->regex, param->result);
3181 CommandObjectTypeSynthList::CommandOptions::g_option_table[] =
3183 { LLDB_OPT_SET_ALL, false, "category-regex", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Only show categories matching this filter."},
3184 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
3187 #endif // #ifndef LLDB_DISABLE_PYTHON
3188 //-------------------------------------------------------------------------
3189 // CommandObjectTypeFilterDelete
3190 //-------------------------------------------------------------------------
3192 class CommandObjectTypeFilterDelete : public CommandObjectParsed
3195 class CommandOptions : public Options
3199 CommandOptions (CommandInterpreter &interpreter) :
3200 Options (interpreter)
3205 ~CommandOptions (){}
3208 SetOptionValue (uint32_t option_idx, const char *option_arg)
3211 const int short_option = m_getopt_table[option_idx].val;
3213 switch (short_option)
3216 m_delete_all = true;
3219 m_category = std::string(option_arg);
3222 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
3230 OptionParsingStarting ()
3232 m_delete_all = false;
3233 m_category = "default";
3236 const OptionDefinition*
3239 return g_option_table;
3242 // Options table: Required for subclasses of Options.
3244 static OptionDefinition g_option_table[];
3246 // Instance variables to hold the values for command options.
3249 std::string m_category;
3253 CommandOptions m_options;
3262 PerCategoryCallback(void* param,
3263 const lldb::TypeCategoryImplSP& cate)
3265 ConstString *name = (ConstString*)param;
3266 return cate->Delete(*name, eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter);
3270 CommandObjectTypeFilterDelete (CommandInterpreter &interpreter) :
3271 CommandObjectParsed (interpreter,
3272 "type filter delete",
3273 "Delete an existing filter for a type.",
3275 m_options(interpreter)
3277 CommandArgumentEntry type_arg;
3278 CommandArgumentData type_style_arg;
3280 type_style_arg.arg_type = eArgTypeName;
3281 type_style_arg.arg_repetition = eArgRepeatPlain;
3283 type_arg.push_back (type_style_arg);
3285 m_arguments.push_back (type_arg);
3289 ~CommandObjectTypeFilterDelete ()
3295 DoExecute (Args& command, CommandReturnObject &result)
3297 const size_t argc = command.GetArgumentCount();
3301 result.AppendErrorWithFormat ("%s takes 1 arg.\n", m_cmd_name.c_str());
3302 result.SetStatus(eReturnStatusFailed);
3306 const char* typeA = command.GetArgumentAtIndex(0);
3307 ConstString typeCS(typeA);
3311 result.AppendError("empty typenames not allowed");
3312 result.SetStatus(eReturnStatusFailed);
3316 if (m_options.m_delete_all)
3318 DataVisualization::Categories::LoopThrough(PerCategoryCallback, (void*)&typeCS);
3319 result.SetStatus(eReturnStatusSuccessFinishNoResult);
3320 return result.Succeeded();
3323 lldb::TypeCategoryImplSP category;
3324 DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
3326 bool delete_category = category->GetTypeFiltersContainer()->Delete(typeCS);
3327 delete_category = category->GetRegexTypeFiltersContainer()->Delete(typeCS) || delete_category;
3329 if (delete_category)
3331 result.SetStatus(eReturnStatusSuccessFinishNoResult);
3332 return result.Succeeded();
3336 result.AppendErrorWithFormat ("no custom synthetic provider for %s.\n", typeA);
3337 result.SetStatus(eReturnStatusFailed);
3345 CommandObjectTypeFilterDelete::CommandOptions::g_option_table[] =
3347 { LLDB_OPT_SET_1, false, "all", 'a', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Delete from every category."},
3348 { LLDB_OPT_SET_2, false, "category", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Delete from given category."},
3349 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
3352 #ifndef LLDB_DISABLE_PYTHON
3354 //-------------------------------------------------------------------------
3355 // CommandObjectTypeSynthDelete
3356 //-------------------------------------------------------------------------
3358 class CommandObjectTypeSynthDelete : public CommandObjectParsed
3361 class CommandOptions : public Options
3365 CommandOptions (CommandInterpreter &interpreter) :
3366 Options (interpreter)
3371 ~CommandOptions (){}
3374 SetOptionValue (uint32_t option_idx, const char *option_arg)
3377 const int short_option = m_getopt_table[option_idx].val;
3379 switch (short_option)
3382 m_delete_all = true;
3385 m_category = std::string(option_arg);
3388 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
3396 OptionParsingStarting ()
3398 m_delete_all = false;
3399 m_category = "default";
3402 const OptionDefinition*
3405 return g_option_table;
3408 // Options table: Required for subclasses of Options.
3410 static OptionDefinition g_option_table[];
3412 // Instance variables to hold the values for command options.
3415 std::string m_category;
3419 CommandOptions m_options;
3428 PerCategoryCallback(void* param,
3429 const lldb::TypeCategoryImplSP& cate)
3431 ConstString* name = (ConstString*)param;
3432 return cate->Delete(*name, eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth);
3436 CommandObjectTypeSynthDelete (CommandInterpreter &interpreter) :
3437 CommandObjectParsed (interpreter,
3438 "type synthetic delete",
3439 "Delete an existing synthetic provider for a type.",
3441 m_options(interpreter)
3443 CommandArgumentEntry type_arg;
3444 CommandArgumentData type_style_arg;
3446 type_style_arg.arg_type = eArgTypeName;
3447 type_style_arg.arg_repetition = eArgRepeatPlain;
3449 type_arg.push_back (type_style_arg);
3451 m_arguments.push_back (type_arg);
3455 ~CommandObjectTypeSynthDelete ()
3461 DoExecute (Args& command, CommandReturnObject &result)
3463 const size_t argc = command.GetArgumentCount();
3467 result.AppendErrorWithFormat ("%s takes 1 arg.\n", m_cmd_name.c_str());
3468 result.SetStatus(eReturnStatusFailed);
3472 const char* typeA = command.GetArgumentAtIndex(0);
3473 ConstString typeCS(typeA);
3477 result.AppendError("empty typenames not allowed");
3478 result.SetStatus(eReturnStatusFailed);
3482 if (m_options.m_delete_all)
3484 DataVisualization::Categories::LoopThrough(PerCategoryCallback, (void*)&typeCS);
3485 result.SetStatus(eReturnStatusSuccessFinishNoResult);
3486 return result.Succeeded();
3489 lldb::TypeCategoryImplSP category;
3490 DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
3492 bool delete_category = category->GetTypeSyntheticsContainer()->Delete(typeCS);
3493 delete_category = category->GetRegexTypeSyntheticsContainer()->Delete(typeCS) || delete_category;
3495 if (delete_category)
3497 result.SetStatus(eReturnStatusSuccessFinishNoResult);
3498 return result.Succeeded();
3502 result.AppendErrorWithFormat ("no custom synthetic provider for %s.\n", typeA);
3503 result.SetStatus(eReturnStatusFailed);
3511 CommandObjectTypeSynthDelete::CommandOptions::g_option_table[] =
3513 { LLDB_OPT_SET_1, false, "all", 'a', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Delete from every category."},
3514 { LLDB_OPT_SET_2, false, "category", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Delete from given category."},
3515 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
3518 #endif // #ifndef LLDB_DISABLE_PYTHON
3520 //-------------------------------------------------------------------------
3521 // CommandObjectTypeFilterClear
3522 //-------------------------------------------------------------------------
3524 class CommandObjectTypeFilterClear : public CommandObjectParsed
3528 class CommandOptions : public Options
3532 CommandOptions (CommandInterpreter &interpreter) :
3533 Options (interpreter)
3538 ~CommandOptions (){}
3541 SetOptionValue (uint32_t option_idx, const char *option_arg)
3544 const int short_option = m_getopt_table[option_idx].val;
3546 switch (short_option)
3549 m_delete_all = true;
3552 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
3560 OptionParsingStarting ()
3562 m_delete_all = false;
3565 const OptionDefinition*
3568 return g_option_table;
3571 // Options table: Required for subclasses of Options.
3573 static OptionDefinition g_option_table[];
3575 // Instance variables to hold the values for command options.
3578 bool m_delete_named;
3581 CommandOptions m_options;
3590 PerCategoryCallback(void* param,
3591 const lldb::TypeCategoryImplSP& cate)
3593 cate->Clear(eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter);
3599 CommandObjectTypeFilterClear (CommandInterpreter &interpreter) :
3600 CommandObjectParsed (interpreter,
3601 "type filter clear",
3602 "Delete all existing filters.",
3604 m_options(interpreter)
3608 ~CommandObjectTypeFilterClear ()
3614 DoExecute (Args& command, CommandReturnObject &result)
3617 if (m_options.m_delete_all)
3618 DataVisualization::Categories::LoopThrough(PerCategoryCallback, NULL);
3622 lldb::TypeCategoryImplSP category;
3623 if (command.GetArgumentCount() > 0)
3625 const char* cat_name = command.GetArgumentAtIndex(0);
3626 ConstString cat_nameCS(cat_name);
3627 DataVisualization::Categories::GetCategory(cat_nameCS, category);
3630 DataVisualization::Categories::GetCategory(ConstString(NULL), category);
3631 category->GetTypeFiltersContainer()->Clear();
3632 category->GetRegexTypeFiltersContainer()->Clear();
3635 result.SetStatus(eReturnStatusSuccessFinishResult);
3636 return result.Succeeded();
3642 CommandObjectTypeFilterClear::CommandOptions::g_option_table[] =
3644 { LLDB_OPT_SET_ALL, false, "all", 'a', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Clear every category."},
3645 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
3648 #ifndef LLDB_DISABLE_PYTHON
3649 //-------------------------------------------------------------------------
3650 // CommandObjectTypeSynthClear
3651 //-------------------------------------------------------------------------
3653 class CommandObjectTypeSynthClear : public CommandObjectParsed
3657 class CommandOptions : public Options
3661 CommandOptions (CommandInterpreter &interpreter) :
3662 Options (interpreter)
3667 ~CommandOptions (){}
3670 SetOptionValue (uint32_t option_idx, const char *option_arg)
3673 const int short_option = m_getopt_table[option_idx].val;
3675 switch (short_option)
3678 m_delete_all = true;
3681 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
3689 OptionParsingStarting ()
3691 m_delete_all = false;
3694 const OptionDefinition*
3697 return g_option_table;
3700 // Options table: Required for subclasses of Options.
3702 static OptionDefinition g_option_table[];
3704 // Instance variables to hold the values for command options.
3707 bool m_delete_named;
3710 CommandOptions m_options;
3719 PerCategoryCallback(void* param,
3720 const lldb::TypeCategoryImplSP& cate)
3722 cate->Clear(eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth);
3728 CommandObjectTypeSynthClear (CommandInterpreter &interpreter) :
3729 CommandObjectParsed (interpreter,
3730 "type synthetic clear",
3731 "Delete all existing synthetic providers.",
3733 m_options(interpreter)
3737 ~CommandObjectTypeSynthClear ()
3743 DoExecute (Args& command, CommandReturnObject &result)
3746 if (m_options.m_delete_all)
3747 DataVisualization::Categories::LoopThrough(PerCategoryCallback, NULL);
3751 lldb::TypeCategoryImplSP category;
3752 if (command.GetArgumentCount() > 0)
3754 const char* cat_name = command.GetArgumentAtIndex(0);
3755 ConstString cat_nameCS(cat_name);
3756 DataVisualization::Categories::GetCategory(cat_nameCS, category);
3759 DataVisualization::Categories::GetCategory(ConstString(NULL), category);
3760 category->GetTypeSyntheticsContainer()->Clear();
3761 category->GetRegexTypeSyntheticsContainer()->Clear();
3764 result.SetStatus(eReturnStatusSuccessFinishResult);
3765 return result.Succeeded();
3771 CommandObjectTypeSynthClear::CommandOptions::g_option_table[] =
3773 { LLDB_OPT_SET_ALL, false, "all", 'a', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Clear every category."},
3774 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
3779 CommandObjectTypeSynthAdd::Execute_HandwritePython (Args& command, CommandReturnObject &result)
3781 SynthAddOptions *options = new SynthAddOptions ( m_options.m_skip_pointers,
3782 m_options.m_skip_references,
3783 m_options.m_cascade,
3785 m_options.m_category);
3787 const size_t argc = command.GetArgumentCount();
3789 for (size_t i = 0; i < argc; i++)
3791 const char* typeA = command.GetArgumentAtIndex(i);
3792 if (typeA && *typeA)
3793 options->m_target_types << typeA;
3796 result.AppendError("empty typenames not allowed");
3797 result.SetStatus(eReturnStatusFailed);
3802 m_interpreter.GetPythonCommandsFromIOHandler (" ", // Prompt
3803 *this, // IOHandlerDelegate
3804 true, // Run IOHandler in async mode
3805 options); // Baton for the "io_handler" that will be passed back into our IOHandlerDelegate functions
3806 result.SetStatus(eReturnStatusSuccessFinishNoResult);
3807 return result.Succeeded();
3811 CommandObjectTypeSynthAdd::Execute_PythonClass (Args& command, CommandReturnObject &result)
3813 const size_t argc = command.GetArgumentCount();
3817 result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
3818 result.SetStatus(eReturnStatusFailed);
3822 if (m_options.m_class_name.empty() && !m_options.m_input_python)
3824 result.AppendErrorWithFormat ("%s needs either a Python class name or -P to directly input Python code.\n", m_cmd_name.c_str());
3825 result.SetStatus(eReturnStatusFailed);
3829 SyntheticChildrenSP entry;
3831 ScriptedSyntheticChildren* impl = new ScriptedSyntheticChildren(SyntheticChildren::Flags().
3832 SetCascades(m_options.m_cascade).
3833 SetSkipPointers(m_options.m_skip_pointers).
3834 SetSkipReferences(m_options.m_skip_references),
3835 m_options.m_class_name.c_str());
3839 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
3841 if (interpreter && interpreter->CheckObjectExists(impl->GetPythonClassName()) == false)
3842 result.AppendWarning("The provided class does not exist - please define it before attempting to use this synthetic provider");
3844 // now I have a valid provider, let's add it to every type
3846 lldb::TypeCategoryImplSP category;
3847 DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
3851 for (size_t i = 0; i < argc; i++)
3853 const char* typeA = command.GetArgumentAtIndex(i);
3854 ConstString typeCS(typeA);
3857 if (!AddSynth(typeCS,
3859 m_options.m_regex ? eRegexSynth : eRegularSynth,
3860 m_options.m_category,
3863 result.AppendError(error.AsCString());
3864 result.SetStatus(eReturnStatusFailed);
3870 result.AppendError("empty typenames not allowed");
3871 result.SetStatus(eReturnStatusFailed);
3876 result.SetStatus(eReturnStatusSuccessFinishNoResult);
3877 return result.Succeeded();
3880 CommandObjectTypeSynthAdd::CommandObjectTypeSynthAdd (CommandInterpreter &interpreter) :
3881 CommandObjectParsed (interpreter,
3882 "type synthetic add",
3883 "Add a new synthetic provider for a type.",
3885 IOHandlerDelegateMultiline ("DONE"),
3886 m_options (interpreter)
3888 CommandArgumentEntry type_arg;
3889 CommandArgumentData type_style_arg;
3891 type_style_arg.arg_type = eArgTypeName;
3892 type_style_arg.arg_repetition = eArgRepeatPlus;
3894 type_arg.push_back (type_style_arg);
3896 m_arguments.push_back (type_arg);
3901 CommandObjectTypeSynthAdd::AddSynth(ConstString type_name,
3902 SyntheticChildrenSP entry,
3903 SynthFormatType type,
3904 std::string category_name,
3907 lldb::TypeCategoryImplSP category;
3908 DataVisualization::Categories::GetCategory(ConstString(category_name.c_str()), category);
3910 if (type == eRegularSynth)
3912 if (FixArrayTypeNameWithRegex (type_name))
3916 if (category->AnyMatches(type_name,
3917 eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter,
3921 error->SetErrorStringWithFormat("cannot add synthetic for type %s when filter is defined in same category!", type_name.AsCString());
3925 if (type == eRegexSynth)
3927 RegularExpressionSP typeRX(new RegularExpression());
3928 if (!typeRX->Compile(type_name.GetCString()))
3931 error->SetErrorString("regex format error (maybe this is not really a regex?)");
3935 category->GetRegexTypeSyntheticsContainer()->Delete(type_name);
3936 category->GetRegexTypeSyntheticsContainer()->Add(typeRX, entry);
3942 category->GetTypeSyntheticsContainer()->Add(type_name, entry);
3948 CommandObjectTypeSynthAdd::CommandOptions::g_option_table[] =
3950 { LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "If true, cascade through typedef chains."},
3951 { LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."},
3952 { LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Don't use this format for references-to-tNULL, ype objects."},
3953 { LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Add this to the given category instead of the default one."},
3954 { LLDB_OPT_SET_2, false, "python-class", 'l', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePythonClass, "Use this Python class to produce synthetic children."},
3955 { LLDB_OPT_SET_3, false, "input-python", 'P', OptionParser::eNoArgument,NULL, NULL, 0, eArgTypeNone, "Type Python code to generate a class that NULL, provides synthetic children."},
3956 { LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Type names are actually regular expressions."},
3957 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
3960 #endif // #ifndef LLDB_DISABLE_PYTHON
3962 class CommandObjectTypeFilterAdd : public CommandObjectParsed
3967 class CommandOptions : public Options
3969 typedef std::vector<std::string> option_vector;
3972 CommandOptions (CommandInterpreter &interpreter) :
3973 Options (interpreter)
3978 ~CommandOptions (){}
3981 SetOptionValue (uint32_t option_idx, const char *option_arg)
3984 const int short_option = m_getopt_table[option_idx].val;
3987 switch (short_option)
3990 m_cascade = Args::StringToBoolean(option_arg, true, &success);
3992 error.SetErrorStringWithFormat("invalid value for cascade: %s", option_arg);
3995 m_expr_paths.push_back(option_arg);
3996 has_child_list = true;
3999 m_skip_pointers = true;
4002 m_skip_references = true;
4005 m_category = std::string(option_arg);
4011 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
4019 OptionParsingStarting ()
4022 m_skip_pointers = false;
4023 m_skip_references = false;
4024 m_category = "default";
4025 m_expr_paths.clear();
4026 has_child_list = false;
4030 const OptionDefinition*
4033 return g_option_table;
4036 // Options table: Required for subclasses of Options.
4038 static OptionDefinition g_option_table[];
4040 // Instance variables to hold the values for command options.
4043 bool m_skip_references;
4044 bool m_skip_pointers;
4045 bool m_input_python;
4046 option_vector m_expr_paths;
4047 std::string m_category;
4049 bool has_child_list;
4053 typedef option_vector::iterator ExpressionPathsIterator;
4056 CommandOptions m_options;
4064 enum FilterFormatType
4071 AddFilter(ConstString type_name,
4072 SyntheticChildrenSP entry,
4073 FilterFormatType type,
4074 std::string category_name,
4077 lldb::TypeCategoryImplSP category;
4078 DataVisualization::Categories::GetCategory(ConstString(category_name.c_str()), category);
4080 if (type == eRegularFilter)
4082 if (FixArrayTypeNameWithRegex (type_name))
4083 type = eRegexFilter;
4086 if (category->AnyMatches(type_name,
4087 eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth,
4091 error->SetErrorStringWithFormat("cannot add filter for type %s when synthetic is defined in same category!", type_name.AsCString());
4095 if (type == eRegexFilter)
4097 RegularExpressionSP typeRX(new RegularExpression());
4098 if (!typeRX->Compile(type_name.GetCString()))
4101 error->SetErrorString("regex format error (maybe this is not really a regex?)");
4105 category->GetRegexTypeFiltersContainer()->Delete(type_name);
4106 category->GetRegexTypeFiltersContainer()->Add(typeRX, entry);
4112 category->GetTypeFiltersContainer()->Add(type_name, entry);
4120 CommandObjectTypeFilterAdd (CommandInterpreter &interpreter) :
4121 CommandObjectParsed (interpreter,
4123 "Add a new filter for a type.",
4125 m_options (interpreter)
4127 CommandArgumentEntry type_arg;
4128 CommandArgumentData type_style_arg;
4130 type_style_arg.arg_type = eArgTypeName;
4131 type_style_arg.arg_repetition = eArgRepeatPlus;
4133 type_arg.push_back (type_style_arg);
4135 m_arguments.push_back (type_arg);
4138 "Some examples of using this command.\n"
4139 "We use as reference the following snippet of code:\n"
4153 "type filter add --child a --child g Foo\n"
4154 "frame variable a_foo\n"
4155 "will produce an output where only a and g are displayed\n"
4156 "Other children of a_foo (b,c,d,e,f,h and i) are available by asking for them, as in:\n"
4157 "frame variable a_foo.b a_foo.c ... a_foo.i\n"
4159 "Use option --raw to frame variable prevails on the filter\n"
4160 "frame variable a_foo --raw\n"
4161 "shows all the children of a_foo (a thru i) as if no filter was defined\n"
4165 ~CommandObjectTypeFilterAdd ()
4171 DoExecute (Args& command, CommandReturnObject &result)
4173 const size_t argc = command.GetArgumentCount();
4177 result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
4178 result.SetStatus(eReturnStatusFailed);
4182 if (m_options.m_expr_paths.size() == 0)
4184 result.AppendErrorWithFormat ("%s needs one or more children.\n", m_cmd_name.c_str());
4185 result.SetStatus(eReturnStatusFailed);
4189 SyntheticChildrenSP entry;
4191 TypeFilterImpl* impl = new TypeFilterImpl(SyntheticChildren::Flags().SetCascades(m_options.m_cascade).
4192 SetSkipPointers(m_options.m_skip_pointers).
4193 SetSkipReferences(m_options.m_skip_references));
4197 // go through the expression paths
4198 CommandOptions::ExpressionPathsIterator begin, end = m_options.m_expr_paths.end();
4200 for (begin = m_options.m_expr_paths.begin(); begin != end; begin++)
4201 impl->AddExpressionPath(*begin);
4204 // now I have a valid provider, let's add it to every type
4206 lldb::TypeCategoryImplSP category;
4207 DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
4211 WarnOnPotentialUnquotedUnsignedType(command, result);
4213 for (size_t i = 0; i < argc; i++)
4215 const char* typeA = command.GetArgumentAtIndex(i);
4216 ConstString typeCS(typeA);
4219 if (!AddFilter(typeCS,
4221 m_options.m_regex ? eRegexFilter : eRegularFilter,
4222 m_options.m_category,
4225 result.AppendError(error.AsCString());
4226 result.SetStatus(eReturnStatusFailed);
4232 result.AppendError("empty typenames not allowed");
4233 result.SetStatus(eReturnStatusFailed);
4238 result.SetStatus(eReturnStatusSuccessFinishNoResult);
4239 return result.Succeeded();
4245 CommandObjectTypeFilterAdd::CommandOptions::g_option_table[] =
4247 { LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "If true, cascade through typedef chains."},
4248 { LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."},
4249 { LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Don't use this format for references-to-type objects."},
4250 { LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Add this to the given category instead of the default one."},
4251 { LLDB_OPT_SET_ALL, false, "child", 'c', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeExpressionPath, "Include this expression path in the synthetic view."},
4252 { LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Type names are actually regular expressions."},
4253 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
4256 class CommandObjectTypeFormat : public CommandObjectMultiword
4259 CommandObjectTypeFormat (CommandInterpreter &interpreter) :
4260 CommandObjectMultiword (interpreter,
4262 "A set of commands for editing variable value display options",
4263 "type format [<sub-command-options>] ")
4265 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTypeFormatAdd (interpreter)));
4266 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTypeFormatClear (interpreter)));
4267 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeFormatDelete (interpreter)));
4268 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeFormatList (interpreter)));
4272 ~CommandObjectTypeFormat ()
4277 #ifndef LLDB_DISABLE_PYTHON
4279 class CommandObjectTypeSynth : public CommandObjectMultiword
4282 CommandObjectTypeSynth (CommandInterpreter &interpreter) :
4283 CommandObjectMultiword (interpreter,
4285 "A set of commands for operating on synthetic type representations",
4286 "type synthetic [<sub-command-options>] ")
4288 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTypeSynthAdd (interpreter)));
4289 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTypeSynthClear (interpreter)));
4290 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeSynthDelete (interpreter)));
4291 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeSynthList (interpreter)));
4295 ~CommandObjectTypeSynth ()
4300 #endif // #ifndef LLDB_DISABLE_PYTHON
4302 class CommandObjectTypeFilter : public CommandObjectMultiword
4305 CommandObjectTypeFilter (CommandInterpreter &interpreter) :
4306 CommandObjectMultiword (interpreter,
4308 "A set of commands for operating on type filters",
4309 "type synthetic [<sub-command-options>] ")
4311 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTypeFilterAdd (interpreter)));
4312 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTypeFilterClear (interpreter)));
4313 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeFilterDelete (interpreter)));
4314 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeFilterList (interpreter)));
4318 ~CommandObjectTypeFilter ()
4323 class CommandObjectTypeCategory : public CommandObjectMultiword
4326 CommandObjectTypeCategory (CommandInterpreter &interpreter) :
4327 CommandObjectMultiword (interpreter,
4329 "A set of commands for operating on categories",
4330 "type category [<sub-command-options>] ")
4332 LoadSubCommand ("enable", CommandObjectSP (new CommandObjectTypeCategoryEnable (interpreter)));
4333 LoadSubCommand ("disable", CommandObjectSP (new CommandObjectTypeCategoryDisable (interpreter)));
4334 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeCategoryDelete (interpreter)));
4335 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeCategoryList (interpreter)));
4339 ~CommandObjectTypeCategory ()
4344 class CommandObjectTypeSummary : public CommandObjectMultiword
4347 CommandObjectTypeSummary (CommandInterpreter &interpreter) :
4348 CommandObjectMultiword (interpreter,
4350 "A set of commands for editing variable summary display options",
4351 "type summary [<sub-command-options>] ")
4353 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTypeSummaryAdd (interpreter)));
4354 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTypeSummaryClear (interpreter)));
4355 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeSummaryDelete (interpreter)));
4356 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeSummaryList (interpreter)));
4360 ~CommandObjectTypeSummary ()
4365 //-------------------------------------------------------------------------
4366 // CommandObjectType
4367 //-------------------------------------------------------------------------
4369 CommandObjectType::CommandObjectType (CommandInterpreter &interpreter) :
4370 CommandObjectMultiword (interpreter,
4372 "A set of commands for operating on the type system",
4373 "type [<sub-command-options>]")
4375 LoadSubCommand ("category", CommandObjectSP (new CommandObjectTypeCategory (interpreter)));
4376 LoadSubCommand ("filter", CommandObjectSP (new CommandObjectTypeFilter (interpreter)));
4377 LoadSubCommand ("format", CommandObjectSP (new CommandObjectTypeFormat (interpreter)));
4378 LoadSubCommand ("summary", CommandObjectSP (new CommandObjectTypeSummary (interpreter)));
4379 #ifndef LLDB_DISABLE_PYTHON
4380 LoadSubCommand ("synthetic", CommandObjectSP (new CommandObjectTypeSynth (interpreter)));
4385 CommandObjectType::~CommandObjectType ()