130fdc8d8SChris Lattner //===-- CommandObject.cpp ---------------------------------------*- C++ -*-===// 230fdc8d8SChris Lattner // 330fdc8d8SChris Lattner // The LLVM Compiler Infrastructure 430fdc8d8SChris Lattner // 530fdc8d8SChris Lattner // This file is distributed under the University of Illinois Open Source 630fdc8d8SChris Lattner // License. See LICENSE.TXT for details. 730fdc8d8SChris Lattner // 830fdc8d8SChris Lattner //===----------------------------------------------------------------------===// 930fdc8d8SChris Lattner 1030fdc8d8SChris Lattner #include "lldb/Interpreter/CommandObject.h" 1130fdc8d8SChris Lattner 1230fdc8d8SChris Lattner #include <string> 1330fdc8d8SChris Lattner #include <map> 1430fdc8d8SChris Lattner 1530fdc8d8SChris Lattner #include <getopt.h> 1630fdc8d8SChris Lattner #include <stdlib.h> 1730fdc8d8SChris Lattner #include <ctype.h> 1830fdc8d8SChris Lattner 1930fdc8d8SChris Lattner #include "lldb/Core/Address.h" 2040af72e1SJim Ingham #include "lldb/Interpreter/Options.h" 2130fdc8d8SChris Lattner 2230fdc8d8SChris Lattner // These are for the Sourcename completers. 2330fdc8d8SChris Lattner // FIXME: Make a separate file for the completers. 2453239f00SGreg Clayton #include "lldb/Host/FileSpec.h" 2530fdc8d8SChris Lattner #include "lldb/Core/FileSpecList.h" 2630fdc8d8SChris Lattner #include "lldb/Target/Process.h" 2730fdc8d8SChris Lattner #include "lldb/Target/Target.h" 2830fdc8d8SChris Lattner 2930fdc8d8SChris Lattner #include "lldb/Interpreter/CommandInterpreter.h" 3030fdc8d8SChris Lattner #include "lldb/Interpreter/CommandReturnObject.h" 3130fdc8d8SChris Lattner #include "lldb/Interpreter/ScriptInterpreter.h" 3230fdc8d8SChris Lattner #include "lldb/Interpreter/ScriptInterpreterPython.h" 3330fdc8d8SChris Lattner 3430fdc8d8SChris Lattner using namespace lldb; 3530fdc8d8SChris Lattner using namespace lldb_private; 3630fdc8d8SChris Lattner 3730fdc8d8SChris Lattner //------------------------------------------------------------------------- 3830fdc8d8SChris Lattner // CommandObject 3930fdc8d8SChris Lattner //------------------------------------------------------------------------- 4030fdc8d8SChris Lattner 41a7015092SGreg Clayton CommandObject::CommandObject 42a7015092SGreg Clayton ( 43a7015092SGreg Clayton CommandInterpreter &interpreter, 44a7015092SGreg Clayton const char *name, 45a7015092SGreg Clayton const char *help, 46a7015092SGreg Clayton const char *syntax, 47a7015092SGreg Clayton uint32_t flags 48a7015092SGreg Clayton ) : 49a7015092SGreg Clayton m_interpreter (interpreter), 5030fdc8d8SChris Lattner m_cmd_name (name), 5130fdc8d8SChris Lattner m_cmd_help_short (), 5230fdc8d8SChris Lattner m_cmd_help_long (), 5330fdc8d8SChris Lattner m_cmd_syntax (), 54279a6c26SJim Ingham m_is_alias (false), 55e139cf23SCaroline Tice m_flags (flags), 56e139cf23SCaroline Tice m_arguments() 5730fdc8d8SChris Lattner { 5830fdc8d8SChris Lattner if (help && help[0]) 5930fdc8d8SChris Lattner m_cmd_help_short = help; 6030fdc8d8SChris Lattner if (syntax && syntax[0]) 6130fdc8d8SChris Lattner m_cmd_syntax = syntax; 6230fdc8d8SChris Lattner } 6330fdc8d8SChris Lattner 6430fdc8d8SChris Lattner CommandObject::~CommandObject () 6530fdc8d8SChris Lattner { 6630fdc8d8SChris Lattner } 6730fdc8d8SChris Lattner 6830fdc8d8SChris Lattner const char * 6930fdc8d8SChris Lattner CommandObject::GetHelp () 7030fdc8d8SChris Lattner { 7130fdc8d8SChris Lattner return m_cmd_help_short.c_str(); 7230fdc8d8SChris Lattner } 7330fdc8d8SChris Lattner 7430fdc8d8SChris Lattner const char * 7530fdc8d8SChris Lattner CommandObject::GetHelpLong () 7630fdc8d8SChris Lattner { 7730fdc8d8SChris Lattner return m_cmd_help_long.c_str(); 7830fdc8d8SChris Lattner } 7930fdc8d8SChris Lattner 8030fdc8d8SChris Lattner const char * 8130fdc8d8SChris Lattner CommandObject::GetSyntax () 8230fdc8d8SChris Lattner { 83e139cf23SCaroline Tice if (m_cmd_syntax.length() == 0) 84e139cf23SCaroline Tice { 85e139cf23SCaroline Tice StreamString syntax_str; 86e139cf23SCaroline Tice syntax_str.Printf ("%s", GetCommandName()); 87e139cf23SCaroline Tice if (GetOptions() != NULL) 88e139cf23SCaroline Tice syntax_str.Printf (" <cmd-options>"); 89e139cf23SCaroline Tice if (m_arguments.size() > 0) 90e139cf23SCaroline Tice { 91e139cf23SCaroline Tice syntax_str.Printf (" "); 92e139cf23SCaroline Tice GetFormattedCommandArguments (syntax_str); 93e139cf23SCaroline Tice } 94e139cf23SCaroline Tice m_cmd_syntax = syntax_str.GetData (); 95e139cf23SCaroline Tice } 96e139cf23SCaroline Tice 9730fdc8d8SChris Lattner return m_cmd_syntax.c_str(); 9830fdc8d8SChris Lattner } 9930fdc8d8SChris Lattner 10030fdc8d8SChris Lattner const char * 10130fdc8d8SChris Lattner CommandObject::Translate () 10230fdc8d8SChris Lattner { 10330fdc8d8SChris Lattner //return m_cmd_func_name.c_str(); 10430fdc8d8SChris Lattner return "This function is currently not implemented."; 10530fdc8d8SChris Lattner } 10630fdc8d8SChris Lattner 10730fdc8d8SChris Lattner const char * 10830fdc8d8SChris Lattner CommandObject::GetCommandName () 10930fdc8d8SChris Lattner { 11030fdc8d8SChris Lattner return m_cmd_name.c_str(); 11130fdc8d8SChris Lattner } 11230fdc8d8SChris Lattner 11330fdc8d8SChris Lattner void 11430fdc8d8SChris Lattner CommandObject::SetCommandName (const char *name) 11530fdc8d8SChris Lattner { 11630fdc8d8SChris Lattner m_cmd_name = name; 11730fdc8d8SChris Lattner } 11830fdc8d8SChris Lattner 11930fdc8d8SChris Lattner void 12030fdc8d8SChris Lattner CommandObject::SetHelp (const char *cstr) 12130fdc8d8SChris Lattner { 12230fdc8d8SChris Lattner m_cmd_help_short = cstr; 12330fdc8d8SChris Lattner } 12430fdc8d8SChris Lattner 12530fdc8d8SChris Lattner void 12630fdc8d8SChris Lattner CommandObject::SetHelpLong (const char *cstr) 12730fdc8d8SChris Lattner { 12830fdc8d8SChris Lattner m_cmd_help_long = cstr; 12930fdc8d8SChris Lattner } 13030fdc8d8SChris Lattner 13130fdc8d8SChris Lattner void 13299f0b8f9SEnrico Granata CommandObject::SetHelpLong (std::string str) 13399f0b8f9SEnrico Granata { 13499f0b8f9SEnrico Granata m_cmd_help_long = str; 13599f0b8f9SEnrico Granata } 13699f0b8f9SEnrico Granata 13799f0b8f9SEnrico Granata void 13830fdc8d8SChris Lattner CommandObject::SetSyntax (const char *cstr) 13930fdc8d8SChris Lattner { 14030fdc8d8SChris Lattner m_cmd_syntax = cstr; 14130fdc8d8SChris Lattner } 14230fdc8d8SChris Lattner 14330fdc8d8SChris Lattner Options * 14430fdc8d8SChris Lattner CommandObject::GetOptions () 14530fdc8d8SChris Lattner { 14630fdc8d8SChris Lattner // By default commands don't have options unless this virtual function 14730fdc8d8SChris Lattner // is overridden by base classes. 14830fdc8d8SChris Lattner return NULL; 14930fdc8d8SChris Lattner } 15030fdc8d8SChris Lattner 15130fdc8d8SChris Lattner Flags& 15230fdc8d8SChris Lattner CommandObject::GetFlags() 15330fdc8d8SChris Lattner { 15430fdc8d8SChris Lattner return m_flags; 15530fdc8d8SChris Lattner } 15630fdc8d8SChris Lattner 15730fdc8d8SChris Lattner const Flags& 15830fdc8d8SChris Lattner CommandObject::GetFlags() const 15930fdc8d8SChris Lattner { 16030fdc8d8SChris Lattner return m_flags; 16130fdc8d8SChris Lattner } 16230fdc8d8SChris Lattner 16330fdc8d8SChris Lattner bool 16430fdc8d8SChris Lattner CommandObject::ExecuteCommandString 16530fdc8d8SChris Lattner ( 16630fdc8d8SChris Lattner const char *command_line, 16730fdc8d8SChris Lattner CommandReturnObject &result 16830fdc8d8SChris Lattner ) 16930fdc8d8SChris Lattner { 17030fdc8d8SChris Lattner Args command_args(command_line); 171a7015092SGreg Clayton return ExecuteWithOptions (command_args, result); 17230fdc8d8SChris Lattner } 17330fdc8d8SChris Lattner 17430fdc8d8SChris Lattner bool 17530fdc8d8SChris Lattner CommandObject::ParseOptions 17630fdc8d8SChris Lattner ( 17730fdc8d8SChris Lattner Args& args, 17830fdc8d8SChris Lattner CommandReturnObject &result 17930fdc8d8SChris Lattner ) 18030fdc8d8SChris Lattner { 18130fdc8d8SChris Lattner // See if the subclass has options? 18230fdc8d8SChris Lattner Options *options = GetOptions(); 18330fdc8d8SChris Lattner if (options != NULL) 18430fdc8d8SChris Lattner { 18530fdc8d8SChris Lattner Error error; 186f6b8b581SGreg Clayton options->NotifyOptionParsingStarting(); 18730fdc8d8SChris Lattner 18830fdc8d8SChris Lattner // ParseOptions calls getopt_long, which always skips the zero'th item in the array and starts at position 1, 18930fdc8d8SChris Lattner // so we need to push a dummy value into position zero. 19030fdc8d8SChris Lattner args.Unshift("dummy_string"); 19130fdc8d8SChris Lattner error = args.ParseOptions (*options); 19230fdc8d8SChris Lattner 19330fdc8d8SChris Lattner // The "dummy_string" will have already been removed by ParseOptions, 19430fdc8d8SChris Lattner // so no need to remove it. 19530fdc8d8SChris Lattner 196f6b8b581SGreg Clayton if (error.Success()) 197f6b8b581SGreg Clayton error = options->NotifyOptionParsingFinished(); 198f6b8b581SGreg Clayton 199f6b8b581SGreg Clayton if (error.Success()) 200f6b8b581SGreg Clayton { 201f6b8b581SGreg Clayton if (options->VerifyOptions (result)) 202f6b8b581SGreg Clayton return true; 203f6b8b581SGreg Clayton } 204f6b8b581SGreg Clayton else 20530fdc8d8SChris Lattner { 20630fdc8d8SChris Lattner const char *error_cstr = error.AsCString(); 20730fdc8d8SChris Lattner if (error_cstr) 20830fdc8d8SChris Lattner { 20930fdc8d8SChris Lattner // We got an error string, lets use that 21086edbf41SGreg Clayton result.AppendError(error_cstr); 21130fdc8d8SChris Lattner } 21230fdc8d8SChris Lattner else 21330fdc8d8SChris Lattner { 21430fdc8d8SChris Lattner // No error string, output the usage information into result 215eb0103f2SGreg Clayton options->GenerateOptionUsage (result.GetErrorStream(), this); 21630fdc8d8SChris Lattner } 217f6b8b581SGreg Clayton } 21830fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 21930fdc8d8SChris Lattner return false; 22030fdc8d8SChris Lattner } 22130fdc8d8SChris Lattner return true; 22230fdc8d8SChris Lattner } 22330fdc8d8SChris Lattner bool 224a7015092SGreg Clayton CommandObject::ExecuteWithOptions (Args& args, CommandReturnObject &result) 22530fdc8d8SChris Lattner { 22630fdc8d8SChris Lattner for (size_t i = 0; i < args.GetArgumentCount(); ++i) 22730fdc8d8SChris Lattner { 22830fdc8d8SChris Lattner const char *tmp_str = args.GetArgumentAtIndex (i); 22930fdc8d8SChris Lattner if (tmp_str[0] == '`') // back-quote 230a7015092SGreg Clayton args.ReplaceArgumentAtIndex (i, m_interpreter.ProcessEmbeddedScriptCommands (tmp_str)); 23130fdc8d8SChris Lattner } 23230fdc8d8SChris Lattner 233b766a73dSGreg Clayton if (GetFlags().AnySet (CommandObject::eFlagProcessMustBeLaunched | CommandObject::eFlagProcessMustBePaused)) 234b766a73dSGreg Clayton { 235c14ee32dSGreg Clayton Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); 23630fdc8d8SChris Lattner if (process == NULL) 23730fdc8d8SChris Lattner { 238b8e8a5f3SJim Ingham // A process that is not running is considered paused. 239b8e8a5f3SJim Ingham if (GetFlags().Test(CommandObject::eFlagProcessMustBeLaunched)) 240b8e8a5f3SJim Ingham { 24130fdc8d8SChris Lattner result.AppendError ("Process must exist."); 24230fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 24330fdc8d8SChris Lattner return false; 24430fdc8d8SChris Lattner } 245b8e8a5f3SJim Ingham } 24630fdc8d8SChris Lattner else 24730fdc8d8SChris Lattner { 24830fdc8d8SChris Lattner StateType state = process->GetState(); 24930fdc8d8SChris Lattner 25030fdc8d8SChris Lattner switch (state) 25130fdc8d8SChris Lattner { 2527a5388bfSGreg Clayton case eStateInvalid: 25330fdc8d8SChris Lattner case eStateSuspended: 25430fdc8d8SChris Lattner case eStateCrashed: 25530fdc8d8SChris Lattner case eStateStopped: 25630fdc8d8SChris Lattner break; 25730fdc8d8SChris Lattner 258b766a73dSGreg Clayton case eStateConnected: 259b766a73dSGreg Clayton case eStateAttaching: 260b766a73dSGreg Clayton case eStateLaunching: 26130fdc8d8SChris Lattner case eStateDetached: 26230fdc8d8SChris Lattner case eStateExited: 26330fdc8d8SChris Lattner case eStateUnloaded: 26473b472d4SGreg Clayton if (GetFlags().Test(CommandObject::eFlagProcessMustBeLaunched)) 26530fdc8d8SChris Lattner { 26630fdc8d8SChris Lattner result.AppendError ("Process must be launched."); 26730fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 26830fdc8d8SChris Lattner return false; 26930fdc8d8SChris Lattner } 27030fdc8d8SChris Lattner break; 27130fdc8d8SChris Lattner 27230fdc8d8SChris Lattner case eStateRunning: 27330fdc8d8SChris Lattner case eStateStepping: 27473b472d4SGreg Clayton if (GetFlags().Test(CommandObject::eFlagProcessMustBePaused)) 27530fdc8d8SChris Lattner { 27630fdc8d8SChris Lattner result.AppendError ("Process is running. Use 'process interrupt' to pause execution."); 27730fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 27830fdc8d8SChris Lattner return false; 27930fdc8d8SChris Lattner } 28030fdc8d8SChris Lattner } 28130fdc8d8SChris Lattner } 282b766a73dSGreg Clayton } 28330fdc8d8SChris Lattner 284a7015092SGreg Clayton if (!ParseOptions (args, result)) 28530fdc8d8SChris Lattner return false; 28630fdc8d8SChris Lattner 28730fdc8d8SChris Lattner // Call the command-specific version of 'Execute', passing it the already processed arguments. 288a7015092SGreg Clayton return Execute (args, result); 28930fdc8d8SChris Lattner } 29030fdc8d8SChris Lattner 29130fdc8d8SChris Lattner class CommandDictCommandPartialMatch 29230fdc8d8SChris Lattner { 29330fdc8d8SChris Lattner public: 29430fdc8d8SChris Lattner CommandDictCommandPartialMatch (const char *match_str) 29530fdc8d8SChris Lattner { 29630fdc8d8SChris Lattner m_match_str = match_str; 29730fdc8d8SChris Lattner } 29830fdc8d8SChris Lattner bool operator() (const std::pair<std::string, lldb::CommandObjectSP> map_element) const 29930fdc8d8SChris Lattner { 30030fdc8d8SChris Lattner // A NULL or empty string matches everything. 30130fdc8d8SChris Lattner if (m_match_str == NULL || *m_match_str == '\0') 30230fdc8d8SChris Lattner return 1; 30330fdc8d8SChris Lattner 30430fdc8d8SChris Lattner size_t found = map_element.first.find (m_match_str, 0); 30530fdc8d8SChris Lattner if (found == std::string::npos) 30630fdc8d8SChris Lattner return 0; 30730fdc8d8SChris Lattner else 30830fdc8d8SChris Lattner return found == 0; 30930fdc8d8SChris Lattner } 31030fdc8d8SChris Lattner 31130fdc8d8SChris Lattner private: 31230fdc8d8SChris Lattner const char *m_match_str; 31330fdc8d8SChris Lattner }; 31430fdc8d8SChris Lattner 31530fdc8d8SChris Lattner int 31630fdc8d8SChris Lattner CommandObject::AddNamesMatchingPartialString (CommandObject::CommandMap &in_map, const char *cmd_str, 31730fdc8d8SChris Lattner StringList &matches) 31830fdc8d8SChris Lattner { 31930fdc8d8SChris Lattner int number_added = 0; 32030fdc8d8SChris Lattner CommandDictCommandPartialMatch matcher(cmd_str); 32130fdc8d8SChris Lattner 32230fdc8d8SChris Lattner CommandObject::CommandMap::iterator matching_cmds = std::find_if (in_map.begin(), in_map.end(), matcher); 32330fdc8d8SChris Lattner 32430fdc8d8SChris Lattner while (matching_cmds != in_map.end()) 32530fdc8d8SChris Lattner { 32630fdc8d8SChris Lattner ++number_added; 32730fdc8d8SChris Lattner matches.AppendString((*matching_cmds).first.c_str()); 32830fdc8d8SChris Lattner matching_cmds = std::find_if (++matching_cmds, in_map.end(), matcher);; 32930fdc8d8SChris Lattner } 33030fdc8d8SChris Lattner return number_added; 33130fdc8d8SChris Lattner } 33230fdc8d8SChris Lattner 33330fdc8d8SChris Lattner int 33430fdc8d8SChris Lattner CommandObject::HandleCompletion 33530fdc8d8SChris Lattner ( 33630fdc8d8SChris Lattner Args &input, 33730fdc8d8SChris Lattner int &cursor_index, 33830fdc8d8SChris Lattner int &cursor_char_position, 33930fdc8d8SChris Lattner int match_start_point, 34030fdc8d8SChris Lattner int max_return_elements, 341558ce124SJim Ingham bool &word_complete, 34230fdc8d8SChris Lattner StringList &matches 34330fdc8d8SChris Lattner ) 34430fdc8d8SChris Lattner { 34530fdc8d8SChris Lattner if (WantsRawCommandString()) 34630fdc8d8SChris Lattner { 34730fdc8d8SChris Lattner // FIXME: Abstract telling the completion to insert the completion character. 34830fdc8d8SChris Lattner matches.Clear(); 34930fdc8d8SChris Lattner return -1; 35030fdc8d8SChris Lattner } 35130fdc8d8SChris Lattner else 35230fdc8d8SChris Lattner { 35330fdc8d8SChris Lattner // Can we do anything generic with the options? 35430fdc8d8SChris Lattner Options *cur_options = GetOptions(); 35530fdc8d8SChris Lattner CommandReturnObject result; 35630fdc8d8SChris Lattner OptionElementVector opt_element_vector; 35730fdc8d8SChris Lattner 35830fdc8d8SChris Lattner if (cur_options != NULL) 35930fdc8d8SChris Lattner { 36030fdc8d8SChris Lattner // Re-insert the dummy command name string which will have been 36130fdc8d8SChris Lattner // stripped off: 36230fdc8d8SChris Lattner input.Unshift ("dummy-string"); 36330fdc8d8SChris Lattner cursor_index++; 36430fdc8d8SChris Lattner 36530fdc8d8SChris Lattner 36630fdc8d8SChris Lattner // I stick an element on the end of the input, because if the last element is 36730fdc8d8SChris Lattner // option that requires an argument, getopt_long will freak out. 36830fdc8d8SChris Lattner 36930fdc8d8SChris Lattner input.AppendArgument ("<FAKE-VALUE>"); 37030fdc8d8SChris Lattner 371d43e0094SJim Ingham input.ParseArgsForCompletion (*cur_options, opt_element_vector, cursor_index); 37230fdc8d8SChris Lattner 37330fdc8d8SChris Lattner input.DeleteArgumentAtIndex(input.GetArgumentCount() - 1); 37430fdc8d8SChris Lattner 37530fdc8d8SChris Lattner bool handled_by_options; 376eb0103f2SGreg Clayton handled_by_options = cur_options->HandleOptionCompletion (input, 37730fdc8d8SChris Lattner opt_element_vector, 37830fdc8d8SChris Lattner cursor_index, 37930fdc8d8SChris Lattner cursor_char_position, 38030fdc8d8SChris Lattner match_start_point, 38130fdc8d8SChris Lattner max_return_elements, 382558ce124SJim Ingham word_complete, 38330fdc8d8SChris Lattner matches); 38430fdc8d8SChris Lattner if (handled_by_options) 38530fdc8d8SChris Lattner return matches.GetSize(); 38630fdc8d8SChris Lattner } 38730fdc8d8SChris Lattner 38830fdc8d8SChris Lattner // If we got here, the last word is not an option or an option argument. 389a7015092SGreg Clayton return HandleArgumentCompletion (input, 39030fdc8d8SChris Lattner cursor_index, 39130fdc8d8SChris Lattner cursor_char_position, 39230fdc8d8SChris Lattner opt_element_vector, 39330fdc8d8SChris Lattner match_start_point, 39430fdc8d8SChris Lattner max_return_elements, 395558ce124SJim Ingham word_complete, 39630fdc8d8SChris Lattner matches); 39730fdc8d8SChris Lattner } 39830fdc8d8SChris Lattner } 39930fdc8d8SChris Lattner 40030fdc8d8SChris Lattner bool 401a7015092SGreg Clayton CommandObject::HelpTextContainsWord (const char *search_word) 40230fdc8d8SChris Lattner { 40330fdc8d8SChris Lattner const char *short_help; 40430fdc8d8SChris Lattner const char *long_help; 40530fdc8d8SChris Lattner const char *syntax_help; 40630fdc8d8SChris Lattner std::string options_usage_help; 40730fdc8d8SChris Lattner 40830fdc8d8SChris Lattner 40930fdc8d8SChris Lattner bool found_word = false; 41030fdc8d8SChris Lattner 41130fdc8d8SChris Lattner short_help = GetHelp(); 41230fdc8d8SChris Lattner long_help = GetHelpLong(); 41330fdc8d8SChris Lattner syntax_help = GetSyntax(); 41430fdc8d8SChris Lattner 4154b6fbf37SCaroline Tice if (strcasestr (short_help, search_word)) 41630fdc8d8SChris Lattner found_word = true; 4174b6fbf37SCaroline Tice else if (strcasestr (long_help, search_word)) 41830fdc8d8SChris Lattner found_word = true; 4194b6fbf37SCaroline Tice else if (strcasestr (syntax_help, search_word)) 42030fdc8d8SChris Lattner found_word = true; 42130fdc8d8SChris Lattner 42230fdc8d8SChris Lattner if (!found_word 42330fdc8d8SChris Lattner && GetOptions() != NULL) 42430fdc8d8SChris Lattner { 42530fdc8d8SChris Lattner StreamString usage_help; 426eb0103f2SGreg Clayton GetOptions()->GenerateOptionUsage (usage_help, this); 42730fdc8d8SChris Lattner if (usage_help.GetSize() > 0) 42830fdc8d8SChris Lattner { 42930fdc8d8SChris Lattner const char *usage_text = usage_help.GetData(); 4304b6fbf37SCaroline Tice if (strcasestr (usage_text, search_word)) 43130fdc8d8SChris Lattner found_word = true; 43230fdc8d8SChris Lattner } 43330fdc8d8SChris Lattner } 43430fdc8d8SChris Lattner 43530fdc8d8SChris Lattner return found_word; 43630fdc8d8SChris Lattner } 437e139cf23SCaroline Tice 438e139cf23SCaroline Tice int 439e139cf23SCaroline Tice CommandObject::GetNumArgumentEntries () 440e139cf23SCaroline Tice { 441e139cf23SCaroline Tice return m_arguments.size(); 442e139cf23SCaroline Tice } 443e139cf23SCaroline Tice 444e139cf23SCaroline Tice CommandObject::CommandArgumentEntry * 445e139cf23SCaroline Tice CommandObject::GetArgumentEntryAtIndex (int idx) 446e139cf23SCaroline Tice { 447e139cf23SCaroline Tice if (idx < m_arguments.size()) 448e139cf23SCaroline Tice return &(m_arguments[idx]); 449e139cf23SCaroline Tice 450e139cf23SCaroline Tice return NULL; 451e139cf23SCaroline Tice } 452e139cf23SCaroline Tice 453e139cf23SCaroline Tice CommandObject::ArgumentTableEntry * 454e139cf23SCaroline Tice CommandObject::FindArgumentDataByType (CommandArgumentType arg_type) 455e139cf23SCaroline Tice { 456e139cf23SCaroline Tice const ArgumentTableEntry *table = CommandObject::GetArgumentTable(); 457e139cf23SCaroline Tice 458e139cf23SCaroline Tice for (int i = 0; i < eArgTypeLastArg; ++i) 459e139cf23SCaroline Tice if (table[i].arg_type == arg_type) 460e139cf23SCaroline Tice return (ArgumentTableEntry *) &(table[i]); 461e139cf23SCaroline Tice 462e139cf23SCaroline Tice return NULL; 463e139cf23SCaroline Tice } 464e139cf23SCaroline Tice 465e139cf23SCaroline Tice void 466e139cf23SCaroline Tice CommandObject::GetArgumentHelp (Stream &str, CommandArgumentType arg_type, CommandInterpreter &interpreter) 467e139cf23SCaroline Tice { 468e139cf23SCaroline Tice const ArgumentTableEntry* table = CommandObject::GetArgumentTable(); 469e139cf23SCaroline Tice ArgumentTableEntry *entry = (ArgumentTableEntry *) &(table[arg_type]); 470e139cf23SCaroline Tice 471e139cf23SCaroline Tice // The table is *supposed* to be kept in arg_type order, but someone *could* have messed it up... 472e139cf23SCaroline Tice 473e139cf23SCaroline Tice if (entry->arg_type != arg_type) 474e139cf23SCaroline Tice entry = CommandObject::FindArgumentDataByType (arg_type); 475e139cf23SCaroline Tice 476e139cf23SCaroline Tice if (!entry) 477e139cf23SCaroline Tice return; 478e139cf23SCaroline Tice 479e139cf23SCaroline Tice StreamString name_str; 480e139cf23SCaroline Tice name_str.Printf ("<%s>", entry->arg_name); 481e139cf23SCaroline Tice 482fc7a7f3bSEnrico Granata if (entry->help_function) 48382a7d983SEnrico Granata { 484fc7a7f3bSEnrico Granata const char* help_text = entry->help_function(); 48582a7d983SEnrico Granata if (!entry->help_function.self_formatting) 48682a7d983SEnrico Granata { 48782a7d983SEnrico Granata interpreter.OutputFormattedHelpText (str, name_str.GetData(), "--", help_text, 488e139cf23SCaroline Tice name_str.GetSize()); 48982a7d983SEnrico Granata } 49082a7d983SEnrico Granata else 49182a7d983SEnrico Granata { 49282a7d983SEnrico Granata interpreter.OutputHelpText(str, name_str.GetData(), "--", help_text, 49382a7d983SEnrico Granata name_str.GetSize()); 49482a7d983SEnrico Granata } 49582a7d983SEnrico Granata } 496e139cf23SCaroline Tice else 497e139cf23SCaroline Tice interpreter.OutputFormattedHelpText (str, name_str.GetData(), "--", entry->help_text, name_str.GetSize()); 498e139cf23SCaroline Tice } 499e139cf23SCaroline Tice 500e139cf23SCaroline Tice const char * 501e139cf23SCaroline Tice CommandObject::GetArgumentName (CommandArgumentType arg_type) 502e139cf23SCaroline Tice { 503deaab222SCaroline Tice ArgumentTableEntry *entry = (ArgumentTableEntry *) &(CommandObject::GetArgumentTable()[arg_type]); 504deaab222SCaroline Tice 505deaab222SCaroline Tice // The table is *supposed* to be kept in arg_type order, but someone *could* have messed it up... 506deaab222SCaroline Tice 507deaab222SCaroline Tice if (entry->arg_type != arg_type) 508deaab222SCaroline Tice entry = CommandObject::FindArgumentDataByType (arg_type); 509deaab222SCaroline Tice 510e6acf355SJohnny Chen if (entry) 511deaab222SCaroline Tice return entry->arg_name; 512e6acf355SJohnny Chen 513e6acf355SJohnny Chen StreamString str; 514e6acf355SJohnny Chen str << "Arg name for type (" << arg_type << ") not in arg table!"; 515e6acf355SJohnny Chen return str.GetData(); 516e139cf23SCaroline Tice } 517e139cf23SCaroline Tice 518405fe67fSCaroline Tice bool 519e0d378b3SGreg Clayton CommandObject::IsPairType (ArgumentRepetitionType arg_repeat_type) 520405fe67fSCaroline Tice { 521405fe67fSCaroline Tice if ((arg_repeat_type == eArgRepeatPairPlain) 522405fe67fSCaroline Tice || (arg_repeat_type == eArgRepeatPairOptional) 523405fe67fSCaroline Tice || (arg_repeat_type == eArgRepeatPairPlus) 524405fe67fSCaroline Tice || (arg_repeat_type == eArgRepeatPairStar) 525405fe67fSCaroline Tice || (arg_repeat_type == eArgRepeatPairRange) 526405fe67fSCaroline Tice || (arg_repeat_type == eArgRepeatPairRangeOptional)) 527405fe67fSCaroline Tice return true; 528405fe67fSCaroline Tice 529405fe67fSCaroline Tice return false; 530405fe67fSCaroline Tice } 531405fe67fSCaroline Tice 532e139cf23SCaroline Tice void 533e139cf23SCaroline Tice CommandObject::GetFormattedCommandArguments (Stream &str) 534e139cf23SCaroline Tice { 535e139cf23SCaroline Tice int num_args = m_arguments.size(); 536e139cf23SCaroline Tice for (int i = 0; i < num_args; ++i) 537e139cf23SCaroline Tice { 538e139cf23SCaroline Tice if (i > 0) 539e139cf23SCaroline Tice str.Printf (" "); 540e139cf23SCaroline Tice CommandArgumentEntry arg_entry = m_arguments[i]; 541e139cf23SCaroline Tice int num_alternatives = arg_entry.size(); 542405fe67fSCaroline Tice 543405fe67fSCaroline Tice if ((num_alternatives == 2) 544405fe67fSCaroline Tice && IsPairType (arg_entry[0].arg_repetition)) 545405fe67fSCaroline Tice { 546405fe67fSCaroline Tice const char *first_name = GetArgumentName (arg_entry[0].arg_type); 547405fe67fSCaroline Tice const char *second_name = GetArgumentName (arg_entry[1].arg_type); 548405fe67fSCaroline Tice switch (arg_entry[0].arg_repetition) 549405fe67fSCaroline Tice { 550405fe67fSCaroline Tice case eArgRepeatPairPlain: 551405fe67fSCaroline Tice str.Printf ("<%s> <%s>", first_name, second_name); 552405fe67fSCaroline Tice break; 553405fe67fSCaroline Tice case eArgRepeatPairOptional: 554405fe67fSCaroline Tice str.Printf ("[<%s> <%s>]", first_name, second_name); 555405fe67fSCaroline Tice break; 556405fe67fSCaroline Tice case eArgRepeatPairPlus: 557405fe67fSCaroline Tice str.Printf ("<%s> <%s> [<%s> <%s> [...]]", first_name, second_name, first_name, second_name); 558405fe67fSCaroline Tice break; 559405fe67fSCaroline Tice case eArgRepeatPairStar: 560405fe67fSCaroline Tice str.Printf ("[<%s> <%s> [<%s> <%s> [...]]]", first_name, second_name, first_name, second_name); 561405fe67fSCaroline Tice break; 562405fe67fSCaroline Tice case eArgRepeatPairRange: 563405fe67fSCaroline Tice str.Printf ("<%s_1> <%s_1> ... <%s_n> <%s_n>", first_name, second_name, first_name, second_name); 564405fe67fSCaroline Tice break; 565405fe67fSCaroline Tice case eArgRepeatPairRangeOptional: 566405fe67fSCaroline Tice str.Printf ("[<%s_1> <%s_1> ... <%s_n> <%s_n>]", first_name, second_name, first_name, second_name); 567405fe67fSCaroline Tice break; 568ca1176aaSCaroline Tice // Explicitly test for all the rest of the cases, so if new types get added we will notice the 569ca1176aaSCaroline Tice // missing case statement(s). 570ca1176aaSCaroline Tice case eArgRepeatPlain: 571ca1176aaSCaroline Tice case eArgRepeatOptional: 572ca1176aaSCaroline Tice case eArgRepeatPlus: 573ca1176aaSCaroline Tice case eArgRepeatStar: 574ca1176aaSCaroline Tice case eArgRepeatRange: 575ca1176aaSCaroline Tice // These should not be reached, as they should fail the IsPairType test above. 576ca1176aaSCaroline Tice break; 577405fe67fSCaroline Tice } 578405fe67fSCaroline Tice } 579405fe67fSCaroline Tice else 580405fe67fSCaroline Tice { 581e139cf23SCaroline Tice StreamString names; 582e139cf23SCaroline Tice for (int j = 0; j < num_alternatives; ++j) 583e139cf23SCaroline Tice { 584e139cf23SCaroline Tice if (j > 0) 585e139cf23SCaroline Tice names.Printf (" | "); 586e139cf23SCaroline Tice names.Printf ("%s", GetArgumentName (arg_entry[j].arg_type)); 587e139cf23SCaroline Tice } 588e139cf23SCaroline Tice switch (arg_entry[0].arg_repetition) 589e139cf23SCaroline Tice { 590e139cf23SCaroline Tice case eArgRepeatPlain: 591e139cf23SCaroline Tice str.Printf ("<%s>", names.GetData()); 592e139cf23SCaroline Tice break; 593e139cf23SCaroline Tice case eArgRepeatPlus: 594e139cf23SCaroline Tice str.Printf ("<%s> [<%s> [...]]", names.GetData(), names.GetData()); 595e139cf23SCaroline Tice break; 596e139cf23SCaroline Tice case eArgRepeatStar: 597e139cf23SCaroline Tice str.Printf ("[<%s> [<%s> [...]]]", names.GetData(), names.GetData()); 598e139cf23SCaroline Tice break; 599e139cf23SCaroline Tice case eArgRepeatOptional: 600e139cf23SCaroline Tice str.Printf ("[<%s>]", names.GetData()); 601e139cf23SCaroline Tice break; 602405fe67fSCaroline Tice case eArgRepeatRange: 603fd54b368SJason Molenda str.Printf ("<%s_1> .. <%s_n>", names.GetData(), names.GetData()); 604ca1176aaSCaroline Tice break; 605ca1176aaSCaroline Tice // Explicitly test for all the rest of the cases, so if new types get added we will notice the 606ca1176aaSCaroline Tice // missing case statement(s). 607ca1176aaSCaroline Tice case eArgRepeatPairPlain: 608ca1176aaSCaroline Tice case eArgRepeatPairOptional: 609ca1176aaSCaroline Tice case eArgRepeatPairPlus: 610ca1176aaSCaroline Tice case eArgRepeatPairStar: 611ca1176aaSCaroline Tice case eArgRepeatPairRange: 612ca1176aaSCaroline Tice case eArgRepeatPairRangeOptional: 613ca1176aaSCaroline Tice // These should not be hit, as they should pass the IsPairType test above, and control should 614ca1176aaSCaroline Tice // have gone into the other branch of the if statement. 615ca1176aaSCaroline Tice break; 616405fe67fSCaroline Tice } 617e139cf23SCaroline Tice } 618e139cf23SCaroline Tice } 619e139cf23SCaroline Tice } 620e139cf23SCaroline Tice 6210c16aa6dSStephen Wilson CommandArgumentType 622e139cf23SCaroline Tice CommandObject::LookupArgumentName (const char *arg_name) 623e139cf23SCaroline Tice { 624e139cf23SCaroline Tice CommandArgumentType return_type = eArgTypeLastArg; 625e139cf23SCaroline Tice 626e139cf23SCaroline Tice std::string arg_name_str (arg_name); 627e139cf23SCaroline Tice size_t len = arg_name_str.length(); 628e139cf23SCaroline Tice if (arg_name[0] == '<' 629e139cf23SCaroline Tice && arg_name[len-1] == '>') 630e139cf23SCaroline Tice arg_name_str = arg_name_str.substr (1, len-2); 631e139cf23SCaroline Tice 632331eff39SJohnny Chen const ArgumentTableEntry *table = GetArgumentTable(); 633e139cf23SCaroline Tice for (int i = 0; i < eArgTypeLastArg; ++i) 634331eff39SJohnny Chen if (arg_name_str.compare (table[i].arg_name) == 0) 635e139cf23SCaroline Tice return_type = g_arguments_data[i].arg_type; 636e139cf23SCaroline Tice 637e139cf23SCaroline Tice return return_type; 638e139cf23SCaroline Tice } 639e139cf23SCaroline Tice 640e139cf23SCaroline Tice static const char * 641e139cf23SCaroline Tice BreakpointIDHelpTextCallback () 642e139cf23SCaroline Tice { 64386edbf41SGreg Clayton return "Breakpoint ID's consist major and minor numbers; the major number " 64486edbf41SGreg Clayton "corresponds to the single entity that was created with a 'breakpoint set' " 64586edbf41SGreg Clayton "command; the minor numbers correspond to all the locations that were actually " 64686edbf41SGreg Clayton "found/set based on the major breakpoint. A full breakpoint ID might look like " 64786edbf41SGreg Clayton "3.14, meaning the 14th location set for the 3rd breakpoint. You can specify " 64886edbf41SGreg Clayton "all the locations of a breakpoint by just indicating the major breakpoint " 64986edbf41SGreg Clayton "number. A valid breakpoint id consists either of just the major id number, " 65086edbf41SGreg Clayton "or the major number, a dot, and the location number (e.g. 3 or 3.2 could " 65186edbf41SGreg Clayton "both be valid breakpoint ids)."; 652e139cf23SCaroline Tice } 653e139cf23SCaroline Tice 654e139cf23SCaroline Tice static const char * 655e139cf23SCaroline Tice BreakpointIDRangeHelpTextCallback () 656e139cf23SCaroline Tice { 65786edbf41SGreg Clayton return "A 'breakpoint id list' is a manner of specifying multiple breakpoints. " 65886edbf41SGreg Clayton "This can be done through several mechanisms. The easiest way is to just " 65986edbf41SGreg Clayton "enter a space-separated list of breakpoint ids. To specify all the " 66086edbf41SGreg Clayton "breakpoint locations under a major breakpoint, you can use the major " 66186edbf41SGreg Clayton "breakpoint number followed by '.*', eg. '5.*' means all the locations under " 66286edbf41SGreg Clayton "breakpoint 5. You can also indicate a range of breakpoints by using " 66386edbf41SGreg Clayton "<start-bp-id> - <end-bp-id>. The start-bp-id and end-bp-id for a range can " 66486edbf41SGreg Clayton "be any valid breakpoint ids. It is not legal, however, to specify a range " 66586edbf41SGreg Clayton "using specific locations that cross major breakpoint numbers. I.e. 3.2 - 3.7" 66686edbf41SGreg Clayton " is legal; 2 - 5 is legal; but 3.2 - 4.4 is not legal."; 66786edbf41SGreg Clayton } 66886edbf41SGreg Clayton 66986edbf41SGreg Clayton static const char * 67086edbf41SGreg Clayton GDBFormatHelpTextCallback () 67186edbf41SGreg Clayton { 672f91381e8SGreg Clayton return "A GDB format consists of a repeat count, a format letter and a size letter. " 673f91381e8SGreg Clayton "The repeat count is optional and defaults to 1. The format letter is optional " 674f91381e8SGreg Clayton "and defaults to the previous format that was used. The size letter is optional " 675f91381e8SGreg Clayton "and defaults to the previous size that was used.\n" 676f91381e8SGreg Clayton "\n" 677f91381e8SGreg Clayton "Format letters include:\n" 678f91381e8SGreg Clayton "o - octal\n" 679f91381e8SGreg Clayton "x - hexadecimal\n" 680f91381e8SGreg Clayton "d - decimal\n" 681f91381e8SGreg Clayton "u - unsigned decimal\n" 682f91381e8SGreg Clayton "t - binary\n" 683f91381e8SGreg Clayton "f - float\n" 684f91381e8SGreg Clayton "a - address\n" 685f91381e8SGreg Clayton "i - instruction\n" 686f91381e8SGreg Clayton "c - char\n" 687f91381e8SGreg Clayton "s - string\n" 688f91381e8SGreg Clayton "T - OSType\n" 689f91381e8SGreg Clayton "A - float as hex\n" 690f91381e8SGreg Clayton "\n" 691f91381e8SGreg Clayton "Size letters include:\n" 692f91381e8SGreg Clayton "b - 1 byte (byte)\n" 693f91381e8SGreg Clayton "h - 2 bytes (halfword)\n" 694f91381e8SGreg Clayton "w - 4 bytes (word)\n" 695f91381e8SGreg Clayton "g - 8 bytes (giant)\n" 696f91381e8SGreg Clayton "\n" 697f91381e8SGreg Clayton "Example formats:\n" 698f91381e8SGreg Clayton "32xb - show 32 1 byte hexadecimal integer values\n" 699f91381e8SGreg Clayton "16xh - show 16 2 byte hexadecimal integer values\n" 700f91381e8SGreg Clayton "64 - show 64 2 byte hexadecimal integer values (format and size from the last format)\n" 701f91381e8SGreg Clayton "dw - show 1 4 byte decimal integer value\n" 702f91381e8SGreg Clayton ; 703e139cf23SCaroline Tice } 704e139cf23SCaroline Tice 7050a3958e0SEnrico Granata static const char * 7060a3958e0SEnrico Granata FormatHelpTextCallback () 7070a3958e0SEnrico Granata { 70882a7d983SEnrico Granata 70982a7d983SEnrico Granata static char* help_text_ptr = NULL; 71082a7d983SEnrico Granata 71182a7d983SEnrico Granata if (help_text_ptr) 71282a7d983SEnrico Granata return help_text_ptr; 71382a7d983SEnrico Granata 7140a3958e0SEnrico Granata StreamString sstr; 7150a3958e0SEnrico Granata sstr << "One of the format names (or one-character names) that can be used to show a variable's value:\n"; 7160a3958e0SEnrico Granata for (Format f = eFormatDefault; f < kNumFormats; f = Format(f+1)) 7170a3958e0SEnrico Granata { 71882a7d983SEnrico Granata if (f != eFormatDefault) 71982a7d983SEnrico Granata sstr.PutChar('\n'); 72082a7d983SEnrico Granata 7210a3958e0SEnrico Granata char format_char = FormatManager::GetFormatAsFormatChar(f); 7220a3958e0SEnrico Granata if (format_char) 7230a3958e0SEnrico Granata sstr.Printf("'%c' or ", format_char); 7240a3958e0SEnrico Granata 72582a7d983SEnrico Granata sstr.Printf ("\"%s\"", FormatManager::GetFormatAsCString(f)); 7260a3958e0SEnrico Granata } 7270a3958e0SEnrico Granata 7280a3958e0SEnrico Granata sstr.Flush(); 7290a3958e0SEnrico Granata 7300a3958e0SEnrico Granata std::string data = sstr.GetString(); 7310a3958e0SEnrico Granata 73282a7d983SEnrico Granata help_text_ptr = new char[data.length()+1]; 7330a3958e0SEnrico Granata 73482a7d983SEnrico Granata data.copy(help_text_ptr, data.length()); 7350a3958e0SEnrico Granata 73682a7d983SEnrico Granata return help_text_ptr; 7370a3958e0SEnrico Granata } 7380a3958e0SEnrico Granata 7390a3958e0SEnrico Granata static const char * 74082a7d983SEnrico Granata SummaryStringHelpTextCallback() 7410a3958e0SEnrico Granata { 74282a7d983SEnrico Granata return 74382a7d983SEnrico Granata "A summary string is a way to extract information from variables in order to present them using a summary.\n" 74482a7d983SEnrico Granata "Summary strings contain static text, variables, scopes and control sequences:\n" 74582a7d983SEnrico Granata " - Static text can be any sequence of non-special characters, i.e. anything but '{', '}', '$', or '\\'.\n" 74682a7d983SEnrico Granata " - Variables are sequences of characters beginning with ${, ending with } and that contain symbols in the format described below.\n" 74782a7d983SEnrico Granata " - Scopes are any sequence of text between { and }. Anything included in a scope will only appear in the output summary if there were no errors.\n" 74882a7d983SEnrico Granata " - Control sequences are the usual C/C++ '\\a', '\\n', ..., plus '\\$', '\\{' and '\\}'.\n" 74982a7d983SEnrico Granata "A summary string works by copying static text verbatim, turning control sequences into their character counterpart, expanding variables and trying to expand scopes.\n" 75082a7d983SEnrico Granata "A variable is expanded by giving it a value other than its textual representation, and the way this is done depends on what comes after the ${ marker.\n" 75182a7d983SEnrico Granata "The most common sequence if ${var followed by an expression path, which is the text one would type to access a member of an aggregate types, given a variable of that type" 75282a7d983SEnrico Granata " (e.g. if type T has a member named x, which has a member named y, and if t is of type T, the expression path would be .x.y and the way to fit that into a summary string would be" 7539128ee2fSEnrico Granata " ${var.x.y}). You can also use ${*var followed by an expression path and in that case the object referred by the path will be dereferenced before being displayed." 7549128ee2fSEnrico Granata " If the object is not a pointer, doing so will cause an error. For additional details on expression paths, you can type 'help expr-path'. \n" 75582a7d983SEnrico Granata "By default, summary strings attempt to display the summary for any variable they reference, and if that fails the value. If neither can be shown, nothing is displayed." 75682a7d983SEnrico Granata "In a summary string, you can also use an array index [n], or a slice-like range [n-m]. This can have two different meanings depending on what kind of object the expression" 75782a7d983SEnrico Granata " path refers to:\n" 75882a7d983SEnrico Granata " - if it is a scalar type (any basic type like int, float, ...) the expression is a bitfield, i.e. the bits indicated by the indexing operator are extracted out of the number" 75982a7d983SEnrico Granata " and displayed as an individual variable\n" 76082a7d983SEnrico Granata " - if it is an array or pointer the array items indicated by the indexing operator are shown as the result of the variable. if the expression is an array, real array items are" 76182a7d983SEnrico Granata " printed; if it is a pointer, the pointer-as-array syntax is used to obtain the values (this means, the latter case can have no range checking)\n" 7629128ee2fSEnrico Granata "If you are trying to display an array for which the size is known, you can also use [] instead of giving an exact range. This has the effect of showing items 0 thru size - 1.\n" 7639128ee2fSEnrico Granata "Additionally, a variable can contain an (optional) format code, as in ${var.x.y%code}, where code can be any of the valid formats described in 'help format', or one of the" 7649128ee2fSEnrico Granata " special symbols only allowed as part of a variable:\n" 7659128ee2fSEnrico Granata " %V: show the value of the object by default\n" 7669128ee2fSEnrico Granata " %S: show the summary of the object by default\n" 7679128ee2fSEnrico Granata " %@: show the runtime-provided object description (for Objective-C, it calls NSPrintForDebugger; for C/C++ it does nothing)\n" 7689128ee2fSEnrico Granata " %L: show the location of the object (memory address or a register name)\n" 7699128ee2fSEnrico Granata " %#: show the number of children of the object\n" 7709128ee2fSEnrico Granata " %T: show the type of the object\n" 7719128ee2fSEnrico Granata "Another variable that you can use in summary strings is ${svar . This sequence works exactly like ${var, including the fact that ${*svar is an allowed sequence, but uses" 7729128ee2fSEnrico Granata " the object's synthetic children provider instead of the actual objects. For instance, if you are using STL synthetic children providers, the following summary string would" 7739128ee2fSEnrico Granata " count the number of actual elements stored in an std::list:\n" 7749128ee2fSEnrico Granata "type summary add -s \"${svar%#}\" -x \"std::list<\""; 7759128ee2fSEnrico Granata } 7769128ee2fSEnrico Granata 7779128ee2fSEnrico Granata static const char * 7789128ee2fSEnrico Granata ExprPathHelpTextCallback() 7799128ee2fSEnrico Granata { 7809128ee2fSEnrico Granata return 7819128ee2fSEnrico Granata "An expression path is the sequence of symbols that is used in C/C++ to access a member variable of an aggregate object (class).\n" 7829128ee2fSEnrico Granata "For instance, given a class:\n" 7839128ee2fSEnrico Granata " class foo {\n" 7849128ee2fSEnrico Granata " int a;\n" 7859128ee2fSEnrico Granata " int b; .\n" 7869128ee2fSEnrico Granata " foo* next;\n" 7879128ee2fSEnrico Granata " };\n" 7889128ee2fSEnrico Granata "the expression to read item b in the item pointed to by next for foo aFoo would be aFoo.next->b.\n" 7899128ee2fSEnrico Granata "Given that aFoo could just be any object of type foo, the string '.next->b' is the expression path, because it can be attached to any foo instance to achieve the effect.\n" 7909128ee2fSEnrico Granata "Expression paths in LLDB include dot (.) and arrow (->) operators, and most commands using expression paths have ways to also accept the star (*) operator.\n" 7919128ee2fSEnrico Granata "The meaning of these operators is the same as the usual one given to them by the C/C++ standards.\n" 7929128ee2fSEnrico Granata "LLDB also has support for indexing ([ ]) in expression paths, and extends the traditional meaning of the square brackets operator to allow bitfield extraction:\n" 7939128ee2fSEnrico Granata "for objects of native types (int, float, char, ...) saying '[n-m]' as an expression path (where n and m are any positive integers, e.g. [3-5]) causes LLDB to extract" 7949128ee2fSEnrico Granata " bits n thru m from the value of the variable. If n == m, [n] is also allowed as a shortcut syntax. For arrays and pointers, expression paths can only contain one index" 7959128ee2fSEnrico Granata " and the meaning of the operation is the same as the one defined by C/C++ (item extraction). Some commands extend bitfield-like syntax for arrays and pointers with the" 7969128ee2fSEnrico Granata " meaning of array slicing (taking elements n thru m inside the array or pointed-to memory)."; 7970a3958e0SEnrico Granata } 7980a3958e0SEnrico Granata 799184d7a72SJohnny Chen void 800de753464SJohnny Chen CommandObject::AddIDsArgumentData(CommandArgumentEntry &arg, CommandArgumentType ID, CommandArgumentType IDRange) 801184d7a72SJohnny Chen { 802184d7a72SJohnny Chen CommandArgumentData id_arg; 803184d7a72SJohnny Chen CommandArgumentData id_range_arg; 804184d7a72SJohnny Chen 805184d7a72SJohnny Chen // Create the first variant for the first (and only) argument for this command. 806de753464SJohnny Chen id_arg.arg_type = ID; 807184d7a72SJohnny Chen id_arg.arg_repetition = eArgRepeatOptional; 808184d7a72SJohnny Chen 809184d7a72SJohnny Chen // Create the second variant for the first (and only) argument for this command. 810de753464SJohnny Chen id_range_arg.arg_type = IDRange; 811184d7a72SJohnny Chen id_range_arg.arg_repetition = eArgRepeatOptional; 812184d7a72SJohnny Chen 813a3234732SJohnny Chen // The first (and only) argument for this command could be either an id or an id_range. 814184d7a72SJohnny Chen // Push both variants into the entry for the first argument for this command. 815184d7a72SJohnny Chen arg.push_back(id_arg); 816184d7a72SJohnny Chen arg.push_back(id_range_arg); 817184d7a72SJohnny Chen } 818184d7a72SJohnny Chen 8199d0402b1SGreg Clayton const char * 8209d0402b1SGreg Clayton CommandObject::GetArgumentTypeAsCString (const lldb::CommandArgumentType arg_type) 8219d0402b1SGreg Clayton { 8229d0402b1SGreg Clayton if (arg_type >=0 && arg_type < eArgTypeLastArg) 8239d0402b1SGreg Clayton return g_arguments_data[arg_type].arg_name; 8249d0402b1SGreg Clayton return NULL; 8259d0402b1SGreg Clayton 8269d0402b1SGreg Clayton } 8279d0402b1SGreg Clayton 8289d0402b1SGreg Clayton const char * 8299d0402b1SGreg Clayton CommandObject::GetArgumentDescriptionAsCString (const lldb::CommandArgumentType arg_type) 8309d0402b1SGreg Clayton { 8319d0402b1SGreg Clayton if (arg_type >=0 && arg_type < eArgTypeLastArg) 8329d0402b1SGreg Clayton return g_arguments_data[arg_type].help_text; 8339d0402b1SGreg Clayton return NULL; 8349d0402b1SGreg Clayton } 8359d0402b1SGreg Clayton 836e139cf23SCaroline Tice CommandObject::ArgumentTableEntry 837e139cf23SCaroline Tice CommandObject::g_arguments_data[] = 838e139cf23SCaroline Tice { 8397f941d95SEnrico Granata { eArgTypeAddress, "address", CommandCompletions::eNoCompletion, { NULL, false }, "A valid address in the target program's execution space." }, 8407f941d95SEnrico Granata { eArgTypeAliasName, "alias-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of an abbreviation (alias) for a debugger command." }, 8417f941d95SEnrico Granata { eArgTypeAliasOptions, "options-for-aliased-command", CommandCompletions::eNoCompletion, { NULL, false }, "Command options to be used as part of an alias (abbreviation) definition. (See 'help commands alias' for more information.)" }, 8427f941d95SEnrico Granata { eArgTypeArchitecture, "arch", CommandCompletions::eArchitectureCompletion, { NULL, false }, "The architecture name, e.g. i386 or x86_64." }, 8437f941d95SEnrico Granata { eArgTypeBoolean, "boolean", CommandCompletions::eNoCompletion, { NULL, false }, "A Boolean value: 'true' or 'false'" }, 8447f941d95SEnrico Granata { eArgTypeBreakpointID, "breakpt-id", CommandCompletions::eNoCompletion, { BreakpointIDHelpTextCallback, false }, NULL }, 8457f941d95SEnrico Granata { eArgTypeBreakpointIDRange, "breakpt-id-list", CommandCompletions::eNoCompletion, { BreakpointIDRangeHelpTextCallback, false }, NULL }, 8467f941d95SEnrico Granata { eArgTypeByteSize, "byte-size", CommandCompletions::eNoCompletion, { NULL, false }, "Number of bytes to use." }, 8477f941d95SEnrico Granata { eArgTypeClassName, "class-name", CommandCompletions::eNoCompletion, { NULL, false }, "Then name of a class from the debug information in the program." }, 8487f941d95SEnrico Granata { eArgTypeCommandName, "cmd-name", CommandCompletions::eNoCompletion, { NULL, false }, "A debugger command (may be multiple words), without any options or arguments." }, 8497f941d95SEnrico Granata { eArgTypeCount, "count", CommandCompletions::eNoCompletion, { NULL, false }, "An unsigned integer." }, 8507f941d95SEnrico Granata { eArgTypeEndAddress, "end-address", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, 8517f941d95SEnrico Granata { eArgTypeExpression, "expr", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, 8529128ee2fSEnrico Granata { eArgTypeExpressionPath, "expr-path", CommandCompletions::eNoCompletion, { ExprPathHelpTextCallback, true }, NULL }, 8537f941d95SEnrico Granata { eArgTypeExprFormat, "expression-format", CommandCompletions::eNoCompletion, { NULL, false }, "[ [bool|b] | [bin] | [char|c] | [oct|o] | [dec|i|d|u] | [hex|x] | [float|f] | [cstr|s] ]" }, 8547f941d95SEnrico Granata { eArgTypeFilename, "filename", CommandCompletions::eDiskFileCompletion, { NULL, false }, "The name of a file (can include path)." }, 8557f941d95SEnrico Granata { eArgTypeFormat, "format", CommandCompletions::eNoCompletion, { FormatHelpTextCallback, true }, NULL }, 8567f941d95SEnrico Granata { eArgTypeFrameIndex, "frame-index", CommandCompletions::eNoCompletion, { NULL, false }, "Index into a thread's list of frames." }, 8577f941d95SEnrico Granata { eArgTypeFullName, "fullname", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, 8587f941d95SEnrico Granata { eArgTypeFunctionName, "function-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a function." }, 85986edbf41SGreg Clayton { eArgTypeGDBFormat, "gdb-format", CommandCompletions::eNoCompletion, { GDBFormatHelpTextCallback, true }, NULL }, 8607f941d95SEnrico Granata { eArgTypeIndex, "index", CommandCompletions::eNoCompletion, { NULL, false }, "An index into a list." }, 8617f941d95SEnrico Granata { eArgTypeLineNum, "linenum", CommandCompletions::eNoCompletion, { NULL, false }, "Line number in a source file." }, 8627f941d95SEnrico Granata { eArgTypeLogCategory, "log-category", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a category within a log channel, e.g. all (try \"log list\" to see a list of all channels and their categories." }, 8637f941d95SEnrico Granata { eArgTypeLogChannel, "log-channel", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a log channel, e.g. process.gdb-remote (try \"log list\" to see a list of all channels and their categories)." }, 8647f941d95SEnrico Granata { eArgTypeMethod, "method", CommandCompletions::eNoCompletion, { NULL, false }, "A C++ method name." }, 8657f941d95SEnrico Granata { eArgTypeName, "name", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, 8667f941d95SEnrico Granata { eArgTypeNewPathPrefix, "new-path-prefix", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, 8677f941d95SEnrico Granata { eArgTypeNumLines, "num-lines", CommandCompletions::eNoCompletion, { NULL, false }, "The number of lines to use." }, 8687f941d95SEnrico Granata { eArgTypeNumberPerLine, "number-per-line", CommandCompletions::eNoCompletion, { NULL, false }, "The number of items per line to display." }, 8697f941d95SEnrico Granata { eArgTypeOffset, "offset", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, 8707f941d95SEnrico Granata { eArgTypeOldPathPrefix, "old-path-prefix", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, 8717f941d95SEnrico Granata { eArgTypeOneLiner, "one-line-command", CommandCompletions::eNoCompletion, { NULL, false }, "A command that is entered as a single line of text." }, 8727f941d95SEnrico Granata { eArgTypePath, "path", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, 8737f941d95SEnrico Granata { eArgTypePid, "pid", CommandCompletions::eNoCompletion, { NULL, false }, "The process ID number." }, 8747f941d95SEnrico Granata { eArgTypePlugin, "plugin", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, 8757f941d95SEnrico Granata { eArgTypeProcessName, "process-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of the process." }, 8769128ee2fSEnrico Granata { eArgTypePythonClass, "python-class", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a Python class." }, 8779128ee2fSEnrico Granata { eArgTypePythonFunction, "python-function", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a Python function." }, 8789128ee2fSEnrico Granata { eArgTypePythonScript, "python-script", CommandCompletions::eNoCompletion, { NULL, false }, "Source code written in Python." }, 8797f941d95SEnrico Granata { eArgTypeQueueName, "queue-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of the thread queue." }, 8807f941d95SEnrico Granata { eArgTypeRegisterName, "register-name", CommandCompletions::eNoCompletion, { NULL, false }, "A register name." }, 8817f941d95SEnrico Granata { eArgTypeRegularExpression, "regular-expression", CommandCompletions::eNoCompletion, { NULL, false }, "A regular expression." }, 8827f941d95SEnrico Granata { eArgTypeRunArgs, "run-args", CommandCompletions::eNoCompletion, { NULL, false }, "Arguments to be passed to the target program when it starts executing." }, 8837f941d95SEnrico Granata { eArgTypeRunMode, "run-mode", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, 884*0a305db7SEnrico Granata { eArgTypeScriptedCommandSynchronicity, "script-cmd-synchronicity", CommandCompletions::eNoCompletion, { NULL, false }, "The synchronicity to use to run scripted commands with regard to LLDB event system." }, 8857f941d95SEnrico Granata { eArgTypeScriptLang, "script-language", CommandCompletions::eNoCompletion, { NULL, false }, "The scripting language to be used for script-based commands. Currently only Python is valid." }, 8867f941d95SEnrico Granata { eArgTypeSearchWord, "search-word", CommandCompletions::eNoCompletion, { NULL, false }, "The word for which you wish to search for information about." }, 8877f941d95SEnrico Granata { eArgTypeSelector, "selector", CommandCompletions::eNoCompletion, { NULL, false }, "An Objective-C selector name." }, 8887f941d95SEnrico Granata { eArgTypeSettingIndex, "setting-index", CommandCompletions::eNoCompletion, { NULL, false }, "An index into a settings variable that is an array (try 'settings list' to see all the possible settings variables and their types)." }, 8897f941d95SEnrico Granata { eArgTypeSettingKey, "setting-key", CommandCompletions::eNoCompletion, { NULL, false }, "A key into a settings variables that is a dictionary (try 'settings list' to see all the possible settings variables and their types)." }, 8907f941d95SEnrico Granata { eArgTypeSettingPrefix, "setting-prefix", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a settable internal debugger variable up to a dot ('.'), e.g. 'target.process.'" }, 8917f941d95SEnrico Granata { eArgTypeSettingVariableName, "setting-variable-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a settable internal debugger variable. Type 'settings list' to see a complete list of such variables." }, 8927f941d95SEnrico Granata { eArgTypeShlibName, "shlib-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a shared library." }, 8937f941d95SEnrico Granata { eArgTypeSourceFile, "source-file", CommandCompletions::eSourceFileCompletion, { NULL, false }, "The name of a source file.." }, 8947f941d95SEnrico Granata { eArgTypeSortOrder, "sort-order", CommandCompletions::eNoCompletion, { NULL, false }, "Specify a sort order when dumping lists." }, 8957f941d95SEnrico Granata { eArgTypeStartAddress, "start-address", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, 8967f941d95SEnrico Granata { eArgTypeSummaryString, "summary-string", CommandCompletions::eNoCompletion, { SummaryStringHelpTextCallback, true }, NULL }, 8977f941d95SEnrico Granata { eArgTypeSymbol, "symbol", CommandCompletions::eSymbolCompletion, { NULL, false }, "Any symbol name (function name, variable, argument, etc.)" }, 8987f941d95SEnrico Granata { eArgTypeThreadID, "thread-id", CommandCompletions::eNoCompletion, { NULL, false }, "Thread ID number." }, 8997f941d95SEnrico Granata { eArgTypeThreadIndex, "thread-index", CommandCompletions::eNoCompletion, { NULL, false }, "Index into the process' list of threads." }, 9007f941d95SEnrico Granata { eArgTypeThreadName, "thread-name", CommandCompletions::eNoCompletion, { NULL, false }, "The thread's name." }, 901331eff39SJohnny Chen { eArgTypeUnsignedInteger, "unsigned-integer", CommandCompletions::eNoCompletion, { NULL, false }, "An unsigned integer." }, 9027f941d95SEnrico Granata { eArgTypeUnixSignal, "unix-signal", CommandCompletions::eNoCompletion, { NULL, false }, "A valid Unix signal name or number (e.g. SIGKILL, KILL or 9)." }, 9037f941d95SEnrico Granata { eArgTypeVarName, "variable-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a variable in your program." }, 9047f941d95SEnrico Granata { eArgTypeValue, "value", CommandCompletions::eNoCompletion, { NULL, false }, "A value could be anything, depending on where and how it is used." }, 9057f941d95SEnrico Granata { eArgTypeWidth, "width", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, 9067f941d95SEnrico Granata { eArgTypeNone, "none", CommandCompletions::eNoCompletion, { NULL, false }, "No help available for this." }, 907b1d7529eSJohnny Chen { eArgTypePlatform, "platform-name", CommandCompletions::ePlatformPluginCompletion, { NULL, false }, "The name of an installed platform plug-in . Type 'platform list' to see a complete list of installed platforms." }, 908de753464SJohnny Chen { eArgTypeWatchpointID, "watchpt-id", CommandCompletions::eNoCompletion, { NULL, false }, "Watchpoint IDs are positive integers." }, 909de753464SJohnny Chen { eArgTypeWatchpointIDRange, "watchpt-id-list", CommandCompletions::eNoCompletion, { NULL, false }, "For example, '1-3' or '1 to 3'." }, 910887062aeSJohnny Chen { eArgTypeWatchType, "watch-type", CommandCompletions::eNoCompletion, { NULL, false }, "Specify the type for a watchpoint." } 911e139cf23SCaroline Tice }; 912e139cf23SCaroline Tice 913e139cf23SCaroline Tice const CommandObject::ArgumentTableEntry* 914e139cf23SCaroline Tice CommandObject::GetArgumentTable () 915e139cf23SCaroline Tice { 9169d0402b1SGreg Clayton // If this assertion fires, then the table above is out of date with the CommandArgumentType enumeration 9179d0402b1SGreg Clayton assert ((sizeof (CommandObject::g_arguments_data) / sizeof (CommandObject::ArgumentTableEntry)) == eArgTypeLastArg); 918e139cf23SCaroline Tice return CommandObject::g_arguments_data; 919e139cf23SCaroline Tice } 920e139cf23SCaroline Tice 921e139cf23SCaroline Tice 922