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"
21 #include "llvm/ADT/StringRef.h"
23 #include "lldb/Core/ConstString.h"
24 #include "lldb/Core/Debugger.h"
25 #include "lldb/Core/IOHandler.h"
26 #include "lldb/Core/RegularExpression.h"
27 #include "lldb/Core/State.h"
28 #include "lldb/Core/StringList.h"
29 #include "lldb/DataFormatters/DataVisualization.h"
30 #include "lldb/Interpreter/CommandInterpreter.h"
31 #include "lldb/Interpreter/CommandObject.h"
32 #include "lldb/Interpreter/CommandReturnObject.h"
33 #include "lldb/Interpreter/Options.h"
34 #include "lldb/Interpreter/OptionGroupFormat.h"
35 #include "lldb/Target/Process.h"
36 #include "lldb/Target/StackFrame.h"
37 #include "lldb/Target/Target.h"
38 #include "lldb/Target/Thread.h"
39 #include "lldb/Target/ThreadList.h"
42 using namespace lldb_private;
45 class ScriptAddOptions
50 TypeSummaryImpl::Flags m_flags;
52 StringList m_target_types;
58 std::string m_category;
60 ScriptAddOptions(const TypeSummaryImpl::Flags& flags,
62 const ConstString& name,
71 typedef std::shared_ptr<ScriptAddOptions> SharedPointer;
81 bool m_skip_references;
84 StringList m_target_types;
86 std::string m_category;
88 SynthAddOptions(bool sptr,
93 m_skip_pointers(sptr),
94 m_skip_references(sref),
102 typedef std::shared_ptr<SynthAddOptions> SharedPointer;
107 WarnOnPotentialUnquotedUnsignedType (Args& command, CommandReturnObject &result)
109 for (unsigned idx = 0; idx < command.GetArgumentCount(); idx++)
111 const char* arg = command.GetArgumentAtIndex(idx);
112 if (idx+1 < command.GetArgumentCount())
114 if (arg && 0 == strcmp(arg,"unsigned"))
116 const char* next = command.GetArgumentAtIndex(idx+1);
118 (0 == strcmp(next, "int") ||
119 0 == strcmp(next, "short") ||
120 0 == strcmp(next, "char") ||
121 0 == strcmp(next, "long")))
123 result.AppendWarningWithFormat("%s %s being treated as two types. if you meant the combined type name use quotes, as in \"%s %s\"\n",
133 class CommandObjectTypeSummaryAdd :
134 public CommandObjectParsed,
135 public IOHandlerDelegateMultiline
140 class CommandOptions : public Options
144 CommandOptions (CommandInterpreter &interpreter) :
145 Options (interpreter)
153 SetOptionValue (uint32_t option_idx, const char *option_arg);
156 OptionParsingStarting ();
158 const OptionDefinition*
161 return g_option_table;
164 // Options table: Required for subclasses of Options.
166 static OptionDefinition g_option_table[];
168 // Instance variables to hold the values for command options.
170 TypeSummaryImpl::Flags m_flags;
172 std::string m_format_string;
174 std::string m_python_script;
175 std::string m_python_function;
176 bool m_is_add_script;
177 std::string m_category;
180 CommandOptions m_options;
189 Execute_ScriptSummary (Args& command, CommandReturnObject &result);
192 Execute_StringSummary (Args& command, CommandReturnObject &result);
196 enum SummaryFormatType
203 CommandObjectTypeSummaryAdd (CommandInterpreter &interpreter);
205 ~CommandObjectTypeSummaryAdd ()
210 IOHandlerActivated (IOHandler &io_handler)
212 static const char *g_summary_addreader_instructions = "Enter your Python command(s). Type 'DONE' to end.\n"
213 "def function (valobj,internal_dict):\n"
214 " \"\"\"valobj: an SBValue which you want to provide a summary for\n"
215 " internal_dict: an LLDB support object not to be used\"\"\"\n";
217 StreamFileSP output_sp(io_handler.GetOutputStreamFile());
220 output_sp->PutCString(g_summary_addreader_instructions);
227 IOHandlerInputComplete (IOHandler &io_handler, std::string &data)
229 StreamFileSP error_sp = io_handler.GetErrorStreamFile();
231 #ifndef LLDB_DISABLE_PYTHON
232 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
236 lines.SplitIntoLines(data);
237 if (lines.GetSize() > 0)
239 ScriptAddOptions *options_ptr = ((ScriptAddOptions*)io_handler.GetUserData());
242 ScriptAddOptions::SharedPointer options(options_ptr); // this will ensure that we get rid of the pointer when going out of scope
244 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
247 std::string funct_name_str;
248 if (interpreter->GenerateTypeScriptFunction (lines, funct_name_str))
250 if (funct_name_str.empty())
252 error_sp->Printf ("unable to obtain a valid function name from the script interpreter.\n");
257 // now I have a valid function name, let's add this as script for every type in the list
259 TypeSummaryImplSP script_format;
260 script_format.reset(new ScriptSummaryFormat(options->m_flags,
261 funct_name_str.c_str(),
262 lines.CopyList(" ").c_str()));
266 for (size_t i = 0; i < options->m_target_types.GetSize(); i++)
268 const char *type_name = options->m_target_types.GetStringAtIndex(i);
269 CommandObjectTypeSummaryAdd::AddSummary(ConstString(type_name),
271 (options->m_regex ? CommandObjectTypeSummaryAdd::eRegexSummary : CommandObjectTypeSummaryAdd::eRegularSummary),
276 error_sp->Printf ("error: %s", error.AsCString());
283 CommandObjectTypeSummaryAdd::AddSummary (options->m_name,
285 CommandObjectTypeSummaryAdd::eNamedSummary,
290 CommandObjectTypeSummaryAdd::AddSummary (options->m_name,
292 CommandObjectTypeSummaryAdd::eNamedSummary,
297 error_sp->Printf ("error: %s", error.AsCString());
303 error_sp->Printf ("error: %s", error.AsCString());
309 if (error.AsCString())
311 error_sp->Printf ("error: %s", error.AsCString());
319 error_sp->Printf ("error: unable to generate a function.\n");
325 error_sp->Printf ("error: no script interpreter.\n");
331 error_sp->Printf ("error: internal synchronization information missing or invalid.\n");
337 error_sp->Printf ("error: empty function, didn't add python command.\n");
343 error_sp->Printf ("error: script interpreter missing, didn't add python command.\n");
346 #endif // #ifndef LLDB_DISABLE_PYTHON
347 io_handler.SetIsDone(true);
351 AddSummary(ConstString type_name,
352 lldb::TypeSummaryImplSP entry,
353 SummaryFormatType type,
354 std::string category,
355 Error* error = NULL);
358 DoExecute (Args& command, CommandReturnObject &result);
362 static const char *g_synth_addreader_instructions = "Enter your Python command(s). Type 'DONE' to end.\n"
363 "You must define a Python class with these methods:\n"
364 " def __init__(self, valobj, dict):\n"
365 " def num_children(self):\n"
366 " def get_child_at_index(self, index):\n"
367 " def get_child_index(self, name):\n"
368 " def update(self):\n"
370 "class synthProvider:\n";
372 class CommandObjectTypeSynthAdd :
373 public CommandObjectParsed,
374 public IOHandlerDelegateMultiline
379 class CommandOptions : public Options
383 CommandOptions (CommandInterpreter &interpreter) :
384 Options (interpreter)
392 SetOptionValue (uint32_t option_idx, const char *option_arg)
395 const int short_option = m_getopt_table[option_idx].val;
398 switch (short_option)
401 m_cascade = Args::StringToBoolean(option_arg, true, &success);
403 error.SetErrorStringWithFormat("invalid value for cascade: %s", option_arg);
406 handwrite_python = true;
409 m_class_name = std::string(option_arg);
410 is_class_based = true;
413 m_skip_pointers = true;
416 m_skip_references = true;
419 m_category = std::string(option_arg);
425 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
433 OptionParsingStarting ()
437 m_skip_pointers = false;
438 m_skip_references = false;
439 m_category = "default";
440 is_class_based = false;
441 handwrite_python = false;
445 const OptionDefinition*
448 return g_option_table;
451 // Options table: Required for subclasses of Options.
453 static OptionDefinition g_option_table[];
455 // Instance variables to hold the values for command options.
458 bool m_skip_references;
459 bool m_skip_pointers;
460 std::string m_class_name;
462 std::string m_category;
466 bool handwrite_python;
472 CommandOptions m_options;
481 Execute_HandwritePython (Args& command, CommandReturnObject &result);
484 Execute_PythonClass (Args& command, CommandReturnObject &result);
488 DoExecute (Args& command, CommandReturnObject &result)
490 WarnOnPotentialUnquotedUnsignedType(command, result);
492 if (m_options.handwrite_python)
493 return Execute_HandwritePython(command, result);
494 else if (m_options.is_class_based)
495 return Execute_PythonClass(command, result);
498 result.AppendError("must either provide a children list, a Python class name, or use -P and type a Python class line-by-line");
499 result.SetStatus(eReturnStatusFailed);
505 IOHandlerActivated (IOHandler &io_handler)
507 StreamFileSP output_sp(io_handler.GetOutputStreamFile());
510 output_sp->PutCString(g_synth_addreader_instructions);
517 IOHandlerInputComplete (IOHandler &io_handler, std::string &data)
519 StreamFileSP error_sp = io_handler.GetErrorStreamFile();
521 #ifndef LLDB_DISABLE_PYTHON
522 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
526 lines.SplitIntoLines(data);
527 if (lines.GetSize() > 0)
529 SynthAddOptions *options_ptr = ((SynthAddOptions*)io_handler.GetUserData());
532 SynthAddOptions::SharedPointer options(options_ptr); // this will ensure that we get rid of the pointer when going out of scope
534 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
537 std::string class_name_str;
538 if (interpreter->GenerateTypeSynthClass (lines, class_name_str))
540 if (class_name_str.empty())
542 error_sp->Printf ("error: unable to obtain a proper name for the class.\n");
547 // everything should be fine now, let's add the synth provider class
549 SyntheticChildrenSP synth_provider;
550 synth_provider.reset(new ScriptedSyntheticChildren(SyntheticChildren::Flags().SetCascades(options->m_cascade).
551 SetSkipPointers(options->m_skip_pointers).
552 SetSkipReferences(options->m_skip_references),
553 class_name_str.c_str()));
556 lldb::TypeCategoryImplSP category;
557 DataVisualization::Categories::GetCategory(ConstString(options->m_category.c_str()), category);
561 for (size_t i = 0; i < options->m_target_types.GetSize(); i++)
563 const char *type_name = options->m_target_types.GetStringAtIndex(i);
564 ConstString const_type_name(type_name);
567 if (!CommandObjectTypeSynthAdd::AddSynth(const_type_name,
569 options->m_regex ? CommandObjectTypeSynthAdd::eRegexSynth : CommandObjectTypeSynthAdd::eRegularSynth,
573 error_sp->Printf("error: %s\n", error.AsCString());
580 error_sp->Printf ("error: invalid type name.\n");
589 error_sp->Printf ("error: unable to generate a class.\n");
595 error_sp->Printf ("error: no script interpreter.\n");
601 error_sp->Printf ("error: internal synchronization data missing.\n");
607 error_sp->Printf ("error: empty function, didn't add python command.\n");
613 error_sp->Printf ("error: script interpreter missing, didn't add python command.\n");
617 #endif // #ifndef LLDB_DISABLE_PYTHON
618 io_handler.SetIsDone(true);
629 CommandObjectTypeSynthAdd (CommandInterpreter &interpreter);
631 ~CommandObjectTypeSynthAdd ()
636 AddSynth(ConstString type_name,
637 lldb::SyntheticChildrenSP entry,
638 SynthFormatType type,
639 std::string category_name,
643 //-------------------------------------------------------------------------
644 // CommandObjectTypeFormatAdd
645 //-------------------------------------------------------------------------
647 class CommandObjectTypeFormatAdd : public CommandObjectParsed
652 class CommandOptions : public OptionGroup
667 GetNumDefinitions ();
669 virtual const OptionDefinition*
672 return g_option_table;
676 OptionParsingStarting (CommandInterpreter &interpreter)
679 m_skip_pointers = false;
680 m_skip_references = false;
682 m_category.assign("default");
683 m_custom_type_name.clear();
686 SetOptionValue (CommandInterpreter &interpreter,
688 const char *option_value)
691 const int short_option = g_option_table[option_idx].short_option;
694 switch (short_option)
697 m_cascade = Args::StringToBoolean(option_value, true, &success);
699 error.SetErrorStringWithFormat("invalid value for cascade: %s", option_value);
702 m_skip_pointers = true;
705 m_category.assign(option_value);
708 m_skip_references = true;
714 m_custom_type_name.assign(option_value);
717 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
724 // Options table: Required for subclasses of Options.
726 static OptionDefinition g_option_table[];
728 // Instance variables to hold the values for command options.
731 bool m_skip_references;
732 bool m_skip_pointers;
734 std::string m_category;
735 std::string m_custom_type_name;
738 OptionGroupOptions m_option_group;
739 OptionGroupFormat m_format_options;
740 CommandOptions m_command_options;
745 return &m_option_group;
749 CommandObjectTypeFormatAdd (CommandInterpreter &interpreter) :
750 CommandObjectParsed (interpreter,
752 "Add a new formatting style for a type.",
754 m_option_group (interpreter),
755 m_format_options (eFormatInvalid),
758 CommandArgumentEntry type_arg;
759 CommandArgumentData type_style_arg;
761 type_style_arg.arg_type = eArgTypeName;
762 type_style_arg.arg_repetition = eArgRepeatPlus;
764 type_arg.push_back (type_style_arg);
766 m_arguments.push_back (type_arg);
769 "Some examples of using this command.\n"
770 "We use as reference the following snippet of code:\n"
772 "typedef int Aint;\n"
773 "typedef float Afloat;\n"
774 "typedef Aint Bint;\n"
775 "typedef Afloat Bfloat;\n"
780 "Afloat fx = 3.14;\n"
781 "BFloat fy = 3.14;\n"
784 "type format add -f hex AInt\n"
785 "frame variable iy\n"
786 "will produce an hex display of iy, because no formatter is available for Bint and the one for Aint is used instead\n"
787 "To prevent this type\n"
788 "type format add -f hex -C no AInt\n"
790 "A similar reasoning applies to\n"
791 "type format add -f hex -C no float -p\n"
792 "which now prints all floats and float&s as hexadecimal, but does not format float*s\n"
793 "and does not change the default display for Afloat and Bfloat objects.\n"
796 // Add the "--format" to all options groups
797 m_option_group.Append (&m_format_options, OptionGroupFormat::OPTION_GROUP_FORMAT, LLDB_OPT_SET_1);
798 m_option_group.Append (&m_command_options);
799 m_option_group.Finalize();
803 ~CommandObjectTypeFormatAdd ()
809 DoExecute (Args& command, CommandReturnObject &result)
811 const size_t argc = command.GetArgumentCount();
815 result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
816 result.SetStatus(eReturnStatusFailed);
820 const Format format = m_format_options.GetFormat();
821 if (format == eFormatInvalid && m_command_options.m_custom_type_name.empty())
823 result.AppendErrorWithFormat ("%s needs a valid format.\n", m_cmd_name.c_str());
824 result.SetStatus(eReturnStatusFailed);
828 TypeFormatImplSP entry;
830 if (m_command_options.m_custom_type_name.empty())
831 entry.reset(new TypeFormatImpl_Format(format,
832 TypeFormatImpl::Flags().SetCascades(m_command_options.m_cascade).
833 SetSkipPointers(m_command_options.m_skip_pointers).
834 SetSkipReferences(m_command_options.m_skip_references)));
836 entry.reset(new TypeFormatImpl_EnumType(ConstString(m_command_options.m_custom_type_name.c_str()),
837 TypeFormatImpl::Flags().SetCascades(m_command_options.m_cascade).
838 SetSkipPointers(m_command_options.m_skip_pointers).
839 SetSkipReferences(m_command_options.m_skip_references)));
841 // now I have a valid format, let's add it to every type
843 TypeCategoryImplSP category_sp;
844 DataVisualization::Categories::GetCategory(ConstString(m_command_options.m_category), category_sp);
848 WarnOnPotentialUnquotedUnsignedType(command, result);
850 for (size_t i = 0; i < argc; i++)
852 const char* typeA = command.GetArgumentAtIndex(i);
853 ConstString typeCS(typeA);
856 if (m_command_options.m_regex)
858 RegularExpressionSP typeRX(new RegularExpression());
859 if (!typeRX->Compile(typeCS.GetCString()))
861 result.AppendError("regex format error (maybe this is not really a regex?)");
862 result.SetStatus(eReturnStatusFailed);
865 category_sp->GetRegexTypeSummariesContainer()->Delete(typeCS);
866 category_sp->GetRegexTypeFormatsContainer()->Add(typeRX, entry);
869 category_sp->GetTypeFormatsContainer()->Add(typeCS, entry);
873 result.AppendError("empty typenames not allowed");
874 result.SetStatus(eReturnStatusFailed);
879 result.SetStatus(eReturnStatusSuccessFinishNoResult);
880 return result.Succeeded();
885 CommandObjectTypeFormatAdd::CommandOptions::g_option_table[] =
887 { LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Add this to the given category instead of the default one."},
888 { LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "If true, cascade through typedef chains."},
889 { LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."},
890 { LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Don't use this format for references-to-type objects."},
891 { LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Type names are actually regular expressions."},
892 { LLDB_OPT_SET_2, false, "type", 't', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Format variables as if they were of this type."},
893 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
898 CommandObjectTypeFormatAdd::CommandOptions::GetNumDefinitions ()
900 return sizeof(g_option_table) / sizeof (OptionDefinition);
904 //-------------------------------------------------------------------------
905 // CommandObjectTypeFormatDelete
906 //-------------------------------------------------------------------------
908 class CommandObjectTypeFormatDelete : public CommandObjectParsed
911 class CommandOptions : public Options
915 CommandOptions (CommandInterpreter &interpreter) :
916 Options (interpreter)
924 SetOptionValue (uint32_t option_idx, const char *option_arg)
927 const int short_option = m_getopt_table[option_idx].val;
929 switch (short_option)
935 m_category = std::string(option_arg);
938 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
946 OptionParsingStarting ()
948 m_delete_all = false;
949 m_category = "default";
952 const OptionDefinition*
955 return g_option_table;
958 // Options table: Required for subclasses of Options.
960 static OptionDefinition g_option_table[];
962 // Instance variables to hold the values for command options.
965 std::string m_category;
969 CommandOptions m_options;
978 PerCategoryCallback(void* param,
979 const lldb::TypeCategoryImplSP& category_sp)
981 ConstString *name = (ConstString*)param;
982 category_sp->Delete(*name, eFormatCategoryItemValue | eFormatCategoryItemRegexValue);
987 CommandObjectTypeFormatDelete (CommandInterpreter &interpreter) :
988 CommandObjectParsed (interpreter,
989 "type format delete",
990 "Delete an existing formatting style for a type.",
992 m_options(interpreter)
994 CommandArgumentEntry type_arg;
995 CommandArgumentData type_style_arg;
997 type_style_arg.arg_type = eArgTypeName;
998 type_style_arg.arg_repetition = eArgRepeatPlain;
1000 type_arg.push_back (type_style_arg);
1002 m_arguments.push_back (type_arg);
1006 ~CommandObjectTypeFormatDelete ()
1012 DoExecute (Args& command, CommandReturnObject &result)
1014 const size_t argc = command.GetArgumentCount();
1018 result.AppendErrorWithFormat ("%s takes 1 arg.\n", m_cmd_name.c_str());
1019 result.SetStatus(eReturnStatusFailed);
1023 const char* typeA = command.GetArgumentAtIndex(0);
1024 ConstString typeCS(typeA);
1028 result.AppendError("empty typenames not allowed");
1029 result.SetStatus(eReturnStatusFailed);
1033 if (m_options.m_delete_all)
1035 DataVisualization::Categories::LoopThrough(PerCategoryCallback, &typeCS);
1036 result.SetStatus(eReturnStatusSuccessFinishNoResult);
1037 return result.Succeeded();
1040 lldb::TypeCategoryImplSP category;
1041 DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
1043 bool delete_category = category->Delete(typeCS,
1044 eFormatCategoryItemValue | eFormatCategoryItemRegexValue);
1046 if (delete_category)
1048 result.SetStatus(eReturnStatusSuccessFinishNoResult);
1049 return result.Succeeded();
1053 result.AppendErrorWithFormat ("no custom format for %s.\n", typeA);
1054 result.SetStatus(eReturnStatusFailed);
1063 CommandObjectTypeFormatDelete::CommandOptions::g_option_table[] =
1065 { LLDB_OPT_SET_1, false, "all", 'a', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Delete from every category."},
1066 { LLDB_OPT_SET_2, false, "category", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Delete from given category."},
1067 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
1070 //-------------------------------------------------------------------------
1071 // CommandObjectTypeFormatClear
1072 //-------------------------------------------------------------------------
1074 class CommandObjectTypeFormatClear : public CommandObjectParsed
1078 class CommandOptions : public Options
1082 CommandOptions (CommandInterpreter &interpreter) :
1083 Options (interpreter)
1088 ~CommandOptions (){}
1091 SetOptionValue (uint32_t option_idx, const char *option_arg)
1094 const int short_option = m_getopt_table[option_idx].val;
1096 switch (short_option)
1099 m_delete_all = true;
1102 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1110 OptionParsingStarting ()
1112 m_delete_all = false;
1115 const OptionDefinition*
1118 return g_option_table;
1121 // Options table: Required for subclasses of Options.
1123 static OptionDefinition g_option_table[];
1125 // Instance variables to hold the values for command options.
1128 bool m_delete_named;
1131 CommandOptions m_options;
1140 PerCategoryCallback(void* param,
1141 const lldb::TypeCategoryImplSP& cate)
1143 cate->GetTypeFormatsContainer()->Clear();
1144 cate->GetRegexTypeFormatsContainer()->Clear();
1150 CommandObjectTypeFormatClear (CommandInterpreter &interpreter) :
1151 CommandObjectParsed (interpreter,
1152 "type format clear",
1153 "Delete all existing format styles.",
1155 m_options(interpreter)
1159 ~CommandObjectTypeFormatClear ()
1165 DoExecute (Args& command, CommandReturnObject &result)
1167 if (m_options.m_delete_all)
1168 DataVisualization::Categories::LoopThrough(PerCategoryCallback, NULL);
1172 lldb::TypeCategoryImplSP category;
1173 if (command.GetArgumentCount() > 0)
1175 const char* cat_name = command.GetArgumentAtIndex(0);
1176 ConstString cat_nameCS(cat_name);
1177 DataVisualization::Categories::GetCategory(cat_nameCS, category);
1180 DataVisualization::Categories::GetCategory(ConstString(NULL), category);
1181 category->Clear(eFormatCategoryItemValue | eFormatCategoryItemRegexValue);
1184 result.SetStatus(eReturnStatusSuccessFinishResult);
1185 return result.Succeeded();
1191 CommandObjectTypeFormatClear::CommandOptions::g_option_table[] =
1193 { LLDB_OPT_SET_ALL, false, "all", 'a', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Clear every category."},
1194 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
1197 //-------------------------------------------------------------------------
1198 // CommandObjectTypeFormatList
1199 //-------------------------------------------------------------------------
1201 bool CommandObjectTypeFormatList_LoopCallback(void* pt2self, ConstString type, const lldb::TypeFormatImplSP& entry);
1202 bool CommandObjectTypeRXFormatList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const lldb::TypeFormatImplSP& entry);
1204 class CommandObjectTypeFormatList;
1206 struct CommandObjectTypeFormatList_LoopCallbackParam {
1207 CommandObjectTypeFormatList* self;
1208 CommandReturnObject* result;
1209 RegularExpression* regex;
1210 RegularExpression* cate_regex;
1211 CommandObjectTypeFormatList_LoopCallbackParam(CommandObjectTypeFormatList* S, CommandReturnObject* R,
1212 RegularExpression* X = NULL, RegularExpression* CX = NULL) : self(S), result(R), regex(X), cate_regex(CX) {}
1215 class CommandObjectTypeFormatList : public CommandObjectParsed
1217 class CommandOptions : public Options
1221 CommandOptions (CommandInterpreter &interpreter) :
1222 Options (interpreter)
1227 ~CommandOptions (){}
1230 SetOptionValue (uint32_t option_idx, const char *option_arg)
1233 const int short_option = m_getopt_table[option_idx].val;
1235 switch (short_option)
1238 m_category_regex = std::string(option_arg);
1241 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1249 OptionParsingStarting ()
1251 m_category_regex = "";
1254 const OptionDefinition*
1257 return g_option_table;
1260 // Options table: Required for subclasses of Options.
1262 static OptionDefinition g_option_table[];
1264 // Instance variables to hold the values for command options.
1266 std::string m_category_regex;
1270 CommandOptions m_options;
1279 CommandObjectTypeFormatList (CommandInterpreter &interpreter) :
1280 CommandObjectParsed (interpreter,
1282 "Show a list of current formatting styles.",
1284 m_options(interpreter)
1286 CommandArgumentEntry type_arg;
1287 CommandArgumentData type_style_arg;
1289 type_style_arg.arg_type = eArgTypeName;
1290 type_style_arg.arg_repetition = eArgRepeatOptional;
1292 type_arg.push_back (type_style_arg);
1294 m_arguments.push_back (type_arg);
1297 ~CommandObjectTypeFormatList ()
1303 DoExecute (Args& command, CommandReturnObject &result)
1305 const size_t argc = command.GetArgumentCount();
1307 CommandObjectTypeFormatList_LoopCallbackParam *param;
1308 RegularExpression* cate_regex =
1309 m_options.m_category_regex.empty() ? NULL :
1310 new RegularExpression(m_options.m_category_regex.c_str());
1314 RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
1315 regex->Compile(command.GetArgumentAtIndex(0));
1316 param = new CommandObjectTypeFormatList_LoopCallbackParam(this,&result,regex,cate_regex);
1319 param = new CommandObjectTypeFormatList_LoopCallbackParam(this,&result,NULL,cate_regex);
1321 DataVisualization::Categories::LoopThrough(PerCategoryCallback,param);
1327 result.SetStatus(eReturnStatusSuccessFinishResult);
1328 return result.Succeeded();
1334 PerCategoryCallback(void* param_vp,
1335 const lldb::TypeCategoryImplSP& cate)
1338 CommandObjectTypeFormatList_LoopCallbackParam* param =
1339 (CommandObjectTypeFormatList_LoopCallbackParam*)param_vp;
1340 CommandReturnObject* result = param->result;
1342 const char* cate_name = cate->GetName();
1344 // if the category is disabled or empty and there is no regex, just skip it
1345 if ((cate->IsEnabled() == false || cate->GetCount(eFormatCategoryItemValue | eFormatCategoryItemRegexValue) == 0) && param->cate_regex == NULL)
1348 // if we have a regex and this category does not match it, just skip it
1349 if(param->cate_regex != NULL && strcmp(cate_name,param->cate_regex->GetText()) != 0 && param->cate_regex->Execute(cate_name) == false)
1352 result->GetOutputStream().Printf("-----------------------\nCategory: %s (%s)\n-----------------------\n",
1354 (cate->IsEnabled() ? "enabled" : "disabled"));
1356 cate->GetTypeFormatsContainer()->LoopThrough(CommandObjectTypeFormatList_LoopCallback, param_vp);
1358 if (cate->GetRegexTypeSummariesContainer()->GetCount() > 0)
1360 result->GetOutputStream().Printf("Regex-based summaries (slower):\n");
1361 cate->GetRegexTypeFormatsContainer()->LoopThrough(CommandObjectTypeRXFormatList_LoopCallback, param_vp);
1368 LoopCallback (const char* type,
1369 const lldb::TypeFormatImplSP& entry,
1370 RegularExpression* regex,
1371 CommandReturnObject *result)
1373 if (regex == NULL || strcmp(type,regex->GetText()) == 0 || regex->Execute(type))
1374 result->GetOutputStream().Printf ("%s: %s\n", type, entry->GetDescription().c_str());
1378 friend bool CommandObjectTypeFormatList_LoopCallback(void* pt2self, ConstString type, const lldb::TypeFormatImplSP& entry);
1379 friend bool CommandObjectTypeRXFormatList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const lldb::TypeFormatImplSP& entry);
1384 CommandObjectTypeFormatList_LoopCallback (
1387 const lldb::TypeFormatImplSP& entry)
1389 CommandObjectTypeFormatList_LoopCallbackParam* param = (CommandObjectTypeFormatList_LoopCallbackParam*)pt2self;
1390 return param->self->LoopCallback(type.AsCString(), entry, param->regex, param->result);
1394 CommandObjectTypeRXFormatList_LoopCallback (
1396 lldb::RegularExpressionSP regex,
1397 const lldb::TypeFormatImplSP& entry)
1399 CommandObjectTypeFormatList_LoopCallbackParam* param = (CommandObjectTypeFormatList_LoopCallbackParam*)pt2self;
1400 return param->self->LoopCallback(regex->GetText(), entry, param->regex, param->result);
1404 CommandObjectTypeFormatList::CommandOptions::g_option_table[] =
1406 { LLDB_OPT_SET_ALL, false, "category-regex", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Only show categories matching this filter."},
1407 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
1410 #ifndef LLDB_DISABLE_PYTHON
1412 //-------------------------------------------------------------------------
1413 // CommandObjectTypeSummaryAdd
1414 //-------------------------------------------------------------------------
1416 #endif // #ifndef LLDB_DISABLE_PYTHON
1419 CommandObjectTypeSummaryAdd::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
1422 const int short_option = m_getopt_table[option_idx].val;
1425 switch (short_option)
1428 m_flags.SetCascades(Args::StringToBoolean(option_arg, true, &success));
1430 error.SetErrorStringWithFormat("invalid value for cascade: %s", option_arg);
1433 m_flags.SetDontShowChildren(false);
1436 m_flags.SetDontShowValue(true);
1439 m_flags.SetShowMembersOneLiner(true);
1442 m_format_string = std::string(option_arg);
1445 m_flags.SetSkipPointers(true);
1448 m_flags.SetSkipReferences(true);
1454 m_name.SetCString(option_arg);
1457 m_python_script = std::string(option_arg);
1458 m_is_add_script = true;
1461 m_python_function = std::string(option_arg);
1462 m_is_add_script = true;
1465 m_is_add_script = true;
1468 m_category = std::string(option_arg);
1471 m_flags.SetHideItemNames(true);
1474 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1482 CommandObjectTypeSummaryAdd::CommandOptions::OptionParsingStarting ()
1484 m_flags.Clear().SetCascades().SetDontShowChildren().SetDontShowValue(false);
1485 m_flags.SetShowMembersOneLiner(false).SetSkipPointers(false).SetSkipReferences(false).SetHideItemNames(false);
1489 m_python_script = "";
1490 m_python_function = "";
1491 m_format_string = "";
1492 m_is_add_script = false;
1493 m_category = "default";
1498 #ifndef LLDB_DISABLE_PYTHON
1501 CommandObjectTypeSummaryAdd::Execute_ScriptSummary (Args& command, CommandReturnObject &result)
1503 const size_t argc = command.GetArgumentCount();
1505 if (argc < 1 && !m_options.m_name)
1507 result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
1508 result.SetStatus(eReturnStatusFailed);
1512 TypeSummaryImplSP script_format;
1514 if (!m_options.m_python_function.empty()) // we have a Python function ready to use
1516 const char *funct_name = m_options.m_python_function.c_str();
1517 if (!funct_name || !funct_name[0])
1519 result.AppendError ("function name empty.\n");
1520 result.SetStatus (eReturnStatusFailed);
1524 std::string code = (" " + m_options.m_python_function + "(valobj,internal_dict)");
1526 script_format.reset(new ScriptSummaryFormat(m_options.m_flags,
1530 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
1532 if (interpreter && interpreter->CheckObjectExists(funct_name) == false)
1533 result.AppendWarningWithFormat("The provided function \"%s\" does not exist - "
1534 "please define it before attempting to use this summary.\n",
1537 else if (!m_options.m_python_script.empty()) // we have a quick 1-line script, just use it
1539 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
1542 result.AppendError ("script interpreter missing - unable to generate function wrapper.\n");
1543 result.SetStatus (eReturnStatusFailed);
1546 StringList funct_sl;
1547 funct_sl << m_options.m_python_script.c_str();
1548 std::string funct_name_str;
1549 if (!interpreter->GenerateTypeScriptFunction (funct_sl,
1552 result.AppendError ("unable to generate function wrapper.\n");
1553 result.SetStatus (eReturnStatusFailed);
1556 if (funct_name_str.empty())
1558 result.AppendError ("script interpreter failed to generate a valid function name.\n");
1559 result.SetStatus (eReturnStatusFailed);
1563 std::string code = " " + m_options.m_python_script;
1565 script_format.reset(new ScriptSummaryFormat(m_options.m_flags,
1566 funct_name_str.c_str(),
1571 // Use an IOHandler to grab Python code from the user
1572 ScriptAddOptions *options = new ScriptAddOptions(m_options.m_flags,
1575 m_options.m_category);
1577 for (size_t i = 0; i < argc; i++)
1579 const char* typeA = command.GetArgumentAtIndex(i);
1580 if (typeA && *typeA)
1581 options->m_target_types << typeA;
1584 result.AppendError("empty typenames not allowed");
1585 result.SetStatus(eReturnStatusFailed);
1590 m_interpreter.GetPythonCommandsFromIOHandler (" ", // Prompt
1591 *this, // IOHandlerDelegate
1592 true, // Run IOHandler in async mode
1593 options); // Baton for the "io_handler" that will be passed back into our IOHandlerDelegate functions
1594 result.SetStatus(eReturnStatusSuccessFinishNoResult);
1596 return result.Succeeded();
1599 // if I am here, script_format must point to something good, so I can add that
1600 // as a script summary to all interested parties
1604 for (size_t i = 0; i < command.GetArgumentCount(); i++)
1606 const char *type_name = command.GetArgumentAtIndex(i);
1607 CommandObjectTypeSummaryAdd::AddSummary(ConstString(type_name),
1609 (m_options.m_regex ? eRegexSummary : eRegularSummary),
1610 m_options.m_category,
1614 result.AppendError(error.AsCString());
1615 result.SetStatus(eReturnStatusFailed);
1620 if (m_options.m_name)
1622 AddSummary(m_options.m_name, script_format, eNamedSummary, m_options.m_category, &error);
1625 result.AppendError(error.AsCString());
1626 result.AppendError("added to types, but not given a name");
1627 result.SetStatus(eReturnStatusFailed);
1632 return result.Succeeded();
1639 CommandObjectTypeSummaryAdd::Execute_StringSummary (Args& command, CommandReturnObject &result)
1641 const size_t argc = command.GetArgumentCount();
1643 if (argc < 1 && !m_options.m_name)
1645 result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
1646 result.SetStatus(eReturnStatusFailed);
1650 if (!m_options.m_flags.GetShowMembersOneLiner() && m_options.m_format_string.empty())
1652 result.AppendError("empty summary strings not allowed");
1653 result.SetStatus(eReturnStatusFailed);
1657 const char* format_cstr = (m_options.m_flags.GetShowMembersOneLiner() ? "" : m_options.m_format_string.c_str());
1659 // ${var%S} is an endless recursion, prevent it
1660 if (strcmp(format_cstr, "${var%S}") == 0)
1662 result.AppendError("recursive summary not allowed");
1663 result.SetStatus(eReturnStatusFailed);
1669 lldb::TypeSummaryImplSP entry(new StringSummaryFormat(m_options.m_flags,
1674 result.AppendError(error.AsCString());
1675 result.SetStatus(eReturnStatusFailed);
1679 // now I have a valid format, let's add it to every type
1681 for (size_t i = 0; i < argc; i++)
1683 const char* typeA = command.GetArgumentAtIndex(i);
1684 if (!typeA || typeA[0] == '\0')
1686 result.AppendError("empty typenames not allowed");
1687 result.SetStatus(eReturnStatusFailed);
1690 ConstString typeCS(typeA);
1694 (m_options.m_regex ? eRegexSummary : eRegularSummary),
1695 m_options.m_category,
1700 result.AppendError(error.AsCString());
1701 result.SetStatus(eReturnStatusFailed);
1706 if (m_options.m_name)
1708 AddSummary(m_options.m_name, entry, eNamedSummary, m_options.m_category, &error);
1711 result.AppendError(error.AsCString());
1712 result.AppendError("added to types, but not given a name");
1713 result.SetStatus(eReturnStatusFailed);
1718 result.SetStatus(eReturnStatusSuccessFinishNoResult);
1719 return result.Succeeded();
1722 CommandObjectTypeSummaryAdd::CommandObjectTypeSummaryAdd (CommandInterpreter &interpreter) :
1723 CommandObjectParsed (interpreter,
1725 "Add a new summary style for a type.",
1727 IOHandlerDelegateMultiline ("DONE"),
1728 m_options (interpreter)
1730 CommandArgumentEntry type_arg;
1731 CommandArgumentData type_style_arg;
1733 type_style_arg.arg_type = eArgTypeName;
1734 type_style_arg.arg_repetition = eArgRepeatPlus;
1736 type_arg.push_back (type_style_arg);
1738 m_arguments.push_back (type_arg);
1741 "Some examples of using this command.\n"
1742 "We use as reference the following snippet of code:\n"
1743 "struct JustADemo\n"
1747 "JustADemo(int p = 1, float v = 0.1) : ptr(new int(p)), value(v) {}\n"
1749 "JustADemo object(42,3.14);\n"
1750 "struct AnotherDemo : public JustADemo\n"
1753 "AnotherDemo(uint8_t b = 'E', int p = 1, float v = 0.1) : JustADemo(p,v), byte(b) {}\n"
1755 "AnotherDemo *another_object = new AnotherDemo('E',42,3.14);\n"
1757 "type summary add --summary-string \"the answer is ${*var.ptr}\" JustADemo\n"
1758 "when typing frame variable object you will get \"the answer is 42\"\n"
1759 "type summary add --summary-string \"the answer is ${*var.ptr}, and the question is ${var.value}\" JustADemo\n"
1760 "when typing frame variable object you will get \"the answer is 42 and the question is 3.14\"\n"
1762 "Alternatively, you could also say\n"
1763 "type summary add --summary-string \"${var%V} -> ${*var}\" \"int *\"\n"
1764 "and replace the above summary string with\n"
1765 "type summary add --summary-string \"the answer is ${var.ptr}, and the question is ${var.value}\" JustADemo\n"
1766 "to obtain a similar result\n"
1768 "To add a summary valid for both JustADemo and AnotherDemo you can use the scoping operator, as in:\n"
1769 "type summary add --summary-string \"${var.ptr}, ${var.value},{${var.byte}}\" JustADemo -C yes\n"
1771 "This will be used for both variables of type JustADemo and AnotherDemo. To prevent this, change the -C to read -C no\n"
1772 "If you do not want pointers to be shown using that summary, you can use the -p option, as in:\n"
1773 "type summary add --summary-string \"${var.ptr}, ${var.value},{${var.byte}}\" JustADemo -C yes -p\n"
1774 "A similar option -r exists for references.\n"
1776 "If you simply want a one-line summary of the content of your variable, without typing an explicit string to that effect\n"
1777 "you can use the -c option, without giving any summary string:\n"
1778 "type summary add -c JustADemo\n"
1779 "frame variable object\n"
1780 "the output being similar to (ptr=0xsomeaddress, value=3.14)\n"
1782 "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"
1783 "type summary add -e --summary-string \"*ptr = ${*var.ptr}\" JustADemo\n"
1784 "Here the value of the int* is displayed, followed by the standard LLDB sequence of children objects, one per line.\n"
1785 "to get an output like:\n"
1788 " ptr = 0xsomeaddress\n"
1792 "You can also add Python summaries, in which case you will use lldb public API to gather information from your variables"
1793 "and elaborate them to a meaningful summary inside a script written in Python. The variable object will be passed to your"
1794 "script as an SBValue object. The following example might help you when starting to use the Python summaries feature:\n"
1795 "type summary add JustADemo -o \"value = valobj.GetChildMemberWithName('value'); return 'My value is ' + value.GetValue();\"\n"
1796 "If you prefer to type your scripts on multiple lines, you will use the -P option and then type your script, ending it with "
1797 "the word DONE on a line by itself to mark you're finished editing your code:\n"
1798 "(lldb)type summary add JustADemo -P\n"
1799 " value = valobj.GetChildMemberWithName('value');\n"
1800 " return 'My value is ' + value.GetValue();\n"
1802 "(lldb) <-- type further LLDB commands here\n"
1807 CommandObjectTypeSummaryAdd::DoExecute (Args& command, CommandReturnObject &result)
1809 WarnOnPotentialUnquotedUnsignedType(command, result);
1811 if (m_options.m_is_add_script)
1813 #ifndef LLDB_DISABLE_PYTHON
1814 return Execute_ScriptSummary(command, result);
1816 result.AppendError ("python is disabled");
1817 result.SetStatus(eReturnStatusFailed);
1822 return Execute_StringSummary(command, result);
1826 FixArrayTypeNameWithRegex (ConstString &type_name)
1828 llvm::StringRef type_name_ref(type_name.GetStringRef());
1830 if (type_name_ref.endswith("[]"))
1832 std::string type_name_str(type_name.GetCString());
1833 type_name_str.resize(type_name_str.length()-2);
1834 if (type_name_str.back() != ' ')
1835 type_name_str.append(" \\[[0-9]+\\]");
1837 type_name_str.append("\\[[0-9]+\\]");
1838 type_name.SetCString(type_name_str.c_str());
1845 CommandObjectTypeSummaryAdd::AddSummary(ConstString type_name,
1846 TypeSummaryImplSP entry,
1847 SummaryFormatType type,
1848 std::string category_name,
1851 lldb::TypeCategoryImplSP category;
1852 DataVisualization::Categories::GetCategory(ConstString(category_name.c_str()), category);
1854 if (type == eRegularSummary)
1856 if (FixArrayTypeNameWithRegex (type_name))
1857 type = eRegexSummary;
1860 if (type == eRegexSummary)
1862 RegularExpressionSP typeRX(new RegularExpression());
1863 if (!typeRX->Compile(type_name.GetCString()))
1866 error->SetErrorString("regex format error (maybe this is not really a regex?)");
1870 category->GetRegexTypeSummariesContainer()->Delete(type_name);
1871 category->GetRegexTypeSummariesContainer()->Add(typeRX, entry);
1875 else if (type == eNamedSummary)
1877 // system named summaries do not exist (yet?)
1878 DataVisualization::NamedSummaryFormats::Add(type_name,entry);
1883 category->GetTypeSummariesContainer()->Add(type_name, entry);
1889 CommandObjectTypeSummaryAdd::CommandOptions::g_option_table[] =
1891 { LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Add this to the given category instead of the default one."},
1892 { LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "If true, cascade through typedef chains."},
1893 { LLDB_OPT_SET_ALL, false, "no-value", 'v', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Don't show the value, just show the summary, for this type."},
1894 { LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."},
1895 { LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Don't use this format for references-to-type objects."},
1896 { LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Type names are actually regular expressions."},
1897 { LLDB_OPT_SET_1 , true, "inline-children", 'c', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "If true, inline all child values into summary string."},
1898 { LLDB_OPT_SET_1 , false, "omit-names", 'O', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "If true, omit value names in the summary display."},
1899 { LLDB_OPT_SET_2 , true, "summary-string", 's', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeSummaryString, "Summary string used to display text and object contents."},
1900 { LLDB_OPT_SET_3, false, "python-script", 'o', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePythonScript, "Give a one-liner Python script as part of the command."},
1901 { LLDB_OPT_SET_3, false, "python-function", 'F', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePythonFunction, "Give the name of a Python function to use for this type."},
1902 { LLDB_OPT_SET_3, false, "input-python", 'P', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Input Python code to use for this type manually."},
1903 { LLDB_OPT_SET_2 | LLDB_OPT_SET_3, false, "expand", 'e', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Expand aggregate data types to show children on separate lines."},
1904 { LLDB_OPT_SET_2 | LLDB_OPT_SET_3, false, "name", 'n', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "A name for this summary string."},
1905 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
1909 //-------------------------------------------------------------------------
1910 // CommandObjectTypeSummaryDelete
1911 //-------------------------------------------------------------------------
1913 class CommandObjectTypeSummaryDelete : public CommandObjectParsed
1916 class CommandOptions : public Options
1920 CommandOptions (CommandInterpreter &interpreter) :
1921 Options (interpreter)
1926 ~CommandOptions (){}
1929 SetOptionValue (uint32_t option_idx, const char *option_arg)
1932 const int short_option = m_getopt_table[option_idx].val;
1934 switch (short_option)
1937 m_delete_all = true;
1940 m_category = std::string(option_arg);
1943 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1951 OptionParsingStarting ()
1953 m_delete_all = false;
1954 m_category = "default";
1957 const OptionDefinition*
1960 return g_option_table;
1963 // Options table: Required for subclasses of Options.
1965 static OptionDefinition g_option_table[];
1967 // Instance variables to hold the values for command options.
1970 std::string m_category;
1974 CommandOptions m_options;
1983 PerCategoryCallback(void* param,
1984 const lldb::TypeCategoryImplSP& category_sp)
1986 ConstString *name = (ConstString*)param;
1987 category_sp->Delete(*name, eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
1992 CommandObjectTypeSummaryDelete (CommandInterpreter &interpreter) :
1993 CommandObjectParsed (interpreter,
1994 "type summary delete",
1995 "Delete an existing summary style for a type.",
1997 m_options(interpreter)
1999 CommandArgumentEntry type_arg;
2000 CommandArgumentData type_style_arg;
2002 type_style_arg.arg_type = eArgTypeName;
2003 type_style_arg.arg_repetition = eArgRepeatPlain;
2005 type_arg.push_back (type_style_arg);
2007 m_arguments.push_back (type_arg);
2011 ~CommandObjectTypeSummaryDelete ()
2017 DoExecute (Args& command, CommandReturnObject &result)
2019 const size_t argc = command.GetArgumentCount();
2023 result.AppendErrorWithFormat ("%s takes 1 arg.\n", m_cmd_name.c_str());
2024 result.SetStatus(eReturnStatusFailed);
2028 const char* typeA = command.GetArgumentAtIndex(0);
2029 ConstString typeCS(typeA);
2033 result.AppendError("empty typenames not allowed");
2034 result.SetStatus(eReturnStatusFailed);
2038 if (m_options.m_delete_all)
2040 DataVisualization::Categories::LoopThrough(PerCategoryCallback, &typeCS);
2041 result.SetStatus(eReturnStatusSuccessFinishNoResult);
2042 return result.Succeeded();
2045 lldb::TypeCategoryImplSP category;
2046 DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
2048 bool delete_category = category->Delete(typeCS,
2049 eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
2050 bool delete_named = DataVisualization::NamedSummaryFormats::Delete(typeCS);
2052 if (delete_category || delete_named)
2054 result.SetStatus(eReturnStatusSuccessFinishNoResult);
2055 return result.Succeeded();
2059 result.AppendErrorWithFormat ("no custom summary for %s.\n", typeA);
2060 result.SetStatus(eReturnStatusFailed);
2068 CommandObjectTypeSummaryDelete::CommandOptions::g_option_table[] =
2070 { LLDB_OPT_SET_1, false, "all", 'a', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Delete from every category."},
2071 { LLDB_OPT_SET_2, false, "category", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Delete from given category."},
2072 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
2075 class CommandObjectTypeSummaryClear : public CommandObjectParsed
2079 class CommandOptions : public Options
2083 CommandOptions (CommandInterpreter &interpreter) :
2084 Options (interpreter)
2089 ~CommandOptions (){}
2092 SetOptionValue (uint32_t option_idx, const char *option_arg)
2095 const int short_option = m_getopt_table[option_idx].val;
2097 switch (short_option)
2100 m_delete_all = true;
2103 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
2111 OptionParsingStarting ()
2113 m_delete_all = false;
2116 const OptionDefinition*
2119 return g_option_table;
2122 // Options table: Required for subclasses of Options.
2124 static OptionDefinition g_option_table[];
2126 // Instance variables to hold the values for command options.
2129 bool m_delete_named;
2132 CommandOptions m_options;
2141 PerCategoryCallback(void* param,
2142 const lldb::TypeCategoryImplSP& cate)
2144 cate->GetTypeSummariesContainer()->Clear();
2145 cate->GetRegexTypeSummariesContainer()->Clear();
2151 CommandObjectTypeSummaryClear (CommandInterpreter &interpreter) :
2152 CommandObjectParsed (interpreter,
2153 "type summary clear",
2154 "Delete all existing summary styles.",
2156 m_options(interpreter)
2160 ~CommandObjectTypeSummaryClear ()
2166 DoExecute (Args& command, CommandReturnObject &result)
2169 if (m_options.m_delete_all)
2170 DataVisualization::Categories::LoopThrough(PerCategoryCallback, NULL);
2174 lldb::TypeCategoryImplSP category;
2175 if (command.GetArgumentCount() > 0)
2177 const char* cat_name = command.GetArgumentAtIndex(0);
2178 ConstString cat_nameCS(cat_name);
2179 DataVisualization::Categories::GetCategory(cat_nameCS, category);
2182 DataVisualization::Categories::GetCategory(ConstString(NULL), category);
2183 category->Clear(eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
2186 DataVisualization::NamedSummaryFormats::Clear();
2188 result.SetStatus(eReturnStatusSuccessFinishResult);
2189 return result.Succeeded();
2195 CommandObjectTypeSummaryClear::CommandOptions::g_option_table[] =
2197 { LLDB_OPT_SET_ALL, false, "all", 'a', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Clear every category."},
2198 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
2201 //-------------------------------------------------------------------------
2202 // CommandObjectTypeSummaryList
2203 //-------------------------------------------------------------------------
2205 bool CommandObjectTypeSummaryList_LoopCallback(void* pt2self, ConstString type, const StringSummaryFormat::SharedPointer& entry);
2206 bool CommandObjectTypeRXSummaryList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const StringSummaryFormat::SharedPointer& entry);
2208 class CommandObjectTypeSummaryList;
2210 struct CommandObjectTypeSummaryList_LoopCallbackParam {
2211 CommandObjectTypeSummaryList* self;
2212 CommandReturnObject* result;
2213 RegularExpression* regex;
2214 RegularExpression* cate_regex;
2215 CommandObjectTypeSummaryList_LoopCallbackParam(CommandObjectTypeSummaryList* S, CommandReturnObject* R,
2216 RegularExpression* X = NULL,
2217 RegularExpression* CX = NULL) : self(S), result(R), regex(X), cate_regex(CX) {}
2220 class CommandObjectTypeSummaryList : public CommandObjectParsed
2223 class CommandOptions : public Options
2227 CommandOptions (CommandInterpreter &interpreter) :
2228 Options (interpreter)
2233 ~CommandOptions (){}
2236 SetOptionValue (uint32_t option_idx, const char *option_arg)
2239 const int short_option = m_getopt_table[option_idx].val;
2241 switch (short_option)
2244 m_category_regex = std::string(option_arg);
2247 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
2255 OptionParsingStarting ()
2257 m_category_regex = "";
2260 const OptionDefinition*
2263 return g_option_table;
2266 // Options table: Required for subclasses of Options.
2268 static OptionDefinition g_option_table[];
2270 // Instance variables to hold the values for command options.
2272 std::string m_category_regex;
2276 CommandOptions m_options;
2285 CommandObjectTypeSummaryList (CommandInterpreter &interpreter) :
2286 CommandObjectParsed (interpreter,
2287 "type summary list",
2288 "Show a list of current summary styles.",
2290 m_options(interpreter)
2292 CommandArgumentEntry type_arg;
2293 CommandArgumentData type_style_arg;
2295 type_style_arg.arg_type = eArgTypeName;
2296 type_style_arg.arg_repetition = eArgRepeatOptional;
2298 type_arg.push_back (type_style_arg);
2300 m_arguments.push_back (type_arg);
2303 ~CommandObjectTypeSummaryList ()
2309 DoExecute (Args& command, CommandReturnObject &result)
2311 const size_t argc = command.GetArgumentCount();
2313 CommandObjectTypeSummaryList_LoopCallbackParam *param;
2314 RegularExpression* cate_regex =
2315 m_options.m_category_regex.empty() ? NULL :
2316 new RegularExpression(m_options.m_category_regex.c_str());
2320 RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
2321 regex->Compile(command.GetArgumentAtIndex(0));
2322 param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result,regex,cate_regex);
2325 param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result,NULL,cate_regex);
2327 DataVisualization::Categories::LoopThrough(PerCategoryCallback,param);
2330 if (DataVisualization::NamedSummaryFormats::GetCount() > 0)
2332 result.GetOutputStream().Printf("Named summaries:\n");
2335 RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
2336 regex->Compile(command.GetArgumentAtIndex(0));
2337 param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result,regex);
2340 param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result);
2341 DataVisualization::NamedSummaryFormats::LoopThrough(CommandObjectTypeSummaryList_LoopCallback, param);
2348 result.SetStatus(eReturnStatusSuccessFinishResult);
2349 return result.Succeeded();
2355 PerCategoryCallback(void* param_vp,
2356 const lldb::TypeCategoryImplSP& cate)
2359 CommandObjectTypeSummaryList_LoopCallbackParam* param =
2360 (CommandObjectTypeSummaryList_LoopCallbackParam*)param_vp;
2361 CommandReturnObject* result = param->result;
2363 const char* cate_name = cate->GetName();
2365 // if the category is disabled or empty and there is no regex, just skip it
2366 if ((cate->IsEnabled() == false || cate->GetCount(eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary) == 0) && param->cate_regex == NULL)
2369 // if we have a regex and this category does not match it, just skip it
2370 if(param->cate_regex != NULL && strcmp(cate_name,param->cate_regex->GetText()) != 0 && param->cate_regex->Execute(cate_name) == false)
2373 result->GetOutputStream().Printf("-----------------------\nCategory: %s (%s)\n-----------------------\n",
2375 (cate->IsEnabled() ? "enabled" : "disabled"));
2377 cate->GetTypeSummariesContainer()->LoopThrough(CommandObjectTypeSummaryList_LoopCallback, param_vp);
2379 if (cate->GetRegexTypeSummariesContainer()->GetCount() > 0)
2381 result->GetOutputStream().Printf("Regex-based summaries (slower):\n");
2382 cate->GetRegexTypeSummariesContainer()->LoopThrough(CommandObjectTypeRXSummaryList_LoopCallback, param_vp);
2389 LoopCallback (const char* type,
2390 const lldb::TypeSummaryImplSP& entry,
2391 RegularExpression* regex,
2392 CommandReturnObject *result)
2394 if (regex == NULL || strcmp(type,regex->GetText()) == 0 || regex->Execute(type))
2395 result->GetOutputStream().Printf ("%s: %s\n", type, entry->GetDescription().c_str());
2399 friend bool CommandObjectTypeSummaryList_LoopCallback(void* pt2self, ConstString type, const lldb::TypeSummaryImplSP& entry);
2400 friend bool CommandObjectTypeRXSummaryList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const lldb::TypeSummaryImplSP& entry);
2404 CommandObjectTypeSummaryList_LoopCallback (
2407 const lldb::TypeSummaryImplSP& entry)
2409 CommandObjectTypeSummaryList_LoopCallbackParam* param = (CommandObjectTypeSummaryList_LoopCallbackParam*)pt2self;
2410 return param->self->LoopCallback(type.AsCString(), entry, param->regex, param->result);
2414 CommandObjectTypeRXSummaryList_LoopCallback (
2416 lldb::RegularExpressionSP regex,
2417 const lldb::TypeSummaryImplSP& entry)
2419 CommandObjectTypeSummaryList_LoopCallbackParam* param = (CommandObjectTypeSummaryList_LoopCallbackParam*)pt2self;
2420 return param->self->LoopCallback(regex->GetText(), entry, param->regex, param->result);
2424 CommandObjectTypeSummaryList::CommandOptions::g_option_table[] =
2426 { LLDB_OPT_SET_ALL, false, "category-regex", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Only show categories matching this filter."},
2427 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
2430 //-------------------------------------------------------------------------
2431 // CommandObjectTypeCategoryEnable
2432 //-------------------------------------------------------------------------
2434 class CommandObjectTypeCategoryEnable : public CommandObjectParsed
2437 CommandObjectTypeCategoryEnable (CommandInterpreter &interpreter) :
2438 CommandObjectParsed (interpreter,
2439 "type category enable",
2440 "Enable a category as a source of formatters.",
2443 CommandArgumentEntry type_arg;
2444 CommandArgumentData type_style_arg;
2446 type_style_arg.arg_type = eArgTypeName;
2447 type_style_arg.arg_repetition = eArgRepeatPlus;
2449 type_arg.push_back (type_style_arg);
2451 m_arguments.push_back (type_arg);
2455 ~CommandObjectTypeCategoryEnable ()
2461 DoExecute (Args& command, CommandReturnObject &result)
2463 const size_t argc = command.GetArgumentCount();
2467 result.AppendErrorWithFormat ("%s takes 1 or more args.\n", m_cmd_name.c_str());
2468 result.SetStatus(eReturnStatusFailed);
2472 if (argc == 1 && strcmp(command.GetArgumentAtIndex(0),"*") == 0)
2474 DataVisualization::Categories::EnableStar();
2478 for (int i = argc - 1; i >= 0; i--)
2480 const char* typeA = command.GetArgumentAtIndex(i);
2481 ConstString typeCS(typeA);
2485 result.AppendError("empty category name not allowed");
2486 result.SetStatus(eReturnStatusFailed);
2489 DataVisualization::Categories::Enable(typeCS);
2490 lldb::TypeCategoryImplSP cate;
2491 if (DataVisualization::Categories::GetCategory(typeCS, cate) && cate.get())
2493 if (cate->GetCount() == 0)
2495 result.AppendWarning("empty category enabled (typo?)");
2501 result.SetStatus(eReturnStatusSuccessFinishResult);
2502 return result.Succeeded();
2507 //-------------------------------------------------------------------------
2508 // CommandObjectTypeCategoryDelete
2509 //-------------------------------------------------------------------------
2511 class CommandObjectTypeCategoryDelete : public CommandObjectParsed
2514 CommandObjectTypeCategoryDelete (CommandInterpreter &interpreter) :
2515 CommandObjectParsed (interpreter,
2516 "type category delete",
2517 "Delete a category and all associated formatters.",
2520 CommandArgumentEntry type_arg;
2521 CommandArgumentData type_style_arg;
2523 type_style_arg.arg_type = eArgTypeName;
2524 type_style_arg.arg_repetition = eArgRepeatPlus;
2526 type_arg.push_back (type_style_arg);
2528 m_arguments.push_back (type_arg);
2532 ~CommandObjectTypeCategoryDelete ()
2538 DoExecute (Args& command, CommandReturnObject &result)
2540 const size_t argc = command.GetArgumentCount();
2544 result.AppendErrorWithFormat ("%s takes 1 or more arg.\n", m_cmd_name.c_str());
2545 result.SetStatus(eReturnStatusFailed);
2549 bool success = true;
2551 // the order is not relevant here
2552 for (int i = argc - 1; i >= 0; i--)
2554 const char* typeA = command.GetArgumentAtIndex(i);
2555 ConstString typeCS(typeA);
2559 result.AppendError("empty category name not allowed");
2560 result.SetStatus(eReturnStatusFailed);
2563 if (!DataVisualization::Categories::Delete(typeCS))
2564 success = false; // keep deleting even if we hit an error
2568 result.SetStatus(eReturnStatusSuccessFinishResult);
2569 return result.Succeeded();
2573 result.AppendError("cannot delete one or more categories\n");
2574 result.SetStatus(eReturnStatusFailed);
2580 //-------------------------------------------------------------------------
2581 // CommandObjectTypeCategoryDisable
2582 //-------------------------------------------------------------------------
2584 class CommandObjectTypeCategoryDisable : public CommandObjectParsed
2587 CommandObjectTypeCategoryDisable (CommandInterpreter &interpreter) :
2588 CommandObjectParsed (interpreter,
2589 "type category disable",
2590 "Disable a category as a source of formatters.",
2593 CommandArgumentEntry type_arg;
2594 CommandArgumentData type_style_arg;
2596 type_style_arg.arg_type = eArgTypeName;
2597 type_style_arg.arg_repetition = eArgRepeatPlus;
2599 type_arg.push_back (type_style_arg);
2601 m_arguments.push_back (type_arg);
2605 ~CommandObjectTypeCategoryDisable ()
2611 DoExecute (Args& command, CommandReturnObject &result)
2613 const size_t argc = command.GetArgumentCount();
2617 result.AppendErrorWithFormat ("%s takes 1 or more args.\n", m_cmd_name.c_str());
2618 result.SetStatus(eReturnStatusFailed);
2622 if (argc == 1 && strcmp(command.GetArgumentAtIndex(0),"*") == 0)
2624 DataVisualization::Categories::DisableStar();
2628 // the order is not relevant here
2629 for (int i = argc - 1; i >= 0; i--)
2631 const char* typeA = command.GetArgumentAtIndex(i);
2632 ConstString typeCS(typeA);
2636 result.AppendError("empty category name not allowed");
2637 result.SetStatus(eReturnStatusFailed);
2640 DataVisualization::Categories::Disable(typeCS);
2644 result.SetStatus(eReturnStatusSuccessFinishResult);
2645 return result.Succeeded();
2650 //-------------------------------------------------------------------------
2651 // CommandObjectTypeCategoryList
2652 //-------------------------------------------------------------------------
2654 class CommandObjectTypeCategoryList : public CommandObjectParsed
2658 struct CommandObjectTypeCategoryList_CallbackParam
2660 CommandReturnObject* result;
2661 RegularExpression* regex;
2663 CommandObjectTypeCategoryList_CallbackParam(CommandReturnObject* res,
2664 RegularExpression* rex = NULL) :
2673 PerCategoryCallback(void* param_vp,
2674 const lldb::TypeCategoryImplSP& cate)
2676 CommandObjectTypeCategoryList_CallbackParam* param =
2677 (CommandObjectTypeCategoryList_CallbackParam*)param_vp;
2678 CommandReturnObject* result = param->result;
2679 RegularExpression* regex = param->regex;
2681 const char* cate_name = cate->GetName();
2683 if (regex == NULL || strcmp(cate_name, regex->GetText()) == 0 || regex->Execute(cate_name))
2684 result->GetOutputStream().Printf("Category %s is%s enabled\n",
2686 (cate->IsEnabled() ? "" : " not"));
2690 CommandObjectTypeCategoryList (CommandInterpreter &interpreter) :
2691 CommandObjectParsed (interpreter,
2692 "type category list",
2693 "Provide a list of all existing categories.",
2696 CommandArgumentEntry type_arg;
2697 CommandArgumentData type_style_arg;
2699 type_style_arg.arg_type = eArgTypeName;
2700 type_style_arg.arg_repetition = eArgRepeatOptional;
2702 type_arg.push_back (type_style_arg);
2704 m_arguments.push_back (type_arg);
2707 ~CommandObjectTypeCategoryList ()
2713 DoExecute (Args& command, CommandReturnObject &result)
2715 const size_t argc = command.GetArgumentCount();
2716 RegularExpression* regex = NULL;
2721 regex = new RegularExpression(command.GetArgumentAtIndex(0));
2724 result.AppendErrorWithFormat ("%s takes 0 or one arg.\n", m_cmd_name.c_str());
2725 result.SetStatus(eReturnStatusFailed);
2729 CommandObjectTypeCategoryList_CallbackParam param(&result,
2732 DataVisualization::Categories::LoopThrough(PerCategoryCallback, ¶m);
2737 result.SetStatus(eReturnStatusSuccessFinishResult);
2738 return result.Succeeded();
2743 //-------------------------------------------------------------------------
2744 // CommandObjectTypeFilterList
2745 //-------------------------------------------------------------------------
2747 bool CommandObjectTypeFilterList_LoopCallback(void* pt2self, ConstString type, const SyntheticChildren::SharedPointer& entry);
2748 bool CommandObjectTypeFilterRXList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const SyntheticChildren::SharedPointer& entry);
2750 class CommandObjectTypeFilterList;
2752 struct CommandObjectTypeFilterList_LoopCallbackParam {
2753 CommandObjectTypeFilterList* self;
2754 CommandReturnObject* result;
2755 RegularExpression* regex;
2756 RegularExpression* cate_regex;
2757 CommandObjectTypeFilterList_LoopCallbackParam(CommandObjectTypeFilterList* S, CommandReturnObject* R,
2758 RegularExpression* X = NULL,
2759 RegularExpression* CX = NULL) : self(S), result(R), regex(X), cate_regex(CX) {}
2762 class CommandObjectTypeFilterList : public CommandObjectParsed
2765 class CommandOptions : public Options
2769 CommandOptions (CommandInterpreter &interpreter) :
2770 Options (interpreter)
2775 ~CommandOptions (){}
2778 SetOptionValue (uint32_t option_idx, const char *option_arg)
2781 const int short_option = m_getopt_table[option_idx].val;
2783 switch (short_option)
2786 m_category_regex = std::string(option_arg);
2789 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
2797 OptionParsingStarting ()
2799 m_category_regex = "";
2802 const OptionDefinition*
2805 return g_option_table;
2808 // Options table: Required for subclasses of Options.
2810 static OptionDefinition g_option_table[];
2812 // Instance variables to hold the values for command options.
2814 std::string m_category_regex;
2818 CommandOptions m_options;
2827 CommandObjectTypeFilterList (CommandInterpreter &interpreter) :
2828 CommandObjectParsed (interpreter,
2830 "Show a list of current filters.",
2832 m_options(interpreter)
2834 CommandArgumentEntry type_arg;
2835 CommandArgumentData type_style_arg;
2837 type_style_arg.arg_type = eArgTypeName;
2838 type_style_arg.arg_repetition = eArgRepeatOptional;
2840 type_arg.push_back (type_style_arg);
2842 m_arguments.push_back (type_arg);
2845 ~CommandObjectTypeFilterList ()
2851 DoExecute (Args& command, CommandReturnObject &result)
2853 const size_t argc = command.GetArgumentCount();
2855 CommandObjectTypeFilterList_LoopCallbackParam *param;
2856 RegularExpression* cate_regex =
2857 m_options.m_category_regex.empty() ? NULL :
2858 new RegularExpression(m_options.m_category_regex.c_str());
2862 RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
2863 regex->Compile(command.GetArgumentAtIndex(0));
2864 param = new CommandObjectTypeFilterList_LoopCallbackParam(this,&result,regex,cate_regex);
2867 param = new CommandObjectTypeFilterList_LoopCallbackParam(this,&result,NULL,cate_regex);
2869 DataVisualization::Categories::LoopThrough(PerCategoryCallback,param);
2875 result.SetStatus(eReturnStatusSuccessFinishResult);
2876 return result.Succeeded();
2882 PerCategoryCallback(void* param_vp,
2883 const lldb::TypeCategoryImplSP& cate)
2886 const char* cate_name = cate->GetName();
2888 CommandObjectTypeFilterList_LoopCallbackParam* param =
2889 (CommandObjectTypeFilterList_LoopCallbackParam*)param_vp;
2890 CommandReturnObject* result = param->result;
2892 // if the category is disabled or empty and there is no regex, just skip it
2893 if ((cate->IsEnabled() == false || cate->GetCount(eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter) == 0) && param->cate_regex == NULL)
2896 // if we have a regex and this category does not match it, just skip it
2897 if(param->cate_regex != NULL && strcmp(cate_name,param->cate_regex->GetText()) != 0 && param->cate_regex->Execute(cate_name) == false)
2900 result->GetOutputStream().Printf("-----------------------\nCategory: %s (%s)\n-----------------------\n",
2902 (cate->IsEnabled() ? "enabled" : "disabled"));
2904 cate->GetTypeFiltersContainer()->LoopThrough(CommandObjectTypeFilterList_LoopCallback, param_vp);
2906 if (cate->GetRegexTypeFiltersContainer()->GetCount() > 0)
2908 result->GetOutputStream().Printf("Regex-based filters (slower):\n");
2909 cate->GetRegexTypeFiltersContainer()->LoopThrough(CommandObjectTypeFilterRXList_LoopCallback, param_vp);
2916 LoopCallback (const char* type,
2917 const SyntheticChildren::SharedPointer& entry,
2918 RegularExpression* regex,
2919 CommandReturnObject *result)
2921 if (regex == NULL || regex->Execute(type))
2922 result->GetOutputStream().Printf ("%s: %s\n", type, entry->GetDescription().c_str());
2926 friend bool CommandObjectTypeFilterList_LoopCallback(void* pt2self, ConstString type, const SyntheticChildren::SharedPointer& entry);
2927 friend bool CommandObjectTypeFilterRXList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const SyntheticChildren::SharedPointer& entry);
2931 CommandObjectTypeFilterList_LoopCallback (void* pt2self,
2933 const SyntheticChildren::SharedPointer& entry)
2935 CommandObjectTypeFilterList_LoopCallbackParam* param = (CommandObjectTypeFilterList_LoopCallbackParam*)pt2self;
2936 return param->self->LoopCallback(type.AsCString(), entry, param->regex, param->result);
2940 CommandObjectTypeFilterRXList_LoopCallback (void* pt2self,
2941 lldb::RegularExpressionSP regex,
2942 const SyntheticChildren::SharedPointer& entry)
2944 CommandObjectTypeFilterList_LoopCallbackParam* param = (CommandObjectTypeFilterList_LoopCallbackParam*)pt2self;
2945 return param->self->LoopCallback(regex->GetText(), entry, param->regex, param->result);
2950 CommandObjectTypeFilterList::CommandOptions::g_option_table[] =
2952 { LLDB_OPT_SET_ALL, false, "category-regex", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Only show categories matching this filter."},
2953 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
2956 #ifndef LLDB_DISABLE_PYTHON
2958 //-------------------------------------------------------------------------
2959 // CommandObjectTypeSynthList
2960 //-------------------------------------------------------------------------
2962 bool CommandObjectTypeSynthList_LoopCallback(void* pt2self, ConstString type, const SyntheticChildren::SharedPointer& entry);
2963 bool CommandObjectTypeSynthRXList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const SyntheticChildren::SharedPointer& entry);
2965 class CommandObjectTypeSynthList;
2967 struct CommandObjectTypeSynthList_LoopCallbackParam {
2968 CommandObjectTypeSynthList* self;
2969 CommandReturnObject* result;
2970 RegularExpression* regex;
2971 RegularExpression* cate_regex;
2972 CommandObjectTypeSynthList_LoopCallbackParam(CommandObjectTypeSynthList* S, CommandReturnObject* R,
2973 RegularExpression* X = NULL,
2974 RegularExpression* CX = NULL) : self(S), result(R), regex(X), cate_regex(CX) {}
2977 class CommandObjectTypeSynthList : public CommandObjectParsed
2980 class CommandOptions : public Options
2984 CommandOptions (CommandInterpreter &interpreter) :
2985 Options (interpreter)
2990 ~CommandOptions (){}
2993 SetOptionValue (uint32_t option_idx, const char *option_arg)
2996 const int short_option = m_getopt_table[option_idx].val;
2998 switch (short_option)
3001 m_category_regex = std::string(option_arg);
3004 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
3012 OptionParsingStarting ()
3014 m_category_regex = "";
3017 const OptionDefinition*
3020 return g_option_table;
3023 // Options table: Required for subclasses of Options.
3025 static OptionDefinition g_option_table[];
3027 // Instance variables to hold the values for command options.
3029 std::string m_category_regex;
3033 CommandOptions m_options;
3042 CommandObjectTypeSynthList (CommandInterpreter &interpreter) :
3043 CommandObjectParsed (interpreter,
3044 "type synthetic list",
3045 "Show a list of current synthetic providers.",
3047 m_options(interpreter)
3049 CommandArgumentEntry type_arg;
3050 CommandArgumentData type_style_arg;
3052 type_style_arg.arg_type = eArgTypeName;
3053 type_style_arg.arg_repetition = eArgRepeatOptional;
3055 type_arg.push_back (type_style_arg);
3057 m_arguments.push_back (type_arg);
3060 ~CommandObjectTypeSynthList ()
3066 DoExecute (Args& command, CommandReturnObject &result)
3068 const size_t argc = command.GetArgumentCount();
3070 CommandObjectTypeSynthList_LoopCallbackParam *param;
3071 RegularExpression* cate_regex =
3072 m_options.m_category_regex.empty() ? NULL :
3073 new RegularExpression(m_options.m_category_regex.c_str());
3077 RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
3078 regex->Compile(command.GetArgumentAtIndex(0));
3079 param = new CommandObjectTypeSynthList_LoopCallbackParam(this,&result,regex,cate_regex);
3082 param = new CommandObjectTypeSynthList_LoopCallbackParam(this,&result,NULL,cate_regex);
3084 DataVisualization::Categories::LoopThrough(PerCategoryCallback,param);
3090 result.SetStatus(eReturnStatusSuccessFinishResult);
3091 return result.Succeeded();
3097 PerCategoryCallback(void* param_vp,
3098 const lldb::TypeCategoryImplSP& cate)
3101 CommandObjectTypeSynthList_LoopCallbackParam* param =
3102 (CommandObjectTypeSynthList_LoopCallbackParam*)param_vp;
3103 CommandReturnObject* result = param->result;
3105 const char* cate_name = cate->GetName();
3107 // if the category is disabled or empty and there is no regex, just skip it
3108 if ((cate->IsEnabled() == false || cate->GetCount(eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth) == 0) && param->cate_regex == NULL)
3111 // if we have a regex and this category does not match it, just skip it
3112 if(param->cate_regex != NULL && strcmp(cate_name,param->cate_regex->GetText()) != 0 && param->cate_regex->Execute(cate_name) == false)
3115 result->GetOutputStream().Printf("-----------------------\nCategory: %s (%s)\n-----------------------\n",
3117 (cate->IsEnabled() ? "enabled" : "disabled"));
3119 cate->GetTypeSyntheticsContainer()->LoopThrough(CommandObjectTypeSynthList_LoopCallback, param_vp);
3121 if (cate->GetRegexTypeSyntheticsContainer()->GetCount() > 0)
3123 result->GetOutputStream().Printf("Regex-based synthetic providers (slower):\n");
3124 cate->GetRegexTypeSyntheticsContainer()->LoopThrough(CommandObjectTypeSynthRXList_LoopCallback, param_vp);
3131 LoopCallback (const char* type,
3132 const SyntheticChildren::SharedPointer& entry,
3133 RegularExpression* regex,
3134 CommandReturnObject *result)
3136 if (regex == NULL || regex->Execute(type))
3137 result->GetOutputStream().Printf ("%s: %s\n", type, entry->GetDescription().c_str());
3141 friend bool CommandObjectTypeSynthList_LoopCallback(void* pt2self, ConstString type, const SyntheticChildren::SharedPointer& entry);
3142 friend bool CommandObjectTypeSynthRXList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const SyntheticChildren::SharedPointer& entry);
3146 CommandObjectTypeSynthList_LoopCallback (void* pt2self,
3148 const SyntheticChildren::SharedPointer& entry)
3150 CommandObjectTypeSynthList_LoopCallbackParam* param = (CommandObjectTypeSynthList_LoopCallbackParam*)pt2self;
3151 return param->self->LoopCallback(type.AsCString(), entry, param->regex, param->result);
3155 CommandObjectTypeSynthRXList_LoopCallback (void* pt2self,
3156 lldb::RegularExpressionSP regex,
3157 const SyntheticChildren::SharedPointer& entry)
3159 CommandObjectTypeSynthList_LoopCallbackParam* param = (CommandObjectTypeSynthList_LoopCallbackParam*)pt2self;
3160 return param->self->LoopCallback(regex->GetText(), entry, param->regex, param->result);
3165 CommandObjectTypeSynthList::CommandOptions::g_option_table[] =
3167 { LLDB_OPT_SET_ALL, false, "category-regex", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Only show categories matching this filter."},
3168 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
3171 #endif // #ifndef LLDB_DISABLE_PYTHON
3172 //-------------------------------------------------------------------------
3173 // CommandObjectTypeFilterDelete
3174 //-------------------------------------------------------------------------
3176 class CommandObjectTypeFilterDelete : public CommandObjectParsed
3179 class CommandOptions : public Options
3183 CommandOptions (CommandInterpreter &interpreter) :
3184 Options (interpreter)
3189 ~CommandOptions (){}
3192 SetOptionValue (uint32_t option_idx, const char *option_arg)
3195 const int short_option = m_getopt_table[option_idx].val;
3197 switch (short_option)
3200 m_delete_all = true;
3203 m_category = std::string(option_arg);
3206 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
3214 OptionParsingStarting ()
3216 m_delete_all = false;
3217 m_category = "default";
3220 const OptionDefinition*
3223 return g_option_table;
3226 // Options table: Required for subclasses of Options.
3228 static OptionDefinition g_option_table[];
3230 // Instance variables to hold the values for command options.
3233 std::string m_category;
3237 CommandOptions m_options;
3246 PerCategoryCallback(void* param,
3247 const lldb::TypeCategoryImplSP& cate)
3249 ConstString *name = (ConstString*)param;
3250 return cate->Delete(*name, eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter);
3254 CommandObjectTypeFilterDelete (CommandInterpreter &interpreter) :
3255 CommandObjectParsed (interpreter,
3256 "type filter delete",
3257 "Delete an existing filter for a type.",
3259 m_options(interpreter)
3261 CommandArgumentEntry type_arg;
3262 CommandArgumentData type_style_arg;
3264 type_style_arg.arg_type = eArgTypeName;
3265 type_style_arg.arg_repetition = eArgRepeatPlain;
3267 type_arg.push_back (type_style_arg);
3269 m_arguments.push_back (type_arg);
3273 ~CommandObjectTypeFilterDelete ()
3279 DoExecute (Args& command, CommandReturnObject &result)
3281 const size_t argc = command.GetArgumentCount();
3285 result.AppendErrorWithFormat ("%s takes 1 arg.\n", m_cmd_name.c_str());
3286 result.SetStatus(eReturnStatusFailed);
3290 const char* typeA = command.GetArgumentAtIndex(0);
3291 ConstString typeCS(typeA);
3295 result.AppendError("empty typenames not allowed");
3296 result.SetStatus(eReturnStatusFailed);
3300 if (m_options.m_delete_all)
3302 DataVisualization::Categories::LoopThrough(PerCategoryCallback, (void*)&typeCS);
3303 result.SetStatus(eReturnStatusSuccessFinishNoResult);
3304 return result.Succeeded();
3307 lldb::TypeCategoryImplSP category;
3308 DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
3310 bool delete_category = category->GetTypeFiltersContainer()->Delete(typeCS);
3311 delete_category = category->GetRegexTypeFiltersContainer()->Delete(typeCS) || delete_category;
3313 if (delete_category)
3315 result.SetStatus(eReturnStatusSuccessFinishNoResult);
3316 return result.Succeeded();
3320 result.AppendErrorWithFormat ("no custom synthetic provider for %s.\n", typeA);
3321 result.SetStatus(eReturnStatusFailed);
3329 CommandObjectTypeFilterDelete::CommandOptions::g_option_table[] =
3331 { LLDB_OPT_SET_1, false, "all", 'a', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Delete from every category."},
3332 { LLDB_OPT_SET_2, false, "category", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Delete from given category."},
3333 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
3336 #ifndef LLDB_DISABLE_PYTHON
3338 //-------------------------------------------------------------------------
3339 // CommandObjectTypeSynthDelete
3340 //-------------------------------------------------------------------------
3342 class CommandObjectTypeSynthDelete : public CommandObjectParsed
3345 class CommandOptions : public Options
3349 CommandOptions (CommandInterpreter &interpreter) :
3350 Options (interpreter)
3355 ~CommandOptions (){}
3358 SetOptionValue (uint32_t option_idx, const char *option_arg)
3361 const int short_option = m_getopt_table[option_idx].val;
3363 switch (short_option)
3366 m_delete_all = true;
3369 m_category = std::string(option_arg);
3372 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
3380 OptionParsingStarting ()
3382 m_delete_all = false;
3383 m_category = "default";
3386 const OptionDefinition*
3389 return g_option_table;
3392 // Options table: Required for subclasses of Options.
3394 static OptionDefinition g_option_table[];
3396 // Instance variables to hold the values for command options.
3399 std::string m_category;
3403 CommandOptions m_options;
3412 PerCategoryCallback(void* param,
3413 const lldb::TypeCategoryImplSP& cate)
3415 ConstString* name = (ConstString*)param;
3416 return cate->Delete(*name, eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth);
3420 CommandObjectTypeSynthDelete (CommandInterpreter &interpreter) :
3421 CommandObjectParsed (interpreter,
3422 "type synthetic delete",
3423 "Delete an existing synthetic provider for a type.",
3425 m_options(interpreter)
3427 CommandArgumentEntry type_arg;
3428 CommandArgumentData type_style_arg;
3430 type_style_arg.arg_type = eArgTypeName;
3431 type_style_arg.arg_repetition = eArgRepeatPlain;
3433 type_arg.push_back (type_style_arg);
3435 m_arguments.push_back (type_arg);
3439 ~CommandObjectTypeSynthDelete ()
3445 DoExecute (Args& command, CommandReturnObject &result)
3447 const size_t argc = command.GetArgumentCount();
3451 result.AppendErrorWithFormat ("%s takes 1 arg.\n", m_cmd_name.c_str());
3452 result.SetStatus(eReturnStatusFailed);
3456 const char* typeA = command.GetArgumentAtIndex(0);
3457 ConstString typeCS(typeA);
3461 result.AppendError("empty typenames not allowed");
3462 result.SetStatus(eReturnStatusFailed);
3466 if (m_options.m_delete_all)
3468 DataVisualization::Categories::LoopThrough(PerCategoryCallback, (void*)&typeCS);
3469 result.SetStatus(eReturnStatusSuccessFinishNoResult);
3470 return result.Succeeded();
3473 lldb::TypeCategoryImplSP category;
3474 DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
3476 bool delete_category = category->GetTypeSyntheticsContainer()->Delete(typeCS);
3477 delete_category = category->GetRegexTypeSyntheticsContainer()->Delete(typeCS) || delete_category;
3479 if (delete_category)
3481 result.SetStatus(eReturnStatusSuccessFinishNoResult);
3482 return result.Succeeded();
3486 result.AppendErrorWithFormat ("no custom synthetic provider for %s.\n", typeA);
3487 result.SetStatus(eReturnStatusFailed);
3495 CommandObjectTypeSynthDelete::CommandOptions::g_option_table[] =
3497 { LLDB_OPT_SET_1, false, "all", 'a', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Delete from every category."},
3498 { LLDB_OPT_SET_2, false, "category", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Delete from given category."},
3499 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
3502 #endif // #ifndef LLDB_DISABLE_PYTHON
3504 //-------------------------------------------------------------------------
3505 // CommandObjectTypeFilterClear
3506 //-------------------------------------------------------------------------
3508 class CommandObjectTypeFilterClear : public CommandObjectParsed
3512 class CommandOptions : public Options
3516 CommandOptions (CommandInterpreter &interpreter) :
3517 Options (interpreter)
3522 ~CommandOptions (){}
3525 SetOptionValue (uint32_t option_idx, const char *option_arg)
3528 const int short_option = m_getopt_table[option_idx].val;
3530 switch (short_option)
3533 m_delete_all = true;
3536 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
3544 OptionParsingStarting ()
3546 m_delete_all = false;
3549 const OptionDefinition*
3552 return g_option_table;
3555 // Options table: Required for subclasses of Options.
3557 static OptionDefinition g_option_table[];
3559 // Instance variables to hold the values for command options.
3562 bool m_delete_named;
3565 CommandOptions m_options;
3574 PerCategoryCallback(void* param,
3575 const lldb::TypeCategoryImplSP& cate)
3577 cate->Clear(eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter);
3583 CommandObjectTypeFilterClear (CommandInterpreter &interpreter) :
3584 CommandObjectParsed (interpreter,
3585 "type filter clear",
3586 "Delete all existing filters.",
3588 m_options(interpreter)
3592 ~CommandObjectTypeFilterClear ()
3598 DoExecute (Args& command, CommandReturnObject &result)
3601 if (m_options.m_delete_all)
3602 DataVisualization::Categories::LoopThrough(PerCategoryCallback, NULL);
3606 lldb::TypeCategoryImplSP category;
3607 if (command.GetArgumentCount() > 0)
3609 const char* cat_name = command.GetArgumentAtIndex(0);
3610 ConstString cat_nameCS(cat_name);
3611 DataVisualization::Categories::GetCategory(cat_nameCS, category);
3614 DataVisualization::Categories::GetCategory(ConstString(NULL), category);
3615 category->GetTypeFiltersContainer()->Clear();
3616 category->GetRegexTypeFiltersContainer()->Clear();
3619 result.SetStatus(eReturnStatusSuccessFinishResult);
3620 return result.Succeeded();
3626 CommandObjectTypeFilterClear::CommandOptions::g_option_table[] =
3628 { LLDB_OPT_SET_ALL, false, "all", 'a', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Clear every category."},
3629 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
3632 #ifndef LLDB_DISABLE_PYTHON
3633 //-------------------------------------------------------------------------
3634 // CommandObjectTypeSynthClear
3635 //-------------------------------------------------------------------------
3637 class CommandObjectTypeSynthClear : public CommandObjectParsed
3641 class CommandOptions : public Options
3645 CommandOptions (CommandInterpreter &interpreter) :
3646 Options (interpreter)
3651 ~CommandOptions (){}
3654 SetOptionValue (uint32_t option_idx, const char *option_arg)
3657 const int short_option = m_getopt_table[option_idx].val;
3659 switch (short_option)
3662 m_delete_all = true;
3665 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
3673 OptionParsingStarting ()
3675 m_delete_all = false;
3678 const OptionDefinition*
3681 return g_option_table;
3684 // Options table: Required for subclasses of Options.
3686 static OptionDefinition g_option_table[];
3688 // Instance variables to hold the values for command options.
3691 bool m_delete_named;
3694 CommandOptions m_options;
3703 PerCategoryCallback(void* param,
3704 const lldb::TypeCategoryImplSP& cate)
3706 cate->Clear(eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth);
3712 CommandObjectTypeSynthClear (CommandInterpreter &interpreter) :
3713 CommandObjectParsed (interpreter,
3714 "type synthetic clear",
3715 "Delete all existing synthetic providers.",
3717 m_options(interpreter)
3721 ~CommandObjectTypeSynthClear ()
3727 DoExecute (Args& command, CommandReturnObject &result)
3730 if (m_options.m_delete_all)
3731 DataVisualization::Categories::LoopThrough(PerCategoryCallback, NULL);
3735 lldb::TypeCategoryImplSP category;
3736 if (command.GetArgumentCount() > 0)
3738 const char* cat_name = command.GetArgumentAtIndex(0);
3739 ConstString cat_nameCS(cat_name);
3740 DataVisualization::Categories::GetCategory(cat_nameCS, category);
3743 DataVisualization::Categories::GetCategory(ConstString(NULL), category);
3744 category->GetTypeSyntheticsContainer()->Clear();
3745 category->GetRegexTypeSyntheticsContainer()->Clear();
3748 result.SetStatus(eReturnStatusSuccessFinishResult);
3749 return result.Succeeded();
3755 CommandObjectTypeSynthClear::CommandOptions::g_option_table[] =
3757 { LLDB_OPT_SET_ALL, false, "all", 'a', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Clear every category."},
3758 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
3763 CommandObjectTypeSynthAdd::Execute_HandwritePython (Args& command, CommandReturnObject &result)
3765 SynthAddOptions *options = new SynthAddOptions ( m_options.m_skip_pointers,
3766 m_options.m_skip_references,
3767 m_options.m_cascade,
3769 m_options.m_category);
3771 const size_t argc = command.GetArgumentCount();
3773 for (size_t i = 0; i < argc; i++)
3775 const char* typeA = command.GetArgumentAtIndex(i);
3776 if (typeA && *typeA)
3777 options->m_target_types << typeA;
3780 result.AppendError("empty typenames not allowed");
3781 result.SetStatus(eReturnStatusFailed);
3786 m_interpreter.GetPythonCommandsFromIOHandler (" ", // Prompt
3787 *this, // IOHandlerDelegate
3788 true, // Run IOHandler in async mode
3789 options); // Baton for the "io_handler" that will be passed back into our IOHandlerDelegate functions
3790 result.SetStatus(eReturnStatusSuccessFinishNoResult);
3791 return result.Succeeded();
3795 CommandObjectTypeSynthAdd::Execute_PythonClass (Args& command, CommandReturnObject &result)
3797 const size_t argc = command.GetArgumentCount();
3801 result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
3802 result.SetStatus(eReturnStatusFailed);
3806 if (m_options.m_class_name.empty() && !m_options.m_input_python)
3808 result.AppendErrorWithFormat ("%s needs either a Python class name or -P to directly input Python code.\n", m_cmd_name.c_str());
3809 result.SetStatus(eReturnStatusFailed);
3813 SyntheticChildrenSP entry;
3815 ScriptedSyntheticChildren* impl = new ScriptedSyntheticChildren(SyntheticChildren::Flags().
3816 SetCascades(m_options.m_cascade).
3817 SetSkipPointers(m_options.m_skip_pointers).
3818 SetSkipReferences(m_options.m_skip_references),
3819 m_options.m_class_name.c_str());
3823 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
3825 if (interpreter && interpreter->CheckObjectExists(impl->GetPythonClassName()) == false)
3826 result.AppendWarning("The provided class does not exist - please define it before attempting to use this synthetic provider");
3828 // now I have a valid provider, let's add it to every type
3830 lldb::TypeCategoryImplSP category;
3831 DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
3835 for (size_t i = 0; i < argc; i++)
3837 const char* typeA = command.GetArgumentAtIndex(i);
3838 ConstString typeCS(typeA);
3841 if (!AddSynth(typeCS,
3843 m_options.m_regex ? eRegexSynth : eRegularSynth,
3844 m_options.m_category,
3847 result.AppendError(error.AsCString());
3848 result.SetStatus(eReturnStatusFailed);
3854 result.AppendError("empty typenames not allowed");
3855 result.SetStatus(eReturnStatusFailed);
3860 result.SetStatus(eReturnStatusSuccessFinishNoResult);
3861 return result.Succeeded();
3864 CommandObjectTypeSynthAdd::CommandObjectTypeSynthAdd (CommandInterpreter &interpreter) :
3865 CommandObjectParsed (interpreter,
3866 "type synthetic add",
3867 "Add a new synthetic provider for a type.",
3869 IOHandlerDelegateMultiline ("DONE"),
3870 m_options (interpreter)
3872 CommandArgumentEntry type_arg;
3873 CommandArgumentData type_style_arg;
3875 type_style_arg.arg_type = eArgTypeName;
3876 type_style_arg.arg_repetition = eArgRepeatPlus;
3878 type_arg.push_back (type_style_arg);
3880 m_arguments.push_back (type_arg);
3885 CommandObjectTypeSynthAdd::AddSynth(ConstString type_name,
3886 SyntheticChildrenSP entry,
3887 SynthFormatType type,
3888 std::string category_name,
3891 lldb::TypeCategoryImplSP category;
3892 DataVisualization::Categories::GetCategory(ConstString(category_name.c_str()), category);
3894 if (type == eRegularSynth)
3896 if (FixArrayTypeNameWithRegex (type_name))
3900 if (category->AnyMatches(type_name,
3901 eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter,
3905 error->SetErrorStringWithFormat("cannot add synthetic for type %s when filter is defined in same category!", type_name.AsCString());
3909 if (type == eRegexSynth)
3911 RegularExpressionSP typeRX(new RegularExpression());
3912 if (!typeRX->Compile(type_name.GetCString()))
3915 error->SetErrorString("regex format error (maybe this is not really a regex?)");
3919 category->GetRegexTypeSyntheticsContainer()->Delete(type_name);
3920 category->GetRegexTypeSyntheticsContainer()->Add(typeRX, entry);
3926 category->GetTypeSyntheticsContainer()->Add(type_name, entry);
3932 CommandObjectTypeSynthAdd::CommandOptions::g_option_table[] =
3934 { LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "If true, cascade through typedef chains."},
3935 { LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."},
3936 { LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Don't use this format for references-to-tNULL, ype objects."},
3937 { LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Add this to the given category instead of the default one."},
3938 { LLDB_OPT_SET_2, false, "python-class", 'l', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePythonClass, "Use this Python class to produce synthetic children."},
3939 { LLDB_OPT_SET_3, false, "input-python", 'P', OptionParser::eNoArgument,NULL, NULL, 0, eArgTypeNone, "Type Python code to generate a class that NULL, provides synthetic children."},
3940 { LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Type names are actually regular expressions."},
3941 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
3944 #endif // #ifndef LLDB_DISABLE_PYTHON
3946 class CommandObjectTypeFilterAdd : public CommandObjectParsed
3951 class CommandOptions : public Options
3953 typedef std::vector<std::string> option_vector;
3956 CommandOptions (CommandInterpreter &interpreter) :
3957 Options (interpreter)
3962 ~CommandOptions (){}
3965 SetOptionValue (uint32_t option_idx, const char *option_arg)
3968 const int short_option = m_getopt_table[option_idx].val;
3971 switch (short_option)
3974 m_cascade = Args::StringToBoolean(option_arg, true, &success);
3976 error.SetErrorStringWithFormat("invalid value for cascade: %s", option_arg);
3979 m_expr_paths.push_back(option_arg);
3980 has_child_list = true;
3983 m_skip_pointers = true;
3986 m_skip_references = true;
3989 m_category = std::string(option_arg);
3995 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
4003 OptionParsingStarting ()
4006 m_skip_pointers = false;
4007 m_skip_references = false;
4008 m_category = "default";
4009 m_expr_paths.clear();
4010 has_child_list = false;
4014 const OptionDefinition*
4017 return g_option_table;
4020 // Options table: Required for subclasses of Options.
4022 static OptionDefinition g_option_table[];
4024 // Instance variables to hold the values for command options.
4027 bool m_skip_references;
4028 bool m_skip_pointers;
4029 bool m_input_python;
4030 option_vector m_expr_paths;
4031 std::string m_category;
4033 bool has_child_list;
4037 typedef option_vector::iterator ExpressionPathsIterator;
4040 CommandOptions m_options;
4048 enum FilterFormatType
4055 AddFilter(ConstString type_name,
4056 SyntheticChildrenSP entry,
4057 FilterFormatType type,
4058 std::string category_name,
4061 lldb::TypeCategoryImplSP category;
4062 DataVisualization::Categories::GetCategory(ConstString(category_name.c_str()), category);
4064 if (type == eRegularFilter)
4066 if (FixArrayTypeNameWithRegex (type_name))
4067 type = eRegexFilter;
4070 if (category->AnyMatches(type_name,
4071 eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth,
4075 error->SetErrorStringWithFormat("cannot add filter for type %s when synthetic is defined in same category!", type_name.AsCString());
4079 if (type == eRegexFilter)
4081 RegularExpressionSP typeRX(new RegularExpression());
4082 if (!typeRX->Compile(type_name.GetCString()))
4085 error->SetErrorString("regex format error (maybe this is not really a regex?)");
4089 category->GetRegexTypeFiltersContainer()->Delete(type_name);
4090 category->GetRegexTypeFiltersContainer()->Add(typeRX, entry);
4096 category->GetTypeFiltersContainer()->Add(type_name, entry);
4104 CommandObjectTypeFilterAdd (CommandInterpreter &interpreter) :
4105 CommandObjectParsed (interpreter,
4107 "Add a new filter for a type.",
4109 m_options (interpreter)
4111 CommandArgumentEntry type_arg;
4112 CommandArgumentData type_style_arg;
4114 type_style_arg.arg_type = eArgTypeName;
4115 type_style_arg.arg_repetition = eArgRepeatPlus;
4117 type_arg.push_back (type_style_arg);
4119 m_arguments.push_back (type_arg);
4122 "Some examples of using this command.\n"
4123 "We use as reference the following snippet of code:\n"
4137 "type filter add --child a --child g Foo\n"
4138 "frame variable a_foo\n"
4139 "will produce an output where only a and g are displayed\n"
4140 "Other children of a_foo (b,c,d,e,f,h and i) are available by asking for them, as in:\n"
4141 "frame variable a_foo.b a_foo.c ... a_foo.i\n"
4143 "Use option --raw to frame variable prevails on the filter\n"
4144 "frame variable a_foo --raw\n"
4145 "shows all the children of a_foo (a thru i) as if no filter was defined\n"
4149 ~CommandObjectTypeFilterAdd ()
4155 DoExecute (Args& command, CommandReturnObject &result)
4157 const size_t argc = command.GetArgumentCount();
4161 result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
4162 result.SetStatus(eReturnStatusFailed);
4166 if (m_options.m_expr_paths.size() == 0)
4168 result.AppendErrorWithFormat ("%s needs one or more children.\n", m_cmd_name.c_str());
4169 result.SetStatus(eReturnStatusFailed);
4173 SyntheticChildrenSP entry;
4175 TypeFilterImpl* impl = new TypeFilterImpl(SyntheticChildren::Flags().SetCascades(m_options.m_cascade).
4176 SetSkipPointers(m_options.m_skip_pointers).
4177 SetSkipReferences(m_options.m_skip_references));
4181 // go through the expression paths
4182 CommandOptions::ExpressionPathsIterator begin, end = m_options.m_expr_paths.end();
4184 for (begin = m_options.m_expr_paths.begin(); begin != end; begin++)
4185 impl->AddExpressionPath(*begin);
4188 // now I have a valid provider, let's add it to every type
4190 lldb::TypeCategoryImplSP category;
4191 DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
4195 WarnOnPotentialUnquotedUnsignedType(command, result);
4197 for (size_t i = 0; i < argc; i++)
4199 const char* typeA = command.GetArgumentAtIndex(i);
4200 ConstString typeCS(typeA);
4203 if (!AddFilter(typeCS,
4205 m_options.m_regex ? eRegexFilter : eRegularFilter,
4206 m_options.m_category,
4209 result.AppendError(error.AsCString());
4210 result.SetStatus(eReturnStatusFailed);
4216 result.AppendError("empty typenames not allowed");
4217 result.SetStatus(eReturnStatusFailed);
4222 result.SetStatus(eReturnStatusSuccessFinishNoResult);
4223 return result.Succeeded();
4229 CommandObjectTypeFilterAdd::CommandOptions::g_option_table[] =
4231 { LLDB_OPT_SET_ALL, false, "cascade", 'C', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "If true, cascade through typedef chains."},
4232 { LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."},
4233 { LLDB_OPT_SET_ALL, false, "skip-references", 'r', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Don't use this format for references-to-type objects."},
4234 { LLDB_OPT_SET_ALL, false, "category", 'w', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeName, "Add this to the given category instead of the default one."},
4235 { LLDB_OPT_SET_ALL, false, "child", 'c', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeExpressionPath, "Include this expression path in the synthetic view."},
4236 { LLDB_OPT_SET_ALL, false, "regex", 'x', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeNone, "Type names are actually regular expressions."},
4237 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
4240 template <typename FormatterType>
4241 class CommandObjectFormatterInfo : public CommandObjectRaw
4244 typedef std::function<typename FormatterType::SharedPointer(ValueObject&)> DiscoveryFunction;
4245 CommandObjectFormatterInfo (CommandInterpreter &interpreter,
4246 const char* formatter_name,
4247 DiscoveryFunction discovery_func) :
4248 CommandObjectRaw(interpreter,
4252 eFlagRequiresFrame),
4253 m_formatter_name(formatter_name ? formatter_name : ""),
4254 m_discovery_function(discovery_func)
4257 name.Printf("type %s info", formatter_name);
4258 SetCommandName(name.GetData());
4260 help.Printf("This command evaluates the provided expression and shows which %s is applied to the resulting value (if any).", formatter_name);
4261 SetHelp(help.GetData());
4262 StreamString syntax;
4263 syntax.Printf("type %s info <expr>", formatter_name);
4264 SetSyntax(syntax.GetData());
4268 ~CommandObjectFormatterInfo ()
4274 DoExecute (const char *command, CommandReturnObject &result)
4276 auto target_sp = m_interpreter.GetDebugger().GetSelectedTarget();
4277 auto frame_sp = target_sp->GetProcessSP()->GetThreadList().GetSelectedThread()->GetSelectedFrame();
4278 ValueObjectSP result_valobj_sp;
4279 EvaluateExpressionOptions options;
4280 lldb::ExpressionResults expr_result = target_sp->EvaluateExpression(command, frame_sp.get(), result_valobj_sp, options);
4281 if (expr_result == eExpressionCompleted && result_valobj_sp)
4283 result_valobj_sp = result_valobj_sp->GetQualifiedRepresentationIfAvailable(target_sp->GetPreferDynamicValue(), target_sp->GetEnableSyntheticValue());
4284 typename FormatterType::SharedPointer formatter_sp = m_discovery_function(*result_valobj_sp);
4287 std::string description(formatter_sp->GetDescription());
4288 result.AppendMessageWithFormat("%s applied to (%s) %s is: %s\n",
4289 m_formatter_name.c_str(),
4290 result_valobj_sp->GetDisplayTypeName().AsCString("<unknown>"),
4292 description.c_str());
4293 result.SetStatus(lldb::eReturnStatusSuccessFinishResult);
4297 result.AppendMessageWithFormat("no %s applies to (%s) %s\n",
4298 m_formatter_name.c_str(),
4299 result_valobj_sp->GetDisplayTypeName().AsCString("<unknown>"),
4301 result.SetStatus(lldb::eReturnStatusSuccessFinishNoResult);
4307 result.AppendError("failed to evaluate expression");
4308 result.SetStatus(lldb::eReturnStatusFailed);
4314 std::string m_formatter_name;
4315 DiscoveryFunction m_discovery_function;
4318 class CommandObjectTypeFormat : public CommandObjectMultiword
4321 CommandObjectTypeFormat (CommandInterpreter &interpreter) :
4322 CommandObjectMultiword (interpreter,
4324 "A set of commands for editing variable value display options",
4325 "type format [<sub-command-options>] ")
4327 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTypeFormatAdd (interpreter)));
4328 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTypeFormatClear (interpreter)));
4329 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeFormatDelete (interpreter)));
4330 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeFormatList (interpreter)));
4331 LoadSubCommand ("info", CommandObjectSP (new CommandObjectFormatterInfo<TypeFormatImpl>(interpreter,
4333 [](ValueObject& valobj) -> TypeFormatImpl::SharedPointer {
4334 return valobj.GetValueFormat();
4339 ~CommandObjectTypeFormat ()
4344 #ifndef LLDB_DISABLE_PYTHON
4346 class CommandObjectTypeSynth : public CommandObjectMultiword
4349 CommandObjectTypeSynth (CommandInterpreter &interpreter) :
4350 CommandObjectMultiword (interpreter,
4352 "A set of commands for operating on synthetic type representations",
4353 "type synthetic [<sub-command-options>] ")
4355 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTypeSynthAdd (interpreter)));
4356 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTypeSynthClear (interpreter)));
4357 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeSynthDelete (interpreter)));
4358 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeSynthList (interpreter)));
4359 LoadSubCommand ("info", CommandObjectSP (new CommandObjectFormatterInfo<SyntheticChildren>(interpreter,
4361 [](ValueObject& valobj) -> SyntheticChildren::SharedPointer {
4362 return valobj.GetSyntheticChildren();
4367 ~CommandObjectTypeSynth ()
4372 #endif // #ifndef LLDB_DISABLE_PYTHON
4374 class CommandObjectTypeFilter : public CommandObjectMultiword
4377 CommandObjectTypeFilter (CommandInterpreter &interpreter) :
4378 CommandObjectMultiword (interpreter,
4380 "A set of commands for operating on type filters",
4381 "type synthetic [<sub-command-options>] ")
4383 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTypeFilterAdd (interpreter)));
4384 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTypeFilterClear (interpreter)));
4385 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeFilterDelete (interpreter)));
4386 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeFilterList (interpreter)));
4390 ~CommandObjectTypeFilter ()
4395 class CommandObjectTypeCategory : public CommandObjectMultiword
4398 CommandObjectTypeCategory (CommandInterpreter &interpreter) :
4399 CommandObjectMultiword (interpreter,
4401 "A set of commands for operating on categories",
4402 "type category [<sub-command-options>] ")
4404 LoadSubCommand ("enable", CommandObjectSP (new CommandObjectTypeCategoryEnable (interpreter)));
4405 LoadSubCommand ("disable", CommandObjectSP (new CommandObjectTypeCategoryDisable (interpreter)));
4406 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeCategoryDelete (interpreter)));
4407 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeCategoryList (interpreter)));
4411 ~CommandObjectTypeCategory ()
4416 class CommandObjectTypeSummary : public CommandObjectMultiword
4419 CommandObjectTypeSummary (CommandInterpreter &interpreter) :
4420 CommandObjectMultiword (interpreter,
4422 "A set of commands for editing variable summary display options",
4423 "type summary [<sub-command-options>] ")
4425 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTypeSummaryAdd (interpreter)));
4426 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTypeSummaryClear (interpreter)));
4427 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeSummaryDelete (interpreter)));
4428 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeSummaryList (interpreter)));
4429 LoadSubCommand ("info", CommandObjectSP (new CommandObjectFormatterInfo<TypeSummaryImpl>(interpreter,
4431 [](ValueObject& valobj) -> TypeSummaryImpl::SharedPointer {
4432 return valobj.GetSummaryFormat();
4437 ~CommandObjectTypeSummary ()
4442 //-------------------------------------------------------------------------
4443 // CommandObjectType
4444 //-------------------------------------------------------------------------
4446 CommandObjectType::CommandObjectType (CommandInterpreter &interpreter) :
4447 CommandObjectMultiword (interpreter,
4449 "A set of commands for operating on the type system",
4450 "type [<sub-command-options>]")
4452 LoadSubCommand ("category", CommandObjectSP (new CommandObjectTypeCategory (interpreter)));
4453 LoadSubCommand ("filter", CommandObjectSP (new CommandObjectTypeFilter (interpreter)));
4454 LoadSubCommand ("format", CommandObjectSP (new CommandObjectTypeFormat (interpreter)));
4455 LoadSubCommand ("summary", CommandObjectSP (new CommandObjectTypeSummary (interpreter)));
4456 #ifndef LLDB_DISABLE_PYTHON
4457 LoadSubCommand ("synthetic", CommandObjectSP (new CommandObjectTypeSynth (interpreter)));
4462 CommandObjectType::~CommandObjectType ()