1 //===-- CommandObjectType.cpp ----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/lldb-python.h"
12 #include "CommandObjectType.h"
20 #include "lldb/Core/ConstString.h"
21 #include "lldb/Core/Debugger.h"
22 #include "lldb/Core/InputReaderEZ.h"
23 #include "lldb/Core/RegularExpression.h"
24 #include "lldb/Core/State.h"
25 #include "lldb/Core/StringList.h"
26 #include "lldb/DataFormatters/DataVisualization.h"
27 #include "lldb/Interpreter/CommandInterpreter.h"
28 #include "lldb/Interpreter/CommandObject.h"
29 #include "lldb/Interpreter/CommandReturnObject.h"
30 #include "lldb/Interpreter/Options.h"
31 #include "lldb/Interpreter/OptionGroupFormat.h"
34 using namespace lldb_private;
37 class ScriptAddOptions
42 TypeSummaryImpl::Flags m_flags;
44 StringList m_target_types;
45 StringList m_user_source;
51 std::string m_category;
53 ScriptAddOptions(const TypeSummaryImpl::Flags& flags,
55 const ConstString& name,
64 typedef std::shared_ptr<ScriptAddOptions> SharedPointer;
74 bool m_skip_references;
77 StringList m_user_source;
78 StringList m_target_types;
80 std::string m_category;
82 SynthAddOptions(bool sptr,
87 m_skip_pointers(sptr),
88 m_skip_references(sref),
97 typedef std::shared_ptr<SynthAddOptions> SharedPointer;
103 class CommandObjectTypeSummaryAdd : public CommandObjectParsed
108 class CommandOptions : public Options
112 CommandOptions (CommandInterpreter &interpreter) :
113 Options (interpreter)
121 SetOptionValue (uint32_t option_idx, const char *option_arg);
124 OptionParsingStarting ();
126 const OptionDefinition*
129 return g_option_table;
132 // Options table: Required for subclasses of Options.
134 static OptionDefinition g_option_table[];
136 // Instance variables to hold the values for command options.
138 TypeSummaryImpl::Flags m_flags;
140 std::string m_format_string;
142 std::string m_python_script;
143 std::string m_python_function;
144 bool m_is_add_script;
145 std::string m_category;
148 CommandOptions m_options;
157 CollectPythonScript(ScriptAddOptions *options,
158 CommandReturnObject &result);
161 Execute_ScriptSummary (Args& command, CommandReturnObject &result);
164 Execute_StringSummary (Args& command, CommandReturnObject &result);
168 enum SummaryFormatType
175 CommandObjectTypeSummaryAdd (CommandInterpreter &interpreter);
177 ~CommandObjectTypeSummaryAdd ()
182 AddSummary(ConstString type_name,
183 lldb::TypeSummaryImplSP entry,
184 SummaryFormatType type,
185 std::string category,
186 Error* error = NULL);
189 DoExecute (Args& command, CommandReturnObject &result);
193 class CommandObjectTypeSynthAdd : public CommandObjectParsed
198 class CommandOptions : public Options
202 CommandOptions (CommandInterpreter &interpreter) :
203 Options (interpreter)
211 SetOptionValue (uint32_t option_idx, const char *option_arg)
214 const int short_option = m_getopt_table[option_idx].val;
217 switch (short_option)
220 m_cascade = Args::StringToBoolean(option_arg, true, &success);
222 error.SetErrorStringWithFormat("invalid value for cascade: %s", option_arg);
225 handwrite_python = true;
228 m_class_name = std::string(option_arg);
229 is_class_based = true;
232 m_skip_pointers = true;
235 m_skip_references = true;
238 m_category = std::string(option_arg);
244 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
252 OptionParsingStarting ()
256 m_skip_pointers = false;
257 m_skip_references = false;
258 m_category = "default";
259 is_class_based = false;
260 handwrite_python = false;
264 const OptionDefinition*
267 return g_option_table;
270 // Options table: Required for subclasses of Options.
272 static OptionDefinition g_option_table[];
274 // Instance variables to hold the values for command options.
277 bool m_skip_references;
278 bool m_skip_pointers;
279 std::string m_class_name;
281 std::string m_category;
285 bool handwrite_python;
291 CommandOptions m_options;
300 CollectPythonScript (SynthAddOptions *options,
301 CommandReturnObject &result);
303 Execute_HandwritePython (Args& command, CommandReturnObject &result);
306 Execute_PythonClass (Args& command, CommandReturnObject &result);
310 DoExecute (Args& command, CommandReturnObject &result);
320 CommandObjectTypeSynthAdd (CommandInterpreter &interpreter);
322 ~CommandObjectTypeSynthAdd ()
327 AddSynth(ConstString type_name,
328 lldb::SyntheticChildrenSP entry,
329 SynthFormatType type,
330 std::string category_name,
334 //-------------------------------------------------------------------------
335 // CommandObjectTypeFormatAdd
336 //-------------------------------------------------------------------------
338 class CommandObjectTypeFormatAdd : public CommandObjectParsed
343 class CommandOptions : public OptionGroup
358 GetNumDefinitions ();
360 virtual const OptionDefinition*
363 return g_option_table;
367 OptionParsingStarting (CommandInterpreter &interpreter)
370 m_skip_pointers = false;
371 m_skip_references = false;
374 SetOptionValue (CommandInterpreter &interpreter,
376 const char *option_value)
379 const int short_option = g_option_table[option_idx].short_option;
382 switch (short_option)
385 m_cascade = Args::StringToBoolean(option_value, true, &success);
387 error.SetErrorStringWithFormat("invalid value for cascade: %s", option_value);
390 m_skip_pointers = true;
393 m_skip_references = true;
396 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
403 // Options table: Required for subclasses of Options.
405 static OptionDefinition g_option_table[];
407 // Instance variables to hold the values for command options.
410 bool m_skip_references;
411 bool m_skip_pointers;
414 OptionGroupOptions m_option_group;
415 OptionGroupFormat m_format_options;
416 CommandOptions m_command_options;
421 return &m_option_group;
425 CommandObjectTypeFormatAdd (CommandInterpreter &interpreter) :
426 CommandObjectParsed (interpreter,
428 "Add a new formatting style for a type.",
430 m_option_group (interpreter),
431 m_format_options (eFormatInvalid),
434 CommandArgumentEntry type_arg;
435 CommandArgumentData type_style_arg;
437 type_style_arg.arg_type = eArgTypeName;
438 type_style_arg.arg_repetition = eArgRepeatPlus;
440 type_arg.push_back (type_style_arg);
442 m_arguments.push_back (type_arg);
445 "Some examples of using this command.\n"
446 "We use as reference the following snippet of code:\n"
448 "typedef int Aint;\n"
449 "typedef float Afloat;\n"
450 "typedef Aint Bint;\n"
451 "typedef Afloat Bfloat;\n"
456 "Afloat fx = 3.14;\n"
457 "BFloat fy = 3.14;\n"
460 "type format add -f hex AInt\n"
461 "frame variable iy\n"
462 "will produce an hex display of iy, because no formatter is available for Bint and the one for Aint is used instead\n"
463 "To prevent this type\n"
464 "type format add -f hex -C no AInt\n"
466 "A similar reasoning applies to\n"
467 "type format add -f hex -C no float -p\n"
468 "which now prints all floats and float&s as hexadecimal, but does not format float*s\n"
469 "and does not change the default display for Afloat and Bfloat objects.\n"
472 // Add the "--format" to all options groups
473 m_option_group.Append (&m_format_options, OptionGroupFormat::OPTION_GROUP_FORMAT, LLDB_OPT_SET_ALL);
474 m_option_group.Append (&m_command_options);
475 m_option_group.Finalize();
479 ~CommandObjectTypeFormatAdd ()
485 DoExecute (Args& command, CommandReturnObject &result)
487 const size_t argc = command.GetArgumentCount();
491 result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
492 result.SetStatus(eReturnStatusFailed);
496 const Format format = m_format_options.GetFormat();
497 if (format == eFormatInvalid)
499 result.AppendErrorWithFormat ("%s needs a valid format.\n", m_cmd_name.c_str());
500 result.SetStatus(eReturnStatusFailed);
504 TypeFormatImplSP entry;
506 entry.reset(new TypeFormatImpl(format,
507 TypeFormatImpl::Flags().SetCascades(m_command_options.m_cascade).
508 SetSkipPointers(m_command_options.m_skip_pointers).
509 SetSkipReferences(m_command_options.m_skip_references)));
511 // now I have a valid format, let's add it to every type
513 for (size_t i = 0; i < argc; i++)
515 const char* typeA = command.GetArgumentAtIndex(i);
516 ConstString typeCS(typeA);
518 DataVisualization::ValueFormats::Add(typeCS, entry);
521 result.AppendError("empty typenames not allowed");
522 result.SetStatus(eReturnStatusFailed);
527 result.SetStatus(eReturnStatusSuccessFinishNoResult);
528 return result.Succeeded();
533 CommandObjectTypeFormatAdd::CommandOptions::g_option_table[] =
535 { LLDB_OPT_SET_ALL, false, "cascade", 'C', required_argument, NULL, 0, eArgTypeBoolean, "If true, cascade through typedef chains."},
536 { LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', no_argument, NULL, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."},
537 { LLDB_OPT_SET_ALL, false, "skip-references", 'r', no_argument, NULL, 0, eArgTypeNone, "Don't use this format for references-to-type objects."},
542 CommandObjectTypeFormatAdd::CommandOptions::GetNumDefinitions ()
544 return sizeof(g_option_table) / sizeof (OptionDefinition);
548 //-------------------------------------------------------------------------
549 // CommandObjectTypeFormatDelete
550 //-------------------------------------------------------------------------
552 class CommandObjectTypeFormatDelete : public CommandObjectParsed
555 CommandObjectTypeFormatDelete (CommandInterpreter &interpreter) :
556 CommandObjectParsed (interpreter,
557 "type format delete",
558 "Delete an existing formatting style for a type.",
561 CommandArgumentEntry type_arg;
562 CommandArgumentData type_style_arg;
564 type_style_arg.arg_type = eArgTypeName;
565 type_style_arg.arg_repetition = eArgRepeatPlain;
567 type_arg.push_back (type_style_arg);
569 m_arguments.push_back (type_arg);
573 ~CommandObjectTypeFormatDelete ()
579 DoExecute (Args& command, CommandReturnObject &result)
581 const size_t argc = command.GetArgumentCount();
585 result.AppendErrorWithFormat ("%s takes 1 arg.\n", m_cmd_name.c_str());
586 result.SetStatus(eReturnStatusFailed);
590 const char* typeA = command.GetArgumentAtIndex(0);
591 ConstString typeCS(typeA);
595 result.AppendError("empty typenames not allowed");
596 result.SetStatus(eReturnStatusFailed);
601 if (DataVisualization::ValueFormats::Delete(typeCS))
603 result.SetStatus(eReturnStatusSuccessFinishNoResult);
604 return result.Succeeded();
608 result.AppendErrorWithFormat ("no custom format for %s.\n", typeA);
609 result.SetStatus(eReturnStatusFailed);
617 //-------------------------------------------------------------------------
618 // CommandObjectTypeFormatClear
619 //-------------------------------------------------------------------------
621 class CommandObjectTypeFormatClear : public CommandObjectParsed
624 CommandObjectTypeFormatClear (CommandInterpreter &interpreter) :
625 CommandObjectParsed (interpreter,
627 "Delete all existing format styles.",
632 ~CommandObjectTypeFormatClear ()
638 DoExecute (Args& command, CommandReturnObject &result)
640 DataVisualization::ValueFormats::Clear();
641 result.SetStatus(eReturnStatusSuccessFinishResult);
642 return result.Succeeded();
647 //-------------------------------------------------------------------------
648 // CommandObjectTypeFormatList
649 //-------------------------------------------------------------------------
651 bool CommandObjectTypeFormatList_LoopCallback(void* pt2self, ConstString type, const lldb::TypeFormatImplSP& entry);
653 class CommandObjectTypeFormatList;
655 struct CommandObjectTypeFormatList_LoopCallbackParam {
656 CommandObjectTypeFormatList* self;
657 CommandReturnObject* result;
658 RegularExpression* regex;
659 CommandObjectTypeFormatList_LoopCallbackParam(CommandObjectTypeFormatList* S, CommandReturnObject* R,
660 RegularExpression* X = NULL) : self(S), result(R), regex(X) {}
663 class CommandObjectTypeFormatList : public CommandObjectParsed
666 CommandObjectTypeFormatList (CommandInterpreter &interpreter) :
667 CommandObjectParsed (interpreter,
669 "Show a list of current formatting styles.",
672 CommandArgumentEntry type_arg;
673 CommandArgumentData type_style_arg;
675 type_style_arg.arg_type = eArgTypeName;
676 type_style_arg.arg_repetition = eArgRepeatOptional;
678 type_arg.push_back (type_style_arg);
680 m_arguments.push_back (type_arg);
683 ~CommandObjectTypeFormatList ()
689 DoExecute (Args& command, CommandReturnObject &result)
691 const size_t argc = command.GetArgumentCount();
693 CommandObjectTypeFormatList_LoopCallbackParam *param;
697 RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
698 regex->Compile(command.GetArgumentAtIndex(0));
699 param = new CommandObjectTypeFormatList_LoopCallbackParam(this,&result,regex);
702 param = new CommandObjectTypeFormatList_LoopCallbackParam(this,&result);
703 DataVisualization::ValueFormats::LoopThrough(CommandObjectTypeFormatList_LoopCallback, param);
705 result.SetStatus(eReturnStatusSuccessFinishResult);
706 return result.Succeeded();
712 LoopCallback (ConstString type,
713 const lldb::TypeFormatImplSP& entry,
714 RegularExpression* regex,
715 CommandReturnObject *result)
717 if (regex == NULL || regex->Execute(type.AsCString()))
719 result->GetOutputStream().Printf ("%s: %s\n", type.AsCString(),
720 entry->GetDescription().c_str());
725 friend bool CommandObjectTypeFormatList_LoopCallback(void* pt2self, ConstString type, const lldb::TypeFormatImplSP& entry);
730 CommandObjectTypeFormatList_LoopCallback (
733 const lldb::TypeFormatImplSP& entry)
735 CommandObjectTypeFormatList_LoopCallbackParam* param = (CommandObjectTypeFormatList_LoopCallbackParam*)pt2self;
736 return param->self->LoopCallback(type, entry, param->regex, param->result);
740 #ifndef LLDB_DISABLE_PYTHON
742 //-------------------------------------------------------------------------
743 // CommandObjectTypeSummaryAdd
744 //-------------------------------------------------------------------------
746 static const char *g_summary_addreader_instructions = "Enter your Python command(s). Type 'DONE' to end.\n"
747 "def function (valobj,internal_dict):\n"
748 " \"\"\"valobj: an SBValue which you want to provide a summary for\n"
749 " internal_dict: an LLDB support object not to be used\"\"\"";
751 class TypeScriptAddInputReader : public InputReaderEZ
754 DISALLOW_COPY_AND_ASSIGN (TypeScriptAddInputReader);
756 TypeScriptAddInputReader(Debugger& debugger) :
757 InputReaderEZ(debugger)
761 ~TypeScriptAddInputReader()
765 virtual void ActivateHandler(HandlerData& data)
767 StreamSP out_stream = data.reader.GetDebugger().GetAsyncOutputStream();
768 bool batch_mode = data.reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
771 out_stream->Printf ("%s\n", g_summary_addreader_instructions);
772 if (data.reader.GetPrompt())
773 out_stream->Printf ("%s", data.reader.GetPrompt());
778 virtual void ReactivateHandler(HandlerData& data)
780 StreamSP out_stream = data.reader.GetDebugger().GetAsyncOutputStream();
781 bool batch_mode = data.reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
782 if (data.reader.GetPrompt() && !batch_mode)
784 out_stream->Printf ("%s", data.reader.GetPrompt());
788 virtual void GotTokenHandler(HandlerData& data)
790 StreamSP out_stream = data.reader.GetDebugger().GetAsyncOutputStream();
791 bool batch_mode = data.reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
792 if (data.bytes && data.bytes_len && data.baton)
794 ((ScriptAddOptions*)data.baton)->m_user_source.AppendString(data.bytes, data.bytes_len);
796 if (!data.reader.IsDone() && data.reader.GetPrompt() && !batch_mode)
798 out_stream->Printf ("%s", data.reader.GetPrompt());
802 virtual void InterruptHandler(HandlerData& data)
804 StreamSP out_stream = data.reader.GetDebugger().GetAsyncOutputStream();
805 bool batch_mode = data.reader.GetDebugger().GetCommandInterpreter().GetBatchCommandMode();
806 data.reader.SetIsDone (true);
809 out_stream->Printf ("Warning: No command attached to breakpoint.\n");
813 virtual void EOFHandler(HandlerData& data)
815 data.reader.SetIsDone (true);
817 virtual void DoneHandler(HandlerData& data)
819 StreamSP out_stream = data.reader.GetDebugger().GetAsyncOutputStream();
820 ScriptAddOptions *options_ptr = ((ScriptAddOptions*)data.baton);
823 out_stream->Printf ("internal synchronization information missing or invalid.\n");
828 ScriptAddOptions::SharedPointer options(options_ptr); // this will ensure that we get rid of the pointer when going out of scope
830 ScriptInterpreter *interpreter = data.reader.GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
833 out_stream->Printf ("no script interpreter.\n");
837 std::string funct_name_str;
838 if (!interpreter->GenerateTypeScriptFunction (options->m_user_source,
841 out_stream->Printf ("unable to generate a function.\n");
845 if (funct_name_str.empty())
847 out_stream->Printf ("unable to obtain a valid function name from the script interpreter.\n");
851 // now I have a valid function name, let's add this as script for every type in the list
853 TypeSummaryImplSP script_format;
854 script_format.reset(new ScriptSummaryFormat(options->m_flags,
855 funct_name_str.c_str(),
856 options->m_user_source.CopyList(" ").c_str()));
860 for (size_t i = 0; i < options->m_target_types.GetSize(); i++)
862 const char *type_name = options->m_target_types.GetStringAtIndex(i);
863 CommandObjectTypeSummaryAdd::AddSummary(ConstString(type_name),
865 (options->m_regex ? CommandObjectTypeSummaryAdd::eRegexSummary : CommandObjectTypeSummaryAdd::eRegularSummary),
870 out_stream->Printf ("%s", error.AsCString());
878 CommandObjectTypeSummaryAdd::AddSummary (options->m_name,
880 CommandObjectTypeSummaryAdd::eNamedSummary,
885 CommandObjectTypeSummaryAdd::AddSummary (options->m_name,
887 CommandObjectTypeSummaryAdd::eNamedSummary,
892 out_stream->Printf ("%s", error.AsCString());
899 out_stream->Printf ("%s", error.AsCString());
906 if (error.AsCString())
908 out_stream->PutCString (error.AsCString());
916 #endif // #ifndef LLDB_DISABLE_PYTHON
919 CommandObjectTypeSummaryAdd::CommandOptions::SetOptionValue (uint32_t option_idx, const char *option_arg)
922 const int short_option = m_getopt_table[option_idx].val;
925 switch (short_option)
928 m_flags.SetCascades(Args::StringToBoolean(option_arg, true, &success));
930 error.SetErrorStringWithFormat("invalid value for cascade: %s", option_arg);
933 m_flags.SetDontShowChildren(false);
936 m_flags.SetDontShowValue(true);
939 m_flags.SetShowMembersOneLiner(true);
942 m_format_string = std::string(option_arg);
945 m_flags.SetSkipPointers(true);
948 m_flags.SetSkipReferences(true);
954 m_name.SetCString(option_arg);
957 m_python_script = std::string(option_arg);
958 m_is_add_script = true;
961 m_python_function = std::string(option_arg);
962 m_is_add_script = true;
965 m_is_add_script = true;
968 m_category = std::string(option_arg);
971 m_flags.SetHideItemNames(true);
974 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
982 CommandObjectTypeSummaryAdd::CommandOptions::OptionParsingStarting ()
984 m_flags.Clear().SetCascades().SetDontShowChildren().SetDontShowValue(false);
985 m_flags.SetShowMembersOneLiner(false).SetSkipPointers(false).SetSkipReferences(false).SetHideItemNames(false);
989 m_python_script = "";
990 m_python_function = "";
991 m_format_string = "";
992 m_is_add_script = false;
993 m_category = "default";
996 #ifndef LLDB_DISABLE_PYTHON
998 CommandObjectTypeSummaryAdd::CollectPythonScript (ScriptAddOptions *options,
999 CommandReturnObject &result)
1001 InputReaderSP reader_sp (new TypeScriptAddInputReader(m_interpreter.GetDebugger()));
1002 if (reader_sp && options)
1005 InputReaderEZ::InitializationParameters ipr;
1007 Error err (reader_sp->Initialize (ipr.SetBaton(options).SetPrompt(" ")));
1010 m_interpreter.GetDebugger().PushInputReader (reader_sp);
1011 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1015 result.AppendError (err.AsCString());
1016 result.SetStatus (eReturnStatusFailed);
1021 result.AppendError("out of memory");
1022 result.SetStatus (eReturnStatusFailed);
1027 CommandObjectTypeSummaryAdd::Execute_ScriptSummary (Args& command, CommandReturnObject &result)
1029 const size_t argc = command.GetArgumentCount();
1031 if (argc < 1 && !m_options.m_name)
1033 result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
1034 result.SetStatus(eReturnStatusFailed);
1038 TypeSummaryImplSP script_format;
1040 if (!m_options.m_python_function.empty()) // we have a Python function ready to use
1042 const char *funct_name = m_options.m_python_function.c_str();
1043 if (!funct_name || !funct_name[0])
1045 result.AppendError ("function name empty.\n");
1046 result.SetStatus (eReturnStatusFailed);
1050 std::string code = (" " + m_options.m_python_function + "(valobj,internal_dict)");
1052 script_format.reset(new ScriptSummaryFormat(m_options.m_flags,
1056 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
1058 if (interpreter && interpreter->CheckObjectExists(funct_name) == false)
1059 result.AppendWarningWithFormat("The provided function \"%s\" does not exist - "
1060 "please define it before attempting to use this summary.\n",
1063 else if (!m_options.m_python_script.empty()) // we have a quick 1-line script, just use it
1065 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
1068 result.AppendError ("script interpreter missing - unable to generate function wrapper.\n");
1069 result.SetStatus (eReturnStatusFailed);
1072 StringList funct_sl;
1073 funct_sl << m_options.m_python_script.c_str();
1074 std::string funct_name_str;
1075 if (!interpreter->GenerateTypeScriptFunction (funct_sl,
1078 result.AppendError ("unable to generate function wrapper.\n");
1079 result.SetStatus (eReturnStatusFailed);
1082 if (funct_name_str.empty())
1084 result.AppendError ("script interpreter failed to generate a valid function name.\n");
1085 result.SetStatus (eReturnStatusFailed);
1089 std::string code = " " + m_options.m_python_script;
1091 script_format.reset(new ScriptSummaryFormat(m_options.m_flags,
1092 funct_name_str.c_str(),
1095 else // use an InputReader to grab Python code from the user
1097 ScriptAddOptions *options = new ScriptAddOptions(m_options.m_flags,
1100 m_options.m_category);
1102 for (size_t i = 0; i < argc; i++)
1104 const char* typeA = command.GetArgumentAtIndex(i);
1105 if (typeA && *typeA)
1106 options->m_target_types << typeA;
1109 result.AppendError("empty typenames not allowed");
1110 result.SetStatus(eReturnStatusFailed);
1115 CollectPythonScript(options,result);
1116 return result.Succeeded();
1119 // if I am here, script_format must point to something good, so I can add that
1120 // as a script summary to all interested parties
1124 for (size_t i = 0; i < command.GetArgumentCount(); i++)
1126 const char *type_name = command.GetArgumentAtIndex(i);
1127 CommandObjectTypeSummaryAdd::AddSummary(ConstString(type_name),
1129 (m_options.m_regex ? eRegexSummary : eRegularSummary),
1130 m_options.m_category,
1134 result.AppendError(error.AsCString());
1135 result.SetStatus(eReturnStatusFailed);
1140 if (m_options.m_name)
1142 AddSummary(m_options.m_name, script_format, eNamedSummary, m_options.m_category, &error);
1145 result.AppendError(error.AsCString());
1146 result.AppendError("added to types, but not given a name");
1147 result.SetStatus(eReturnStatusFailed);
1152 return result.Succeeded();
1159 CommandObjectTypeSummaryAdd::Execute_StringSummary (Args& command, CommandReturnObject &result)
1161 const size_t argc = command.GetArgumentCount();
1163 if (argc < 1 && !m_options.m_name)
1165 result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
1166 result.SetStatus(eReturnStatusFailed);
1170 if (!m_options.m_flags.GetShowMembersOneLiner() && m_options.m_format_string.empty())
1172 result.AppendError("empty summary strings not allowed");
1173 result.SetStatus(eReturnStatusFailed);
1177 const char* format_cstr = (m_options.m_flags.GetShowMembersOneLiner() ? "" : m_options.m_format_string.c_str());
1179 // ${var%S} is an endless recursion, prevent it
1180 if (strcmp(format_cstr, "${var%S}") == 0)
1182 result.AppendError("recursive summary not allowed");
1183 result.SetStatus(eReturnStatusFailed);
1189 lldb::TypeSummaryImplSP entry(new StringSummaryFormat(m_options.m_flags,
1194 result.AppendError(error.AsCString());
1195 result.SetStatus(eReturnStatusFailed);
1199 // now I have a valid format, let's add it to every type
1201 for (size_t i = 0; i < argc; i++)
1203 const char* typeA = command.GetArgumentAtIndex(i);
1204 if (!typeA || typeA[0] == '\0')
1206 result.AppendError("empty typenames not allowed");
1207 result.SetStatus(eReturnStatusFailed);
1210 ConstString typeCS(typeA);
1214 (m_options.m_regex ? eRegexSummary : eRegularSummary),
1215 m_options.m_category,
1220 result.AppendError(error.AsCString());
1221 result.SetStatus(eReturnStatusFailed);
1226 if (m_options.m_name)
1228 AddSummary(m_options.m_name, entry, eNamedSummary, m_options.m_category, &error);
1231 result.AppendError(error.AsCString());
1232 result.AppendError("added to types, but not given a name");
1233 result.SetStatus(eReturnStatusFailed);
1238 result.SetStatus(eReturnStatusSuccessFinishNoResult);
1239 return result.Succeeded();
1242 CommandObjectTypeSummaryAdd::CommandObjectTypeSummaryAdd (CommandInterpreter &interpreter) :
1243 CommandObjectParsed (interpreter,
1245 "Add a new summary style for a type.",
1247 m_options (interpreter)
1249 CommandArgumentEntry type_arg;
1250 CommandArgumentData type_style_arg;
1252 type_style_arg.arg_type = eArgTypeName;
1253 type_style_arg.arg_repetition = eArgRepeatPlus;
1255 type_arg.push_back (type_style_arg);
1257 m_arguments.push_back (type_arg);
1260 "Some examples of using this command.\n"
1261 "We use as reference the following snippet of code:\n"
1262 "struct JustADemo\n"
1266 "JustADemo(int p = 1, float v = 0.1) : ptr(new int(p)), value(v) {}\n"
1268 "JustADemo object(42,3.14);\n"
1269 "struct AnotherDemo : public JustADemo\n"
1272 "AnotherDemo(uint8_t b = 'E', int p = 1, float v = 0.1) : JustADemo(p,v), byte(b) {}\n"
1274 "AnotherDemo *another_object = new AnotherDemo('E',42,3.14);\n"
1276 "type summary add --summary-string \"the answer is ${*var.ptr}\" JustADemo\n"
1277 "when typing frame variable object you will get \"the answer is 42\"\n"
1278 "type summary add --summary-string \"the answer is ${*var.ptr}, and the question is ${var.value}\" JustADemo\n"
1279 "when typing frame variable object you will get \"the answer is 42 and the question is 3.14\"\n"
1281 "Alternatively, you could also say\n"
1282 "type summary add --summary-string \"${var%V} -> ${*var}\" \"int *\"\n"
1283 "and replace the above summary string with\n"
1284 "type summary add --summary-string \"the answer is ${var.ptr}, and the question is ${var.value}\" JustADemo\n"
1285 "to obtain a similar result\n"
1287 "To add a summary valid for both JustADemo and AnotherDemo you can use the scoping operator, as in:\n"
1288 "type summary add --summary-string \"${var.ptr}, ${var.value},{${var.byte}}\" JustADemo -C yes\n"
1290 "This will be used for both variables of type JustADemo and AnotherDemo. To prevent this, change the -C to read -C no\n"
1291 "If you do not want pointers to be shown using that summary, you can use the -p option, as in:\n"
1292 "type summary add --summary-string \"${var.ptr}, ${var.value},{${var.byte}}\" JustADemo -C yes -p\n"
1293 "A similar option -r exists for references.\n"
1295 "If you simply want a one-line summary of the content of your variable, without typing an explicit string to that effect\n"
1296 "you can use the -c option, without giving any summary string:\n"
1297 "type summary add -c JustADemo\n"
1298 "frame variable object\n"
1299 "the output being similar to (ptr=0xsomeaddress, value=3.14)\n"
1301 "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"
1302 "type summary add -e --summary-string \"*ptr = ${*var.ptr}\" JustADemo\n"
1303 "Here the value of the int* is displayed, followed by the standard LLDB sequence of children objects, one per line.\n"
1304 "to get an output like:\n"
1307 " ptr = 0xsomeaddress\n"
1311 "You can also add Python summaries, in which case you will use lldb public API to gather information from your variables"
1312 "and elaborate them to a meaningful summary inside a script written in Python. The variable object will be passed to your"
1313 "script as an SBValue object. The following example might help you when starting to use the Python summaries feature:\n"
1314 "type summary add JustADemo -o \"value = valobj.GetChildMemberWithName('value'); return 'My value is ' + value.GetValue();\"\n"
1315 "If you prefer to type your scripts on multiple lines, you will use the -P option and then type your script, ending it with "
1316 "the word DONE on a line by itself to mark you're finished editing your code:\n"
1317 "(lldb)type summary add JustADemo -P\n"
1318 " value = valobj.GetChildMemberWithName('value');\n"
1319 " return 'My value is ' + value.GetValue();\n"
1321 "(lldb) <-- type further LLDB commands here\n"
1326 CommandObjectTypeSummaryAdd::DoExecute (Args& command, CommandReturnObject &result)
1328 if (m_options.m_is_add_script)
1330 #ifndef LLDB_DISABLE_PYTHON
1331 return Execute_ScriptSummary(command, result);
1333 result.AppendError ("python is disabled");
1334 result.SetStatus(eReturnStatusFailed);
1339 return Execute_StringSummary(command, result);
1343 CommandObjectTypeSummaryAdd::AddSummary(ConstString type_name,
1344 TypeSummaryImplSP entry,
1345 SummaryFormatType type,
1346 std::string category_name,
1349 lldb::TypeCategoryImplSP category;
1350 DataVisualization::Categories::GetCategory(ConstString(category_name.c_str()), category);
1352 if (type == eRegularSummary)
1354 std::string type_name_str(type_name.GetCString());
1355 if (type_name_str.compare(type_name_str.length() - 2, 2, "[]") == 0)
1357 type_name_str.resize(type_name_str.length()-2);
1358 if (type_name_str.back() != ' ')
1359 type_name_str.append(" \\[[0-9]+\\]");
1361 type_name_str.append("\\[[0-9]+\\]");
1362 type_name.SetCString(type_name_str.c_str());
1363 type = eRegexSummary;
1367 if (type == eRegexSummary)
1369 RegularExpressionSP typeRX(new RegularExpression());
1370 if (!typeRX->Compile(type_name.GetCString()))
1373 error->SetErrorString("regex format error (maybe this is not really a regex?)");
1377 category->GetRegexSummaryNavigator()->Delete(type_name);
1378 category->GetRegexSummaryNavigator()->Add(typeRX, entry);
1382 else if (type == eNamedSummary)
1384 // system named summaries do not exist (yet?)
1385 DataVisualization::NamedSummaryFormats::Add(type_name,entry);
1390 category->GetSummaryNavigator()->Add(type_name, entry);
1396 CommandObjectTypeSummaryAdd::CommandOptions::g_option_table[] =
1398 { LLDB_OPT_SET_ALL, false, "category", 'w', required_argument, NULL, 0, eArgTypeName, "Add this to the given category instead of the default one."},
1399 { LLDB_OPT_SET_ALL, false, "cascade", 'C', required_argument, NULL, 0, eArgTypeBoolean, "If true, cascade through typedef chains."},
1400 { LLDB_OPT_SET_ALL, false, "no-value", 'v', no_argument, NULL, 0, eArgTypeNone, "Don't show the value, just show the summary, for this type."},
1401 { LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', no_argument, NULL, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."},
1402 { LLDB_OPT_SET_ALL, false, "skip-references", 'r', no_argument, NULL, 0, eArgTypeNone, "Don't use this format for references-to-type objects."},
1403 { LLDB_OPT_SET_ALL, false, "regex", 'x', no_argument, NULL, 0, eArgTypeNone, "Type names are actually regular expressions."},
1404 { LLDB_OPT_SET_1 , true, "inline-children", 'c', no_argument, NULL, 0, eArgTypeNone, "If true, inline all child values into summary string."},
1405 { LLDB_OPT_SET_1 , false, "omit-names", 'O', no_argument, NULL, 0, eArgTypeNone, "If true, omit value names in the summary display."},
1406 { LLDB_OPT_SET_2 , true, "summary-string", 's', required_argument, NULL, 0, eArgTypeSummaryString, "Summary string used to display text and object contents."},
1407 { LLDB_OPT_SET_3, false, "python-script", 'o', required_argument, NULL, 0, eArgTypePythonScript, "Give a one-liner Python script as part of the command."},
1408 { LLDB_OPT_SET_3, false, "python-function", 'F', required_argument, NULL, 0, eArgTypePythonFunction, "Give the name of a Python function to use for this type."},
1409 { LLDB_OPT_SET_3, false, "input-python", 'P', no_argument, NULL, 0, eArgTypeNone, "Input Python code to use for this type manually."},
1410 { LLDB_OPT_SET_2 | LLDB_OPT_SET_3, false, "expand", 'e', no_argument, NULL, 0, eArgTypeNone, "Expand aggregate data types to show children on separate lines."},
1411 { LLDB_OPT_SET_2 | LLDB_OPT_SET_3, false, "name", 'n', required_argument, NULL, 0, eArgTypeName, "A name for this summary string."},
1412 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
1416 //-------------------------------------------------------------------------
1417 // CommandObjectTypeSummaryDelete
1418 //-------------------------------------------------------------------------
1420 class CommandObjectTypeSummaryDelete : public CommandObjectParsed
1423 class CommandOptions : public Options
1427 CommandOptions (CommandInterpreter &interpreter) :
1428 Options (interpreter)
1433 ~CommandOptions (){}
1436 SetOptionValue (uint32_t option_idx, const char *option_arg)
1439 const int short_option = m_getopt_table[option_idx].val;
1441 switch (short_option)
1444 m_delete_all = true;
1447 m_category = std::string(option_arg);
1450 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1458 OptionParsingStarting ()
1460 m_delete_all = false;
1461 m_category = "default";
1464 const OptionDefinition*
1467 return g_option_table;
1470 // Options table: Required for subclasses of Options.
1472 static OptionDefinition g_option_table[];
1474 // Instance variables to hold the values for command options.
1477 std::string m_category;
1481 CommandOptions m_options;
1490 PerCategoryCallback(void* param,
1491 const lldb::TypeCategoryImplSP& category_sp)
1493 ConstString *name = (ConstString*)param;
1494 category_sp->Delete(*name, eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
1499 CommandObjectTypeSummaryDelete (CommandInterpreter &interpreter) :
1500 CommandObjectParsed (interpreter,
1501 "type summary delete",
1502 "Delete an existing summary style for a type.",
1504 m_options(interpreter)
1506 CommandArgumentEntry type_arg;
1507 CommandArgumentData type_style_arg;
1509 type_style_arg.arg_type = eArgTypeName;
1510 type_style_arg.arg_repetition = eArgRepeatPlain;
1512 type_arg.push_back (type_style_arg);
1514 m_arguments.push_back (type_arg);
1518 ~CommandObjectTypeSummaryDelete ()
1524 DoExecute (Args& command, CommandReturnObject &result)
1526 const size_t argc = command.GetArgumentCount();
1530 result.AppendErrorWithFormat ("%s takes 1 arg.\n", m_cmd_name.c_str());
1531 result.SetStatus(eReturnStatusFailed);
1535 const char* typeA = command.GetArgumentAtIndex(0);
1536 ConstString typeCS(typeA);
1540 result.AppendError("empty typenames not allowed");
1541 result.SetStatus(eReturnStatusFailed);
1545 if (m_options.m_delete_all)
1547 DataVisualization::Categories::LoopThrough(PerCategoryCallback, &typeCS);
1548 result.SetStatus(eReturnStatusSuccessFinishNoResult);
1549 return result.Succeeded();
1552 lldb::TypeCategoryImplSP category;
1553 DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
1555 bool delete_category = category->Delete(typeCS,
1556 eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
1557 bool delete_named = DataVisualization::NamedSummaryFormats::Delete(typeCS);
1559 if (delete_category || delete_named)
1561 result.SetStatus(eReturnStatusSuccessFinishNoResult);
1562 return result.Succeeded();
1566 result.AppendErrorWithFormat ("no custom summary for %s.\n", typeA);
1567 result.SetStatus(eReturnStatusFailed);
1575 CommandObjectTypeSummaryDelete::CommandOptions::g_option_table[] =
1577 { LLDB_OPT_SET_1, false, "all", 'a', no_argument, NULL, 0, eArgTypeNone, "Delete from every category."},
1578 { LLDB_OPT_SET_2, false, "category", 'w', required_argument, NULL, 0, eArgTypeName, "Delete from given category."},
1579 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
1582 class CommandObjectTypeSummaryClear : public CommandObjectParsed
1586 class CommandOptions : public Options
1590 CommandOptions (CommandInterpreter &interpreter) :
1591 Options (interpreter)
1596 ~CommandOptions (){}
1599 SetOptionValue (uint32_t option_idx, const char *option_arg)
1602 const int short_option = m_getopt_table[option_idx].val;
1604 switch (short_option)
1607 m_delete_all = true;
1610 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1618 OptionParsingStarting ()
1620 m_delete_all = false;
1623 const OptionDefinition*
1626 return g_option_table;
1629 // Options table: Required for subclasses of Options.
1631 static OptionDefinition g_option_table[];
1633 // Instance variables to hold the values for command options.
1636 bool m_delete_named;
1639 CommandOptions m_options;
1648 PerCategoryCallback(void* param,
1649 const lldb::TypeCategoryImplSP& cate)
1651 cate->GetSummaryNavigator()->Clear();
1652 cate->GetRegexSummaryNavigator()->Clear();
1658 CommandObjectTypeSummaryClear (CommandInterpreter &interpreter) :
1659 CommandObjectParsed (interpreter,
1660 "type summary clear",
1661 "Delete all existing summary styles.",
1663 m_options(interpreter)
1667 ~CommandObjectTypeSummaryClear ()
1673 DoExecute (Args& command, CommandReturnObject &result)
1676 if (m_options.m_delete_all)
1677 DataVisualization::Categories::LoopThrough(PerCategoryCallback, NULL);
1681 lldb::TypeCategoryImplSP category;
1682 if (command.GetArgumentCount() > 0)
1684 const char* cat_name = command.GetArgumentAtIndex(0);
1685 ConstString cat_nameCS(cat_name);
1686 DataVisualization::Categories::GetCategory(cat_nameCS, category);
1689 DataVisualization::Categories::GetCategory(ConstString(NULL), category);
1690 category->Clear(eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary);
1693 DataVisualization::NamedSummaryFormats::Clear();
1695 result.SetStatus(eReturnStatusSuccessFinishResult);
1696 return result.Succeeded();
1702 CommandObjectTypeSummaryClear::CommandOptions::g_option_table[] =
1704 { LLDB_OPT_SET_ALL, false, "all", 'a', no_argument, NULL, 0, eArgTypeNone, "Clear every category."},
1705 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
1708 //-------------------------------------------------------------------------
1709 // CommandObjectTypeSummaryList
1710 //-------------------------------------------------------------------------
1712 bool CommandObjectTypeSummaryList_LoopCallback(void* pt2self, ConstString type, const StringSummaryFormat::SharedPointer& entry);
1713 bool CommandObjectTypeRXSummaryList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const StringSummaryFormat::SharedPointer& entry);
1715 class CommandObjectTypeSummaryList;
1717 struct CommandObjectTypeSummaryList_LoopCallbackParam {
1718 CommandObjectTypeSummaryList* self;
1719 CommandReturnObject* result;
1720 RegularExpression* regex;
1721 RegularExpression* cate_regex;
1722 CommandObjectTypeSummaryList_LoopCallbackParam(CommandObjectTypeSummaryList* S, CommandReturnObject* R,
1723 RegularExpression* X = NULL,
1724 RegularExpression* CX = NULL) : self(S), result(R), regex(X), cate_regex(CX) {}
1727 class CommandObjectTypeSummaryList : public CommandObjectParsed
1730 class CommandOptions : public Options
1734 CommandOptions (CommandInterpreter &interpreter) :
1735 Options (interpreter)
1740 ~CommandOptions (){}
1743 SetOptionValue (uint32_t option_idx, const char *option_arg)
1746 const int short_option = m_getopt_table[option_idx].val;
1748 switch (short_option)
1751 m_category_regex = std::string(option_arg);
1754 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1762 OptionParsingStarting ()
1764 m_category_regex = "";
1767 const OptionDefinition*
1770 return g_option_table;
1773 // Options table: Required for subclasses of Options.
1775 static OptionDefinition g_option_table[];
1777 // Instance variables to hold the values for command options.
1779 std::string m_category_regex;
1783 CommandOptions m_options;
1792 CommandObjectTypeSummaryList (CommandInterpreter &interpreter) :
1793 CommandObjectParsed (interpreter,
1794 "type summary list",
1795 "Show a list of current summary styles.",
1797 m_options(interpreter)
1799 CommandArgumentEntry type_arg;
1800 CommandArgumentData type_style_arg;
1802 type_style_arg.arg_type = eArgTypeName;
1803 type_style_arg.arg_repetition = eArgRepeatOptional;
1805 type_arg.push_back (type_style_arg);
1807 m_arguments.push_back (type_arg);
1810 ~CommandObjectTypeSummaryList ()
1816 DoExecute (Args& command, CommandReturnObject &result)
1818 const size_t argc = command.GetArgumentCount();
1820 CommandObjectTypeSummaryList_LoopCallbackParam *param;
1821 RegularExpression* cate_regex =
1822 m_options.m_category_regex.empty() ? NULL :
1823 new RegularExpression(m_options.m_category_regex.c_str());
1827 RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
1828 regex->Compile(command.GetArgumentAtIndex(0));
1829 param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result,regex,cate_regex);
1832 param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result,NULL,cate_regex);
1834 DataVisualization::Categories::LoopThrough(PerCategoryCallback,param);
1836 if (DataVisualization::NamedSummaryFormats::GetCount() > 0)
1838 result.GetOutputStream().Printf("Named summaries:\n");
1841 RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
1842 regex->Compile(command.GetArgumentAtIndex(0));
1843 param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result,regex);
1846 param = new CommandObjectTypeSummaryList_LoopCallbackParam(this,&result);
1847 DataVisualization::NamedSummaryFormats::LoopThrough(CommandObjectTypeSummaryList_LoopCallback, param);
1854 result.SetStatus(eReturnStatusSuccessFinishResult);
1855 return result.Succeeded();
1861 PerCategoryCallback(void* param_vp,
1862 const lldb::TypeCategoryImplSP& cate)
1865 CommandObjectTypeSummaryList_LoopCallbackParam* param =
1866 (CommandObjectTypeSummaryList_LoopCallbackParam*)param_vp;
1867 CommandReturnObject* result = param->result;
1869 const char* cate_name = cate->GetName();
1871 // if the category is disabled or empty and there is no regex, just skip it
1872 if ((cate->IsEnabled() == false || cate->GetCount(eFormatCategoryItemSummary | eFormatCategoryItemRegexSummary) == 0) && param->cate_regex == NULL)
1875 // if we have a regex and this category does not match it, just skip it
1876 if(param->cate_regex != NULL && strcmp(cate_name,param->cate_regex->GetText()) != 0 && param->cate_regex->Execute(cate_name) == false)
1879 result->GetOutputStream().Printf("-----------------------\nCategory: %s (%s)\n-----------------------\n",
1881 (cate->IsEnabled() ? "enabled" : "disabled"));
1883 cate->GetSummaryNavigator()->LoopThrough(CommandObjectTypeSummaryList_LoopCallback, param_vp);
1885 if (cate->GetRegexSummaryNavigator()->GetCount() > 0)
1887 result->GetOutputStream().Printf("Regex-based summaries (slower):\n");
1888 cate->GetRegexSummaryNavigator()->LoopThrough(CommandObjectTypeRXSummaryList_LoopCallback, param_vp);
1895 LoopCallback (const char* type,
1896 const lldb::TypeSummaryImplSP& entry,
1897 RegularExpression* regex,
1898 CommandReturnObject *result)
1900 if (regex == NULL || strcmp(type,regex->GetText()) == 0 || regex->Execute(type))
1901 result->GetOutputStream().Printf ("%s: %s\n", type, entry->GetDescription().c_str());
1905 friend bool CommandObjectTypeSummaryList_LoopCallback(void* pt2self, ConstString type, const lldb::TypeSummaryImplSP& entry);
1906 friend bool CommandObjectTypeRXSummaryList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const lldb::TypeSummaryImplSP& entry);
1910 CommandObjectTypeSummaryList_LoopCallback (
1913 const lldb::TypeSummaryImplSP& entry)
1915 CommandObjectTypeSummaryList_LoopCallbackParam* param = (CommandObjectTypeSummaryList_LoopCallbackParam*)pt2self;
1916 return param->self->LoopCallback(type.AsCString(), entry, param->regex, param->result);
1920 CommandObjectTypeRXSummaryList_LoopCallback (
1922 lldb::RegularExpressionSP regex,
1923 const lldb::TypeSummaryImplSP& entry)
1925 CommandObjectTypeSummaryList_LoopCallbackParam* param = (CommandObjectTypeSummaryList_LoopCallbackParam*)pt2self;
1926 return param->self->LoopCallback(regex->GetText(), entry, param->regex, param->result);
1930 CommandObjectTypeSummaryList::CommandOptions::g_option_table[] =
1932 { LLDB_OPT_SET_ALL, false, "category-regex", 'w', required_argument, NULL, 0, eArgTypeName, "Only show categories matching this filter."},
1933 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
1936 //-------------------------------------------------------------------------
1937 // CommandObjectTypeCategoryEnable
1938 //-------------------------------------------------------------------------
1940 class CommandObjectTypeCategoryEnable : public CommandObjectParsed
1943 CommandObjectTypeCategoryEnable (CommandInterpreter &interpreter) :
1944 CommandObjectParsed (interpreter,
1945 "type category enable",
1946 "Enable a category as a source of formatters.",
1949 CommandArgumentEntry type_arg;
1950 CommandArgumentData type_style_arg;
1952 type_style_arg.arg_type = eArgTypeName;
1953 type_style_arg.arg_repetition = eArgRepeatPlus;
1955 type_arg.push_back (type_style_arg);
1957 m_arguments.push_back (type_arg);
1961 ~CommandObjectTypeCategoryEnable ()
1967 DoExecute (Args& command, CommandReturnObject &result)
1969 const size_t argc = command.GetArgumentCount();
1973 result.AppendErrorWithFormat ("%s takes 1 or more args.\n", m_cmd_name.c_str());
1974 result.SetStatus(eReturnStatusFailed);
1978 if (argc == 1 && strcmp(command.GetArgumentAtIndex(0),"*") == 0)
1980 // we want to make sure to enable "system" last and "default" first
1981 DataVisualization::Categories::Enable(ConstString("default"), TypeCategoryMap::First);
1982 uint32_t num_categories = DataVisualization::Categories::GetCount();
1983 for (uint32_t i = 0; i < num_categories; i++)
1985 lldb::TypeCategoryImplSP category_sp = DataVisualization::Categories::GetCategoryAtIndex(i);
1988 if ( ::strcmp(category_sp->GetName(), "system") == 0 ||
1989 ::strcmp(category_sp->GetName(), "default") == 0 )
1992 DataVisualization::Categories::Enable(category_sp, TypeCategoryMap::Default);
1995 DataVisualization::Categories::Enable(ConstString("system"), TypeCategoryMap::Last);
1999 for (int i = argc - 1; i >= 0; i--)
2001 const char* typeA = command.GetArgumentAtIndex(i);
2002 ConstString typeCS(typeA);
2006 result.AppendError("empty category name not allowed");
2007 result.SetStatus(eReturnStatusFailed);
2010 DataVisualization::Categories::Enable(typeCS);
2011 lldb::TypeCategoryImplSP cate;
2012 if (DataVisualization::Categories::GetCategory(typeCS, cate) && cate.get())
2014 if (cate->GetCount() == 0)
2016 result.AppendWarning("empty category enabled (typo?)");
2022 result.SetStatus(eReturnStatusSuccessFinishResult);
2023 return result.Succeeded();
2028 //-------------------------------------------------------------------------
2029 // CommandObjectTypeCategoryDelete
2030 //-------------------------------------------------------------------------
2032 class CommandObjectTypeCategoryDelete : public CommandObjectParsed
2035 CommandObjectTypeCategoryDelete (CommandInterpreter &interpreter) :
2036 CommandObjectParsed (interpreter,
2037 "type category delete",
2038 "Delete a category and all associated formatters.",
2041 CommandArgumentEntry type_arg;
2042 CommandArgumentData type_style_arg;
2044 type_style_arg.arg_type = eArgTypeName;
2045 type_style_arg.arg_repetition = eArgRepeatPlus;
2047 type_arg.push_back (type_style_arg);
2049 m_arguments.push_back (type_arg);
2053 ~CommandObjectTypeCategoryDelete ()
2059 DoExecute (Args& command, CommandReturnObject &result)
2061 const size_t argc = command.GetArgumentCount();
2065 result.AppendErrorWithFormat ("%s takes 1 or more arg.\n", m_cmd_name.c_str());
2066 result.SetStatus(eReturnStatusFailed);
2070 bool success = true;
2072 // the order is not relevant here
2073 for (int i = argc - 1; i >= 0; i--)
2075 const char* typeA = command.GetArgumentAtIndex(i);
2076 ConstString typeCS(typeA);
2080 result.AppendError("empty category name not allowed");
2081 result.SetStatus(eReturnStatusFailed);
2084 if (!DataVisualization::Categories::Delete(typeCS))
2085 success = false; // keep deleting even if we hit an error
2089 result.SetStatus(eReturnStatusSuccessFinishResult);
2090 return result.Succeeded();
2094 result.AppendError("cannot delete one or more categories\n");
2095 result.SetStatus(eReturnStatusFailed);
2101 //-------------------------------------------------------------------------
2102 // CommandObjectTypeCategoryDisable
2103 //-------------------------------------------------------------------------
2105 class CommandObjectTypeCategoryDisable : public CommandObjectParsed
2108 CommandObjectTypeCategoryDisable (CommandInterpreter &interpreter) :
2109 CommandObjectParsed (interpreter,
2110 "type category disable",
2111 "Disable a category as a source of formatters.",
2114 CommandArgumentEntry type_arg;
2115 CommandArgumentData type_style_arg;
2117 type_style_arg.arg_type = eArgTypeName;
2118 type_style_arg.arg_repetition = eArgRepeatPlus;
2120 type_arg.push_back (type_style_arg);
2122 m_arguments.push_back (type_arg);
2126 ~CommandObjectTypeCategoryDisable ()
2132 DoExecute (Args& command, CommandReturnObject &result)
2134 const size_t argc = command.GetArgumentCount();
2138 result.AppendErrorWithFormat ("%s takes 1 or more args.\n", m_cmd_name.c_str());
2139 result.SetStatus(eReturnStatusFailed);
2143 if (argc == 1 && strcmp(command.GetArgumentAtIndex(0),"*") == 0)
2145 uint32_t num_categories = DataVisualization::Categories::GetCount();
2146 for (uint32_t i = 0; i < num_categories; i++)
2148 lldb::TypeCategoryImplSP category_sp = DataVisualization::Categories::GetCategoryAtIndex(i);
2149 // no need to check if the category is enabled - disabling a disabled category has no effect
2151 DataVisualization::Categories::Disable(category_sp);
2156 // the order is not relevant here
2157 for (int i = argc - 1; i >= 0; i--)
2159 const char* typeA = command.GetArgumentAtIndex(i);
2160 ConstString typeCS(typeA);
2164 result.AppendError("empty category name not allowed");
2165 result.SetStatus(eReturnStatusFailed);
2168 DataVisualization::Categories::Disable(typeCS);
2172 result.SetStatus(eReturnStatusSuccessFinishResult);
2173 return result.Succeeded();
2178 //-------------------------------------------------------------------------
2179 // CommandObjectTypeCategoryList
2180 //-------------------------------------------------------------------------
2182 class CommandObjectTypeCategoryList : public CommandObjectParsed
2186 struct CommandObjectTypeCategoryList_CallbackParam
2188 CommandReturnObject* result;
2189 RegularExpression* regex;
2191 CommandObjectTypeCategoryList_CallbackParam(CommandReturnObject* res,
2192 RegularExpression* rex = NULL) :
2201 PerCategoryCallback(void* param_vp,
2202 const lldb::TypeCategoryImplSP& cate)
2204 CommandObjectTypeCategoryList_CallbackParam* param =
2205 (CommandObjectTypeCategoryList_CallbackParam*)param_vp;
2206 CommandReturnObject* result = param->result;
2207 RegularExpression* regex = param->regex;
2209 const char* cate_name = cate->GetName();
2211 if (regex == NULL || strcmp(cate_name, regex->GetText()) == 0 || regex->Execute(cate_name))
2212 result->GetOutputStream().Printf("Category %s is%s enabled\n",
2214 (cate->IsEnabled() ? "" : " not"));
2218 CommandObjectTypeCategoryList (CommandInterpreter &interpreter) :
2219 CommandObjectParsed (interpreter,
2220 "type category list",
2221 "Provide a list of all existing categories.",
2224 CommandArgumentEntry type_arg;
2225 CommandArgumentData type_style_arg;
2227 type_style_arg.arg_type = eArgTypeName;
2228 type_style_arg.arg_repetition = eArgRepeatOptional;
2230 type_arg.push_back (type_style_arg);
2232 m_arguments.push_back (type_arg);
2235 ~CommandObjectTypeCategoryList ()
2241 DoExecute (Args& command, CommandReturnObject &result)
2243 const size_t argc = command.GetArgumentCount();
2244 RegularExpression* regex = NULL;
2249 regex = new RegularExpression(command.GetArgumentAtIndex(0));
2252 result.AppendErrorWithFormat ("%s takes 0 or one arg.\n", m_cmd_name.c_str());
2253 result.SetStatus(eReturnStatusFailed);
2257 CommandObjectTypeCategoryList_CallbackParam param(&result,
2260 DataVisualization::Categories::LoopThrough(PerCategoryCallback, ¶m);
2265 result.SetStatus(eReturnStatusSuccessFinishResult);
2266 return result.Succeeded();
2271 //-------------------------------------------------------------------------
2272 // CommandObjectTypeFilterList
2273 //-------------------------------------------------------------------------
2275 bool CommandObjectTypeFilterList_LoopCallback(void* pt2self, ConstString type, const SyntheticChildren::SharedPointer& entry);
2276 bool CommandObjectTypeFilterRXList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const SyntheticChildren::SharedPointer& entry);
2278 class CommandObjectTypeFilterList;
2280 struct CommandObjectTypeFilterList_LoopCallbackParam {
2281 CommandObjectTypeFilterList* self;
2282 CommandReturnObject* result;
2283 RegularExpression* regex;
2284 RegularExpression* cate_regex;
2285 CommandObjectTypeFilterList_LoopCallbackParam(CommandObjectTypeFilterList* S, CommandReturnObject* R,
2286 RegularExpression* X = NULL,
2287 RegularExpression* CX = NULL) : self(S), result(R), regex(X), cate_regex(CX) {}
2290 class CommandObjectTypeFilterList : public CommandObjectParsed
2293 class CommandOptions : public Options
2297 CommandOptions (CommandInterpreter &interpreter) :
2298 Options (interpreter)
2303 ~CommandOptions (){}
2306 SetOptionValue (uint32_t option_idx, const char *option_arg)
2309 const int short_option = m_getopt_table[option_idx].val;
2311 switch (short_option)
2314 m_category_regex = std::string(option_arg);
2317 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
2325 OptionParsingStarting ()
2327 m_category_regex = "";
2330 const OptionDefinition*
2333 return g_option_table;
2336 // Options table: Required for subclasses of Options.
2338 static OptionDefinition g_option_table[];
2340 // Instance variables to hold the values for command options.
2342 std::string m_category_regex;
2346 CommandOptions m_options;
2355 CommandObjectTypeFilterList (CommandInterpreter &interpreter) :
2356 CommandObjectParsed (interpreter,
2358 "Show a list of current filters.",
2360 m_options(interpreter)
2362 CommandArgumentEntry type_arg;
2363 CommandArgumentData type_style_arg;
2365 type_style_arg.arg_type = eArgTypeName;
2366 type_style_arg.arg_repetition = eArgRepeatOptional;
2368 type_arg.push_back (type_style_arg);
2370 m_arguments.push_back (type_arg);
2373 ~CommandObjectTypeFilterList ()
2379 DoExecute (Args& command, CommandReturnObject &result)
2381 const size_t argc = command.GetArgumentCount();
2383 CommandObjectTypeFilterList_LoopCallbackParam *param;
2384 RegularExpression* cate_regex =
2385 m_options.m_category_regex.empty() ? NULL :
2386 new RegularExpression(m_options.m_category_regex.c_str());
2390 RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
2391 regex->Compile(command.GetArgumentAtIndex(0));
2392 param = new CommandObjectTypeFilterList_LoopCallbackParam(this,&result,regex,cate_regex);
2395 param = new CommandObjectTypeFilterList_LoopCallbackParam(this,&result,NULL,cate_regex);
2397 DataVisualization::Categories::LoopThrough(PerCategoryCallback,param);
2402 result.SetStatus(eReturnStatusSuccessFinishResult);
2403 return result.Succeeded();
2409 PerCategoryCallback(void* param_vp,
2410 const lldb::TypeCategoryImplSP& cate)
2413 const char* cate_name = cate->GetName();
2415 CommandObjectTypeFilterList_LoopCallbackParam* param =
2416 (CommandObjectTypeFilterList_LoopCallbackParam*)param_vp;
2417 CommandReturnObject* result = param->result;
2419 // if the category is disabled or empty and there is no regex, just skip it
2420 if ((cate->IsEnabled() == false || cate->GetCount(eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter) == 0) && param->cate_regex == NULL)
2423 // if we have a regex and this category does not match it, just skip it
2424 if(param->cate_regex != NULL && strcmp(cate_name,param->cate_regex->GetText()) != 0 && param->cate_regex->Execute(cate_name) == false)
2427 result->GetOutputStream().Printf("-----------------------\nCategory: %s (%s)\n-----------------------\n",
2429 (cate->IsEnabled() ? "enabled" : "disabled"));
2431 cate->GetFilterNavigator()->LoopThrough(CommandObjectTypeFilterList_LoopCallback, param_vp);
2433 if (cate->GetRegexFilterNavigator()->GetCount() > 0)
2435 result->GetOutputStream().Printf("Regex-based filters (slower):\n");
2436 cate->GetRegexFilterNavigator()->LoopThrough(CommandObjectTypeFilterRXList_LoopCallback, param_vp);
2443 LoopCallback (const char* type,
2444 const SyntheticChildren::SharedPointer& entry,
2445 RegularExpression* regex,
2446 CommandReturnObject *result)
2448 if (regex == NULL || regex->Execute(type))
2449 result->GetOutputStream().Printf ("%s: %s\n", type, entry->GetDescription().c_str());
2453 friend bool CommandObjectTypeFilterList_LoopCallback(void* pt2self, ConstString type, const SyntheticChildren::SharedPointer& entry);
2454 friend bool CommandObjectTypeFilterRXList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const SyntheticChildren::SharedPointer& entry);
2458 CommandObjectTypeFilterList_LoopCallback (void* pt2self,
2460 const SyntheticChildren::SharedPointer& entry)
2462 CommandObjectTypeFilterList_LoopCallbackParam* param = (CommandObjectTypeFilterList_LoopCallbackParam*)pt2self;
2463 return param->self->LoopCallback(type.AsCString(), entry, param->regex, param->result);
2467 CommandObjectTypeFilterRXList_LoopCallback (void* pt2self,
2468 lldb::RegularExpressionSP regex,
2469 const SyntheticChildren::SharedPointer& entry)
2471 CommandObjectTypeFilterList_LoopCallbackParam* param = (CommandObjectTypeFilterList_LoopCallbackParam*)pt2self;
2472 return param->self->LoopCallback(regex->GetText(), entry, param->regex, param->result);
2477 CommandObjectTypeFilterList::CommandOptions::g_option_table[] =
2479 { LLDB_OPT_SET_ALL, false, "category-regex", 'w', required_argument, NULL, 0, eArgTypeName, "Only show categories matching this filter."},
2480 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
2483 #ifndef LLDB_DISABLE_PYTHON
2485 //-------------------------------------------------------------------------
2486 // CommandObjectTypeSynthList
2487 //-------------------------------------------------------------------------
2489 bool CommandObjectTypeSynthList_LoopCallback(void* pt2self, ConstString type, const SyntheticChildren::SharedPointer& entry);
2490 bool CommandObjectTypeSynthRXList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const SyntheticChildren::SharedPointer& entry);
2492 class CommandObjectTypeSynthList;
2494 struct CommandObjectTypeSynthList_LoopCallbackParam {
2495 CommandObjectTypeSynthList* self;
2496 CommandReturnObject* result;
2497 RegularExpression* regex;
2498 RegularExpression* cate_regex;
2499 CommandObjectTypeSynthList_LoopCallbackParam(CommandObjectTypeSynthList* S, CommandReturnObject* R,
2500 RegularExpression* X = NULL,
2501 RegularExpression* CX = NULL) : self(S), result(R), regex(X), cate_regex(CX) {}
2504 class CommandObjectTypeSynthList : public CommandObjectParsed
2507 class CommandOptions : public Options
2511 CommandOptions (CommandInterpreter &interpreter) :
2512 Options (interpreter)
2517 ~CommandOptions (){}
2520 SetOptionValue (uint32_t option_idx, const char *option_arg)
2523 const int short_option = m_getopt_table[option_idx].val;
2525 switch (short_option)
2528 m_category_regex = std::string(option_arg);
2531 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
2539 OptionParsingStarting ()
2541 m_category_regex = "";
2544 const OptionDefinition*
2547 return g_option_table;
2550 // Options table: Required for subclasses of Options.
2552 static OptionDefinition g_option_table[];
2554 // Instance variables to hold the values for command options.
2556 std::string m_category_regex;
2560 CommandOptions m_options;
2569 CommandObjectTypeSynthList (CommandInterpreter &interpreter) :
2570 CommandObjectParsed (interpreter,
2571 "type synthetic list",
2572 "Show a list of current synthetic providers.",
2574 m_options(interpreter)
2576 CommandArgumentEntry type_arg;
2577 CommandArgumentData type_style_arg;
2579 type_style_arg.arg_type = eArgTypeName;
2580 type_style_arg.arg_repetition = eArgRepeatOptional;
2582 type_arg.push_back (type_style_arg);
2584 m_arguments.push_back (type_arg);
2587 ~CommandObjectTypeSynthList ()
2593 DoExecute (Args& command, CommandReturnObject &result)
2595 const size_t argc = command.GetArgumentCount();
2597 CommandObjectTypeSynthList_LoopCallbackParam *param;
2598 RegularExpression* cate_regex =
2599 m_options.m_category_regex.empty() ? NULL :
2600 new RegularExpression(m_options.m_category_regex.c_str());
2604 RegularExpression* regex = new RegularExpression(command.GetArgumentAtIndex(0));
2605 regex->Compile(command.GetArgumentAtIndex(0));
2606 param = new CommandObjectTypeSynthList_LoopCallbackParam(this,&result,regex,cate_regex);
2609 param = new CommandObjectTypeSynthList_LoopCallbackParam(this,&result,NULL,cate_regex);
2611 DataVisualization::Categories::LoopThrough(PerCategoryCallback,param);
2616 result.SetStatus(eReturnStatusSuccessFinishResult);
2617 return result.Succeeded();
2623 PerCategoryCallback(void* param_vp,
2624 const lldb::TypeCategoryImplSP& cate)
2627 CommandObjectTypeSynthList_LoopCallbackParam* param =
2628 (CommandObjectTypeSynthList_LoopCallbackParam*)param_vp;
2629 CommandReturnObject* result = param->result;
2631 const char* cate_name = cate->GetName();
2633 // if the category is disabled or empty and there is no regex, just skip it
2634 if ((cate->IsEnabled() == false || cate->GetCount(eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth) == 0) && param->cate_regex == NULL)
2637 // if we have a regex and this category does not match it, just skip it
2638 if(param->cate_regex != NULL && strcmp(cate_name,param->cate_regex->GetText()) != 0 && param->cate_regex->Execute(cate_name) == false)
2641 result->GetOutputStream().Printf("-----------------------\nCategory: %s (%s)\n-----------------------\n",
2643 (cate->IsEnabled() ? "enabled" : "disabled"));
2645 cate->GetSyntheticNavigator()->LoopThrough(CommandObjectTypeSynthList_LoopCallback, param_vp);
2647 if (cate->GetRegexSyntheticNavigator()->GetCount() > 0)
2649 result->GetOutputStream().Printf("Regex-based synthetic providers (slower):\n");
2650 cate->GetRegexSyntheticNavigator()->LoopThrough(CommandObjectTypeSynthRXList_LoopCallback, param_vp);
2657 LoopCallback (const char* type,
2658 const SyntheticChildren::SharedPointer& entry,
2659 RegularExpression* regex,
2660 CommandReturnObject *result)
2662 if (regex == NULL || regex->Execute(type))
2663 result->GetOutputStream().Printf ("%s: %s\n", type, entry->GetDescription().c_str());
2667 friend bool CommandObjectTypeSynthList_LoopCallback(void* pt2self, ConstString type, const SyntheticChildren::SharedPointer& entry);
2668 friend bool CommandObjectTypeSynthRXList_LoopCallback(void* pt2self, lldb::RegularExpressionSP regex, const SyntheticChildren::SharedPointer& entry);
2672 CommandObjectTypeSynthList_LoopCallback (void* pt2self,
2674 const SyntheticChildren::SharedPointer& entry)
2676 CommandObjectTypeSynthList_LoopCallbackParam* param = (CommandObjectTypeSynthList_LoopCallbackParam*)pt2self;
2677 return param->self->LoopCallback(type.AsCString(), entry, param->regex, param->result);
2681 CommandObjectTypeSynthRXList_LoopCallback (void* pt2self,
2682 lldb::RegularExpressionSP regex,
2683 const SyntheticChildren::SharedPointer& entry)
2685 CommandObjectTypeSynthList_LoopCallbackParam* param = (CommandObjectTypeSynthList_LoopCallbackParam*)pt2self;
2686 return param->self->LoopCallback(regex->GetText(), entry, param->regex, param->result);
2691 CommandObjectTypeSynthList::CommandOptions::g_option_table[] =
2693 { LLDB_OPT_SET_ALL, false, "category-regex", 'w', required_argument, NULL, 0, eArgTypeName, "Only show categories matching this filter."},
2694 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
2697 #endif // #ifndef LLDB_DISABLE_PYTHON
2698 //-------------------------------------------------------------------------
2699 // CommandObjectTypeFilterDelete
2700 //-------------------------------------------------------------------------
2702 class CommandObjectTypeFilterDelete : public CommandObjectParsed
2705 class CommandOptions : public Options
2709 CommandOptions (CommandInterpreter &interpreter) :
2710 Options (interpreter)
2715 ~CommandOptions (){}
2718 SetOptionValue (uint32_t option_idx, const char *option_arg)
2721 const int short_option = m_getopt_table[option_idx].val;
2723 switch (short_option)
2726 m_delete_all = true;
2729 m_category = std::string(option_arg);
2732 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
2740 OptionParsingStarting ()
2742 m_delete_all = false;
2743 m_category = "default";
2746 const OptionDefinition*
2749 return g_option_table;
2752 // Options table: Required for subclasses of Options.
2754 static OptionDefinition g_option_table[];
2756 // Instance variables to hold the values for command options.
2759 std::string m_category;
2763 CommandOptions m_options;
2772 PerCategoryCallback(void* param,
2773 const lldb::TypeCategoryImplSP& cate)
2775 ConstString *name = (ConstString*)param;
2776 return cate->Delete(*name, eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter);
2780 CommandObjectTypeFilterDelete (CommandInterpreter &interpreter) :
2781 CommandObjectParsed (interpreter,
2782 "type filter delete",
2783 "Delete an existing filter for a type.",
2785 m_options(interpreter)
2787 CommandArgumentEntry type_arg;
2788 CommandArgumentData type_style_arg;
2790 type_style_arg.arg_type = eArgTypeName;
2791 type_style_arg.arg_repetition = eArgRepeatPlain;
2793 type_arg.push_back (type_style_arg);
2795 m_arguments.push_back (type_arg);
2799 ~CommandObjectTypeFilterDelete ()
2805 DoExecute (Args& command, CommandReturnObject &result)
2807 const size_t argc = command.GetArgumentCount();
2811 result.AppendErrorWithFormat ("%s takes 1 arg.\n", m_cmd_name.c_str());
2812 result.SetStatus(eReturnStatusFailed);
2816 const char* typeA = command.GetArgumentAtIndex(0);
2817 ConstString typeCS(typeA);
2821 result.AppendError("empty typenames not allowed");
2822 result.SetStatus(eReturnStatusFailed);
2826 if (m_options.m_delete_all)
2828 DataVisualization::Categories::LoopThrough(PerCategoryCallback, (void*)&typeCS);
2829 result.SetStatus(eReturnStatusSuccessFinishNoResult);
2830 return result.Succeeded();
2833 lldb::TypeCategoryImplSP category;
2834 DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
2836 bool delete_category = category->GetFilterNavigator()->Delete(typeCS);
2837 delete_category = category->GetRegexFilterNavigator()->Delete(typeCS) || delete_category;
2839 if (delete_category)
2841 result.SetStatus(eReturnStatusSuccessFinishNoResult);
2842 return result.Succeeded();
2846 result.AppendErrorWithFormat ("no custom synthetic provider for %s.\n", typeA);
2847 result.SetStatus(eReturnStatusFailed);
2855 CommandObjectTypeFilterDelete::CommandOptions::g_option_table[] =
2857 { LLDB_OPT_SET_1, false, "all", 'a', no_argument, NULL, 0, eArgTypeNone, "Delete from every category."},
2858 { LLDB_OPT_SET_2, false, "category", 'w', required_argument, NULL, 0, eArgTypeName, "Delete from given category."},
2859 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
2862 #ifndef LLDB_DISABLE_PYTHON
2864 //-------------------------------------------------------------------------
2865 // CommandObjectTypeSynthDelete
2866 //-------------------------------------------------------------------------
2868 class CommandObjectTypeSynthDelete : public CommandObjectParsed
2871 class CommandOptions : public Options
2875 CommandOptions (CommandInterpreter &interpreter) :
2876 Options (interpreter)
2881 ~CommandOptions (){}
2884 SetOptionValue (uint32_t option_idx, const char *option_arg)
2887 const int short_option = m_getopt_table[option_idx].val;
2889 switch (short_option)
2892 m_delete_all = true;
2895 m_category = std::string(option_arg);
2898 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
2906 OptionParsingStarting ()
2908 m_delete_all = false;
2909 m_category = "default";
2912 const OptionDefinition*
2915 return g_option_table;
2918 // Options table: Required for subclasses of Options.
2920 static OptionDefinition g_option_table[];
2922 // Instance variables to hold the values for command options.
2925 std::string m_category;
2929 CommandOptions m_options;
2938 PerCategoryCallback(void* param,
2939 const lldb::TypeCategoryImplSP& cate)
2941 ConstString* name = (ConstString*)param;
2942 return cate->Delete(*name, eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth);
2946 CommandObjectTypeSynthDelete (CommandInterpreter &interpreter) :
2947 CommandObjectParsed (interpreter,
2948 "type synthetic delete",
2949 "Delete an existing synthetic provider for a type.",
2951 m_options(interpreter)
2953 CommandArgumentEntry type_arg;
2954 CommandArgumentData type_style_arg;
2956 type_style_arg.arg_type = eArgTypeName;
2957 type_style_arg.arg_repetition = eArgRepeatPlain;
2959 type_arg.push_back (type_style_arg);
2961 m_arguments.push_back (type_arg);
2965 ~CommandObjectTypeSynthDelete ()
2971 DoExecute (Args& command, CommandReturnObject &result)
2973 const size_t argc = command.GetArgumentCount();
2977 result.AppendErrorWithFormat ("%s takes 1 arg.\n", m_cmd_name.c_str());
2978 result.SetStatus(eReturnStatusFailed);
2982 const char* typeA = command.GetArgumentAtIndex(0);
2983 ConstString typeCS(typeA);
2987 result.AppendError("empty typenames not allowed");
2988 result.SetStatus(eReturnStatusFailed);
2992 if (m_options.m_delete_all)
2994 DataVisualization::Categories::LoopThrough(PerCategoryCallback, (void*)&typeCS);
2995 result.SetStatus(eReturnStatusSuccessFinishNoResult);
2996 return result.Succeeded();
2999 lldb::TypeCategoryImplSP category;
3000 DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
3002 bool delete_category = category->GetSyntheticNavigator()->Delete(typeCS);
3003 delete_category = category->GetRegexSyntheticNavigator()->Delete(typeCS) || delete_category;
3005 if (delete_category)
3007 result.SetStatus(eReturnStatusSuccessFinishNoResult);
3008 return result.Succeeded();
3012 result.AppendErrorWithFormat ("no custom synthetic provider for %s.\n", typeA);
3013 result.SetStatus(eReturnStatusFailed);
3021 CommandObjectTypeSynthDelete::CommandOptions::g_option_table[] =
3023 { LLDB_OPT_SET_1, false, "all", 'a', no_argument, NULL, 0, eArgTypeNone, "Delete from every category."},
3024 { LLDB_OPT_SET_2, false, "category", 'w', required_argument, NULL, 0, eArgTypeName, "Delete from given category."},
3025 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
3028 #endif // #ifndef LLDB_DISABLE_PYTHON
3030 //-------------------------------------------------------------------------
3031 // CommandObjectTypeFilterClear
3032 //-------------------------------------------------------------------------
3034 class CommandObjectTypeFilterClear : public CommandObjectParsed
3038 class CommandOptions : public Options
3042 CommandOptions (CommandInterpreter &interpreter) :
3043 Options (interpreter)
3048 ~CommandOptions (){}
3051 SetOptionValue (uint32_t option_idx, const char *option_arg)
3054 const int short_option = m_getopt_table[option_idx].val;
3056 switch (short_option)
3059 m_delete_all = true;
3062 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
3070 OptionParsingStarting ()
3072 m_delete_all = false;
3075 const OptionDefinition*
3078 return g_option_table;
3081 // Options table: Required for subclasses of Options.
3083 static OptionDefinition g_option_table[];
3085 // Instance variables to hold the values for command options.
3088 bool m_delete_named;
3091 CommandOptions m_options;
3100 PerCategoryCallback(void* param,
3101 const lldb::TypeCategoryImplSP& cate)
3103 cate->Clear(eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter);
3109 CommandObjectTypeFilterClear (CommandInterpreter &interpreter) :
3110 CommandObjectParsed (interpreter,
3111 "type filter clear",
3112 "Delete all existing filters.",
3114 m_options(interpreter)
3118 ~CommandObjectTypeFilterClear ()
3124 DoExecute (Args& command, CommandReturnObject &result)
3127 if (m_options.m_delete_all)
3128 DataVisualization::Categories::LoopThrough(PerCategoryCallback, NULL);
3132 lldb::TypeCategoryImplSP category;
3133 if (command.GetArgumentCount() > 0)
3135 const char* cat_name = command.GetArgumentAtIndex(0);
3136 ConstString cat_nameCS(cat_name);
3137 DataVisualization::Categories::GetCategory(cat_nameCS, category);
3140 DataVisualization::Categories::GetCategory(ConstString(NULL), category);
3141 category->GetFilterNavigator()->Clear();
3142 category->GetRegexFilterNavigator()->Clear();
3145 result.SetStatus(eReturnStatusSuccessFinishResult);
3146 return result.Succeeded();
3152 CommandObjectTypeFilterClear::CommandOptions::g_option_table[] =
3154 { LLDB_OPT_SET_ALL, false, "all", 'a', no_argument, NULL, 0, eArgTypeNone, "Clear every category."},
3155 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
3158 #ifndef LLDB_DISABLE_PYTHON
3159 //-------------------------------------------------------------------------
3160 // CommandObjectTypeSynthClear
3161 //-------------------------------------------------------------------------
3163 class CommandObjectTypeSynthClear : public CommandObjectParsed
3167 class CommandOptions : public Options
3171 CommandOptions (CommandInterpreter &interpreter) :
3172 Options (interpreter)
3177 ~CommandOptions (){}
3180 SetOptionValue (uint32_t option_idx, const char *option_arg)
3183 const int short_option = m_getopt_table[option_idx].val;
3185 switch (short_option)
3188 m_delete_all = true;
3191 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
3199 OptionParsingStarting ()
3201 m_delete_all = false;
3204 const OptionDefinition*
3207 return g_option_table;
3210 // Options table: Required for subclasses of Options.
3212 static OptionDefinition g_option_table[];
3214 // Instance variables to hold the values for command options.
3217 bool m_delete_named;
3220 CommandOptions m_options;
3229 PerCategoryCallback(void* param,
3230 const lldb::TypeCategoryImplSP& cate)
3232 cate->Clear(eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth);
3238 CommandObjectTypeSynthClear (CommandInterpreter &interpreter) :
3239 CommandObjectParsed (interpreter,
3240 "type synthetic clear",
3241 "Delete all existing synthetic providers.",
3243 m_options(interpreter)
3247 ~CommandObjectTypeSynthClear ()
3253 DoExecute (Args& command, CommandReturnObject &result)
3256 if (m_options.m_delete_all)
3257 DataVisualization::Categories::LoopThrough(PerCategoryCallback, NULL);
3261 lldb::TypeCategoryImplSP category;
3262 if (command.GetArgumentCount() > 0)
3264 const char* cat_name = command.GetArgumentAtIndex(0);
3265 ConstString cat_nameCS(cat_name);
3266 DataVisualization::Categories::GetCategory(cat_nameCS, category);
3269 DataVisualization::Categories::GetCategory(ConstString(NULL), category);
3270 category->GetSyntheticNavigator()->Clear();
3271 category->GetRegexSyntheticNavigator()->Clear();
3274 result.SetStatus(eReturnStatusSuccessFinishResult);
3275 return result.Succeeded();
3281 CommandObjectTypeSynthClear::CommandOptions::g_option_table[] =
3283 { LLDB_OPT_SET_ALL, false, "all", 'a', no_argument, NULL, 0, eArgTypeNone, "Clear every category."},
3284 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
3288 //-------------------------------------------------------------------------
3289 // TypeSynthAddInputReader
3290 //-------------------------------------------------------------------------
3292 static const char *g_synth_addreader_instructions = "Enter your Python command(s). Type 'DONE' to end.\n"
3293 "You must define a Python class with these methods:\n"
3294 " def __init__(self, valobj, dict):\n"
3295 " def num_children(self):\n"
3296 " def get_child_at_index(self, index):\n"
3297 " def get_child_index(self, name):\n"
3298 "Optionally, you can also define a method:\n"
3299 " def update(self):\n"
3300 "if your synthetic provider is holding on to any per-object state variables (currently, this is not implemented because of the way LLDB handles instances of SBValue and you should not rely on object persistence and per-object state)\n"
3301 "class synthProvider:";
3303 class TypeSynthAddInputReader : public InputReaderEZ
3306 TypeSynthAddInputReader(Debugger& debugger) :
3307 InputReaderEZ(debugger)
3311 ~TypeSynthAddInputReader()
3315 virtual void ActivateHandler(HandlerData& data)
3317 StreamSP out_stream = data.GetOutStream();
3318 bool batch_mode = data.GetBatchMode();
3321 out_stream->Printf ("%s\n", g_synth_addreader_instructions);
3322 if (data.reader.GetPrompt())
3323 out_stream->Printf ("%s", data.reader.GetPrompt());
3324 out_stream->Flush();
3328 virtual void ReactivateHandler(HandlerData& data)
3330 StreamSP out_stream = data.GetOutStream();
3331 bool batch_mode = data.GetBatchMode();
3332 if (data.reader.GetPrompt() && !batch_mode)
3334 out_stream->Printf ("%s", data.reader.GetPrompt());
3335 out_stream->Flush();
3338 virtual void GotTokenHandler(HandlerData& data)
3340 StreamSP out_stream = data.GetOutStream();
3341 bool batch_mode = data.GetBatchMode();
3342 if (data.bytes && data.bytes_len && data.baton)
3344 ((SynthAddOptions*)data.baton)->m_user_source.AppendString(data.bytes, data.bytes_len);
3346 if (!data.reader.IsDone() && data.reader.GetPrompt() && !batch_mode)
3348 out_stream->Printf ("%s", data.reader.GetPrompt());
3349 out_stream->Flush();
3352 virtual void InterruptHandler(HandlerData& data)
3354 StreamSP out_stream = data.GetOutStream();
3355 bool batch_mode = data.GetBatchMode();
3356 data.reader.SetIsDone (true);
3359 out_stream->Printf ("Warning: No command attached to breakpoint.\n");
3360 out_stream->Flush();
3363 virtual void EOFHandler(HandlerData& data)
3365 data.reader.SetIsDone (true);
3367 virtual void DoneHandler(HandlerData& data)
3369 StreamSP out_stream = data.GetOutStream();
3370 SynthAddOptions *options_ptr = ((SynthAddOptions*)data.baton);
3373 out_stream->Printf ("internal synchronization data missing.\n");
3374 out_stream->Flush();
3378 SynthAddOptions::SharedPointer options(options_ptr); // this will ensure that we get rid of the pointer when going out of scope
3380 ScriptInterpreter *interpreter = data.reader.GetDebugger().GetCommandInterpreter().GetScriptInterpreter();
3383 out_stream->Printf ("no script interpreter.\n");
3384 out_stream->Flush();
3387 std::string class_name_str;
3388 if (!interpreter->GenerateTypeSynthClass (options->m_user_source,
3391 out_stream->Printf ("unable to generate a class.\n");
3392 out_stream->Flush();
3395 if (class_name_str.empty())
3397 out_stream->Printf ("unable to obtain a proper name for the class.\n");
3398 out_stream->Flush();
3402 // everything should be fine now, let's add the synth provider class
3404 SyntheticChildrenSP synth_provider;
3405 synth_provider.reset(new ScriptedSyntheticChildren(SyntheticChildren::Flags().SetCascades(options->m_cascade).
3406 SetSkipPointers(options->m_skip_pointers).
3407 SetSkipReferences(options->m_skip_references),
3408 class_name_str.c_str()));
3411 lldb::TypeCategoryImplSP category;
3412 DataVisualization::Categories::GetCategory(ConstString(options->m_category.c_str()), category);
3416 for (size_t i = 0; i < options->m_target_types.GetSize(); i++)
3418 const char *type_name = options->m_target_types.GetStringAtIndex(i);
3419 ConstString typeCS(type_name);
3422 if (!CommandObjectTypeSynthAdd::AddSynth(typeCS,
3424 options->m_regex ? CommandObjectTypeSynthAdd::eRegexSynth : CommandObjectTypeSynthAdd::eRegularSynth,
3425 options->m_category,
3428 out_stream->Printf("%s\n", error.AsCString());
3429 out_stream->Flush();
3435 out_stream->Printf ("invalid type name.\n");
3436 out_stream->Flush();
3443 DISALLOW_COPY_AND_ASSIGN (TypeSynthAddInputReader);
3447 CommandObjectTypeSynthAdd::CollectPythonScript (SynthAddOptions *options,
3448 CommandReturnObject &result)
3450 InputReaderSP reader_sp (new TypeSynthAddInputReader(m_interpreter.GetDebugger()));
3451 if (reader_sp && options)
3454 InputReaderEZ::InitializationParameters ipr;
3456 Error err (reader_sp->Initialize (ipr.SetBaton(options).SetPrompt(" ")));
3459 m_interpreter.GetDebugger().PushInputReader (reader_sp);
3460 result.SetStatus (eReturnStatusSuccessFinishNoResult);
3464 result.AppendError (err.AsCString());
3465 result.SetStatus (eReturnStatusFailed);
3470 result.AppendError("out of memory");
3471 result.SetStatus (eReturnStatusFailed);
3476 CommandObjectTypeSynthAdd::Execute_HandwritePython (Args& command, CommandReturnObject &result)
3478 SynthAddOptions *options = new SynthAddOptions ( m_options.m_skip_pointers,
3479 m_options.m_skip_references,
3480 m_options.m_cascade,
3482 m_options.m_category);
3484 const size_t argc = command.GetArgumentCount();
3486 for (size_t i = 0; i < argc; i++)
3488 const char* typeA = command.GetArgumentAtIndex(i);
3489 if (typeA && *typeA)
3490 options->m_target_types << typeA;
3493 result.AppendError("empty typenames not allowed");
3494 result.SetStatus(eReturnStatusFailed);
3499 CollectPythonScript(options,result);
3500 return result.Succeeded();
3504 CommandObjectTypeSynthAdd::Execute_PythonClass (Args& command, CommandReturnObject &result)
3506 const size_t argc = command.GetArgumentCount();
3510 result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
3511 result.SetStatus(eReturnStatusFailed);
3515 if (m_options.m_class_name.empty() && !m_options.m_input_python)
3517 result.AppendErrorWithFormat ("%s needs either a Python class name or -P to directly input Python code.\n", m_cmd_name.c_str());
3518 result.SetStatus(eReturnStatusFailed);
3522 SyntheticChildrenSP entry;
3524 ScriptedSyntheticChildren* impl = new ScriptedSyntheticChildren(SyntheticChildren::Flags().
3525 SetCascades(m_options.m_cascade).
3526 SetSkipPointers(m_options.m_skip_pointers).
3527 SetSkipReferences(m_options.m_skip_references),
3528 m_options.m_class_name.c_str());
3532 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
3534 if (interpreter && interpreter->CheckObjectExists(impl->GetPythonClassName()) == false)
3535 result.AppendWarning("The provided class does not exist - please define it before attempting to use this synthetic provider");
3537 // now I have a valid provider, let's add it to every type
3539 lldb::TypeCategoryImplSP category;
3540 DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
3544 for (size_t i = 0; i < argc; i++)
3546 const char* typeA = command.GetArgumentAtIndex(i);
3547 ConstString typeCS(typeA);
3550 if (!AddSynth(typeCS,
3552 m_options.m_regex ? eRegexSynth : eRegularSynth,
3553 m_options.m_category,
3556 result.AppendError(error.AsCString());
3557 result.SetStatus(eReturnStatusFailed);
3563 result.AppendError("empty typenames not allowed");
3564 result.SetStatus(eReturnStatusFailed);
3569 result.SetStatus(eReturnStatusSuccessFinishNoResult);
3570 return result.Succeeded();
3573 CommandObjectTypeSynthAdd::CommandObjectTypeSynthAdd (CommandInterpreter &interpreter) :
3574 CommandObjectParsed (interpreter,
3575 "type synthetic add",
3576 "Add a new synthetic provider for a type.",
3578 m_options (interpreter)
3580 CommandArgumentEntry type_arg;
3581 CommandArgumentData type_style_arg;
3583 type_style_arg.arg_type = eArgTypeName;
3584 type_style_arg.arg_repetition = eArgRepeatPlus;
3586 type_arg.push_back (type_style_arg);
3588 m_arguments.push_back (type_arg);
3593 CommandObjectTypeSynthAdd::AddSynth(ConstString type_name,
3594 SyntheticChildrenSP entry,
3595 SynthFormatType type,
3596 std::string category_name,
3599 lldb::TypeCategoryImplSP category;
3600 DataVisualization::Categories::GetCategory(ConstString(category_name.c_str()), category);
3602 if (type == eRegularSynth)
3604 std::string type_name_str(type_name.GetCString());
3605 if (type_name_str.compare(type_name_str.length() - 2, 2, "[]") == 0)
3607 type_name_str.resize(type_name_str.length()-2);
3608 if (type_name_str.back() != ' ')
3609 type_name_str.append(" \\[[0-9]+\\]");
3611 type_name_str.append("\\[[0-9]+\\]");
3612 type_name.SetCString(type_name_str.c_str());
3613 type = eRegularSynth;
3617 if (category->AnyMatches(type_name,
3618 eFormatCategoryItemFilter | eFormatCategoryItemRegexFilter,
3622 error->SetErrorStringWithFormat("cannot add synthetic for type %s when filter is defined in same category!", type_name.AsCString());
3626 if (type == eRegexSynth)
3628 RegularExpressionSP typeRX(new RegularExpression());
3629 if (!typeRX->Compile(type_name.GetCString()))
3632 error->SetErrorString("regex format error (maybe this is not really a regex?)");
3636 category->GetRegexSyntheticNavigator()->Delete(type_name);
3637 category->GetRegexSyntheticNavigator()->Add(typeRX, entry);
3643 category->GetSyntheticNavigator()->Add(type_name, entry);
3649 CommandObjectTypeSynthAdd::DoExecute (Args& command, CommandReturnObject &result)
3651 if (m_options.handwrite_python)
3652 return Execute_HandwritePython(command, result);
3653 else if (m_options.is_class_based)
3654 return Execute_PythonClass(command, result);
3657 result.AppendError("must either provide a children list, a Python class name, or use -P and type a Python class line-by-line");
3658 result.SetStatus(eReturnStatusFailed);
3664 CommandObjectTypeSynthAdd::CommandOptions::g_option_table[] =
3666 { LLDB_OPT_SET_ALL, false, "cascade", 'C', required_argument, NULL, 0, eArgTypeBoolean, "If true, cascade through typedef chains."},
3667 { LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', no_argument, NULL, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."},
3668 { LLDB_OPT_SET_ALL, false, "skip-references", 'r', no_argument, NULL, 0, eArgTypeNone, "Don't use this format for references-to-type objects."},
3669 { LLDB_OPT_SET_ALL, false, "category", 'w', required_argument, NULL, 0, eArgTypeName, "Add this to the given category instead of the default one."},
3670 { LLDB_OPT_SET_2, false, "python-class", 'l', required_argument, NULL, 0, eArgTypePythonClass, "Use this Python class to produce synthetic children."},
3671 { LLDB_OPT_SET_3, false, "input-python", 'P', no_argument, NULL, 0, eArgTypeNone, "Type Python code to generate a class that provides synthetic children."},
3672 { LLDB_OPT_SET_ALL, false, "regex", 'x', no_argument, NULL, 0, eArgTypeNone, "Type names are actually regular expressions."},
3673 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
3676 #endif // #ifndef LLDB_DISABLE_PYTHON
3678 class CommandObjectTypeFilterAdd : public CommandObjectParsed
3683 class CommandOptions : public Options
3685 typedef std::vector<std::string> option_vector;
3688 CommandOptions (CommandInterpreter &interpreter) :
3689 Options (interpreter)
3694 ~CommandOptions (){}
3697 SetOptionValue (uint32_t option_idx, const char *option_arg)
3700 const int short_option = m_getopt_table[option_idx].val;
3703 switch (short_option)
3706 m_cascade = Args::StringToBoolean(option_arg, true, &success);
3708 error.SetErrorStringWithFormat("invalid value for cascade: %s", option_arg);
3711 m_expr_paths.push_back(option_arg);
3712 has_child_list = true;
3715 m_skip_pointers = true;
3718 m_skip_references = true;
3721 m_category = std::string(option_arg);
3727 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
3735 OptionParsingStarting ()
3738 m_skip_pointers = false;
3739 m_skip_references = false;
3740 m_category = "default";
3741 m_expr_paths.clear();
3742 has_child_list = false;
3746 const OptionDefinition*
3749 return g_option_table;
3752 // Options table: Required for subclasses of Options.
3754 static OptionDefinition g_option_table[];
3756 // Instance variables to hold the values for command options.
3759 bool m_skip_references;
3760 bool m_skip_pointers;
3761 bool m_input_python;
3762 option_vector m_expr_paths;
3763 std::string m_category;
3765 bool has_child_list;
3769 typedef option_vector::iterator ExpressionPathsIterator;
3772 CommandOptions m_options;
3780 enum FilterFormatType
3787 AddFilter(ConstString type_name,
3788 SyntheticChildrenSP entry,
3789 FilterFormatType type,
3790 std::string category_name,
3793 lldb::TypeCategoryImplSP category;
3794 DataVisualization::Categories::GetCategory(ConstString(category_name.c_str()), category);
3796 if (type == eRegularFilter)
3798 std::string type_name_str(type_name.GetCString());
3799 if (type_name_str.compare(type_name_str.length() - 2, 2, "[]") == 0)
3801 type_name_str.resize(type_name_str.length()-2);
3802 if (type_name_str.back() != ' ')
3803 type_name_str.append(" \\[[0-9]+\\]");
3805 type_name_str.append("\\[[0-9]+\\]");
3806 type_name.SetCString(type_name_str.c_str());
3807 type = eRegexFilter;
3811 if (category->AnyMatches(type_name,
3812 eFormatCategoryItemSynth | eFormatCategoryItemRegexSynth,
3816 error->SetErrorStringWithFormat("cannot add filter for type %s when synthetic is defined in same category!", type_name.AsCString());
3820 if (type == eRegexFilter)
3822 RegularExpressionSP typeRX(new RegularExpression());
3823 if (!typeRX->Compile(type_name.GetCString()))
3826 error->SetErrorString("regex format error (maybe this is not really a regex?)");
3830 category->GetRegexFilterNavigator()->Delete(type_name);
3831 category->GetRegexFilterNavigator()->Add(typeRX, entry);
3837 category->GetFilterNavigator()->Add(type_name, entry);
3845 CommandObjectTypeFilterAdd (CommandInterpreter &interpreter) :
3846 CommandObjectParsed (interpreter,
3848 "Add a new filter for a type.",
3850 m_options (interpreter)
3852 CommandArgumentEntry type_arg;
3853 CommandArgumentData type_style_arg;
3855 type_style_arg.arg_type = eArgTypeName;
3856 type_style_arg.arg_repetition = eArgRepeatPlus;
3858 type_arg.push_back (type_style_arg);
3860 m_arguments.push_back (type_arg);
3863 "Some examples of using this command.\n"
3864 "We use as reference the following snippet of code:\n"
3878 "type filter add --child a --child g Foo\n"
3879 "frame variable a_foo\n"
3880 "will produce an output where only a and g are displayed\n"
3881 "Other children of a_foo (b,c,d,e,f,h and i) are available by asking for them, as in:\n"
3882 "frame variable a_foo.b a_foo.c ... a_foo.i\n"
3884 "Use option --raw to frame variable prevails on the filter\n"
3885 "frame variable a_foo --raw\n"
3886 "shows all the children of a_foo (a thru i) as if no filter was defined\n"
3890 ~CommandObjectTypeFilterAdd ()
3896 DoExecute (Args& command, CommandReturnObject &result)
3898 const size_t argc = command.GetArgumentCount();
3902 result.AppendErrorWithFormat ("%s takes one or more args.\n", m_cmd_name.c_str());
3903 result.SetStatus(eReturnStatusFailed);
3907 if (m_options.m_expr_paths.size() == 0)
3909 result.AppendErrorWithFormat ("%s needs one or more children.\n", m_cmd_name.c_str());
3910 result.SetStatus(eReturnStatusFailed);
3914 SyntheticChildrenSP entry;
3916 TypeFilterImpl* impl = new TypeFilterImpl(SyntheticChildren::Flags().SetCascades(m_options.m_cascade).
3917 SetSkipPointers(m_options.m_skip_pointers).
3918 SetSkipReferences(m_options.m_skip_references));
3922 // go through the expression paths
3923 CommandOptions::ExpressionPathsIterator begin, end = m_options.m_expr_paths.end();
3925 for (begin = m_options.m_expr_paths.begin(); begin != end; begin++)
3926 impl->AddExpressionPath(*begin);
3929 // now I have a valid provider, let's add it to every type
3931 lldb::TypeCategoryImplSP category;
3932 DataVisualization::Categories::GetCategory(ConstString(m_options.m_category.c_str()), category);
3936 for (size_t i = 0; i < argc; i++)
3938 const char* typeA = command.GetArgumentAtIndex(i);
3939 ConstString typeCS(typeA);
3942 if (!AddFilter(typeCS,
3944 m_options.m_regex ? eRegexFilter : eRegularFilter,
3945 m_options.m_category,
3948 result.AppendError(error.AsCString());
3949 result.SetStatus(eReturnStatusFailed);
3955 result.AppendError("empty typenames not allowed");
3956 result.SetStatus(eReturnStatusFailed);
3961 result.SetStatus(eReturnStatusSuccessFinishNoResult);
3962 return result.Succeeded();
3968 CommandObjectTypeFilterAdd::CommandOptions::g_option_table[] =
3970 { LLDB_OPT_SET_ALL, false, "cascade", 'C', required_argument, NULL, 0, eArgTypeBoolean, "If true, cascade through typedef chains."},
3971 { LLDB_OPT_SET_ALL, false, "skip-pointers", 'p', no_argument, NULL, 0, eArgTypeNone, "Don't use this format for pointers-to-type objects."},
3972 { LLDB_OPT_SET_ALL, false, "skip-references", 'r', no_argument, NULL, 0, eArgTypeNone, "Don't use this format for references-to-type objects."},
3973 { LLDB_OPT_SET_ALL, false, "category", 'w', required_argument, NULL, 0, eArgTypeName, "Add this to the given category instead of the default one."},
3974 { LLDB_OPT_SET_ALL, false, "child", 'c', required_argument, NULL, 0, eArgTypeExpressionPath, "Include this expression path in the synthetic view."},
3975 { LLDB_OPT_SET_ALL, false, "regex", 'x', no_argument, NULL, 0, eArgTypeNone, "Type names are actually regular expressions."},
3976 { 0, false, NULL, 0, 0, NULL, 0, eArgTypeNone, NULL }
3979 class CommandObjectTypeFormat : public CommandObjectMultiword
3982 CommandObjectTypeFormat (CommandInterpreter &interpreter) :
3983 CommandObjectMultiword (interpreter,
3985 "A set of commands for editing variable value display options",
3986 "type format [<sub-command-options>] ")
3988 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTypeFormatAdd (interpreter)));
3989 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTypeFormatClear (interpreter)));
3990 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeFormatDelete (interpreter)));
3991 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeFormatList (interpreter)));
3995 ~CommandObjectTypeFormat ()
4000 #ifndef LLDB_DISABLE_PYTHON
4002 class CommandObjectTypeSynth : public CommandObjectMultiword
4005 CommandObjectTypeSynth (CommandInterpreter &interpreter) :
4006 CommandObjectMultiword (interpreter,
4008 "A set of commands for operating on synthetic type representations",
4009 "type synthetic [<sub-command-options>] ")
4011 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTypeSynthAdd (interpreter)));
4012 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTypeSynthClear (interpreter)));
4013 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeSynthDelete (interpreter)));
4014 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeSynthList (interpreter)));
4018 ~CommandObjectTypeSynth ()
4023 #endif // #ifndef LLDB_DISABLE_PYTHON
4025 class CommandObjectTypeFilter : public CommandObjectMultiword
4028 CommandObjectTypeFilter (CommandInterpreter &interpreter) :
4029 CommandObjectMultiword (interpreter,
4031 "A set of commands for operating on type filters",
4032 "type synthetic [<sub-command-options>] ")
4034 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTypeFilterAdd (interpreter)));
4035 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTypeFilterClear (interpreter)));
4036 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeFilterDelete (interpreter)));
4037 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeFilterList (interpreter)));
4041 ~CommandObjectTypeFilter ()
4046 class CommandObjectTypeCategory : public CommandObjectMultiword
4049 CommandObjectTypeCategory (CommandInterpreter &interpreter) :
4050 CommandObjectMultiword (interpreter,
4052 "A set of commands for operating on categories",
4053 "type category [<sub-command-options>] ")
4055 LoadSubCommand ("enable", CommandObjectSP (new CommandObjectTypeCategoryEnable (interpreter)));
4056 LoadSubCommand ("disable", CommandObjectSP (new CommandObjectTypeCategoryDisable (interpreter)));
4057 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeCategoryDelete (interpreter)));
4058 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeCategoryList (interpreter)));
4062 ~CommandObjectTypeCategory ()
4067 class CommandObjectTypeSummary : public CommandObjectMultiword
4070 CommandObjectTypeSummary (CommandInterpreter &interpreter) :
4071 CommandObjectMultiword (interpreter,
4073 "A set of commands for editing variable summary display options",
4074 "type summary [<sub-command-options>] ")
4076 LoadSubCommand ("add", CommandObjectSP (new CommandObjectTypeSummaryAdd (interpreter)));
4077 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectTypeSummaryClear (interpreter)));
4078 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectTypeSummaryDelete (interpreter)));
4079 LoadSubCommand ("list", CommandObjectSP (new CommandObjectTypeSummaryList (interpreter)));
4083 ~CommandObjectTypeSummary ()
4088 //-------------------------------------------------------------------------
4089 // CommandObjectType
4090 //-------------------------------------------------------------------------
4092 CommandObjectType::CommandObjectType (CommandInterpreter &interpreter) :
4093 CommandObjectMultiword (interpreter,
4095 "A set of commands for operating on the type system",
4096 "type [<sub-command-options>]")
4098 LoadSubCommand ("category", CommandObjectSP (new CommandObjectTypeCategory (interpreter)));
4099 LoadSubCommand ("filter", CommandObjectSP (new CommandObjectTypeFilter (interpreter)));
4100 LoadSubCommand ("format", CommandObjectSP (new CommandObjectTypeFormat (interpreter)));
4101 LoadSubCommand ("summary", CommandObjectSP (new CommandObjectTypeSummary (interpreter)));
4102 #ifndef LLDB_DISABLE_PYTHON
4103 LoadSubCommand ("synthetic", CommandObjectSP (new CommandObjectTypeSynth (interpreter)));
4108 CommandObjectType::~CommandObjectType ()