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 "lldb/Core/ConstString.h"
21 #include "lldb/Core/Debugger.h"
22 #include "lldb/Core/IOHandler.h"
23 #include "lldb/Core/RegularExpression.h"
24 #include "lldb/Core/State.h"
25 #include "lldb/Core/StringList.h"
26 #include "lldb/DataFormatters/DataVisualization.h"
27 #include "lldb/Interpreter/CommandInterpreter.h"
28 #include "lldb/Interpreter/CommandObject.h"
29 #include "lldb/Interpreter/CommandReturnObject.h"
30 #include "lldb/Interpreter/Options.h"
31 #include "lldb/Interpreter/OptionGroupFormat.h"
34 using namespace lldb_private;
37 class ScriptAddOptions
42 TypeSummaryImpl::Flags m_flags;
44 StringList m_target_types;
50 std::string m_category;
52 ScriptAddOptions(const TypeSummaryImpl::Flags& flags,
54 const ConstString& name,
63 typedef std::shared_ptr<ScriptAddOptions> SharedPointer;
73 bool m_skip_references;
76 StringList m_target_types;
78 std::string m_category;
80 SynthAddOptions(bool sptr,
85 m_skip_pointers(sptr),
86 m_skip_references(sref),
94 typedef std::shared_ptr<SynthAddOptions> SharedPointer;
99 WarnOnPotentialUnquotedUnsignedType (Args& command, CommandReturnObject &result)
101 for (int idx = 0; idx < command.GetArgumentCount(); idx++)
103 const char* arg = command.GetArgumentAtIndex(idx);
104 if (idx+1 < command.GetArgumentCount())
106 if (arg && 0 == strcmp(arg,"unsigned"))
108 const char* next = command.GetArgumentAtIndex(idx+1);
110 (0 == strcmp(next, "int") ||
111 0 == strcmp(next, "short") ||
112 0 == strcmp(next, "char") ||
113 0 == strcmp(next, "long")))
115 result.AppendWarningWithFormat("%s %s being treated as two types. if you meant the combined type name use quotes, as in \"%s %s\"\n",
125 class CommandObjectTypeSummaryAdd :
126 public CommandObjectParsed,
127 public IOHandlerDelegateMultiline
132 class CommandOptions : public Options
136 CommandOptions (CommandInterpreter &interpreter) :
137 Options (interpreter)
145 SetOptionValue (uint32_t option_idx, const char *option_arg);
148 OptionParsingStarting ();
150 const OptionDefinition*
153 return g_option_table;
156 // Options table: Required for subclasses of Options.
158 static OptionDefinition g_option_table[];
160 // Instance variables to hold the values for command options.
162 TypeSummaryImpl::Flags m_flags;
164 std::string m_format_string;
166 std::string m_python_script;
167 std::string m_python_function;
168 bool m_is_add_script;
169 std::string m_category;
172 CommandOptions m_options;
181 Execute_ScriptSummary (Args& command, CommandReturnObject &result);
184 Execute_StringSummary (Args& command, CommandReturnObject &result);
188 enum SummaryFormatType
195 CommandObjectTypeSummaryAdd (CommandInterpreter &interpreter);
197 ~CommandObjectTypeSummaryAdd ()
202 IOHandlerActivated (IOHandler &io_handler)
204 static const char *g_summary_addreader_instructions = "Enter your Python command(s). Type 'DONE' to end.\n"
205 "def function (valobj,internal_dict):\n"
206 " \"\"\"valobj: an SBValue which you want to provide a summary for\n"
207 " internal_dict: an LLDB support object not to be used\"\"\"";
209 StreamFileSP output_sp(io_handler.GetOutputStreamFile());
212 output_sp->PutCString(g_summary_addreader_instructions);
219 IOHandlerInputComplete (IOHandler &io_handler, std::string &data)
221 StreamFileSP error_sp = io_handler.GetErrorStreamFile();
223 #ifndef LLDB_DISABLE_PYTHON
224 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
228 lines.SplitIntoLines(data);
229 if (lines.GetSize() > 0)
231 ScriptAddOptions *options_ptr = ((ScriptAddOptions*)io_handler.GetUserData());
234 ScriptAddOptions::SharedPointer options(options_ptr); // this will ensure that we get rid of the pointer when going out of scope
236 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
239 std::string funct_name_str;
240 if (interpreter->GenerateTypeScriptFunction (lines, funct_name_str))
242 if (funct_name_str.empty())
244 error_sp->Printf ("unable to obtain a valid function name from the script interpreter.\n");
249 // now I have a valid function name, let's add this as script for every type in the list
251 TypeSummaryImplSP script_format;
252 script_format.reset(new ScriptSummaryFormat(options->m_flags,
253 funct_name_str.c_str(),
254 lines.CopyList(" ").c_str()));
258 for (size_t i = 0; i < options->m_target_types.GetSize(); i++)
260 const char *type_name = options->m_target_types.GetStringAtIndex(i);
261 CommandObjectTypeSummaryAdd::AddSummary(ConstString(type_name),
263 (options->m_regex ? CommandObjectTypeSummaryAdd::eRegexSummary : CommandObjectTypeSummaryAdd::eRegularSummary),
268 error_sp->Printf ("error: %s", error.AsCString());
275 CommandObjectTypeSummaryAdd::AddSummary (options->m_name,
277 CommandObjectTypeSummaryAdd::eNamedSummary,
282 CommandObjectTypeSummaryAdd::AddSummary (options->m_name,
284 CommandObjectTypeSummaryAdd::eNamedSummary,
289 error_sp->Printf ("error: %s", error.AsCString());
295 error_sp->Printf ("error: %s", error.AsCString());
301 if (error.AsCString())
303 error_sp->Printf ("error: %s", error.AsCString());
311 error_sp->Printf ("error: unable to generate a function.\n");
317 error_sp->Printf ("error: no script interpreter.\n");
323 error_sp->Printf ("error: internal synchronization information missing or invalid.\n");
329 error_sp->Printf ("error: empty function, didn't add python command.\n");
335 error_sp->Printf ("error: script interpreter missing, didn't add python command.\n");
338 #endif // #ifndef LLDB_DISABLE_PYTHON
339 io_handler.SetIsDone(true);
343 AddSummary(ConstString type_name,
344 lldb::TypeSummaryImplSP entry,
345 SummaryFormatType type,
346 std::string category,
347 Error* error = NULL);
350 DoExecute (Args& command, CommandReturnObject &result);
354 static const char *g_synth_addreader_instructions = "Enter your Python command(s). Type 'DONE' to end.\n"
355 "You must define a Python class with these methods:\n"
356 " def __init__(self, valobj, dict):\n"
357 " def num_children(self):\n"
358 " def get_child_at_index(self, index):\n"
359 " def get_child_index(self, name):\n"
360 " def update(self):\n"
362 "class synthProvider:\n";
364 class CommandObjectTypeSynthAdd :
365 public CommandObjectParsed,
366 public IOHandlerDelegateMultiline
371 class CommandOptions : public Options
375 CommandOptions (CommandInterpreter &interpreter) :
376 Options (interpreter)
384 SetOptionValue (uint32_t option_idx, const char *option_arg)
387 const int short_option = m_getopt_table[option_idx].val;
390 switch (short_option)
393 m_cascade = Args::StringToBoolean(option_arg, true, &success);
395 error.SetErrorStringWithFormat("invalid value for cascade: %s", option_arg);
398 handwrite_python = true;
401 m_class_name = std::string(option_arg);
402 is_class_based = true;
405 m_skip_pointers = true;
408 m_skip_references = true;
411 m_category = std::string(option_arg);
417 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
425 OptionParsingStarting ()
429 m_skip_pointers = false;
430 m_skip_references = false;
431 m_category = "default";
432 is_class_based = false;
433 handwrite_python = false;
437 const OptionDefinition*
440 return g_option_table;
443 // Options table: Required for subclasses of Options.
445 static OptionDefinition g_option_table[];
447 // Instance variables to hold the values for command options.
450 bool m_skip_references;
451 bool m_skip_pointers;
452 std::string m_class_name;
454 std::string m_category;
458 bool handwrite_python;
464 CommandOptions m_options;
473 Execute_HandwritePython (Args& command, CommandReturnObject &result);
476 Execute_PythonClass (Args& command, CommandReturnObject &result);
480 DoExecute (Args& command, CommandReturnObject &result)
482 WarnOnPotentialUnquotedUnsignedType(command, result);
484 if (m_options.handwrite_python)
485 return Execute_HandwritePython(command, result);
486 else if (m_options.is_class_based)
487 return Execute_PythonClass(command, result);
490 result.AppendError("must either provide a children list, a Python class name, or use -P and type a Python class line-by-line");
491 result.SetStatus(eReturnStatusFailed);
497 IOHandlerActivated (IOHandler &io_handler)
499 StreamFileSP output_sp(io_handler.GetOutputStreamFile());
502 output_sp->PutCString(g_synth_addreader_instructions);
509 IOHandlerInputComplete (IOHandler &io_handler, std::string &data)
511 StreamFileSP error_sp = io_handler.GetErrorStreamFile();
513 #ifndef LLDB_DISABLE_PYTHON
514 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
518 lines.SplitIntoLines(data);
519 if (lines.GetSize() > 0)
521 SynthAddOptions *options_ptr = ((SynthAddOptions*)io_handler.GetUserData());
524 SynthAddOptions::SharedPointer options(options_ptr); // this will ensure that we get rid of the pointer when going out of scope
526 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
529 std::string class_name_str;
530 if (interpreter->GenerateTypeSynthClass (lines, class_name_str))
532 if (class_name_str.empty())
534 error_sp->Printf ("error: unable to obtain a proper name for the class.\n");
539 // everything should be fine now, let's add the synth provider class
541 SyntheticChildrenSP synth_provider;
542 synth_provider.reset(new ScriptedSyntheticChildren(SyntheticChildren::Flags().SetCascades(options->m_cascade).
543 SetSkipPointers(options->m_skip_pointers).
544 SetSkipReferences(options->m_skip_references),
545 class_name_str.c_str()));
548 lldb::TypeCategoryImplSP category;
549 DataVisualization::Categories::GetCategory(ConstString(options->m_category.c_str()), category);
553 for (size_t i = 0; i < options->m_target_types.GetSize(); i++)
555 const char *type_name = options->m_target_types.GetStringAtIndex(i);
556 ConstString const_type_name(type_name);
559 if (!CommandObjectTypeSynthAdd::AddSynth(const_type_name,
561 options->m_regex ? CommandObjectTypeSynthAdd::eRegexSynth : CommandObjectTypeSynthAdd::eRegularSynth,
565 error_sp->Printf("error: %s\n", error.AsCString());
572 error_sp->Printf ("error: invalid type name.\n");
581 error_sp->Printf ("error: unable to generate a class.\n");
587 error_sp->Printf ("error: no script interpreter.\n");
593 error_sp->Printf ("error: internal synchronization data missing.\n");
599 error_sp->Printf ("error: empty function, didn't add python command.\n");
605 error_sp->Printf ("error: script interpreter missing, didn't add python command.\n");
609 #endif // #ifndef LLDB_DISABLE_PYTHON
610 io_handler.SetIsDone(true);
621 CommandObjectTypeSynthAdd (CommandInterpreter &interpreter);
623 ~CommandObjectTypeSynthAdd ()
628 AddSynth(ConstString type_name,
629 lldb::SyntheticChildrenSP entry,
630 SynthFormatType type,
631 std::string category_name,
635 //-------------------------------------------------------------------------
636 // CommandObjectTypeFormatAdd
637 //-------------------------------------------------------------------------
639 class CommandObjectTypeFormatAdd : public CommandObjectParsed
644 class CommandOptions : public OptionGroup
659 GetNumDefinitions ();
661 virtual const OptionDefinition*
664 return g_option_table;
668 OptionParsingStarting (CommandInterpreter &interpreter)
671 m_skip_pointers = false;
672 m_skip_references = false;
674 m_category.assign("default");
675 m_custom_type_name.clear();
678 SetOptionValue (CommandInterpreter &interpreter,
680 const char *option_value)
683 const int short_option = g_option_table[option_idx].short_option;
686 switch (short_option)
689 m_cascade = Args::StringToBoolean(option_value, true, &success);
691 error.SetErrorStringWithFormat("invalid value for cascade: %s", option_value);
694 m_skip_pointers = true;
697 m_category.assign(option_value);
700 m_skip_references = true;
706 m_custom_type_name.assign(option_value);
709 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
716 // Options table: Required for subclasses of Options.
718 static OptionDefinition g_option_table[];
720 // Instance variables to hold the values for command options.
723 bool m_skip_references;
724 bool m_skip_pointers;
726 std::string m_category;
727 std::string m_custom_type_name;
730 OptionGroupOptions m_option_group;
731 OptionGroupFormat m_format_options;
732 CommandOptions m_command_options;
737 return &m_option_group;
741 CommandObjectTypeFormatAdd (CommandInterpreter &interpreter) :
742 CommandObjectParsed (interpreter,
744 "Add a new formatting style for a type.",
746 m_option_group (interpreter),
747 m_format_options (eFormatInvalid),
750 CommandArgumentEntry type_arg;
751 CommandArgumentData type_style_arg;
753 type_style_arg.arg_type = eArgTypeName;
754 type_style_arg.arg_repetition = eArgRepeatPlus;
756 type_arg.push_back (type_style_arg);
758 m_arguments.push_back (type_arg);
761 "Some examples of using this command.\n"
762 "We use as reference the following snippet of code:\n"
764 "typedef int Aint;\n"
765 "typedef float Afloat;\n"
766 "typedef Aint Bint;\n"
767 "typedef Afloat Bfloat;\n"
772 "Afloat fx = 3.14;\n"
773 "BFloat fy = 3.14;\n"
776 "type format add -f hex AInt\n"
777 "frame variable iy\n"
778 "will produce an hex display of iy, because no formatter is available for Bint and the one for Aint is used instead\n"
779 "To prevent this type\n"
780 "type format add -f hex -C no AInt\n"
782 "A similar reasoning applies to\n"
783 "type format add -f hex -C no float -p\n"
784 "which now prints all floats and float&s as hexadecimal, but does not format float*s\n"
785 "and does not change the default display for Afloat and Bfloat objects.\n"
788 // Add the "--format" to all options groups
789 m_option_group.Append (&m_format_options, OptionGroupFormat::OPTION_GROUP_FORMAT, LLDB_OPT_SET_1);
790 m_option_group.Append (&m_command_options);
791 m_option_group.Finalize();
795 ~CommandObjectTypeFormatAdd ()
801 DoExecute (Args& command, CommandReturnObject &result)
803 const size_t argc = command.GetArgumentCount();
807 result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
808 result.SetStatus(eReturnStatusFailed);
812 const Format format = m_format_options.GetFormat();
813 if (format == eFormatInvalid && m_command_options.m_custom_type_name.empty())
815 result.AppendErrorWithFormat ("%s needs a valid format.\n", m_cmd_name.c_str());
816 result.SetStatus(eReturnStatusFailed);
820 TypeFormatImplSP entry;
822 if (m_command_options.m_custom_type_name.empty())
823 entry.reset(new TypeFormatImpl_Format(format,
824 TypeFormatImpl::Flags().SetCascades(m_command_options.m_cascade).
825 SetSkipPointers(m_command_options.m_skip_pointers).
826 SetSkipReferences(m_command_options.m_skip_references)));
828 entry.reset(new TypeFormatImpl_EnumType(ConstString(m_command_options.m_custom_type_name.c_str()),
829 TypeFormatImpl::Flags().SetCascades(m_command_options.m_cascade).
830 SetSkipPointers(m_command_options.m_skip_pointers).
831 SetSkipReferences(m_command_options.m_skip_references)));
833 // now I have a valid format, let's add it to every type
835 TypeCategoryImplSP category_sp;
836 DataVisualization::Categories::GetCategory(ConstString(m_command_options.m_category), category_sp);
840 WarnOnPotentialUnquotedUnsignedType(command, result);
842 for (size_t i = 0; i < argc; i++)
844 const char* typeA = command.GetArgumentAtIndex(i);
845 ConstString typeCS(typeA);
848 if (m_command_options.m_regex)
850 RegularExpressionSP typeRX(new RegularExpression());
851 if (!typeRX->Compile(typeCS.GetCString()))
853 result.AppendError("regex format error (maybe this is not really a regex?)");
854 result.SetStatus(eReturnStatusFailed);
857 category_sp->GetRegexTypeSummariesContainer()->Delete(typeCS);
858 category_sp->GetRegexTypeFormatsContainer()->Add(typeRX, entry);
861 category_sp->GetTypeFormatsContainer()->Add(typeCS, entry);
865 result.AppendError("empty typenames not allowed");
866 result.SetStatus(eReturnStatusFailed);
871 result.SetStatus(eReturnStatusSuccessFinishNoResult);
872 return result.Succeeded();
877 CommandObjectTypeFormatAdd::CommandOptions::g_option_table[] =
879 { LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, NULL, 0, eArgTypeName, "Add this to the given category instead of the default one."},
880 { LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, NULL, 0, eArgTypeBoolean, "If true, cascade through typedef chains."},
881 { LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."},
882 { LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Don't use this format for references-to-type objects."},
883 { LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Type names are actually regular expressions."},
884 { LLDB_OPT_SET_2, false, "type", 't', OptionParser::eRequiredArgument, NULL, 0, eArgTypeName, "Format variables as if they were of this type."},
885 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
890 CommandObjectTypeFormatAdd::CommandOptions::GetNumDefinitions ()
892 return sizeof(g_option_table) / sizeof (OptionDefinition);
896 //-------------------------------------------------------------------------
897 // CommandObjectTypeFormatDelete
898 //-------------------------------------------------------------------------
900 class CommandObjectTypeFormatDelete : public CommandObjectParsed
903 class CommandOptions : public Options
907 CommandOptions (CommandInterpreter &interpreter) :
908 Options (interpreter)
916 SetOptionValue (uint32_t option_idx, const char *option_arg)
919 const int short_option = m_getopt_table[option_idx].val;
921 switch (short_option)
927 m_category = std::string(option_arg);
930 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
938 OptionParsingStarting ()
940 m_delete_all = false;
941 m_category = "default";
944 const OptionDefinition*
947 return g_option_table;
950 // Options table: Required for subclasses of Options.
952 static OptionDefinition g_option_table[];
954 // Instance variables to hold the values for command options.
957 std::string m_category;
961 CommandOptions m_options;
970 PerCategoryCallback(void* param,
971 const lldb::TypeCategoryImplSP& category_sp)
973 ConstString *name = (ConstString*)param;
974 category_sp->Delete(*name, eFormatCategoryItemValue | eFormatCategoryItemRegexValue);
979 CommandObjectTypeFormatDelete (CommandInterpreter &interpreter) :
980 CommandObjectParsed (interpreter,
981 "type format delete",
982 "Delete an existing formatting style for a type.",
984 m_options(interpreter)
986 CommandArgumentEntry type_arg;
987 CommandArgumentData type_style_arg;
989 type_style_arg.arg_type = eArgTypeName;
990 type_style_arg.arg_repetition = eArgRepeatPlain;
992 type_arg.push_back (type_style_arg);
994 m_arguments.push_back (type_arg);
998 ~CommandObjectTypeFormatDelete ()
1004 DoExecute (Args& command, CommandReturnObject &result)
1006 const size_t argc = command.GetArgumentCount();
1010 result.AppendErrorWithFormat ("%s takes 1 arg.\n", m_cmd_name.c_str());
1011 result.SetStatus(eReturnStatusFailed);
1015 const char* typeA = command.GetArgumentAtIndex(0);
1016 ConstString typeCS(typeA);
1020 result.AppendError("empty typenames not allowed");
1021 result.SetStatus(eReturnStatusFailed);
1025 if (m_options.m_delete_all)
1027 DataVisualization::Categories::LoopThrough(PerCategoryCallback, &typeCS);
1028 result.SetStatus(eReturnStatusSuccessFinishNoResult);
1029 return result.Succeeded();
1032 lldb::TypeCategoryImplSP category;
1033 DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
1035 bool delete_category = category->Delete(typeCS,
1036 eFormatCategoryItemValue | eFormatCategoryItemRegexValue);
1038 if (delete_category)
1040 result.SetStatus(eReturnStatusSuccessFinishNoResult);
1041 return result.Succeeded();
1045 result.AppendErrorWithFormat ("no custom format for %s.\n", typeA);
1046 result.SetStatus(eReturnStatusFailed);
1055 CommandObjectTypeFormatDelete::CommandOptions::g_option_table[] =
1057 { LLDB_OPT_SET_1, false, "all", 'a', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Delete from every category."},
1058 { LLDB_OPT_SET_2, false, "category", 'w', OptionParser::eRequiredArgument, NULL, 0, eArgTypeName, "Delete from given category."},
1059 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
1062 //-------------------------------------------------------------------------
1063 // CommandObjectTypeFormatClear
1064 //-------------------------------------------------------------------------
1066 class CommandObjectTypeFormatClear : public CommandObjectParsed
1070 class CommandOptions : public Options
1074 CommandOptions (CommandInterpreter &interpreter) :
1075 Options (interpreter)
1080 ~CommandOptions (){}
1083 SetOptionValue (uint32_t option_idx, const char *option_arg)
1086 const int short_option = m_getopt_table[option_idx].val;
1088 switch (short_option)
1091 m_delete_all = true;
1094 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1102 OptionParsingStarting ()
1104 m_delete_all = false;
1107 const OptionDefinition*
1110 return g_option_table;
1113 // Options table: Required for subclasses of Options.
1115 static OptionDefinition g_option_table[];
1117 // Instance variables to hold the values for command options.
1120 bool m_delete_named;
1123 CommandOptions m_options;
1132 PerCategoryCallback(void* param,
1133 const lldb::TypeCategoryImplSP& cate)
1135 cate->GetTypeFormatsContainer()->Clear();
1136 cate->GetRegexTypeFormatsContainer()->Clear();
1142 CommandObjectTypeFormatClear (CommandInterpreter &interpreter) :
1143 CommandObjectParsed (interpreter,
1144 "type format clear",
1145 "Delete all existing format styles.",
1147 m_options(interpreter)
1151 ~CommandObjectTypeFormatClear ()
1157 DoExecute (Args& command, CommandReturnObject &result)
1159 if (m_options.m_delete_all)
1160 DataVisualization::Categories::LoopThrough(PerCategoryCallback, NULL);
1164 lldb::TypeCategoryImplSP category;
1165 if (command.GetArgumentCount() > 0)
1167 const char* cat_name = command.GetArgumentAtIndex(0);
1168 ConstString cat_nameCS(cat_name);
1169 DataVisualization::Categories::GetCategory(cat_nameCS, category);
1172 DataVisualization::Categories::GetCategory(ConstString(NULL), category);
1173 category->Clear(eFormatCategoryItemValue | eFormatCategoryItemRegexValue);
1176 result.SetStatus(eReturnStatusSuccessFinishResult);
1177 return result.Succeeded();
1183 CommandObjectTypeFormatClear::CommandOptions::g_option_table[] =
1185 { LLDB_OPT_SET_ALL, false, "all", 'a', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Clear every category."},
1186 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
1189 //-------------------------------------------------------------------------
1190 // CommandObjectTypeFormatList
1191 //-------------------------------------------------------------------------
1193 bool CommandObjectTypeFormatList_LoopCallback(void* pt2self, ConstString type, const lldb::TypeFormatImplSP& entry);
1194 bool CommandObjectTypeRXFormatList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const lldb::TypeFormatImplSP& entry);
1196 class CommandObjectTypeFormatList;
1198 struct CommandObjectTypeFormatList_LoopCallbackParam {
1199 CommandObjectTypeFormatList* self;
1200 CommandReturnObject* result;
1201 RegularExpression* regex;
1202 RegularExpression* cate_regex;
1203 CommandObjectTypeFormatList_LoopCallbackParam(CommandObjectTypeFormatList* S, CommandReturnObject* R,
1204 RegularExpression* X = NULL, RegularExpression* CX = NULL) : self(S), result(R), regex(X), cate_regex(CX) {}
1207 class CommandObjectTypeFormatList : public CommandObjectParsed
1209 class CommandOptions : public Options
1213 CommandOptions (CommandInterpreter &interpreter) :
1214 Options (interpreter)
1219 ~CommandOptions (){}
1222 SetOptionValue (uint32_t option_idx, const char *option_arg)
1225 const int short_option = m_getopt_table[option_idx].val;
1227 switch (short_option)
1230 m_category_regex = std::string(option_arg);
1233 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1241 OptionParsingStarting ()
1243 m_category_regex = "";
1246 const OptionDefinition*
1249 return g_option_table;
1252 // Options table: Required for subclasses of Options.
1254 static OptionDefinition g_option_table[];
1256 // Instance variables to hold the values for command options.
1258 std::string m_category_regex;
1262 CommandOptions m_options;
1271 CommandObjectTypeFormatList (CommandInterpreter &interpreter) :
1272 CommandObjectParsed (interpreter,
1274 "Show a list of current formatting styles.",
1276 m_options(interpreter)
1278 CommandArgumentEntry type_arg;
1279 CommandArgumentData type_style_arg;
1281 type_style_arg.arg_type = eArgTypeName;
1282 type_style_arg.arg_repetition = eArgRepeatOptional;
1284 type_arg.push_back (type_style_arg);
1286 m_arguments.push_back (type_arg);
1289 ~CommandObjectTypeFormatList ()
1295 DoExecute (Args& command, CommandReturnObject &result)
1297 const size_t argc = command.GetArgumentCount();
1299 CommandObjectTypeFormatList_LoopCallbackParam *param;
1300 RegularExpression* cate_regex =
1301 m_options.m_category_regex.empty() ? NULL :
1302 new RegularExpression(m_options.m_category_regex.c_str());
1306 RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
1307 regex->Compile(command.GetArgumentAtIndex(0));
1308 param = new CommandObjectTypeFormatList_LoopCallbackParam(this,&result,regex,cate_regex);
1311 param = new CommandObjectTypeFormatList_LoopCallbackParam(this,&result,NULL,cate_regex);
1313 DataVisualization::Categories::LoopThrough(PerCategoryCallback,param);
1319 result.SetStatus(eReturnStatusSuccessFinishResult);
1320 return result.Succeeded();
1326 PerCategoryCallback(void* param_vp,
1327 const lldb::TypeCategoryImplSP& cate)
1330 CommandObjectTypeFormatList_LoopCallbackParam* param =
1331 (CommandObjectTypeFormatList_LoopCallbackParam*)param_vp;
1332 CommandReturnObject* result = param->result;
1334 const char* cate_name = cate->GetName();
1336 // if the category is disabled or empty and there is no regex, just skip it
1337 if ((cate->IsEnabled() == false || cate->GetCount(eFormatCategoryItemValue | eFormatCategoryItemRegexValue) == 0) && param->cate_regex == NULL)
1340 // if we have a regex and this category does not match it, just skip it
1341 if(param->cate_regex != NULL && strcmp(cate_name,param->cate_regex->GetText()) != 0 && param->cate_regex->Execute(cate_name) == false)
1344 result->GetOutputStream().Printf("-----------------------\nCategory: %s (%s)\n-----------------------\n",
1346 (cate->IsEnabled() ? "enabled" : "disabled"));
1348 cate->GetTypeFormatsContainer()->LoopThrough(CommandObjectTypeFormatList_LoopCallback, param_vp);
1350 if (cate->GetRegexTypeSummariesContainer()->GetCount() > 0)
1352 result->GetOutputStream().Printf("Regex-based summaries (slower):\n");
1353 cate->GetRegexTypeFormatsContainer()->LoopThrough(CommandObjectTypeRXFormatList_LoopCallback, param_vp);
1360 LoopCallback (const char* type,
1361 const lldb::TypeFormatImplSP& entry,
1362 RegularExpression* regex,
1363 CommandReturnObject *result)
1365 if (regex == NULL || strcmp(type,regex->GetText()) == 0 || regex->Execute(type))
1366 result->GetOutputStream().Printf ("%s: %s\n", type, entry->GetDescription().c_str());
1370 friend bool CommandObjectTypeFormatList_LoopCallback(void* pt2self, ConstString type, const lldb::TypeFormatImplSP& entry);
1371 friend bool CommandObjectTypeRXFormatList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const lldb::TypeFormatImplSP& entry);
1376 CommandObjectTypeFormatList_LoopCallback (
1379 const lldb::TypeFormatImplSP& entry)
1381 CommandObjectTypeFormatList_LoopCallbackParam* param = (CommandObjectTypeFormatList_LoopCallbackParam*)pt2self;
1382 return param->self->LoopCallback(type.AsCString(), entry, param->regex, param->result);
1386 CommandObjectTypeRXFormatList_LoopCallback (
1388 lldb::RegularExpressionSP regex,
1389 const lldb::TypeFormatImplSP& entry)
1391 CommandObjectTypeFormatList_LoopCallbackParam* param = (CommandObjectTypeFormatList_LoopCallbackParam*)pt2self;
1392 return param->self->LoopCallback(regex->GetText(), entry, param->regex, param->result);
1396 CommandObjectTypeFormatList::CommandOptions::g_option_table[] =
1398 { LLDB_OPT_SET_ALL, false, "category-regex", 'w', OptionParser::eRequiredArgument, NULL, 0, eArgTypeName, "Only show categories matching this filter."},
1399 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
1402 #ifndef LLDB_DISABLE_PYTHON
1404 //-------------------------------------------------------------------------
1405 // CommandObjectTypeSummaryAdd
1406 //-------------------------------------------------------------------------
1408 #endif // #ifndef LLDB_DISABLE_PYTHON
1411 CommandObjectTypeSummaryAdd::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
1414 const int short_option = m_getopt_table[option_idx].val;
1417 switch (short_option)
1420 m_flags.SetCascades(Args::StringToBoolean(option_arg, true, &success));
1422 error.SetErrorStringWithFormat("invalid value for cascade: %s", option_arg);
1425 m_flags.SetDontShowChildren(false);
1428 m_flags.SetDontShowValue(true);
1431 m_flags.SetShowMembersOneLiner(true);
1434 m_format_string = std::string(option_arg);
1437 m_flags.SetSkipPointers(true);
1440 m_flags.SetSkipReferences(true);
1446 m_name.SetCString(option_arg);
1449 m_python_script = std::string(option_arg);
1450 m_is_add_script = true;
1453 m_python_function = std::string(option_arg);
1454 m_is_add_script = true;
1457 m_is_add_script = true;
1460 m_category = std::string(option_arg);
1463 m_flags.SetHideItemNames(true);
1466 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1474 CommandObjectTypeSummaryAdd::CommandOptions::OptionParsingStarting ()
1476 m_flags.Clear().SetCascades().SetDontShowChildren().SetDontShowValue(false);
1477 m_flags.SetShowMembersOneLiner(false).SetSkipPointers(false).SetSkipReferences(false).SetHideItemNames(false);
1481 m_python_script = "";
1482 m_python_function = "";
1483 m_format_string = "";
1484 m_is_add_script = false;
1485 m_category = "default";
1490 #ifndef LLDB_DISABLE_PYTHON
1493 CommandObjectTypeSummaryAdd::Execute_ScriptSummary (Args& command, CommandReturnObject &result)
1495 const size_t argc = command.GetArgumentCount();
1497 if (argc < 1 && !m_options.m_name)
1499 result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
1500 result.SetStatus(eReturnStatusFailed);
1504 TypeSummaryImplSP script_format;
1506 if (!m_options.m_python_function.empty()) // we have a Python function ready to use
1508 const char *funct_name = m_options.m_python_function.c_str();
1509 if (!funct_name || !funct_name[0])
1511 result.AppendError ("function name empty.\n");
1512 result.SetStatus (eReturnStatusFailed);
1516 std::string code = (" " + m_options.m_python_function + "(valobj,internal_dict)");
1518 script_format.reset(new ScriptSummaryFormat(m_options.m_flags,
1522 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
1524 if (interpreter && interpreter->CheckObjectExists(funct_name) == false)
1525 result.AppendWarningWithFormat("The provided function \"%s\" does not exist - "
1526 "please define it before attempting to use this summary.\n",
1529 else if (!m_options.m_python_script.empty()) // we have a quick 1-line script, just use it
1531 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
1534 result.AppendError ("script interpreter missing - unable to generate function wrapper.\n");
1535 result.SetStatus (eReturnStatusFailed);
1538 StringList funct_sl;
1539 funct_sl << m_options.m_python_script.c_str();
1540 std::string funct_name_str;
1541 if (!interpreter->GenerateTypeScriptFunction (funct_sl,
1544 result.AppendError ("unable to generate function wrapper.\n");
1545 result.SetStatus (eReturnStatusFailed);
1548 if (funct_name_str.empty())
1550 result.AppendError ("script interpreter failed to generate a valid function name.\n");
1551 result.SetStatus (eReturnStatusFailed);
1555 std::string code = " " + m_options.m_python_script;
1557 script_format.reset(new ScriptSummaryFormat(m_options.m_flags,
1558 funct_name_str.c_str(),
1563 // Use an IOHandler to grab Python code from the user
1564 ScriptAddOptions *options = new ScriptAddOptions(m_options.m_flags,
1567 m_options.m_category);
1569 for (size_t i = 0; i < argc; i++)
1571 const char* typeA = command.GetArgumentAtIndex(i);
1572 if (typeA && *typeA)
1573 options->m_target_types << typeA;
1576 result.AppendError("empty typenames not allowed");
1577 result.SetStatus(eReturnStatusFailed);
1582 m_interpreter.GetPythonCommandsFromIOHandler (" ", // Prompt
1583 *this, // IOHandlerDelegate
1584 true, // Run IOHandler in async mode
1585 options); // Baton for the "io_handler" that will be passed back into our IOHandlerDelegate functions
1586 result.SetStatus(eReturnStatusSuccessFinishNoResult);
1588 return result.Succeeded();
1591 // if I am here, script_format must point to something good, so I can add that
1592 // as a script summary to all interested parties
1596 for (size_t i = 0; i < command.GetArgumentCount(); i++)
1598 const char *type_name = command.GetArgumentAtIndex(i);
1599 CommandObjectTypeSummaryAdd::AddSummary(ConstString(type_name),
1601 (m_options.m_regex ? eRegexSummary : eRegularSummary),
1602 m_options.m_category,
1606 result.AppendError(error.AsCString());
1607 result.SetStatus(eReturnStatusFailed);
1612 if (m_options.m_name)
1614 AddSummary(m_options.m_name, script_format, eNamedSummary, m_options.m_category, &error);
1617 result.AppendError(error.AsCString());
1618 result.AppendError("added to types, but not given a name");
1619 result.SetStatus(eReturnStatusFailed);
1624 return result.Succeeded();
1631 CommandObjectTypeSummaryAdd::Execute_StringSummary (Args& command, CommandReturnObject &result)
1633 const size_t argc = command.GetArgumentCount();
1635 if (argc < 1 && !m_options.m_name)
1637 result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
1638 result.SetStatus(eReturnStatusFailed);
1642 if (!m_options.m_flags.GetShowMembersOneLiner() && m_options.m_format_string.empty())
1644 result.AppendError("empty summary strings not allowed");
1645 result.SetStatus(eReturnStatusFailed);
1649 const char* format_cstr = (m_options.m_flags.GetShowMembersOneLiner() ? "" : m_options.m_format_string.c_str());
1651 // ${var%S} is an endless recursion, prevent it
1652 if (strcmp(format_cstr, "${var%S}") == 0)
1654 result.AppendError("recursive summary not allowed");
1655 result.SetStatus(eReturnStatusFailed);
1661 lldb::TypeSummaryImplSP entry(new StringSummaryFormat(m_options.m_flags,
1666 result.AppendError(error.AsCString());
1667 result.SetStatus(eReturnStatusFailed);
1671 // now I have a valid format, let's add it to every type
1673 for (size_t i = 0; i < argc; i++)
1675 const char* typeA = command.GetArgumentAtIndex(i);
1676 if (!typeA || typeA[0] == '\0')
1678 result.AppendError("empty typenames not allowed");
1679 result.SetStatus(eReturnStatusFailed);
1682 ConstString typeCS(typeA);
1686 (m_options.m_regex ? eRegexSummary : eRegularSummary),
1687 m_options.m_category,
1692 result.AppendError(error.AsCString());
1693 result.SetStatus(eReturnStatusFailed);
1698 if (m_options.m_name)
1700 AddSummary(m_options.m_name, entry, eNamedSummary, m_options.m_category, &error);
1703 result.AppendError(error.AsCString());
1704 result.AppendError("added to types, but not given a name");
1705 result.SetStatus(eReturnStatusFailed);
1710 result.SetStatus(eReturnStatusSuccessFinishNoResult);
1711 return result.Succeeded();
1714 CommandObjectTypeSummaryAdd::CommandObjectTypeSummaryAdd (CommandInterpreter &interpreter) :
1715 CommandObjectParsed (interpreter,
1717 "Add a new summary style for a type.",
1719 IOHandlerDelegateMultiline ("DONE"),
1720 m_options (interpreter)
1722 CommandArgumentEntry type_arg;
1723 CommandArgumentData type_style_arg;
1725 type_style_arg.arg_type = eArgTypeName;
1726 type_style_arg.arg_repetition = eArgRepeatPlus;
1728 type_arg.push_back (type_style_arg);
1730 m_arguments.push_back (type_arg);
1733 "Some examples of using this command.\n"
1734 "We use as reference the following snippet of code:\n"
1735 "struct JustADemo\n"
1739 "JustADemo(int p = 1, float v = 0.1) : ptr(new int(p)), value(v) {}\n"
1741 "JustADemo object(42,3.14);\n"
1742 "struct AnotherDemo : public JustADemo\n"
1745 "AnotherDemo(uint8_t b = 'E', int p = 1, float v = 0.1) : JustADemo(p,v), byte(b) {}\n"
1747 "AnotherDemo *another_object = new AnotherDemo('E',42,3.14);\n"
1749 "type summary add --summary-string \"the answer is ${*var.ptr}\" JustADemo\n"
1750 "when typing frame variable object you will get \"the answer is 42\"\n"
1751 "type summary add --summary-string \"the answer is ${*var.ptr}, and the question is ${var.value}\" JustADemo\n"
1752 "when typing frame variable object you will get \"the answer is 42 and the question is 3.14\"\n"
1754 "Alternatively, you could also say\n"
1755 "type summary add --summary-string \"${var%V} -> ${*var}\" \"int *\"\n"
1756 "and replace the above summary string with\n"
1757 "type summary add --summary-string \"the answer is ${var.ptr}, and the question is ${var.value}\" JustADemo\n"
1758 "to obtain a similar result\n"
1760 "To add a summary valid for both JustADemo and AnotherDemo you can use the scoping operator, as in:\n"
1761 "type summary add --summary-string \"${var.ptr}, ${var.value},{${var.byte}}\" JustADemo -C yes\n"
1763 "This will be used for both variables of type JustADemo and AnotherDemo. To prevent this, change the -C to read -C no\n"
1764 "If you do not want pointers to be shown using that summary, you can use the -p option, as in:\n"
1765 "type summary add --summary-string \"${var.ptr}, ${var.value},{${var.byte}}\" JustADemo -C yes -p\n"
1766 "A similar option -r exists for references.\n"
1768 "If you simply want a one-line summary of the content of your variable, without typing an explicit string to that effect\n"
1769 "you can use the -c option, without giving any summary string:\n"
1770 "type summary add -c JustADemo\n"
1771 "frame variable object\n"
1772 "the output being similar to (ptr=0xsomeaddress, value=3.14)\n"
1774 "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"
1775 "type summary add -e --summary-string \"*ptr = ${*var.ptr}\" JustADemo\n"
1776 "Here the value of the int* is displayed, followed by the standard LLDB sequence of children objects, one per line.\n"
1777 "to get an output like:\n"
1780 " ptr = 0xsomeaddress\n"
1784 "You can also add Python summaries, in which case you will use lldb public API to gather information from your variables"
1785 "and elaborate them to a meaningful summary inside a script written in Python. The variable object will be passed to your"
1786 "script as an SBValue object. The following example might help you when starting to use the Python summaries feature:\n"
1787 "type summary add JustADemo -o \"value = valobj.GetChildMemberWithName('value'); return 'My value is ' + value.GetValue();\"\n"
1788 "If you prefer to type your scripts on multiple lines, you will use the -P option and then type your script, ending it with "
1789 "the word DONE on a line by itself to mark you're finished editing your code:\n"
1790 "(lldb)type summary add JustADemo -P\n"
1791 " value = valobj.GetChildMemberWithName('value');\n"
1792 " return 'My value is ' + value.GetValue();\n"
1794 "(lldb) <-- type further LLDB commands here\n"
1799 CommandObjectTypeSummaryAdd::DoExecute (Args& command, CommandReturnObject &result)
1801 WarnOnPotentialUnquotedUnsignedType(command, result);
1803 if (m_options.m_is_add_script)
1805 #ifndef LLDB_DISABLE_PYTHON
1806 return Execute_ScriptSummary(command, result);
1808 result.AppendError ("python is disabled");
1809 result.SetStatus(eReturnStatusFailed);
1814 return Execute_StringSummary(command, result);
1818 CommandObjectTypeSummaryAdd::AddSummary(ConstString type_name,
1819 TypeSummaryImplSP entry,
1820 SummaryFormatType type,
1821 std::string category_name,
1824 lldb::TypeCategoryImplSP category;
1825 DataVisualization::Categories::GetCategory(ConstString(category_name.c_str()), category);
1827 if (type == eRegularSummary)
1829 std::string type_name_str(type_name.GetCString());
1830 if (type_name_str.compare(type_name_str.length() - 2, 2, "[]") == 0)
1832 type_name_str.resize(type_name_str.length()-2);
1833 if (type_name_str.back() != ' ')
1834 type_name_str.append(" \\[[0-9]+\\]");
1836 type_name_str.append("\\[[0-9]+\\]");
1837 type_name.SetCString(type_name_str.c_str());
1838 type = eRegexSummary;
1842 if (type == eRegexSummary)
1844 RegularExpressionSP typeRX(new RegularExpression());
1845 if (!typeRX->Compile(type_name.GetCString()))
1848 error->SetErrorString("regex format error (maybe this is not really a regex?)");
1852 category->GetRegexTypeSummariesContainer()->Delete(type_name);
1853 category->GetRegexTypeSummariesContainer()->Add(typeRX, entry);
1857 else if (type == eNamedSummary)
1859 // system named summaries do not exist (yet?)
1860 DataVisualization::NamedSummaryFormats::Add(type_name,entry);
1865 category->GetTypeSummariesContainer()->Add(type_name, entry);
1871 CommandObjectTypeSummaryAdd::CommandOptions::g_option_table[] =
1873 { LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, NULL, 0, eArgTypeName, "Add this to the given category instead of the default one."},
1874 { LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, NULL, 0, eArgTypeBoolean, "If true, cascade through typedef chains."},
1875 { LLDB_OPT_SET_ALL, false, "no-value", 'v', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Don't show the value, just show the summary, for this type."},
1876 { LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."},
1877 { LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Don't use this format for references-to-type objects."},
1878 { LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Type names are actually regular expressions."},
1879 { LLDB_OPT_SET_1 , true, "inline-children", 'c', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "If true, inline all child values into summary string."},
1880 { LLDB_OPT_SET_1 , false, "omit-names", 'O', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "If true, omit value names in the summary display."},
1881 { LLDB_OPT_SET_2 , true, "summary-string", 's', OptionParser::eRequiredArgument, NULL, 0, eArgTypeSummaryString, "Summary string used to display text and object contents."},
1882 { LLDB_OPT_SET_3, false, "python-script", 'o', OptionParser::eRequiredArgument, NULL, 0, eArgTypePythonScript, "Give a one-liner Python script as part of the command."},
1883 { LLDB_OPT_SET_3, false, "python-function", 'F', OptionParser::eRequiredArgument, NULL, 0, eArgTypePythonFunction, "Give the name of a Python function to use for this type."},
1884 { LLDB_OPT_SET_3, false, "input-python", 'P', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Input Python code to use for this type manually."},
1885 { LLDB_OPT_SET_2 | LLDB_OPT_SET_3, false, "expand", 'e', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Expand aggregate data types to show children on separate lines."},
1886 { LLDB_OPT_SET_2 | LLDB_OPT_SET_3, false, "name", 'n', OptionParser::eRequiredArgument, NULL, 0, eArgTypeName, "A name for this summary string."},
1887 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
1891 //-------------------------------------------------------------------------
1892 // CommandObjectTypeSummaryDelete
1893 //-------------------------------------------------------------------------
1895 class CommandObjectTypeSummaryDelete : public CommandObjectParsed
1898 class CommandOptions : public Options
1902 CommandOptions (CommandInterpreter &interpreter) :
1903 Options (interpreter)
1908 ~CommandOptions (){}
1911 SetOptionValue (uint32_t option_idx, const char *option_arg)
1914 const int short_option = m_getopt_table[option_idx].val;
1916 switch (short_option)
1919 m_delete_all = true;
1922 m_category = std::string(option_arg);
1925 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1933 OptionParsingStarting ()
1935 m_delete_all = false;
1936 m_category = "default";
1939 const OptionDefinition*
1942 return g_option_table;
1945 // Options table: Required for subclasses of Options.
1947 static OptionDefinition g_option_table[];
1949 // Instance variables to hold the values for command options.
1952 std::string m_category;
1956 CommandOptions m_options;
1965 PerCategoryCallback(void* param,
1966 const lldb::TypeCategoryImplSP& category_sp)
1968 ConstString *name = (ConstString*)param;
1969 category_sp->Delete(*name, eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
1974 CommandObjectTypeSummaryDelete (CommandInterpreter &interpreter) :
1975 CommandObjectParsed (interpreter,
1976 "type summary delete",
1977 "Delete an existing summary style for a type.",
1979 m_options(interpreter)
1981 CommandArgumentEntry type_arg;
1982 CommandArgumentData type_style_arg;
1984 type_style_arg.arg_type = eArgTypeName;
1985 type_style_arg.arg_repetition = eArgRepeatPlain;
1987 type_arg.push_back (type_style_arg);
1989 m_arguments.push_back (type_arg);
1993 ~CommandObjectTypeSummaryDelete ()
1999 DoExecute (Args& command, CommandReturnObject &result)
2001 const size_t argc = command.GetArgumentCount();
2005 result.AppendErrorWithFormat ("%s takes 1 arg.\n", m_cmd_name.c_str());
2006 result.SetStatus(eReturnStatusFailed);
2010 const char* typeA = command.GetArgumentAtIndex(0);
2011 ConstString typeCS(typeA);
2015 result.AppendError("empty typenames not allowed");
2016 result.SetStatus(eReturnStatusFailed);
2020 if (m_options.m_delete_all)
2022 DataVisualization::Categories::LoopThrough(PerCategoryCallback, &typeCS);
2023 result.SetStatus(eReturnStatusSuccessFinishNoResult);
2024 return result.Succeeded();
2027 lldb::TypeCategoryImplSP category;
2028 DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
2030 bool delete_category = category->Delete(typeCS,
2031 eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
2032 bool delete_named = DataVisualization::NamedSummaryFormats::Delete(typeCS);
2034 if (delete_category || delete_named)
2036 result.SetStatus(eReturnStatusSuccessFinishNoResult);
2037 return result.Succeeded();
2041 result.AppendErrorWithFormat ("no custom summary for %s.\n", typeA);
2042 result.SetStatus(eReturnStatusFailed);
2050 CommandObjectTypeSummaryDelete::CommandOptions::g_option_table[] =
2052 { LLDB_OPT_SET_1, false, "all", 'a', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Delete from every category."},
2053 { LLDB_OPT_SET_2, false, "category", 'w', OptionParser::eRequiredArgument, NULL, 0, eArgTypeName, "Delete from given category."},
2054 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
2057 class CommandObjectTypeSummaryClear : public CommandObjectParsed
2061 class CommandOptions : public Options
2065 CommandOptions (CommandInterpreter &interpreter) :
2066 Options (interpreter)
2071 ~CommandOptions (){}
2074 SetOptionValue (uint32_t option_idx, const char *option_arg)
2077 const int short_option = m_getopt_table[option_idx].val;
2079 switch (short_option)
2082 m_delete_all = true;
2085 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
2093 OptionParsingStarting ()
2095 m_delete_all = false;
2098 const OptionDefinition*
2101 return g_option_table;
2104 // Options table: Required for subclasses of Options.
2106 static OptionDefinition g_option_table[];
2108 // Instance variables to hold the values for command options.
2111 bool m_delete_named;
2114 CommandOptions m_options;
2123 PerCategoryCallback(void* param,
2124 const lldb::TypeCategoryImplSP& cate)
2126 cate->GetTypeSummariesContainer()->Clear();
2127 cate->GetRegexTypeSummariesContainer()->Clear();
2133 CommandObjectTypeSummaryClear (CommandInterpreter &interpreter) :
2134 CommandObjectParsed (interpreter,
2135 "type summary clear",
2136 "Delete all existing summary styles.",
2138 m_options(interpreter)
2142 ~CommandObjectTypeSummaryClear ()
2148 DoExecute (Args& command, CommandReturnObject &result)
2151 if (m_options.m_delete_all)
2152 DataVisualization::Categories::LoopThrough(PerCategoryCallback, NULL);
2156 lldb::TypeCategoryImplSP category;
2157 if (command.GetArgumentCount() > 0)
2159 const char* cat_name = command.GetArgumentAtIndex(0);
2160 ConstString cat_nameCS(cat_name);
2161 DataVisualization::Categories::GetCategory(cat_nameCS, category);
2164 DataVisualization::Categories::GetCategory(ConstString(NULL), category);
2165 category->Clear(eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
2168 DataVisualization::NamedSummaryFormats::Clear();
2170 result.SetStatus(eReturnStatusSuccessFinishResult);
2171 return result.Succeeded();
2177 CommandObjectTypeSummaryClear::CommandOptions::g_option_table[] =
2179 { LLDB_OPT_SET_ALL, false, "all", 'a', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Clear every category."},
2180 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
2183 //-------------------------------------------------------------------------
2184 // CommandObjectTypeSummaryList
2185 //-------------------------------------------------------------------------
2187 bool CommandObjectTypeSummaryList_LoopCallback(void* pt2self, ConstString type, const StringSummaryFormat::SharedPointer& entry);
2188 bool CommandObjectTypeRXSummaryList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const StringSummaryFormat::SharedPointer& entry);
2190 class CommandObjectTypeSummaryList;
2192 struct CommandObjectTypeSummaryList_LoopCallbackParam {
2193 CommandObjectTypeSummaryList* self;
2194 CommandReturnObject* result;
2195 RegularExpression* regex;
2196 RegularExpression* cate_regex;
2197 CommandObjectTypeSummaryList_LoopCallbackParam(CommandObjectTypeSummaryList* S, CommandReturnObject* R,
2198 RegularExpression* X = NULL,
2199 RegularExpression* CX = NULL) : self(S), result(R), regex(X), cate_regex(CX) {}
2202 class CommandObjectTypeSummaryList : public CommandObjectParsed
2205 class CommandOptions : public Options
2209 CommandOptions (CommandInterpreter &interpreter) :
2210 Options (interpreter)
2215 ~CommandOptions (){}
2218 SetOptionValue (uint32_t option_idx, const char *option_arg)
2221 const int short_option = m_getopt_table[option_idx].val;
2223 switch (short_option)
2226 m_category_regex = std::string(option_arg);
2229 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
2237 OptionParsingStarting ()
2239 m_category_regex = "";
2242 const OptionDefinition*
2245 return g_option_table;
2248 // Options table: Required for subclasses of Options.
2250 static OptionDefinition g_option_table[];
2252 // Instance variables to hold the values for command options.
2254 std::string m_category_regex;
2258 CommandOptions m_options;
2267 CommandObjectTypeSummaryList (CommandInterpreter &interpreter) :
2268 CommandObjectParsed (interpreter,
2269 "type summary list",
2270 "Show a list of current summary styles.",
2272 m_options(interpreter)
2274 CommandArgumentEntry type_arg;
2275 CommandArgumentData type_style_arg;
2277 type_style_arg.arg_type = eArgTypeName;
2278 type_style_arg.arg_repetition = eArgRepeatOptional;
2280 type_arg.push_back (type_style_arg);
2282 m_arguments.push_back (type_arg);
2285 ~CommandObjectTypeSummaryList ()
2291 DoExecute (Args& command, CommandReturnObject &result)
2293 const size_t argc = command.GetArgumentCount();
2295 CommandObjectTypeSummaryList_LoopCallbackParam *param;
2296 RegularExpression* cate_regex =
2297 m_options.m_category_regex.empty() ? NULL :
2298 new RegularExpression(m_options.m_category_regex.c_str());
2302 RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
2303 regex->Compile(command.GetArgumentAtIndex(0));
2304 param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result,regex,cate_regex);
2307 param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result,NULL,cate_regex);
2309 DataVisualization::Categories::LoopThrough(PerCategoryCallback,param);
2312 if (DataVisualization::NamedSummaryFormats::GetCount() > 0)
2314 result.GetOutputStream().Printf("Named summaries:\n");
2317 RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
2318 regex->Compile(command.GetArgumentAtIndex(0));
2319 param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result,regex);
2322 param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result);
2323 DataVisualization::NamedSummaryFormats::LoopThrough(CommandObjectTypeSummaryList_LoopCallback, param);
2330 result.SetStatus(eReturnStatusSuccessFinishResult);
2331 return result.Succeeded();
2337 PerCategoryCallback(void* param_vp,
2338 const lldb::TypeCategoryImplSP& cate)
2341 CommandObjectTypeSummaryList_LoopCallbackParam* param =
2342 (CommandObjectTypeSummaryList_LoopCallbackParam*)param_vp;
2343 CommandReturnObject* result = param->result;
2345 const char* cate_name = cate->GetName();
2347 // if the category is disabled or empty and there is no regex, just skip it
2348 if ((cate->IsEnabled() == false || cate->GetCount(eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary) == 0) && param->cate_regex == NULL)
2351 // if we have a regex and this category does not match it, just skip it
2352 if(param->cate_regex != NULL && strcmp(cate_name,param->cate_regex->GetText()) != 0 && param->cate_regex->Execute(cate_name) == false)
2355 result->GetOutputStream().Printf("-----------------------\nCategory: %s (%s)\n-----------------------\n",
2357 (cate->IsEnabled() ? "enabled" : "disabled"));
2359 cate->GetTypeSummariesContainer()->LoopThrough(CommandObjectTypeSummaryList_LoopCallback, param_vp);
2361 if (cate->GetRegexTypeSummariesContainer()->GetCount() > 0)
2363 result->GetOutputStream().Printf("Regex-based summaries (slower):\n");
2364 cate->GetRegexTypeSummariesContainer()->LoopThrough(CommandObjectTypeRXSummaryList_LoopCallback, param_vp);
2371 LoopCallback (const char* type,
2372 const lldb::TypeSummaryImplSP& entry,
2373 RegularExpression* regex,
2374 CommandReturnObject *result)
2376 if (regex == NULL || strcmp(type,regex->GetText()) == 0 || regex->Execute(type))
2377 result->GetOutputStream().Printf ("%s: %s\n", type, entry->GetDescription().c_str());
2381 friend bool CommandObjectTypeSummaryList_LoopCallback(void* pt2self, ConstString type, const lldb::TypeSummaryImplSP& entry);
2382 friend bool CommandObjectTypeRXSummaryList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const lldb::TypeSummaryImplSP& entry);
2386 CommandObjectTypeSummaryList_LoopCallback (
2389 const lldb::TypeSummaryImplSP& entry)
2391 CommandObjectTypeSummaryList_LoopCallbackParam* param = (CommandObjectTypeSummaryList_LoopCallbackParam*)pt2self;
2392 return param->self->LoopCallback(type.AsCString(), entry, param->regex, param->result);
2396 CommandObjectTypeRXSummaryList_LoopCallback (
2398 lldb::RegularExpressionSP regex,
2399 const lldb::TypeSummaryImplSP& entry)
2401 CommandObjectTypeSummaryList_LoopCallbackParam* param = (CommandObjectTypeSummaryList_LoopCallbackParam*)pt2self;
2402 return param->self->LoopCallback(regex->GetText(), entry, param->regex, param->result);
2406 CommandObjectTypeSummaryList::CommandOptions::g_option_table[] =
2408 { LLDB_OPT_SET_ALL, false, "category-regex", 'w', OptionParser::eRequiredArgument, NULL, 0, eArgTypeName, "Only show categories matching this filter."},
2409 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
2412 //-------------------------------------------------------------------------
2413 // CommandObjectTypeCategoryEnable
2414 //-------------------------------------------------------------------------
2416 class CommandObjectTypeCategoryEnable : public CommandObjectParsed
2419 CommandObjectTypeCategoryEnable (CommandInterpreter &interpreter) :
2420 CommandObjectParsed (interpreter,
2421 "type category enable",
2422 "Enable a category as a source of formatters.",
2425 CommandArgumentEntry type_arg;
2426 CommandArgumentData type_style_arg;
2428 type_style_arg.arg_type = eArgTypeName;
2429 type_style_arg.arg_repetition = eArgRepeatPlus;
2431 type_arg.push_back (type_style_arg);
2433 m_arguments.push_back (type_arg);
2437 ~CommandObjectTypeCategoryEnable ()
2443 DoExecute (Args& command, CommandReturnObject &result)
2445 const size_t argc = command.GetArgumentCount();
2449 result.AppendErrorWithFormat ("%s takes 1 or more args.\n", m_cmd_name.c_str());
2450 result.SetStatus(eReturnStatusFailed);
2454 if (argc == 1 && strcmp(command.GetArgumentAtIndex(0),"*") == 0)
2456 // we want to make sure to enable "system" last and "default" first
2457 DataVisualization::Categories::Enable(ConstString("default"), TypeCategoryMap::First);
2458 uint32_t num_categories = DataVisualization::Categories::GetCount();
2459 for (uint32_t i = 0; i < num_categories; i++)
2461 lldb::TypeCategoryImplSP category_sp = DataVisualization::Categories::GetCategoryAtIndex(i);
2464 if ( ::strcmp(category_sp->GetName(), "system") == 0 ||
2465 ::strcmp(category_sp->GetName(), "default") == 0 )
2468 DataVisualization::Categories::Enable(category_sp, TypeCategoryMap::Default);
2471 DataVisualization::Categories::Enable(ConstString("system"), TypeCategoryMap::Last);
2475 for (int i = argc - 1; i >= 0; i--)
2477 const char* typeA = command.GetArgumentAtIndex(i);
2478 ConstString typeCS(typeA);
2482 result.AppendError("empty category name not allowed");
2483 result.SetStatus(eReturnStatusFailed);
2486 DataVisualization::Categories::Enable(typeCS);
2487 lldb::TypeCategoryImplSP cate;
2488 if (DataVisualization::Categories::GetCategory(typeCS, cate) && cate.get())
2490 if (cate->GetCount() == 0)
2492 result.AppendWarning("empty category enabled (typo?)");
2498 result.SetStatus(eReturnStatusSuccessFinishResult);
2499 return result.Succeeded();
2504 //-------------------------------------------------------------------------
2505 // CommandObjectTypeCategoryDelete
2506 //-------------------------------------------------------------------------
2508 class CommandObjectTypeCategoryDelete : public CommandObjectParsed
2511 CommandObjectTypeCategoryDelete (CommandInterpreter &interpreter) :
2512 CommandObjectParsed (interpreter,
2513 "type category delete",
2514 "Delete a category and all associated formatters.",
2517 CommandArgumentEntry type_arg;
2518 CommandArgumentData type_style_arg;
2520 type_style_arg.arg_type = eArgTypeName;
2521 type_style_arg.arg_repetition = eArgRepeatPlus;
2523 type_arg.push_back (type_style_arg);
2525 m_arguments.push_back (type_arg);
2529 ~CommandObjectTypeCategoryDelete ()
2535 DoExecute (Args& command, CommandReturnObject &result)
2537 const size_t argc = command.GetArgumentCount();
2541 result.AppendErrorWithFormat ("%s takes 1 or more arg.\n", m_cmd_name.c_str());
2542 result.SetStatus(eReturnStatusFailed);
2546 bool success = true;
2548 // the order is not relevant here
2549 for (int i = argc - 1; i >= 0; i--)
2551 const char* typeA = command.GetArgumentAtIndex(i);
2552 ConstString typeCS(typeA);
2556 result.AppendError("empty category name not allowed");
2557 result.SetStatus(eReturnStatusFailed);
2560 if (!DataVisualization::Categories::Delete(typeCS))
2561 success = false; // keep deleting even if we hit an error
2565 result.SetStatus(eReturnStatusSuccessFinishResult);
2566 return result.Succeeded();
2570 result.AppendError("cannot delete one or more categories\n");
2571 result.SetStatus(eReturnStatusFailed);
2577 //-------------------------------------------------------------------------
2578 // CommandObjectTypeCategoryDisable
2579 //-------------------------------------------------------------------------
2581 class CommandObjectTypeCategoryDisable : public CommandObjectParsed
2584 CommandObjectTypeCategoryDisable (CommandInterpreter &interpreter) :
2585 CommandObjectParsed (interpreter,
2586 "type category disable",
2587 "Disable a category as a source of formatters.",
2590 CommandArgumentEntry type_arg;
2591 CommandArgumentData type_style_arg;
2593 type_style_arg.arg_type = eArgTypeName;
2594 type_style_arg.arg_repetition = eArgRepeatPlus;
2596 type_arg.push_back (type_style_arg);
2598 m_arguments.push_back (type_arg);
2602 ~CommandObjectTypeCategoryDisable ()
2608 DoExecute (Args& command, CommandReturnObject &result)
2610 const size_t argc = command.GetArgumentCount();
2614 result.AppendErrorWithFormat ("%s takes 1 or more args.\n", m_cmd_name.c_str());
2615 result.SetStatus(eReturnStatusFailed);
2619 if (argc == 1 && strcmp(command.GetArgumentAtIndex(0),"*") == 0)
2621 uint32_t num_categories = DataVisualization::Categories::GetCount();
2622 for (uint32_t i = 0; i < num_categories; i++)
2624 lldb::TypeCategoryImplSP category_sp = DataVisualization::Categories::GetCategoryAtIndex(i);
2625 // no need to check if the category is enabled - disabling a disabled category has no effect
2627 DataVisualization::Categories::Disable(category_sp);
2632 // the order is not relevant here
2633 for (int i = argc - 1; i >= 0; i--)
2635 const char* typeA = command.GetArgumentAtIndex(i);
2636 ConstString typeCS(typeA);
2640 result.AppendError("empty category name not allowed");
2641 result.SetStatus(eReturnStatusFailed);
2644 DataVisualization::Categories::Disable(typeCS);
2648 result.SetStatus(eReturnStatusSuccessFinishResult);
2649 return result.Succeeded();
2654 //-------------------------------------------------------------------------
2655 // CommandObjectTypeCategoryList
2656 //-------------------------------------------------------------------------
2658 class CommandObjectTypeCategoryList : public CommandObjectParsed
2662 struct CommandObjectTypeCategoryList_CallbackParam
2664 CommandReturnObject* result;
2665 RegularExpression* regex;
2667 CommandObjectTypeCategoryList_CallbackParam(CommandReturnObject* res,
2668 RegularExpression* rex = NULL) :
2677 PerCategoryCallback(void* param_vp,
2678 const lldb::TypeCategoryImplSP& cate)
2680 CommandObjectTypeCategoryList_CallbackParam* param =
2681 (CommandObjectTypeCategoryList_CallbackParam*)param_vp;
2682 CommandReturnObject* result = param->result;
2683 RegularExpression* regex = param->regex;
2685 const char* cate_name = cate->GetName();
2687 if (regex == NULL || strcmp(cate_name, regex->GetText()) == 0 || regex->Execute(cate_name))
2688 result->GetOutputStream().Printf("Category %s is%s enabled\n",
2690 (cate->IsEnabled() ? "" : " not"));
2694 CommandObjectTypeCategoryList (CommandInterpreter &interpreter) :
2695 CommandObjectParsed (interpreter,
2696 "type category list",
2697 "Provide a list of all existing categories.",
2700 CommandArgumentEntry type_arg;
2701 CommandArgumentData type_style_arg;
2703 type_style_arg.arg_type = eArgTypeName;
2704 type_style_arg.arg_repetition = eArgRepeatOptional;
2706 type_arg.push_back (type_style_arg);
2708 m_arguments.push_back (type_arg);
2711 ~CommandObjectTypeCategoryList ()
2717 DoExecute (Args& command, CommandReturnObject &result)
2719 const size_t argc = command.GetArgumentCount();
2720 RegularExpression* regex = NULL;
2725 regex = new RegularExpression(command.GetArgumentAtIndex(0));
2728 result.AppendErrorWithFormat ("%s takes 0 or one arg.\n", m_cmd_name.c_str());
2729 result.SetStatus(eReturnStatusFailed);
2733 CommandObjectTypeCategoryList_CallbackParam param(&result,
2736 DataVisualization::Categories::LoopThrough(PerCategoryCallback, ¶m);
2741 result.SetStatus(eReturnStatusSuccessFinishResult);
2742 return result.Succeeded();
2747 //-------------------------------------------------------------------------
2748 // CommandObjectTypeFilterList
2749 //-------------------------------------------------------------------------
2751 bool CommandObjectTypeFilterList_LoopCallback(void* pt2self, ConstString type, const SyntheticChildren::SharedPointer& entry);
2752 bool CommandObjectTypeFilterRXList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const SyntheticChildren::SharedPointer& entry);
2754 class CommandObjectTypeFilterList;
2756 struct CommandObjectTypeFilterList_LoopCallbackParam {
2757 CommandObjectTypeFilterList* self;
2758 CommandReturnObject* result;
2759 RegularExpression* regex;
2760 RegularExpression* cate_regex;
2761 CommandObjectTypeFilterList_LoopCallbackParam(CommandObjectTypeFilterList* S, CommandReturnObject* R,
2762 RegularExpression* X = NULL,
2763 RegularExpression* CX = NULL) : self(S), result(R), regex(X), cate_regex(CX) {}
2766 class CommandObjectTypeFilterList : public CommandObjectParsed
2769 class CommandOptions : public Options
2773 CommandOptions (CommandInterpreter &interpreter) :
2774 Options (interpreter)
2779 ~CommandOptions (){}
2782 SetOptionValue (uint32_t option_idx, const char *option_arg)
2785 const int short_option = m_getopt_table[option_idx].val;
2787 switch (short_option)
2790 m_category_regex = std::string(option_arg);
2793 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
2801 OptionParsingStarting ()
2803 m_category_regex = "";
2806 const OptionDefinition*
2809 return g_option_table;
2812 // Options table: Required for subclasses of Options.
2814 static OptionDefinition g_option_table[];
2816 // Instance variables to hold the values for command options.
2818 std::string m_category_regex;
2822 CommandOptions m_options;
2831 CommandObjectTypeFilterList (CommandInterpreter &interpreter) :
2832 CommandObjectParsed (interpreter,
2834 "Show a list of current filters.",
2836 m_options(interpreter)
2838 CommandArgumentEntry type_arg;
2839 CommandArgumentData type_style_arg;
2841 type_style_arg.arg_type = eArgTypeName;
2842 type_style_arg.arg_repetition = eArgRepeatOptional;
2844 type_arg.push_back (type_style_arg);
2846 m_arguments.push_back (type_arg);
2849 ~CommandObjectTypeFilterList ()
2855 DoExecute (Args& command, CommandReturnObject &result)
2857 const size_t argc = command.GetArgumentCount();
2859 CommandObjectTypeFilterList_LoopCallbackParam *param;
2860 RegularExpression* cate_regex =
2861 m_options.m_category_regex.empty() ? NULL :
2862 new RegularExpression(m_options.m_category_regex.c_str());
2866 RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
2867 regex->Compile(command.GetArgumentAtIndex(0));
2868 param = new CommandObjectTypeFilterList_LoopCallbackParam(this,&result,regex,cate_regex);
2871 param = new CommandObjectTypeFilterList_LoopCallbackParam(this,&result,NULL,cate_regex);
2873 DataVisualization::Categories::LoopThrough(PerCategoryCallback,param);
2879 result.SetStatus(eReturnStatusSuccessFinishResult);
2880 return result.Succeeded();
2886 PerCategoryCallback(void* param_vp,
2887 const lldb::TypeCategoryImplSP& cate)
2890 const char* cate_name = cate->GetName();
2892 CommandObjectTypeFilterList_LoopCallbackParam* param =
2893 (CommandObjectTypeFilterList_LoopCallbackParam*)param_vp;
2894 CommandReturnObject* result = param->result;
2896 // if the category is disabled or empty and there is no regex, just skip it
2897 if ((cate->IsEnabled() == false || cate->GetCount(eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter) == 0) && param->cate_regex == NULL)
2900 // if we have a regex and this category does not match it, just skip it
2901 if(param->cate_regex != NULL && strcmp(cate_name,param->cate_regex->GetText()) != 0 && param->cate_regex->Execute(cate_name) == false)
2904 result->GetOutputStream().Printf("-----------------------\nCategory: %s (%s)\n-----------------------\n",
2906 (cate->IsEnabled() ? "enabled" : "disabled"));
2908 cate->GetTypeFiltersContainer()->LoopThrough(CommandObjectTypeFilterList_LoopCallback, param_vp);
2910 if (cate->GetRegexTypeFiltersContainer()->GetCount() > 0)
2912 result->GetOutputStream().Printf("Regex-based filters (slower):\n");
2913 cate->GetRegexTypeFiltersContainer()->LoopThrough(CommandObjectTypeFilterRXList_LoopCallback, param_vp);
2920 LoopCallback (const char* type,
2921 const SyntheticChildren::SharedPointer& entry,
2922 RegularExpression* regex,
2923 CommandReturnObject *result)
2925 if (regex == NULL || regex->Execute(type))
2926 result->GetOutputStream().Printf ("%s: %s\n", type, entry->GetDescription().c_str());
2930 friend bool CommandObjectTypeFilterList_LoopCallback(void* pt2self, ConstString type, const SyntheticChildren::SharedPointer& entry);
2931 friend bool CommandObjectTypeFilterRXList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const SyntheticChildren::SharedPointer& entry);
2935 CommandObjectTypeFilterList_LoopCallback (void* pt2self,
2937 const SyntheticChildren::SharedPointer& entry)
2939 CommandObjectTypeFilterList_LoopCallbackParam* param = (CommandObjectTypeFilterList_LoopCallbackParam*)pt2self;
2940 return param->self->LoopCallback(type.AsCString(), entry, param->regex, param->result);
2944 CommandObjectTypeFilterRXList_LoopCallback (void* pt2self,
2945 lldb::RegularExpressionSP regex,
2946 const SyntheticChildren::SharedPointer& entry)
2948 CommandObjectTypeFilterList_LoopCallbackParam* param = (CommandObjectTypeFilterList_LoopCallbackParam*)pt2self;
2949 return param->self->LoopCallback(regex->GetText(), entry, param->regex, param->result);
2954 CommandObjectTypeFilterList::CommandOptions::g_option_table[] =
2956 { LLDB_OPT_SET_ALL, false, "category-regex", 'w', OptionParser::eRequiredArgument, NULL, 0, eArgTypeName, "Only show categories matching this filter."},
2957 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
2960 #ifndef LLDB_DISABLE_PYTHON
2962 //-------------------------------------------------------------------------
2963 // CommandObjectTypeSynthList
2964 //-------------------------------------------------------------------------
2966 bool CommandObjectTypeSynthList_LoopCallback(void* pt2self, ConstString type, const SyntheticChildren::SharedPointer& entry);
2967 bool CommandObjectTypeSynthRXList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const SyntheticChildren::SharedPointer& entry);
2969 class CommandObjectTypeSynthList;
2971 struct CommandObjectTypeSynthList_LoopCallbackParam {
2972 CommandObjectTypeSynthList* self;
2973 CommandReturnObject* result;
2974 RegularExpression* regex;
2975 RegularExpression* cate_regex;
2976 CommandObjectTypeSynthList_LoopCallbackParam(CommandObjectTypeSynthList* S, CommandReturnObject* R,
2977 RegularExpression* X = NULL,
2978 RegularExpression* CX = NULL) : self(S), result(R), regex(X), cate_regex(CX) {}
2981 class CommandObjectTypeSynthList : public CommandObjectParsed
2984 class CommandOptions : public Options
2988 CommandOptions (CommandInterpreter &interpreter) :
2989 Options (interpreter)
2994 ~CommandOptions (){}
2997 SetOptionValue (uint32_t option_idx, const char *option_arg)
3000 const int short_option = m_getopt_table[option_idx].val;
3002 switch (short_option)
3005 m_category_regex = std::string(option_arg);
3008 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
3016 OptionParsingStarting ()
3018 m_category_regex = "";
3021 const OptionDefinition*
3024 return g_option_table;
3027 // Options table: Required for subclasses of Options.
3029 static OptionDefinition g_option_table[];
3031 // Instance variables to hold the values for command options.
3033 std::string m_category_regex;
3037 CommandOptions m_options;
3046 CommandObjectTypeSynthList (CommandInterpreter &interpreter) :
3047 CommandObjectParsed (interpreter,
3048 "type synthetic list",
3049 "Show a list of current synthetic providers.",
3051 m_options(interpreter)
3053 CommandArgumentEntry type_arg;
3054 CommandArgumentData type_style_arg;
3056 type_style_arg.arg_type = eArgTypeName;
3057 type_style_arg.arg_repetition = eArgRepeatOptional;
3059 type_arg.push_back (type_style_arg);
3061 m_arguments.push_back (type_arg);
3064 ~CommandObjectTypeSynthList ()
3070 DoExecute (Args& command, CommandReturnObject &result)
3072 const size_t argc = command.GetArgumentCount();
3074 CommandObjectTypeSynthList_LoopCallbackParam *param;
3075 RegularExpression* cate_regex =
3076 m_options.m_category_regex.empty() ? NULL :
3077 new RegularExpression(m_options.m_category_regex.c_str());
3081 RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
3082 regex->Compile(command.GetArgumentAtIndex(0));
3083 param = new CommandObjectTypeSynthList_LoopCallbackParam(this,&result,regex,cate_regex);
3086 param = new CommandObjectTypeSynthList_LoopCallbackParam(this,&result,NULL,cate_regex);
3088 DataVisualization::Categories::LoopThrough(PerCategoryCallback,param);
3094 result.SetStatus(eReturnStatusSuccessFinishResult);
3095 return result.Succeeded();
3101 PerCategoryCallback(void* param_vp,
3102 const lldb::TypeCategoryImplSP& cate)
3105 CommandObjectTypeSynthList_LoopCallbackParam* param =
3106 (CommandObjectTypeSynthList_LoopCallbackParam*)param_vp;
3107 CommandReturnObject* result = param->result;
3109 const char* cate_name = cate->GetName();
3111 // if the category is disabled or empty and there is no regex, just skip it
3112 if ((cate->IsEnabled() == false || cate->GetCount(eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth) == 0) && param->cate_regex == NULL)
3115 // if we have a regex and this category does not match it, just skip it
3116 if(param->cate_regex != NULL && strcmp(cate_name,param->cate_regex->GetText()) != 0 && param->cate_regex->Execute(cate_name) == false)
3119 result->GetOutputStream().Printf("-----------------------\nCategory: %s (%s)\n-----------------------\n",
3121 (cate->IsEnabled() ? "enabled" : "disabled"));
3123 cate->GetTypeSyntheticsContainer()->LoopThrough(CommandObjectTypeSynthList_LoopCallback, param_vp);
3125 if (cate->GetRegexTypeSyntheticsContainer()->GetCount() > 0)
3127 result->GetOutputStream().Printf("Regex-based synthetic providers (slower):\n");
3128 cate->GetRegexTypeSyntheticsContainer()->LoopThrough(CommandObjectTypeSynthRXList_LoopCallback, param_vp);
3135 LoopCallback (const char* type,
3136 const SyntheticChildren::SharedPointer& entry,
3137 RegularExpression* regex,
3138 CommandReturnObject *result)
3140 if (regex == NULL || regex->Execute(type))
3141 result->GetOutputStream().Printf ("%s: %s\n", type, entry->GetDescription().c_str());
3145 friend bool CommandObjectTypeSynthList_LoopCallback(void* pt2self, ConstString type, const SyntheticChildren::SharedPointer& entry);
3146 friend bool CommandObjectTypeSynthRXList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const SyntheticChildren::SharedPointer& entry);
3150 CommandObjectTypeSynthList_LoopCallback (void* pt2self,
3152 const SyntheticChildren::SharedPointer& entry)
3154 CommandObjectTypeSynthList_LoopCallbackParam* param = (CommandObjectTypeSynthList_LoopCallbackParam*)pt2self;
3155 return param->self->LoopCallback(type.AsCString(), entry, param->regex, param->result);
3159 CommandObjectTypeSynthRXList_LoopCallback (void* pt2self,
3160 lldb::RegularExpressionSP regex,
3161 const SyntheticChildren::SharedPointer& entry)
3163 CommandObjectTypeSynthList_LoopCallbackParam* param = (CommandObjectTypeSynthList_LoopCallbackParam*)pt2self;
3164 return param->self->LoopCallback(regex->GetText(), entry, param->regex, param->result);
3169 CommandObjectTypeSynthList::CommandOptions::g_option_table[] =
3171 { LLDB_OPT_SET_ALL, false, "category-regex", 'w', OptionParser::eRequiredArgument, NULL, 0, eArgTypeName, "Only show categories matching this filter."},
3172 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
3175 #endif // #ifndef LLDB_DISABLE_PYTHON
3176 //-------------------------------------------------------------------------
3177 // CommandObjectTypeFilterDelete
3178 //-------------------------------------------------------------------------
3180 class CommandObjectTypeFilterDelete : public CommandObjectParsed
3183 class CommandOptions : public Options
3187 CommandOptions (CommandInterpreter &interpreter) :
3188 Options (interpreter)
3193 ~CommandOptions (){}
3196 SetOptionValue (uint32_t option_idx, const char *option_arg)
3199 const int short_option = m_getopt_table[option_idx].val;
3201 switch (short_option)
3204 m_delete_all = true;
3207 m_category = std::string(option_arg);
3210 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
3218 OptionParsingStarting ()
3220 m_delete_all = false;
3221 m_category = "default";
3224 const OptionDefinition*
3227 return g_option_table;
3230 // Options table: Required for subclasses of Options.
3232 static OptionDefinition g_option_table[];
3234 // Instance variables to hold the values for command options.
3237 std::string m_category;
3241 CommandOptions m_options;
3250 PerCategoryCallback(void* param,
3251 const lldb::TypeCategoryImplSP& cate)
3253 ConstString *name = (ConstString*)param;
3254 return cate->Delete(*name, eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter);
3258 CommandObjectTypeFilterDelete (CommandInterpreter &interpreter) :
3259 CommandObjectParsed (interpreter,
3260 "type filter delete",
3261 "Delete an existing filter for a type.",
3263 m_options(interpreter)
3265 CommandArgumentEntry type_arg;
3266 CommandArgumentData type_style_arg;
3268 type_style_arg.arg_type = eArgTypeName;
3269 type_style_arg.arg_repetition = eArgRepeatPlain;
3271 type_arg.push_back (type_style_arg);
3273 m_arguments.push_back (type_arg);
3277 ~CommandObjectTypeFilterDelete ()
3283 DoExecute (Args& command, CommandReturnObject &result)
3285 const size_t argc = command.GetArgumentCount();
3289 result.AppendErrorWithFormat ("%s takes 1 arg.\n", m_cmd_name.c_str());
3290 result.SetStatus(eReturnStatusFailed);
3294 const char* typeA = command.GetArgumentAtIndex(0);
3295 ConstString typeCS(typeA);
3299 result.AppendError("empty typenames not allowed");
3300 result.SetStatus(eReturnStatusFailed);
3304 if (m_options.m_delete_all)
3306 DataVisualization::Categories::LoopThrough(PerCategoryCallback, (void*)&typeCS);
3307 result.SetStatus(eReturnStatusSuccessFinishNoResult);
3308 return result.Succeeded();
3311 lldb::TypeCategoryImplSP category;
3312 DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
3314 bool delete_category = category->GetTypeFiltersContainer()->Delete(typeCS);
3315 delete_category = category->GetRegexTypeFiltersContainer()->Delete(typeCS) || delete_category;
3317 if (delete_category)
3319 result.SetStatus(eReturnStatusSuccessFinishNoResult);
3320 return result.Succeeded();
3324 result.AppendErrorWithFormat ("no custom synthetic provider for %s.\n", typeA);
3325 result.SetStatus(eReturnStatusFailed);
3333 CommandObjectTypeFilterDelete::CommandOptions::g_option_table[] =
3335 { LLDB_OPT_SET_1, false, "all", 'a', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Delete from every category."},
3336 { LLDB_OPT_SET_2, false, "category", 'w', OptionParser::eRequiredArgument, NULL, 0, eArgTypeName, "Delete from given category."},
3337 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
3340 #ifndef LLDB_DISABLE_PYTHON
3342 //-------------------------------------------------------------------------
3343 // CommandObjectTypeSynthDelete
3344 //-------------------------------------------------------------------------
3346 class CommandObjectTypeSynthDelete : public CommandObjectParsed
3349 class CommandOptions : public Options
3353 CommandOptions (CommandInterpreter &interpreter) :
3354 Options (interpreter)
3359 ~CommandOptions (){}
3362 SetOptionValue (uint32_t option_idx, const char *option_arg)
3365 const int short_option = m_getopt_table[option_idx].val;
3367 switch (short_option)
3370 m_delete_all = true;
3373 m_category = std::string(option_arg);
3376 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
3384 OptionParsingStarting ()
3386 m_delete_all = false;
3387 m_category = "default";
3390 const OptionDefinition*
3393 return g_option_table;
3396 // Options table: Required for subclasses of Options.
3398 static OptionDefinition g_option_table[];
3400 // Instance variables to hold the values for command options.
3403 std::string m_category;
3407 CommandOptions m_options;
3416 PerCategoryCallback(void* param,
3417 const lldb::TypeCategoryImplSP& cate)
3419 ConstString* name = (ConstString*)param;
3420 return cate->Delete(*name, eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth);
3424 CommandObjectTypeSynthDelete (CommandInterpreter &interpreter) :
3425 CommandObjectParsed (interpreter,
3426 "type synthetic delete",
3427 "Delete an existing synthetic provider for a type.",
3429 m_options(interpreter)
3431 CommandArgumentEntry type_arg;
3432 CommandArgumentData type_style_arg;
3434 type_style_arg.arg_type = eArgTypeName;
3435 type_style_arg.arg_repetition = eArgRepeatPlain;
3437 type_arg.push_back (type_style_arg);
3439 m_arguments.push_back (type_arg);
3443 ~CommandObjectTypeSynthDelete ()
3449 DoExecute (Args& command, CommandReturnObject &result)
3451 const size_t argc = command.GetArgumentCount();
3455 result.AppendErrorWithFormat ("%s takes 1 arg.\n", m_cmd_name.c_str());
3456 result.SetStatus(eReturnStatusFailed);
3460 const char* typeA = command.GetArgumentAtIndex(0);
3461 ConstString typeCS(typeA);
3465 result.AppendError("empty typenames not allowed");
3466 result.SetStatus(eReturnStatusFailed);
3470 if (m_options.m_delete_all)
3472 DataVisualization::Categories::LoopThrough(PerCategoryCallback, (void*)&typeCS);
3473 result.SetStatus(eReturnStatusSuccessFinishNoResult);
3474 return result.Succeeded();
3477 lldb::TypeCategoryImplSP category;
3478 DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
3480 bool delete_category = category->GetTypeSyntheticsContainer()->Delete(typeCS);
3481 delete_category = category->GetRegexTypeSyntheticsContainer()->Delete(typeCS) || delete_category;
3483 if (delete_category)
3485 result.SetStatus(eReturnStatusSuccessFinishNoResult);
3486 return result.Succeeded();
3490 result.AppendErrorWithFormat ("no custom synthetic provider for %s.\n", typeA);
3491 result.SetStatus(eReturnStatusFailed);
3499 CommandObjectTypeSynthDelete::CommandOptions::g_option_table[] =
3501 { LLDB_OPT_SET_1, false, "all", 'a', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Delete from every category."},
3502 { LLDB_OPT_SET_2, false, "category", 'w', OptionParser::eRequiredArgument, NULL, 0, eArgTypeName, "Delete from given category."},
3503 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
3506 #endif // #ifndef LLDB_DISABLE_PYTHON
3508 //-------------------------------------------------------------------------
3509 // CommandObjectTypeFilterClear
3510 //-------------------------------------------------------------------------
3512 class CommandObjectTypeFilterClear : public CommandObjectParsed
3516 class CommandOptions : public Options
3520 CommandOptions (CommandInterpreter &interpreter) :
3521 Options (interpreter)
3526 ~CommandOptions (){}
3529 SetOptionValue (uint32_t option_idx, const char *option_arg)
3532 const int short_option = m_getopt_table[option_idx].val;
3534 switch (short_option)
3537 m_delete_all = true;
3540 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
3548 OptionParsingStarting ()
3550 m_delete_all = false;
3553 const OptionDefinition*
3556 return g_option_table;
3559 // Options table: Required for subclasses of Options.
3561 static OptionDefinition g_option_table[];
3563 // Instance variables to hold the values for command options.
3566 bool m_delete_named;
3569 CommandOptions m_options;
3578 PerCategoryCallback(void* param,
3579 const lldb::TypeCategoryImplSP& cate)
3581 cate->Clear(eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter);
3587 CommandObjectTypeFilterClear (CommandInterpreter &interpreter) :
3588 CommandObjectParsed (interpreter,
3589 "type filter clear",
3590 "Delete all existing filters.",
3592 m_options(interpreter)
3596 ~CommandObjectTypeFilterClear ()
3602 DoExecute (Args& command, CommandReturnObject &result)
3605 if (m_options.m_delete_all)
3606 DataVisualization::Categories::LoopThrough(PerCategoryCallback, NULL);
3610 lldb::TypeCategoryImplSP category;
3611 if (command.GetArgumentCount() > 0)
3613 const char* cat_name = command.GetArgumentAtIndex(0);
3614 ConstString cat_nameCS(cat_name);
3615 DataVisualization::Categories::GetCategory(cat_nameCS, category);
3618 DataVisualization::Categories::GetCategory(ConstString(NULL), category);
3619 category->GetTypeFiltersContainer()->Clear();
3620 category->GetRegexTypeFiltersContainer()->Clear();
3623 result.SetStatus(eReturnStatusSuccessFinishResult);
3624 return result.Succeeded();
3630 CommandObjectTypeFilterClear::CommandOptions::g_option_table[] =
3632 { LLDB_OPT_SET_ALL, false, "all", 'a', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Clear every category."},
3633 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
3636 #ifndef LLDB_DISABLE_PYTHON
3637 //-------------------------------------------------------------------------
3638 // CommandObjectTypeSynthClear
3639 //-------------------------------------------------------------------------
3641 class CommandObjectTypeSynthClear : public CommandObjectParsed
3645 class CommandOptions : public Options
3649 CommandOptions (CommandInterpreter &interpreter) :
3650 Options (interpreter)
3655 ~CommandOptions (){}
3658 SetOptionValue (uint32_t option_idx, const char *option_arg)
3661 const int short_option = m_getopt_table[option_idx].val;
3663 switch (short_option)
3666 m_delete_all = true;
3669 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
3677 OptionParsingStarting ()
3679 m_delete_all = false;
3682 const OptionDefinition*
3685 return g_option_table;
3688 // Options table: Required for subclasses of Options.
3690 static OptionDefinition g_option_table[];
3692 // Instance variables to hold the values for command options.
3695 bool m_delete_named;
3698 CommandOptions m_options;
3707 PerCategoryCallback(void* param,
3708 const lldb::TypeCategoryImplSP& cate)
3710 cate->Clear(eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth);
3716 CommandObjectTypeSynthClear (CommandInterpreter &interpreter) :
3717 CommandObjectParsed (interpreter,
3718 "type synthetic clear",
3719 "Delete all existing synthetic providers.",
3721 m_options(interpreter)
3725 ~CommandObjectTypeSynthClear ()
3731 DoExecute (Args& command, CommandReturnObject &result)
3734 if (m_options.m_delete_all)
3735 DataVisualization::Categories::LoopThrough(PerCategoryCallback, NULL);
3739 lldb::TypeCategoryImplSP category;
3740 if (command.GetArgumentCount() > 0)
3742 const char* cat_name = command.GetArgumentAtIndex(0);
3743 ConstString cat_nameCS(cat_name);
3744 DataVisualization::Categories::GetCategory(cat_nameCS, category);
3747 DataVisualization::Categories::GetCategory(ConstString(NULL), category);
3748 category->GetTypeSyntheticsContainer()->Clear();
3749 category->GetRegexTypeSyntheticsContainer()->Clear();
3752 result.SetStatus(eReturnStatusSuccessFinishResult);
3753 return result.Succeeded();
3759 CommandObjectTypeSynthClear::CommandOptions::g_option_table[] =
3761 { LLDB_OPT_SET_ALL, false, "all", 'a', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Clear every category."},
3762 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
3767 CommandObjectTypeSynthAdd::Execute_HandwritePython (Args& command, CommandReturnObject &result)
3769 SynthAddOptions *options = new SynthAddOptions ( m_options.m_skip_pointers,
3770 m_options.m_skip_references,
3771 m_options.m_cascade,
3773 m_options.m_category);
3775 const size_t argc = command.GetArgumentCount();
3777 for (size_t i = 0; i < argc; i++)
3779 const char* typeA = command.GetArgumentAtIndex(i);
3780 if (typeA && *typeA)
3781 options->m_target_types << typeA;
3784 result.AppendError("empty typenames not allowed");
3785 result.SetStatus(eReturnStatusFailed);
3790 m_interpreter.GetPythonCommandsFromIOHandler (" ", // Prompt
3791 *this, // IOHandlerDelegate
3792 true, // Run IOHandler in async mode
3793 options); // Baton for the "io_handler" that will be passed back into our IOHandlerDelegate functions
3794 result.SetStatus(eReturnStatusSuccessFinishNoResult);
3795 return result.Succeeded();
3799 CommandObjectTypeSynthAdd::Execute_PythonClass (Args& command, CommandReturnObject &result)
3801 const size_t argc = command.GetArgumentCount();
3805 result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
3806 result.SetStatus(eReturnStatusFailed);
3810 if (m_options.m_class_name.empty() && !m_options.m_input_python)
3812 result.AppendErrorWithFormat ("%s needs either a Python class name or -P to directly input Python code.\n", m_cmd_name.c_str());
3813 result.SetStatus(eReturnStatusFailed);
3817 SyntheticChildrenSP entry;
3819 ScriptedSyntheticChildren* impl = new ScriptedSyntheticChildren(SyntheticChildren::Flags().
3820 SetCascades(m_options.m_cascade).
3821 SetSkipPointers(m_options.m_skip_pointers).
3822 SetSkipReferences(m_options.m_skip_references),
3823 m_options.m_class_name.c_str());
3827 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
3829 if (interpreter && interpreter->CheckObjectExists(impl->GetPythonClassName()) == false)
3830 result.AppendWarning("The provided class does not exist - please define it before attempting to use this synthetic provider");
3832 // now I have a valid provider, let's add it to every type
3834 lldb::TypeCategoryImplSP category;
3835 DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
3839 for (size_t i = 0; i < argc; i++)
3841 const char* typeA = command.GetArgumentAtIndex(i);
3842 ConstString typeCS(typeA);
3845 if (!AddSynth(typeCS,
3847 m_options.m_regex ? eRegexSynth : eRegularSynth,
3848 m_options.m_category,
3851 result.AppendError(error.AsCString());
3852 result.SetStatus(eReturnStatusFailed);
3858 result.AppendError("empty typenames not allowed");
3859 result.SetStatus(eReturnStatusFailed);
3864 result.SetStatus(eReturnStatusSuccessFinishNoResult);
3865 return result.Succeeded();
3868 CommandObjectTypeSynthAdd::CommandObjectTypeSynthAdd (CommandInterpreter &interpreter) :
3869 CommandObjectParsed (interpreter,
3870 "type synthetic add",
3871 "Add a new synthetic provider for a type.",
3873 IOHandlerDelegateMultiline ("DONE"),
3874 m_options (interpreter)
3876 CommandArgumentEntry type_arg;
3877 CommandArgumentData type_style_arg;
3879 type_style_arg.arg_type = eArgTypeName;
3880 type_style_arg.arg_repetition = eArgRepeatPlus;
3882 type_arg.push_back (type_style_arg);
3884 m_arguments.push_back (type_arg);
3889 CommandObjectTypeSynthAdd::AddSynth(ConstString type_name,
3890 SyntheticChildrenSP entry,
3891 SynthFormatType type,
3892 std::string category_name,
3895 lldb::TypeCategoryImplSP category;
3896 DataVisualization::Categories::GetCategory(ConstString(category_name.c_str()), category);
3898 if (type == eRegularSynth)
3900 std::string type_name_str(type_name.GetCString());
3901 if (type_name_str.compare(type_name_str.length() - 2, 2, "[]") == 0)
3903 type_name_str.resize(type_name_str.length()-2);
3904 if (type_name_str.back() != ' ')
3905 type_name_str.append(" \\[[0-9]+\\]");
3907 type_name_str.append("\\[[0-9]+\\]");
3908 type_name.SetCString(type_name_str.c_str());
3909 type = eRegularSynth;
3913 if (category->AnyMatches(type_name,
3914 eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter,
3918 error->SetErrorStringWithFormat("cannot add synthetic for type %s when filter is defined in same category!", type_name.AsCString());
3922 if (type == eRegexSynth)
3924 RegularExpressionSP typeRX(new RegularExpression());
3925 if (!typeRX->Compile(type_name.GetCString()))
3928 error->SetErrorString("regex format error (maybe this is not really a regex?)");
3932 category->GetRegexTypeSyntheticsContainer()->Delete(type_name);
3933 category->GetRegexTypeSyntheticsContainer()->Add(typeRX, entry);
3939 category->GetTypeSyntheticsContainer()->Add(type_name, entry);
3945 CommandObjectTypeSynthAdd::CommandOptions::g_option_table[] =
3947 { LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, NULL, 0, eArgTypeBoolean, "If true, cascade through typedef chains."},
3948 { LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."},
3949 { LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Don't use this format for references-to-type objects."},
3950 { LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, NULL, 0, eArgTypeName, "Add this to the given category instead of the default one."},
3951 { LLDB_OPT_SET_2, false, "python-class", 'l', OptionParser::eRequiredArgument, NULL, 0, eArgTypePythonClass, "Use this Python class to produce synthetic children."},
3952 { LLDB_OPT_SET_3, false, "input-python", 'P', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Type Python code to generate a class that provides synthetic children."},
3953 { LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Type names are actually regular expressions."},
3954 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
3957 #endif // #ifndef LLDB_DISABLE_PYTHON
3959 class CommandObjectTypeFilterAdd : public CommandObjectParsed
3964 class CommandOptions : public Options
3966 typedef std::vector<std::string> option_vector;
3969 CommandOptions (CommandInterpreter &interpreter) :
3970 Options (interpreter)
3975 ~CommandOptions (){}
3978 SetOptionValue (uint32_t option_idx, const char *option_arg)
3981 const int short_option = m_getopt_table[option_idx].val;
3984 switch (short_option)
3987 m_cascade = Args::StringToBoolean(option_arg, true, &success);
3989 error.SetErrorStringWithFormat("invalid value for cascade: %s", option_arg);
3992 m_expr_paths.push_back(option_arg);
3993 has_child_list = true;
3996 m_skip_pointers = true;
3999 m_skip_references = true;
4002 m_category = std::string(option_arg);
4008 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
4016 OptionParsingStarting ()
4019 m_skip_pointers = false;
4020 m_skip_references = false;
4021 m_category = "default";
4022 m_expr_paths.clear();
4023 has_child_list = false;
4027 const OptionDefinition*
4030 return g_option_table;
4033 // Options table: Required for subclasses of Options.
4035 static OptionDefinition g_option_table[];
4037 // Instance variables to hold the values for command options.
4040 bool m_skip_references;
4041 bool m_skip_pointers;
4042 bool m_input_python;
4043 option_vector m_expr_paths;
4044 std::string m_category;
4046 bool has_child_list;
4050 typedef option_vector::iterator ExpressionPathsIterator;
4053 CommandOptions m_options;
4061 enum FilterFormatType
4068 AddFilter(ConstString type_name,
4069 SyntheticChildrenSP entry,
4070 FilterFormatType type,
4071 std::string category_name,
4074 lldb::TypeCategoryImplSP category;
4075 DataVisualization::Categories::GetCategory(ConstString(category_name.c_str()), category);
4077 if (type == eRegularFilter)
4079 std::string type_name_str(type_name.GetCString());
4080 if (type_name_str.compare(type_name_str.length() - 2, 2, "[]") == 0)
4082 type_name_str.resize(type_name_str.length()-2);
4083 if (type_name_str.back() != ' ')
4084 type_name_str.append(" \\[[0-9]+\\]");
4086 type_name_str.append("\\[[0-9]+\\]");
4087 type_name.SetCString(type_name_str.c_str());
4088 type = eRegexFilter;
4092 if (category->AnyMatches(type_name,
4093 eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth,
4097 error->SetErrorStringWithFormat("cannot add filter for type %s when synthetic is defined in same category!", type_name.AsCString());
4101 if (type == eRegexFilter)
4103 RegularExpressionSP typeRX(new RegularExpression());
4104 if (!typeRX->Compile(type_name.GetCString()))
4107 error->SetErrorString("regex format error (maybe this is not really a regex?)");
4111 category->GetRegexTypeFiltersContainer()->Delete(type_name);
4112 category->GetRegexTypeFiltersContainer()->Add(typeRX, entry);
4118 category->GetTypeFiltersContainer()->Add(type_name, entry);
4126 CommandObjectTypeFilterAdd (CommandInterpreter &interpreter) :
4127 CommandObjectParsed (interpreter,
4129 "Add a new filter for a type.",
4131 m_options (interpreter)
4133 CommandArgumentEntry type_arg;
4134 CommandArgumentData type_style_arg;
4136 type_style_arg.arg_type = eArgTypeName;
4137 type_style_arg.arg_repetition = eArgRepeatPlus;
4139 type_arg.push_back (type_style_arg);
4141 m_arguments.push_back (type_arg);
4144 "Some examples of using this command.\n"
4145 "We use as reference the following snippet of code:\n"
4159 "type filter add --child a --child g Foo\n"
4160 "frame variable a_foo\n"
4161 "will produce an output where only a and g are displayed\n"
4162 "Other children of a_foo (b,c,d,e,f,h and i) are available by asking for them, as in:\n"
4163 "frame variable a_foo.b a_foo.c ... a_foo.i\n"
4165 "Use option --raw to frame variable prevails on the filter\n"
4166 "frame variable a_foo --raw\n"
4167 "shows all the children of a_foo (a thru i) as if no filter was defined\n"
4171 ~CommandObjectTypeFilterAdd ()
4177 DoExecute (Args& command, CommandReturnObject &result)
4179 const size_t argc = command.GetArgumentCount();
4183 result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
4184 result.SetStatus(eReturnStatusFailed);
4188 if (m_options.m_expr_paths.size() == 0)
4190 result.AppendErrorWithFormat ("%s needs one or more children.\n", m_cmd_name.c_str());
4191 result.SetStatus(eReturnStatusFailed);
4195 SyntheticChildrenSP entry;
4197 TypeFilterImpl* impl = new TypeFilterImpl(SyntheticChildren::Flags().SetCascades(m_options.m_cascade).
4198 SetSkipPointers(m_options.m_skip_pointers).
4199 SetSkipReferences(m_options.m_skip_references));
4203 // go through the expression paths
4204 CommandOptions::ExpressionPathsIterator begin, end = m_options.m_expr_paths.end();
4206 for (begin = m_options.m_expr_paths.begin(); begin != end; begin++)
4207 impl->AddExpressionPath(*begin);
4210 // now I have a valid provider, let's add it to every type
4212 lldb::TypeCategoryImplSP category;
4213 DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
4217 WarnOnPotentialUnquotedUnsignedType(command, result);
4219 for (size_t i = 0; i < argc; i++)
4221 const char* typeA = command.GetArgumentAtIndex(i);
4222 ConstString typeCS(typeA);
4225 if (!AddFilter(typeCS,
4227 m_options.m_regex ? eRegexFilter : eRegularFilter,
4228 m_options.m_category,
4231 result.AppendError(error.AsCString());
4232 result.SetStatus(eReturnStatusFailed);
4238 result.AppendError("empty typenames not allowed");
4239 result.SetStatus(eReturnStatusFailed);
4244 result.SetStatus(eReturnStatusSuccessFinishNoResult);
4245 return result.Succeeded();
4251 CommandObjectTypeFilterAdd::CommandOptions::g_option_table[] =
4253 { LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, NULL, 0, eArgTypeBoolean, "If true, cascade through typedef chains."},
4254 { LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."},
4255 { LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Don't use this format for references-to-type objects."},
4256 { LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, NULL, 0, eArgTypeName, "Add this to the given category instead of the default one."},
4257 { LLDB_OPT_SET_ALL, false, "child", 'c', OptionParser::eRequiredArgument, NULL, 0, eArgTypeExpressionPath, "Include this expression path in the synthetic view."},
4258 { LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, NULL, 0, eArgTypeNone, "Type names are actually regular expressions."},
4259 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
4262 class CommandObjectTypeFormat : public CommandObjectMultiword
4265 CommandObjectTypeFormat (CommandInterpreter &interpreter) :
4266 CommandObjectMultiword (interpreter,
4268 "A set of commands for editing variable value display options",
4269 "type format [<sub-command-options>] ")
4271 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTypeFormatAdd (interpreter)));
4272 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTypeFormatClear (interpreter)));
4273 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeFormatDelete (interpreter)));
4274 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeFormatList (interpreter)));
4278 ~CommandObjectTypeFormat ()
4283 #ifndef LLDB_DISABLE_PYTHON
4285 class CommandObjectTypeSynth : public CommandObjectMultiword
4288 CommandObjectTypeSynth (CommandInterpreter &interpreter) :
4289 CommandObjectMultiword (interpreter,
4291 "A set of commands for operating on synthetic type representations",
4292 "type synthetic [<sub-command-options>] ")
4294 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTypeSynthAdd (interpreter)));
4295 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTypeSynthClear (interpreter)));
4296 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeSynthDelete (interpreter)));
4297 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeSynthList (interpreter)));
4301 ~CommandObjectTypeSynth ()
4306 #endif // #ifndef LLDB_DISABLE_PYTHON
4308 class CommandObjectTypeFilter : public CommandObjectMultiword
4311 CommandObjectTypeFilter (CommandInterpreter &interpreter) :
4312 CommandObjectMultiword (interpreter,
4314 "A set of commands for operating on type filters",
4315 "type synthetic [<sub-command-options>] ")
4317 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTypeFilterAdd (interpreter)));
4318 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTypeFilterClear (interpreter)));
4319 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeFilterDelete (interpreter)));
4320 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeFilterList (interpreter)));
4324 ~CommandObjectTypeFilter ()
4329 class CommandObjectTypeCategory : public CommandObjectMultiword
4332 CommandObjectTypeCategory (CommandInterpreter &interpreter) :
4333 CommandObjectMultiword (interpreter,
4335 "A set of commands for operating on categories",
4336 "type category [<sub-command-options>] ")
4338 LoadSubCommand ("enable", CommandObjectSP (new CommandObjectTypeCategoryEnable (interpreter)));
4339 LoadSubCommand ("disable", CommandObjectSP (new CommandObjectTypeCategoryDisable (interpreter)));
4340 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeCategoryDelete (interpreter)));
4341 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeCategoryList (interpreter)));
4345 ~CommandObjectTypeCategory ()
4350 class CommandObjectTypeSummary : public CommandObjectMultiword
4353 CommandObjectTypeSummary (CommandInterpreter &interpreter) :
4354 CommandObjectMultiword (interpreter,
4356 "A set of commands for editing variable summary display options",
4357 "type summary [<sub-command-options>] ")
4359 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTypeSummaryAdd (interpreter)));
4360 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTypeSummaryClear (interpreter)));
4361 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeSummaryDelete (interpreter)));
4362 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeSummaryList (interpreter)));
4366 ~CommandObjectTypeSummary ()
4371 //-------------------------------------------------------------------------
4372 // CommandObjectType
4373 //-------------------------------------------------------------------------
4375 CommandObjectType::CommandObjectType (CommandInterpreter &interpreter) :
4376 CommandObjectMultiword (interpreter,
4378 "A set of commands for operating on the type system",
4379 "type [<sub-command-options>]")
4381 LoadSubCommand ("category", CommandObjectSP (new CommandObjectTypeCategory (interpreter)));
4382 LoadSubCommand ("filter", CommandObjectSP (new CommandObjectTypeFilter (interpreter)));
4383 LoadSubCommand ("format", CommandObjectSP (new CommandObjectTypeFormat (interpreter)));
4384 LoadSubCommand ("summary", CommandObjectSP (new CommandObjectTypeSummary (interpreter)));
4385 #ifndef LLDB_DISABLE_PYTHON
4386 LoadSubCommand ("synthetic", CommandObjectSP (new CommandObjectTypeSynth (interpreter)));
4391 CommandObjectType::~CommandObjectType ()