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), 56a9f7b79dSGreg Clayton m_arguments(), 57a9f7b79dSGreg Clayton m_command_override_callback (NULL), 58a9f7b79dSGreg Clayton m_command_override_baton (NULL) 5930fdc8d8SChris Lattner { 6030fdc8d8SChris Lattner if (help && help[0]) 6130fdc8d8SChris Lattner m_cmd_help_short = help; 6230fdc8d8SChris Lattner if (syntax && syntax[0]) 6330fdc8d8SChris Lattner m_cmd_syntax = syntax; 6430fdc8d8SChris Lattner } 6530fdc8d8SChris Lattner 6630fdc8d8SChris Lattner CommandObject::~CommandObject () 6730fdc8d8SChris Lattner { 6830fdc8d8SChris Lattner } 6930fdc8d8SChris Lattner 7030fdc8d8SChris Lattner const char * 7130fdc8d8SChris Lattner CommandObject::GetHelp () 7230fdc8d8SChris Lattner { 7330fdc8d8SChris Lattner return m_cmd_help_short.c_str(); 7430fdc8d8SChris Lattner } 7530fdc8d8SChris Lattner 7630fdc8d8SChris Lattner const char * 7730fdc8d8SChris Lattner CommandObject::GetHelpLong () 7830fdc8d8SChris Lattner { 7930fdc8d8SChris Lattner return m_cmd_help_long.c_str(); 8030fdc8d8SChris Lattner } 8130fdc8d8SChris Lattner 8230fdc8d8SChris Lattner const char * 8330fdc8d8SChris Lattner CommandObject::GetSyntax () 8430fdc8d8SChris Lattner { 85e139cf23SCaroline Tice if (m_cmd_syntax.length() == 0) 86e139cf23SCaroline Tice { 87e139cf23SCaroline Tice StreamString syntax_str; 88e139cf23SCaroline Tice syntax_str.Printf ("%s", GetCommandName()); 89e139cf23SCaroline Tice if (GetOptions() != NULL) 90e139cf23SCaroline Tice syntax_str.Printf (" <cmd-options>"); 91e139cf23SCaroline Tice if (m_arguments.size() > 0) 92e139cf23SCaroline Tice { 93e139cf23SCaroline Tice syntax_str.Printf (" "); 94a4c6ad19SSean Callanan if (WantsRawCommandString()) 95a4c6ad19SSean Callanan syntax_str.Printf("-- "); 96e139cf23SCaroline Tice GetFormattedCommandArguments (syntax_str); 97e139cf23SCaroline Tice } 98e139cf23SCaroline Tice m_cmd_syntax = syntax_str.GetData (); 99e139cf23SCaroline Tice } 100e139cf23SCaroline Tice 10130fdc8d8SChris Lattner return m_cmd_syntax.c_str(); 10230fdc8d8SChris Lattner } 10330fdc8d8SChris Lattner 10430fdc8d8SChris Lattner const char * 10530fdc8d8SChris Lattner CommandObject::Translate () 10630fdc8d8SChris Lattner { 10730fdc8d8SChris Lattner //return m_cmd_func_name.c_str(); 10830fdc8d8SChris Lattner return "This function is currently not implemented."; 10930fdc8d8SChris Lattner } 11030fdc8d8SChris Lattner 11130fdc8d8SChris Lattner const char * 11230fdc8d8SChris Lattner CommandObject::GetCommandName () 11330fdc8d8SChris Lattner { 11430fdc8d8SChris Lattner return m_cmd_name.c_str(); 11530fdc8d8SChris Lattner } 11630fdc8d8SChris Lattner 11730fdc8d8SChris Lattner void 11830fdc8d8SChris Lattner CommandObject::SetCommandName (const char *name) 11930fdc8d8SChris Lattner { 12030fdc8d8SChris Lattner m_cmd_name = name; 12130fdc8d8SChris Lattner } 12230fdc8d8SChris Lattner 12330fdc8d8SChris Lattner void 12430fdc8d8SChris Lattner CommandObject::SetHelp (const char *cstr) 12530fdc8d8SChris Lattner { 12630fdc8d8SChris Lattner m_cmd_help_short = cstr; 12730fdc8d8SChris Lattner } 12830fdc8d8SChris Lattner 12930fdc8d8SChris Lattner void 13030fdc8d8SChris Lattner CommandObject::SetHelpLong (const char *cstr) 13130fdc8d8SChris Lattner { 13230fdc8d8SChris Lattner m_cmd_help_long = cstr; 13330fdc8d8SChris Lattner } 13430fdc8d8SChris Lattner 13530fdc8d8SChris Lattner void 13699f0b8f9SEnrico Granata CommandObject::SetHelpLong (std::string str) 13799f0b8f9SEnrico Granata { 13899f0b8f9SEnrico Granata m_cmd_help_long = str; 13999f0b8f9SEnrico Granata } 14099f0b8f9SEnrico Granata 14199f0b8f9SEnrico Granata void 14230fdc8d8SChris Lattner CommandObject::SetSyntax (const char *cstr) 14330fdc8d8SChris Lattner { 14430fdc8d8SChris Lattner m_cmd_syntax = cstr; 14530fdc8d8SChris Lattner } 14630fdc8d8SChris Lattner 14730fdc8d8SChris Lattner Options * 14830fdc8d8SChris Lattner CommandObject::GetOptions () 14930fdc8d8SChris Lattner { 15030fdc8d8SChris Lattner // By default commands don't have options unless this virtual function 15130fdc8d8SChris Lattner // is overridden by base classes. 15230fdc8d8SChris Lattner return NULL; 15330fdc8d8SChris Lattner } 15430fdc8d8SChris Lattner 15530fdc8d8SChris Lattner Flags& 15630fdc8d8SChris Lattner CommandObject::GetFlags() 15730fdc8d8SChris Lattner { 15830fdc8d8SChris Lattner return m_flags; 15930fdc8d8SChris Lattner } 16030fdc8d8SChris Lattner 16130fdc8d8SChris Lattner const Flags& 16230fdc8d8SChris Lattner CommandObject::GetFlags() const 16330fdc8d8SChris Lattner { 16430fdc8d8SChris Lattner return m_flags; 16530fdc8d8SChris Lattner } 16630fdc8d8SChris Lattner 16730fdc8d8SChris Lattner bool 16830fdc8d8SChris Lattner CommandObject::ParseOptions 16930fdc8d8SChris Lattner ( 17030fdc8d8SChris Lattner Args& args, 17130fdc8d8SChris Lattner CommandReturnObject &result 17230fdc8d8SChris Lattner ) 17330fdc8d8SChris Lattner { 17430fdc8d8SChris Lattner // See if the subclass has options? 17530fdc8d8SChris Lattner Options *options = GetOptions(); 17630fdc8d8SChris Lattner if (options != NULL) 17730fdc8d8SChris Lattner { 17830fdc8d8SChris Lattner Error error; 179f6b8b581SGreg Clayton options->NotifyOptionParsingStarting(); 18030fdc8d8SChris Lattner 18130fdc8d8SChris Lattner // ParseOptions calls getopt_long, which always skips the zero'th item in the array and starts at position 1, 18230fdc8d8SChris Lattner // so we need to push a dummy value into position zero. 18330fdc8d8SChris Lattner args.Unshift("dummy_string"); 18430fdc8d8SChris Lattner error = args.ParseOptions (*options); 18530fdc8d8SChris Lattner 18630fdc8d8SChris Lattner // The "dummy_string" will have already been removed by ParseOptions, 18730fdc8d8SChris Lattner // so no need to remove it. 18830fdc8d8SChris Lattner 189f6b8b581SGreg Clayton if (error.Success()) 190f6b8b581SGreg Clayton error = options->NotifyOptionParsingFinished(); 191f6b8b581SGreg Clayton 192f6b8b581SGreg Clayton if (error.Success()) 193f6b8b581SGreg Clayton { 194f6b8b581SGreg Clayton if (options->VerifyOptions (result)) 195f6b8b581SGreg Clayton return true; 196f6b8b581SGreg Clayton } 197f6b8b581SGreg Clayton else 19830fdc8d8SChris Lattner { 19930fdc8d8SChris Lattner const char *error_cstr = error.AsCString(); 20030fdc8d8SChris Lattner if (error_cstr) 20130fdc8d8SChris Lattner { 20230fdc8d8SChris Lattner // We got an error string, lets use that 20386edbf41SGreg Clayton result.AppendError(error_cstr); 20430fdc8d8SChris Lattner } 20530fdc8d8SChris Lattner else 20630fdc8d8SChris Lattner { 20730fdc8d8SChris Lattner // No error string, output the usage information into result 208eb0103f2SGreg Clayton options->GenerateOptionUsage (result.GetErrorStream(), this); 20930fdc8d8SChris Lattner } 210f6b8b581SGreg Clayton } 21130fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 21230fdc8d8SChris Lattner return false; 21330fdc8d8SChris Lattner } 21430fdc8d8SChris Lattner return true; 21530fdc8d8SChris Lattner } 21630fdc8d8SChris Lattner bool 217a7015092SGreg Clayton CommandObject::ExecuteWithOptions (Args& args, CommandReturnObject &result) 21830fdc8d8SChris Lattner { 21930fdc8d8SChris Lattner for (size_t i = 0; i < args.GetArgumentCount(); ++i) 22030fdc8d8SChris Lattner { 22130fdc8d8SChris Lattner const char *tmp_str = args.GetArgumentAtIndex (i); 22230fdc8d8SChris Lattner if (tmp_str[0] == '`') // back-quote 223a7015092SGreg Clayton args.ReplaceArgumentAtIndex (i, m_interpreter.ProcessEmbeddedScriptCommands (tmp_str)); 22430fdc8d8SChris Lattner } 22530fdc8d8SChris Lattner 226b766a73dSGreg Clayton if (GetFlags().AnySet (CommandObject::eFlagProcessMustBeLaunched | CommandObject::eFlagProcessMustBePaused)) 227b766a73dSGreg Clayton { 228c14ee32dSGreg Clayton Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); 22930fdc8d8SChris Lattner if (process == NULL) 23030fdc8d8SChris Lattner { 231b8e8a5f3SJim Ingham // A process that is not running is considered paused. 232b8e8a5f3SJim Ingham if (GetFlags().Test(CommandObject::eFlagProcessMustBeLaunched)) 233b8e8a5f3SJim Ingham { 23430fdc8d8SChris Lattner result.AppendError ("Process must exist."); 23530fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 23630fdc8d8SChris Lattner return false; 23730fdc8d8SChris Lattner } 238b8e8a5f3SJim Ingham } 23930fdc8d8SChris Lattner else 24030fdc8d8SChris Lattner { 24130fdc8d8SChris Lattner StateType state = process->GetState(); 24230fdc8d8SChris Lattner 24330fdc8d8SChris Lattner switch (state) 24430fdc8d8SChris Lattner { 2457a5388bfSGreg Clayton case eStateInvalid: 24630fdc8d8SChris Lattner case eStateSuspended: 24730fdc8d8SChris Lattner case eStateCrashed: 24830fdc8d8SChris Lattner case eStateStopped: 24930fdc8d8SChris Lattner break; 25030fdc8d8SChris Lattner 251b766a73dSGreg Clayton case eStateConnected: 252b766a73dSGreg Clayton case eStateAttaching: 253b766a73dSGreg Clayton case eStateLaunching: 25430fdc8d8SChris Lattner case eStateDetached: 25530fdc8d8SChris Lattner case eStateExited: 25630fdc8d8SChris Lattner case eStateUnloaded: 25773b472d4SGreg Clayton if (GetFlags().Test(CommandObject::eFlagProcessMustBeLaunched)) 25830fdc8d8SChris Lattner { 25930fdc8d8SChris Lattner result.AppendError ("Process must be launched."); 26030fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 26130fdc8d8SChris Lattner return false; 26230fdc8d8SChris Lattner } 26330fdc8d8SChris Lattner break; 26430fdc8d8SChris Lattner 26530fdc8d8SChris Lattner case eStateRunning: 26630fdc8d8SChris Lattner case eStateStepping: 26773b472d4SGreg Clayton if (GetFlags().Test(CommandObject::eFlagProcessMustBePaused)) 26830fdc8d8SChris Lattner { 26930fdc8d8SChris Lattner result.AppendError ("Process is running. Use 'process interrupt' to pause execution."); 27030fdc8d8SChris Lattner result.SetStatus (eReturnStatusFailed); 27130fdc8d8SChris Lattner return false; 27230fdc8d8SChris Lattner } 27330fdc8d8SChris Lattner } 27430fdc8d8SChris Lattner } 275b766a73dSGreg Clayton } 27630fdc8d8SChris Lattner 277a7015092SGreg Clayton if (!ParseOptions (args, result)) 27830fdc8d8SChris Lattner return false; 27930fdc8d8SChris Lattner 28030fdc8d8SChris Lattner // Call the command-specific version of 'Execute', passing it the already processed arguments. 281a7015092SGreg Clayton return Execute (args, result); 28230fdc8d8SChris Lattner } 28330fdc8d8SChris Lattner 28430fdc8d8SChris Lattner class CommandDictCommandPartialMatch 28530fdc8d8SChris Lattner { 28630fdc8d8SChris Lattner public: 28730fdc8d8SChris Lattner CommandDictCommandPartialMatch (const char *match_str) 28830fdc8d8SChris Lattner { 28930fdc8d8SChris Lattner m_match_str = match_str; 29030fdc8d8SChris Lattner } 29130fdc8d8SChris Lattner bool operator() (const std::pair<std::string, lldb::CommandObjectSP> map_element) const 29230fdc8d8SChris Lattner { 29330fdc8d8SChris Lattner // A NULL or empty string matches everything. 29430fdc8d8SChris Lattner if (m_match_str == NULL || *m_match_str == '\0') 29530fdc8d8SChris Lattner return 1; 29630fdc8d8SChris Lattner 29730fdc8d8SChris Lattner size_t found = map_element.first.find (m_match_str, 0); 29830fdc8d8SChris Lattner if (found == std::string::npos) 29930fdc8d8SChris Lattner return 0; 30030fdc8d8SChris Lattner else 30130fdc8d8SChris Lattner return found == 0; 30230fdc8d8SChris Lattner } 30330fdc8d8SChris Lattner 30430fdc8d8SChris Lattner private: 30530fdc8d8SChris Lattner const char *m_match_str; 30630fdc8d8SChris Lattner }; 30730fdc8d8SChris Lattner 30830fdc8d8SChris Lattner int 30930fdc8d8SChris Lattner CommandObject::AddNamesMatchingPartialString (CommandObject::CommandMap &in_map, const char *cmd_str, 31030fdc8d8SChris Lattner StringList &matches) 31130fdc8d8SChris Lattner { 31230fdc8d8SChris Lattner int number_added = 0; 31330fdc8d8SChris Lattner CommandDictCommandPartialMatch matcher(cmd_str); 31430fdc8d8SChris Lattner 31530fdc8d8SChris Lattner CommandObject::CommandMap::iterator matching_cmds = std::find_if (in_map.begin(), in_map.end(), matcher); 31630fdc8d8SChris Lattner 31730fdc8d8SChris Lattner while (matching_cmds != in_map.end()) 31830fdc8d8SChris Lattner { 31930fdc8d8SChris Lattner ++number_added; 32030fdc8d8SChris Lattner matches.AppendString((*matching_cmds).first.c_str()); 32130fdc8d8SChris Lattner matching_cmds = std::find_if (++matching_cmds, in_map.end(), matcher);; 32230fdc8d8SChris Lattner } 32330fdc8d8SChris Lattner return number_added; 32430fdc8d8SChris Lattner } 32530fdc8d8SChris Lattner 32630fdc8d8SChris Lattner int 32730fdc8d8SChris Lattner CommandObject::HandleCompletion 32830fdc8d8SChris Lattner ( 32930fdc8d8SChris Lattner Args &input, 33030fdc8d8SChris Lattner int &cursor_index, 33130fdc8d8SChris Lattner int &cursor_char_position, 33230fdc8d8SChris Lattner int match_start_point, 33330fdc8d8SChris Lattner int max_return_elements, 334558ce124SJim Ingham bool &word_complete, 33530fdc8d8SChris Lattner StringList &matches 33630fdc8d8SChris Lattner ) 33730fdc8d8SChris Lattner { 3386561d15dSJohnny Chen // Default implmentation of WantsCompletion() is !WantsRawCommandString(). 3396561d15dSJohnny Chen // Subclasses who want raw command string but desire, for example, 3406561d15dSJohnny Chen // argument completion should override WantsCompletion() to return true, 3416561d15dSJohnny Chen // instead. 3426f99b637SJohnny Chen if (WantsRawCommandString() && !WantsCompletion()) 34330fdc8d8SChris Lattner { 34430fdc8d8SChris Lattner // FIXME: Abstract telling the completion to insert the completion character. 34530fdc8d8SChris Lattner matches.Clear(); 34630fdc8d8SChris Lattner return -1; 34730fdc8d8SChris Lattner } 34830fdc8d8SChris Lattner else 34930fdc8d8SChris Lattner { 35030fdc8d8SChris Lattner // Can we do anything generic with the options? 35130fdc8d8SChris Lattner Options *cur_options = GetOptions(); 35230fdc8d8SChris Lattner CommandReturnObject result; 35330fdc8d8SChris Lattner OptionElementVector opt_element_vector; 35430fdc8d8SChris Lattner 35530fdc8d8SChris Lattner if (cur_options != NULL) 35630fdc8d8SChris Lattner { 35730fdc8d8SChris Lattner // Re-insert the dummy command name string which will have been 35830fdc8d8SChris Lattner // stripped off: 35930fdc8d8SChris Lattner input.Unshift ("dummy-string"); 36030fdc8d8SChris Lattner cursor_index++; 36130fdc8d8SChris Lattner 36230fdc8d8SChris Lattner 36330fdc8d8SChris Lattner // I stick an element on the end of the input, because if the last element is 36430fdc8d8SChris Lattner // option that requires an argument, getopt_long will freak out. 36530fdc8d8SChris Lattner 36630fdc8d8SChris Lattner input.AppendArgument ("<FAKE-VALUE>"); 36730fdc8d8SChris Lattner 368d43e0094SJim Ingham input.ParseArgsForCompletion (*cur_options, opt_element_vector, cursor_index); 36930fdc8d8SChris Lattner 37030fdc8d8SChris Lattner input.DeleteArgumentAtIndex(input.GetArgumentCount() - 1); 37130fdc8d8SChris Lattner 37230fdc8d8SChris Lattner bool handled_by_options; 373eb0103f2SGreg Clayton handled_by_options = cur_options->HandleOptionCompletion (input, 37430fdc8d8SChris Lattner opt_element_vector, 37530fdc8d8SChris Lattner cursor_index, 37630fdc8d8SChris Lattner cursor_char_position, 37730fdc8d8SChris Lattner match_start_point, 37830fdc8d8SChris Lattner max_return_elements, 379558ce124SJim Ingham word_complete, 38030fdc8d8SChris Lattner matches); 38130fdc8d8SChris Lattner if (handled_by_options) 38230fdc8d8SChris Lattner return matches.GetSize(); 38330fdc8d8SChris Lattner } 38430fdc8d8SChris Lattner 38530fdc8d8SChris Lattner // If we got here, the last word is not an option or an option argument. 386a7015092SGreg Clayton return HandleArgumentCompletion (input, 38730fdc8d8SChris Lattner cursor_index, 38830fdc8d8SChris Lattner cursor_char_position, 38930fdc8d8SChris Lattner opt_element_vector, 39030fdc8d8SChris Lattner match_start_point, 39130fdc8d8SChris Lattner max_return_elements, 392558ce124SJim Ingham word_complete, 39330fdc8d8SChris Lattner matches); 39430fdc8d8SChris Lattner } 39530fdc8d8SChris Lattner } 39630fdc8d8SChris Lattner 39730fdc8d8SChris Lattner bool 398a7015092SGreg Clayton CommandObject::HelpTextContainsWord (const char *search_word) 39930fdc8d8SChris Lattner { 40030fdc8d8SChris Lattner const char *short_help; 40130fdc8d8SChris Lattner const char *long_help; 40230fdc8d8SChris Lattner const char *syntax_help; 40330fdc8d8SChris Lattner std::string options_usage_help; 40430fdc8d8SChris Lattner 40530fdc8d8SChris Lattner 40630fdc8d8SChris Lattner bool found_word = false; 40730fdc8d8SChris Lattner 40830fdc8d8SChris Lattner short_help = GetHelp(); 40930fdc8d8SChris Lattner long_help = GetHelpLong(); 41030fdc8d8SChris Lattner syntax_help = GetSyntax(); 41130fdc8d8SChris Lattner 4124b6fbf37SCaroline Tice if (strcasestr (short_help, search_word)) 41330fdc8d8SChris Lattner found_word = true; 4144b6fbf37SCaroline Tice else if (strcasestr (long_help, search_word)) 41530fdc8d8SChris Lattner found_word = true; 4164b6fbf37SCaroline Tice else if (strcasestr (syntax_help, search_word)) 41730fdc8d8SChris Lattner found_word = true; 41830fdc8d8SChris Lattner 41930fdc8d8SChris Lattner if (!found_word 42030fdc8d8SChris Lattner && GetOptions() != NULL) 42130fdc8d8SChris Lattner { 42230fdc8d8SChris Lattner StreamString usage_help; 423eb0103f2SGreg Clayton GetOptions()->GenerateOptionUsage (usage_help, this); 42430fdc8d8SChris Lattner if (usage_help.GetSize() > 0) 42530fdc8d8SChris Lattner { 42630fdc8d8SChris Lattner const char *usage_text = usage_help.GetData(); 4274b6fbf37SCaroline Tice if (strcasestr (usage_text, search_word)) 42830fdc8d8SChris Lattner found_word = true; 42930fdc8d8SChris Lattner } 43030fdc8d8SChris Lattner } 43130fdc8d8SChris Lattner 43230fdc8d8SChris Lattner return found_word; 43330fdc8d8SChris Lattner } 434e139cf23SCaroline Tice 435e139cf23SCaroline Tice int 436e139cf23SCaroline Tice CommandObject::GetNumArgumentEntries () 437e139cf23SCaroline Tice { 438e139cf23SCaroline Tice return m_arguments.size(); 439e139cf23SCaroline Tice } 440e139cf23SCaroline Tice 441e139cf23SCaroline Tice CommandObject::CommandArgumentEntry * 442e139cf23SCaroline Tice CommandObject::GetArgumentEntryAtIndex (int idx) 443e139cf23SCaroline Tice { 444e139cf23SCaroline Tice if (idx < m_arguments.size()) 445e139cf23SCaroline Tice return &(m_arguments[idx]); 446e139cf23SCaroline Tice 447e139cf23SCaroline Tice return NULL; 448e139cf23SCaroline Tice } 449e139cf23SCaroline Tice 450e139cf23SCaroline Tice CommandObject::ArgumentTableEntry * 451e139cf23SCaroline Tice CommandObject::FindArgumentDataByType (CommandArgumentType arg_type) 452e139cf23SCaroline Tice { 453e139cf23SCaroline Tice const ArgumentTableEntry *table = CommandObject::GetArgumentTable(); 454e139cf23SCaroline Tice 455e139cf23SCaroline Tice for (int i = 0; i < eArgTypeLastArg; ++i) 456e139cf23SCaroline Tice if (table[i].arg_type == arg_type) 457e139cf23SCaroline Tice return (ArgumentTableEntry *) &(table[i]); 458e139cf23SCaroline Tice 459e139cf23SCaroline Tice return NULL; 460e139cf23SCaroline Tice } 461e139cf23SCaroline Tice 462e139cf23SCaroline Tice void 463e139cf23SCaroline Tice CommandObject::GetArgumentHelp (Stream &str, CommandArgumentType arg_type, CommandInterpreter &interpreter) 464e139cf23SCaroline Tice { 465e139cf23SCaroline Tice const ArgumentTableEntry* table = CommandObject::GetArgumentTable(); 466e139cf23SCaroline Tice ArgumentTableEntry *entry = (ArgumentTableEntry *) &(table[arg_type]); 467e139cf23SCaroline Tice 468e139cf23SCaroline Tice // The table is *supposed* to be kept in arg_type order, but someone *could* have messed it up... 469e139cf23SCaroline Tice 470e139cf23SCaroline Tice if (entry->arg_type != arg_type) 471e139cf23SCaroline Tice entry = CommandObject::FindArgumentDataByType (arg_type); 472e139cf23SCaroline Tice 473e139cf23SCaroline Tice if (!entry) 474e139cf23SCaroline Tice return; 475e139cf23SCaroline Tice 476e139cf23SCaroline Tice StreamString name_str; 477e139cf23SCaroline Tice name_str.Printf ("<%s>", entry->arg_name); 478e139cf23SCaroline Tice 479fc7a7f3bSEnrico Granata if (entry->help_function) 48082a7d983SEnrico Granata { 481fc7a7f3bSEnrico Granata const char* help_text = entry->help_function(); 48282a7d983SEnrico Granata if (!entry->help_function.self_formatting) 48382a7d983SEnrico Granata { 48482a7d983SEnrico Granata interpreter.OutputFormattedHelpText (str, name_str.GetData(), "--", help_text, 485e139cf23SCaroline Tice name_str.GetSize()); 48682a7d983SEnrico Granata } 48782a7d983SEnrico Granata else 48882a7d983SEnrico Granata { 48982a7d983SEnrico Granata interpreter.OutputHelpText(str, name_str.GetData(), "--", help_text, 49082a7d983SEnrico Granata name_str.GetSize()); 49182a7d983SEnrico Granata } 49282a7d983SEnrico Granata } 493e139cf23SCaroline Tice else 494e139cf23SCaroline Tice interpreter.OutputFormattedHelpText (str, name_str.GetData(), "--", entry->help_text, name_str.GetSize()); 495e139cf23SCaroline Tice } 496e139cf23SCaroline Tice 497e139cf23SCaroline Tice const char * 498e139cf23SCaroline Tice CommandObject::GetArgumentName (CommandArgumentType arg_type) 499e139cf23SCaroline Tice { 500deaab222SCaroline Tice ArgumentTableEntry *entry = (ArgumentTableEntry *) &(CommandObject::GetArgumentTable()[arg_type]); 501deaab222SCaroline Tice 502deaab222SCaroline Tice // The table is *supposed* to be kept in arg_type order, but someone *could* have messed it up... 503deaab222SCaroline Tice 504deaab222SCaroline Tice if (entry->arg_type != arg_type) 505deaab222SCaroline Tice entry = CommandObject::FindArgumentDataByType (arg_type); 506deaab222SCaroline Tice 507e6acf355SJohnny Chen if (entry) 508deaab222SCaroline Tice return entry->arg_name; 509e6acf355SJohnny Chen 510e6acf355SJohnny Chen StreamString str; 511e6acf355SJohnny Chen str << "Arg name for type (" << arg_type << ") not in arg table!"; 512e6acf355SJohnny Chen return str.GetData(); 513e139cf23SCaroline Tice } 514e139cf23SCaroline Tice 515405fe67fSCaroline Tice bool 516e0d378b3SGreg Clayton CommandObject::IsPairType (ArgumentRepetitionType arg_repeat_type) 517405fe67fSCaroline Tice { 518405fe67fSCaroline Tice if ((arg_repeat_type == eArgRepeatPairPlain) 519405fe67fSCaroline Tice || (arg_repeat_type == eArgRepeatPairOptional) 520405fe67fSCaroline Tice || (arg_repeat_type == eArgRepeatPairPlus) 521405fe67fSCaroline Tice || (arg_repeat_type == eArgRepeatPairStar) 522405fe67fSCaroline Tice || (arg_repeat_type == eArgRepeatPairRange) 523405fe67fSCaroline Tice || (arg_repeat_type == eArgRepeatPairRangeOptional)) 524405fe67fSCaroline Tice return true; 525405fe67fSCaroline Tice 526405fe67fSCaroline Tice return false; 527405fe67fSCaroline Tice } 528405fe67fSCaroline Tice 52934ddc8dbSJohnny Chen static CommandObject::CommandArgumentEntry 53034ddc8dbSJohnny Chen OptSetFiltered(uint32_t opt_set_mask, CommandObject::CommandArgumentEntry &cmd_arg_entry) 53134ddc8dbSJohnny Chen { 53234ddc8dbSJohnny Chen CommandObject::CommandArgumentEntry ret_val; 53334ddc8dbSJohnny Chen for (unsigned i = 0; i < cmd_arg_entry.size(); ++i) 53434ddc8dbSJohnny Chen if (opt_set_mask & cmd_arg_entry[i].arg_opt_set_association) 53534ddc8dbSJohnny Chen ret_val.push_back(cmd_arg_entry[i]); 53634ddc8dbSJohnny Chen return ret_val; 53734ddc8dbSJohnny Chen } 53834ddc8dbSJohnny Chen 53934ddc8dbSJohnny Chen // Default parameter value of opt_set_mask is LLDB_OPT_SET_ALL, which means take 54034ddc8dbSJohnny Chen // all the argument data into account. On rare cases where some argument sticks 54134ddc8dbSJohnny Chen // with certain option sets, this function returns the option set filtered args. 542e139cf23SCaroline Tice void 54334ddc8dbSJohnny Chen CommandObject::GetFormattedCommandArguments (Stream &str, uint32_t opt_set_mask) 544e139cf23SCaroline Tice { 545e139cf23SCaroline Tice int num_args = m_arguments.size(); 546e139cf23SCaroline Tice for (int i = 0; i < num_args; ++i) 547e139cf23SCaroline Tice { 548e139cf23SCaroline Tice if (i > 0) 549e139cf23SCaroline Tice str.Printf (" "); 55034ddc8dbSJohnny Chen CommandArgumentEntry arg_entry = 55134ddc8dbSJohnny Chen opt_set_mask == LLDB_OPT_SET_ALL ? m_arguments[i] 55234ddc8dbSJohnny Chen : OptSetFiltered(opt_set_mask, m_arguments[i]); 553e139cf23SCaroline Tice int num_alternatives = arg_entry.size(); 554405fe67fSCaroline Tice 555405fe67fSCaroline Tice if ((num_alternatives == 2) 556405fe67fSCaroline Tice && IsPairType (arg_entry[0].arg_repetition)) 557405fe67fSCaroline Tice { 558405fe67fSCaroline Tice const char *first_name = GetArgumentName (arg_entry[0].arg_type); 559405fe67fSCaroline Tice const char *second_name = GetArgumentName (arg_entry[1].arg_type); 560405fe67fSCaroline Tice switch (arg_entry[0].arg_repetition) 561405fe67fSCaroline Tice { 562405fe67fSCaroline Tice case eArgRepeatPairPlain: 563405fe67fSCaroline Tice str.Printf ("<%s> <%s>", first_name, second_name); 564405fe67fSCaroline Tice break; 565405fe67fSCaroline Tice case eArgRepeatPairOptional: 566405fe67fSCaroline Tice str.Printf ("[<%s> <%s>]", first_name, second_name); 567405fe67fSCaroline Tice break; 568405fe67fSCaroline Tice case eArgRepeatPairPlus: 569405fe67fSCaroline Tice str.Printf ("<%s> <%s> [<%s> <%s> [...]]", first_name, second_name, first_name, second_name); 570405fe67fSCaroline Tice break; 571405fe67fSCaroline Tice case eArgRepeatPairStar: 572405fe67fSCaroline Tice str.Printf ("[<%s> <%s> [<%s> <%s> [...]]]", first_name, second_name, first_name, second_name); 573405fe67fSCaroline Tice break; 574405fe67fSCaroline Tice case eArgRepeatPairRange: 575405fe67fSCaroline Tice str.Printf ("<%s_1> <%s_1> ... <%s_n> <%s_n>", first_name, second_name, first_name, second_name); 576405fe67fSCaroline Tice break; 577405fe67fSCaroline Tice case eArgRepeatPairRangeOptional: 578405fe67fSCaroline Tice str.Printf ("[<%s_1> <%s_1> ... <%s_n> <%s_n>]", first_name, second_name, first_name, second_name); 579405fe67fSCaroline Tice break; 580ca1176aaSCaroline Tice // Explicitly test for all the rest of the cases, so if new types get added we will notice the 581ca1176aaSCaroline Tice // missing case statement(s). 582ca1176aaSCaroline Tice case eArgRepeatPlain: 583ca1176aaSCaroline Tice case eArgRepeatOptional: 584ca1176aaSCaroline Tice case eArgRepeatPlus: 585ca1176aaSCaroline Tice case eArgRepeatStar: 586ca1176aaSCaroline Tice case eArgRepeatRange: 587ca1176aaSCaroline Tice // These should not be reached, as they should fail the IsPairType test above. 588ca1176aaSCaroline Tice break; 589405fe67fSCaroline Tice } 590405fe67fSCaroline Tice } 591405fe67fSCaroline Tice else 592405fe67fSCaroline Tice { 593e139cf23SCaroline Tice StreamString names; 594e139cf23SCaroline Tice for (int j = 0; j < num_alternatives; ++j) 595e139cf23SCaroline Tice { 596e139cf23SCaroline Tice if (j > 0) 597e139cf23SCaroline Tice names.Printf (" | "); 598e139cf23SCaroline Tice names.Printf ("%s", GetArgumentName (arg_entry[j].arg_type)); 599e139cf23SCaroline Tice } 600e139cf23SCaroline Tice switch (arg_entry[0].arg_repetition) 601e139cf23SCaroline Tice { 602e139cf23SCaroline Tice case eArgRepeatPlain: 603e139cf23SCaroline Tice str.Printf ("<%s>", names.GetData()); 604e139cf23SCaroline Tice break; 605e139cf23SCaroline Tice case eArgRepeatPlus: 606e139cf23SCaroline Tice str.Printf ("<%s> [<%s> [...]]", names.GetData(), names.GetData()); 607e139cf23SCaroline Tice break; 608e139cf23SCaroline Tice case eArgRepeatStar: 609e139cf23SCaroline Tice str.Printf ("[<%s> [<%s> [...]]]", names.GetData(), names.GetData()); 610e139cf23SCaroline Tice break; 611e139cf23SCaroline Tice case eArgRepeatOptional: 612e139cf23SCaroline Tice str.Printf ("[<%s>]", names.GetData()); 613e139cf23SCaroline Tice break; 614405fe67fSCaroline Tice case eArgRepeatRange: 615fd54b368SJason Molenda str.Printf ("<%s_1> .. <%s_n>", names.GetData(), names.GetData()); 616ca1176aaSCaroline Tice break; 617ca1176aaSCaroline Tice // Explicitly test for all the rest of the cases, so if new types get added we will notice the 618ca1176aaSCaroline Tice // missing case statement(s). 619ca1176aaSCaroline Tice case eArgRepeatPairPlain: 620ca1176aaSCaroline Tice case eArgRepeatPairOptional: 621ca1176aaSCaroline Tice case eArgRepeatPairPlus: 622ca1176aaSCaroline Tice case eArgRepeatPairStar: 623ca1176aaSCaroline Tice case eArgRepeatPairRange: 624ca1176aaSCaroline Tice case eArgRepeatPairRangeOptional: 625ca1176aaSCaroline Tice // These should not be hit, as they should pass the IsPairType test above, and control should 626ca1176aaSCaroline Tice // have gone into the other branch of the if statement. 627ca1176aaSCaroline Tice break; 628405fe67fSCaroline Tice } 629e139cf23SCaroline Tice } 630e139cf23SCaroline Tice } 631e139cf23SCaroline Tice } 632e139cf23SCaroline Tice 6330c16aa6dSStephen Wilson CommandArgumentType 634e139cf23SCaroline Tice CommandObject::LookupArgumentName (const char *arg_name) 635e139cf23SCaroline Tice { 636e139cf23SCaroline Tice CommandArgumentType return_type = eArgTypeLastArg; 637e139cf23SCaroline Tice 638e139cf23SCaroline Tice std::string arg_name_str (arg_name); 639e139cf23SCaroline Tice size_t len = arg_name_str.length(); 640e139cf23SCaroline Tice if (arg_name[0] == '<' 641e139cf23SCaroline Tice && arg_name[len-1] == '>') 642e139cf23SCaroline Tice arg_name_str = arg_name_str.substr (1, len-2); 643e139cf23SCaroline Tice 644331eff39SJohnny Chen const ArgumentTableEntry *table = GetArgumentTable(); 645e139cf23SCaroline Tice for (int i = 0; i < eArgTypeLastArg; ++i) 646331eff39SJohnny Chen if (arg_name_str.compare (table[i].arg_name) == 0) 647e139cf23SCaroline Tice return_type = g_arguments_data[i].arg_type; 648e139cf23SCaroline Tice 649e139cf23SCaroline Tice return return_type; 650e139cf23SCaroline Tice } 651e139cf23SCaroline Tice 652e139cf23SCaroline Tice static const char * 653e139cf23SCaroline Tice BreakpointIDHelpTextCallback () 654e139cf23SCaroline Tice { 65586edbf41SGreg Clayton return "Breakpoint ID's consist major and minor numbers; the major number " 65686edbf41SGreg Clayton "corresponds to the single entity that was created with a 'breakpoint set' " 65786edbf41SGreg Clayton "command; the minor numbers correspond to all the locations that were actually " 65886edbf41SGreg Clayton "found/set based on the major breakpoint. A full breakpoint ID might look like " 65986edbf41SGreg Clayton "3.14, meaning the 14th location set for the 3rd breakpoint. You can specify " 66086edbf41SGreg Clayton "all the locations of a breakpoint by just indicating the major breakpoint " 66186edbf41SGreg Clayton "number. A valid breakpoint id consists either of just the major id number, " 66286edbf41SGreg Clayton "or the major number, a dot, and the location number (e.g. 3 or 3.2 could " 66386edbf41SGreg Clayton "both be valid breakpoint ids)."; 664e139cf23SCaroline Tice } 665e139cf23SCaroline Tice 666e139cf23SCaroline Tice static const char * 667e139cf23SCaroline Tice BreakpointIDRangeHelpTextCallback () 668e139cf23SCaroline Tice { 66986edbf41SGreg Clayton return "A 'breakpoint id list' is a manner of specifying multiple breakpoints. " 67086edbf41SGreg Clayton "This can be done through several mechanisms. The easiest way is to just " 67186edbf41SGreg Clayton "enter a space-separated list of breakpoint ids. To specify all the " 67286edbf41SGreg Clayton "breakpoint locations under a major breakpoint, you can use the major " 67386edbf41SGreg Clayton "breakpoint number followed by '.*', eg. '5.*' means all the locations under " 67486edbf41SGreg Clayton "breakpoint 5. You can also indicate a range of breakpoints by using " 67586edbf41SGreg Clayton "<start-bp-id> - <end-bp-id>. The start-bp-id and end-bp-id for a range can " 67686edbf41SGreg Clayton "be any valid breakpoint ids. It is not legal, however, to specify a range " 67786edbf41SGreg Clayton "using specific locations that cross major breakpoint numbers. I.e. 3.2 - 3.7" 67886edbf41SGreg Clayton " is legal; 2 - 5 is legal; but 3.2 - 4.4 is not legal."; 67986edbf41SGreg Clayton } 68086edbf41SGreg Clayton 68186edbf41SGreg Clayton static const char * 68286edbf41SGreg Clayton GDBFormatHelpTextCallback () 68386edbf41SGreg Clayton { 684f91381e8SGreg Clayton return "A GDB format consists of a repeat count, a format letter and a size letter. " 685f91381e8SGreg Clayton "The repeat count is optional and defaults to 1. The format letter is optional " 686f91381e8SGreg Clayton "and defaults to the previous format that was used. The size letter is optional " 687f91381e8SGreg Clayton "and defaults to the previous size that was used.\n" 688f91381e8SGreg Clayton "\n" 689f91381e8SGreg Clayton "Format letters include:\n" 690f91381e8SGreg Clayton "o - octal\n" 691f91381e8SGreg Clayton "x - hexadecimal\n" 692f91381e8SGreg Clayton "d - decimal\n" 693f91381e8SGreg Clayton "u - unsigned decimal\n" 694f91381e8SGreg Clayton "t - binary\n" 695f91381e8SGreg Clayton "f - float\n" 696f91381e8SGreg Clayton "a - address\n" 697f91381e8SGreg Clayton "i - instruction\n" 698f91381e8SGreg Clayton "c - char\n" 699f91381e8SGreg Clayton "s - string\n" 700f91381e8SGreg Clayton "T - OSType\n" 701f91381e8SGreg Clayton "A - float as hex\n" 702f91381e8SGreg Clayton "\n" 703f91381e8SGreg Clayton "Size letters include:\n" 704f91381e8SGreg Clayton "b - 1 byte (byte)\n" 705f91381e8SGreg Clayton "h - 2 bytes (halfword)\n" 706f91381e8SGreg Clayton "w - 4 bytes (word)\n" 707f91381e8SGreg Clayton "g - 8 bytes (giant)\n" 708f91381e8SGreg Clayton "\n" 709f91381e8SGreg Clayton "Example formats:\n" 710f91381e8SGreg Clayton "32xb - show 32 1 byte hexadecimal integer values\n" 711f91381e8SGreg Clayton "16xh - show 16 2 byte hexadecimal integer values\n" 712f91381e8SGreg Clayton "64 - show 64 2 byte hexadecimal integer values (format and size from the last format)\n" 713f91381e8SGreg Clayton "dw - show 1 4 byte decimal integer value\n" 714f91381e8SGreg Clayton ; 715e139cf23SCaroline Tice } 716e139cf23SCaroline Tice 7170a3958e0SEnrico Granata static const char * 7180a3958e0SEnrico Granata FormatHelpTextCallback () 7190a3958e0SEnrico Granata { 72082a7d983SEnrico Granata 72182a7d983SEnrico Granata static char* help_text_ptr = NULL; 72282a7d983SEnrico Granata 72382a7d983SEnrico Granata if (help_text_ptr) 72482a7d983SEnrico Granata return help_text_ptr; 72582a7d983SEnrico Granata 7260a3958e0SEnrico Granata StreamString sstr; 7270a3958e0SEnrico Granata sstr << "One of the format names (or one-character names) that can be used to show a variable's value:\n"; 7280a3958e0SEnrico Granata for (Format f = eFormatDefault; f < kNumFormats; f = Format(f+1)) 7290a3958e0SEnrico Granata { 73082a7d983SEnrico Granata if (f != eFormatDefault) 73182a7d983SEnrico Granata sstr.PutChar('\n'); 73282a7d983SEnrico Granata 7330a3958e0SEnrico Granata char format_char = FormatManager::GetFormatAsFormatChar(f); 7340a3958e0SEnrico Granata if (format_char) 7350a3958e0SEnrico Granata sstr.Printf("'%c' or ", format_char); 7360a3958e0SEnrico Granata 73782a7d983SEnrico Granata sstr.Printf ("\"%s\"", FormatManager::GetFormatAsCString(f)); 7380a3958e0SEnrico Granata } 7390a3958e0SEnrico Granata 7400a3958e0SEnrico Granata sstr.Flush(); 7410a3958e0SEnrico Granata 7420a3958e0SEnrico Granata std::string data = sstr.GetString(); 7430a3958e0SEnrico Granata 74482a7d983SEnrico Granata help_text_ptr = new char[data.length()+1]; 7450a3958e0SEnrico Granata 74682a7d983SEnrico Granata data.copy(help_text_ptr, data.length()); 7470a3958e0SEnrico Granata 74882a7d983SEnrico Granata return help_text_ptr; 7490a3958e0SEnrico Granata } 7500a3958e0SEnrico Granata 7510a3958e0SEnrico Granata static const char * 75282a7d983SEnrico Granata SummaryStringHelpTextCallback() 7530a3958e0SEnrico Granata { 75482a7d983SEnrico Granata return 75582a7d983SEnrico Granata "A summary string is a way to extract information from variables in order to present them using a summary.\n" 75682a7d983SEnrico Granata "Summary strings contain static text, variables, scopes and control sequences:\n" 75782a7d983SEnrico Granata " - Static text can be any sequence of non-special characters, i.e. anything but '{', '}', '$', or '\\'.\n" 75882a7d983SEnrico Granata " - Variables are sequences of characters beginning with ${, ending with } and that contain symbols in the format described below.\n" 75982a7d983SEnrico 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" 76082a7d983SEnrico Granata " - Control sequences are the usual C/C++ '\\a', '\\n', ..., plus '\\$', '\\{' and '\\}'.\n" 76182a7d983SEnrico 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" 76282a7d983SEnrico 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" 76382a7d983SEnrico 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" 76482a7d983SEnrico 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" 7659128ee2fSEnrico 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." 7669128ee2fSEnrico 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" 76782a7d983SEnrico 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." 76882a7d983SEnrico 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" 76982a7d983SEnrico Granata " path refers to:\n" 77082a7d983SEnrico 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" 77182a7d983SEnrico Granata " and displayed as an individual variable\n" 77282a7d983SEnrico 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" 77382a7d983SEnrico 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" 7749128ee2fSEnrico 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" 7759128ee2fSEnrico 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" 7769128ee2fSEnrico Granata " special symbols only allowed as part of a variable:\n" 7779128ee2fSEnrico Granata " %V: show the value of the object by default\n" 7789128ee2fSEnrico Granata " %S: show the summary of the object by default\n" 7799128ee2fSEnrico Granata " %@: show the runtime-provided object description (for Objective-C, it calls NSPrintForDebugger; for C/C++ it does nothing)\n" 7809128ee2fSEnrico Granata " %L: show the location of the object (memory address or a register name)\n" 7819128ee2fSEnrico Granata " %#: show the number of children of the object\n" 7829128ee2fSEnrico Granata " %T: show the type of the object\n" 7839128ee2fSEnrico 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" 7849128ee2fSEnrico 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" 7859128ee2fSEnrico Granata " count the number of actual elements stored in an std::list:\n" 7869128ee2fSEnrico Granata "type summary add -s \"${svar%#}\" -x \"std::list<\""; 7879128ee2fSEnrico Granata } 7889128ee2fSEnrico Granata 7899128ee2fSEnrico Granata static const char * 7909128ee2fSEnrico Granata ExprPathHelpTextCallback() 7919128ee2fSEnrico Granata { 7929128ee2fSEnrico Granata return 7939128ee2fSEnrico 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" 7949128ee2fSEnrico Granata "For instance, given a class:\n" 7959128ee2fSEnrico Granata " class foo {\n" 7969128ee2fSEnrico Granata " int a;\n" 7979128ee2fSEnrico Granata " int b; .\n" 7989128ee2fSEnrico Granata " foo* next;\n" 7999128ee2fSEnrico Granata " };\n" 8009128ee2fSEnrico Granata "the expression to read item b in the item pointed to by next for foo aFoo would be aFoo.next->b.\n" 8019128ee2fSEnrico 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" 8029128ee2fSEnrico 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" 8039128ee2fSEnrico Granata "The meaning of these operators is the same as the usual one given to them by the C/C++ standards.\n" 8049128ee2fSEnrico 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" 8059128ee2fSEnrico 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" 8069128ee2fSEnrico 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" 8079128ee2fSEnrico 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" 8089128ee2fSEnrico Granata " meaning of array slicing (taking elements n thru m inside the array or pointed-to memory)."; 8090a3958e0SEnrico Granata } 8100a3958e0SEnrico Granata 811184d7a72SJohnny Chen void 812de753464SJohnny Chen CommandObject::AddIDsArgumentData(CommandArgumentEntry &arg, CommandArgumentType ID, CommandArgumentType IDRange) 813184d7a72SJohnny Chen { 814184d7a72SJohnny Chen CommandArgumentData id_arg; 815184d7a72SJohnny Chen CommandArgumentData id_range_arg; 816184d7a72SJohnny Chen 817184d7a72SJohnny Chen // Create the first variant for the first (and only) argument for this command. 818de753464SJohnny Chen id_arg.arg_type = ID; 819184d7a72SJohnny Chen id_arg.arg_repetition = eArgRepeatOptional; 820184d7a72SJohnny Chen 821184d7a72SJohnny Chen // Create the second variant for the first (and only) argument for this command. 822de753464SJohnny Chen id_range_arg.arg_type = IDRange; 823184d7a72SJohnny Chen id_range_arg.arg_repetition = eArgRepeatOptional; 824184d7a72SJohnny Chen 825a3234732SJohnny Chen // The first (and only) argument for this command could be either an id or an id_range. 826184d7a72SJohnny Chen // Push both variants into the entry for the first argument for this command. 827184d7a72SJohnny Chen arg.push_back(id_arg); 828184d7a72SJohnny Chen arg.push_back(id_range_arg); 829184d7a72SJohnny Chen } 830184d7a72SJohnny Chen 8319d0402b1SGreg Clayton const char * 8329d0402b1SGreg Clayton CommandObject::GetArgumentTypeAsCString (const lldb::CommandArgumentType arg_type) 8339d0402b1SGreg Clayton { 8349d0402b1SGreg Clayton if (arg_type >=0 && arg_type < eArgTypeLastArg) 8359d0402b1SGreg Clayton return g_arguments_data[arg_type].arg_name; 8369d0402b1SGreg Clayton return NULL; 8379d0402b1SGreg Clayton 8389d0402b1SGreg Clayton } 8399d0402b1SGreg Clayton 8409d0402b1SGreg Clayton const char * 8419d0402b1SGreg Clayton CommandObject::GetArgumentDescriptionAsCString (const lldb::CommandArgumentType arg_type) 8429d0402b1SGreg Clayton { 8439d0402b1SGreg Clayton if (arg_type >=0 && arg_type < eArgTypeLastArg) 8449d0402b1SGreg Clayton return g_arguments_data[arg_type].help_text; 8459d0402b1SGreg Clayton return NULL; 8469d0402b1SGreg Clayton } 8479d0402b1SGreg Clayton 848e139cf23SCaroline Tice CommandObject::ArgumentTableEntry 849e139cf23SCaroline Tice CommandObject::g_arguments_data[] = 850e139cf23SCaroline Tice { 8517f941d95SEnrico Granata { eArgTypeAddress, "address", CommandCompletions::eNoCompletion, { NULL, false }, "A valid address in the target program's execution space." }, 8527f941d95SEnrico Granata { eArgTypeAliasName, "alias-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of an abbreviation (alias) for a debugger command." }, 8537f941d95SEnrico 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.)" }, 8547f941d95SEnrico Granata { eArgTypeArchitecture, "arch", CommandCompletions::eArchitectureCompletion, { NULL, false }, "The architecture name, e.g. i386 or x86_64." }, 8557f941d95SEnrico Granata { eArgTypeBoolean, "boolean", CommandCompletions::eNoCompletion, { NULL, false }, "A Boolean value: 'true' or 'false'" }, 8567f941d95SEnrico Granata { eArgTypeBreakpointID, "breakpt-id", CommandCompletions::eNoCompletion, { BreakpointIDHelpTextCallback, false }, NULL }, 8577f941d95SEnrico Granata { eArgTypeBreakpointIDRange, "breakpt-id-list", CommandCompletions::eNoCompletion, { BreakpointIDRangeHelpTextCallback, false }, NULL }, 8587f941d95SEnrico Granata { eArgTypeByteSize, "byte-size", CommandCompletions::eNoCompletion, { NULL, false }, "Number of bytes to use." }, 8597f941d95SEnrico Granata { eArgTypeClassName, "class-name", CommandCompletions::eNoCompletion, { NULL, false }, "Then name of a class from the debug information in the program." }, 8607f941d95SEnrico Granata { eArgTypeCommandName, "cmd-name", CommandCompletions::eNoCompletion, { NULL, false }, "A debugger command (may be multiple words), without any options or arguments." }, 8617f941d95SEnrico Granata { eArgTypeCount, "count", CommandCompletions::eNoCompletion, { NULL, false }, "An unsigned integer." }, 8627f941d95SEnrico Granata { eArgTypeEndAddress, "end-address", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, 8637f941d95SEnrico Granata { eArgTypeExpression, "expr", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, 8649128ee2fSEnrico Granata { eArgTypeExpressionPath, "expr-path", CommandCompletions::eNoCompletion, { ExprPathHelpTextCallback, true }, NULL }, 8657f941d95SEnrico 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] ]" }, 8667f941d95SEnrico Granata { eArgTypeFilename, "filename", CommandCompletions::eDiskFileCompletion, { NULL, false }, "The name of a file (can include path)." }, 8677f941d95SEnrico Granata { eArgTypeFormat, "format", CommandCompletions::eNoCompletion, { FormatHelpTextCallback, true }, NULL }, 8687f941d95SEnrico Granata { eArgTypeFrameIndex, "frame-index", CommandCompletions::eNoCompletion, { NULL, false }, "Index into a thread's list of frames." }, 8697f941d95SEnrico Granata { eArgTypeFullName, "fullname", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, 8707f941d95SEnrico Granata { eArgTypeFunctionName, "function-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a function." }, 87186edbf41SGreg Clayton { eArgTypeGDBFormat, "gdb-format", CommandCompletions::eNoCompletion, { GDBFormatHelpTextCallback, true }, NULL }, 8727f941d95SEnrico Granata { eArgTypeIndex, "index", CommandCompletions::eNoCompletion, { NULL, false }, "An index into a list." }, 873*fab10e89SJim Ingham { eArgTypeLanguage, "language", CommandCompletions::eNoCompletion, { NULL, false }, "A source language name." }, 8747f941d95SEnrico Granata { eArgTypeLineNum, "linenum", CommandCompletions::eNoCompletion, { NULL, false }, "Line number in a source file." }, 8757f941d95SEnrico 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." }, 8767f941d95SEnrico 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)." }, 8777f941d95SEnrico Granata { eArgTypeMethod, "method", CommandCompletions::eNoCompletion, { NULL, false }, "A C++ method name." }, 8787f941d95SEnrico Granata { eArgTypeName, "name", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, 8797f941d95SEnrico Granata { eArgTypeNewPathPrefix, "new-path-prefix", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, 8807f941d95SEnrico Granata { eArgTypeNumLines, "num-lines", CommandCompletions::eNoCompletion, { NULL, false }, "The number of lines to use." }, 8817f941d95SEnrico Granata { eArgTypeNumberPerLine, "number-per-line", CommandCompletions::eNoCompletion, { NULL, false }, "The number of items per line to display." }, 8827f941d95SEnrico Granata { eArgTypeOffset, "offset", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, 8837f941d95SEnrico Granata { eArgTypeOldPathPrefix, "old-path-prefix", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, 8847f941d95SEnrico Granata { eArgTypeOneLiner, "one-line-command", CommandCompletions::eNoCompletion, { NULL, false }, "A command that is entered as a single line of text." }, 8857f941d95SEnrico Granata { eArgTypePath, "path", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, 8867f941d95SEnrico Granata { eArgTypePid, "pid", CommandCompletions::eNoCompletion, { NULL, false }, "The process ID number." }, 8877f941d95SEnrico Granata { eArgTypePlugin, "plugin", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, 8887f941d95SEnrico Granata { eArgTypeProcessName, "process-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of the process." }, 8899128ee2fSEnrico Granata { eArgTypePythonClass, "python-class", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a Python class." }, 8909128ee2fSEnrico Granata { eArgTypePythonFunction, "python-function", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a Python function." }, 8919128ee2fSEnrico Granata { eArgTypePythonScript, "python-script", CommandCompletions::eNoCompletion, { NULL, false }, "Source code written in Python." }, 8927f941d95SEnrico Granata { eArgTypeQueueName, "queue-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of the thread queue." }, 8937f941d95SEnrico Granata { eArgTypeRegisterName, "register-name", CommandCompletions::eNoCompletion, { NULL, false }, "A register name." }, 8947f941d95SEnrico Granata { eArgTypeRegularExpression, "regular-expression", CommandCompletions::eNoCompletion, { NULL, false }, "A regular expression." }, 8957f941d95SEnrico Granata { eArgTypeRunArgs, "run-args", CommandCompletions::eNoCompletion, { NULL, false }, "Arguments to be passed to the target program when it starts executing." }, 8967f941d95SEnrico Granata { eArgTypeRunMode, "run-mode", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, 8970a305db7SEnrico Granata { eArgTypeScriptedCommandSynchronicity, "script-cmd-synchronicity", CommandCompletions::eNoCompletion, { NULL, false }, "The synchronicity to use to run scripted commands with regard to LLDB event system." }, 8987f941d95SEnrico Granata { eArgTypeScriptLang, "script-language", CommandCompletions::eNoCompletion, { NULL, false }, "The scripting language to be used for script-based commands. Currently only Python is valid." }, 8997f941d95SEnrico Granata { eArgTypeSearchWord, "search-word", CommandCompletions::eNoCompletion, { NULL, false }, "The word for which you wish to search for information about." }, 9007f941d95SEnrico Granata { eArgTypeSelector, "selector", CommandCompletions::eNoCompletion, { NULL, false }, "An Objective-C selector name." }, 9017f941d95SEnrico 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)." }, 9027f941d95SEnrico 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)." }, 9037f941d95SEnrico Granata { eArgTypeSettingPrefix, "setting-prefix", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a settable internal debugger variable up to a dot ('.'), e.g. 'target.process.'" }, 9047f941d95SEnrico 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." }, 9057f941d95SEnrico Granata { eArgTypeShlibName, "shlib-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a shared library." }, 9067f941d95SEnrico Granata { eArgTypeSourceFile, "source-file", CommandCompletions::eSourceFileCompletion, { NULL, false }, "The name of a source file.." }, 9077f941d95SEnrico Granata { eArgTypeSortOrder, "sort-order", CommandCompletions::eNoCompletion, { NULL, false }, "Specify a sort order when dumping lists." }, 9087f941d95SEnrico Granata { eArgTypeStartAddress, "start-address", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, 9097f941d95SEnrico Granata { eArgTypeSummaryString, "summary-string", CommandCompletions::eNoCompletion, { SummaryStringHelpTextCallback, true }, NULL }, 9107f941d95SEnrico Granata { eArgTypeSymbol, "symbol", CommandCompletions::eSymbolCompletion, { NULL, false }, "Any symbol name (function name, variable, argument, etc.)" }, 9117f941d95SEnrico Granata { eArgTypeThreadID, "thread-id", CommandCompletions::eNoCompletion, { NULL, false }, "Thread ID number." }, 9127f941d95SEnrico Granata { eArgTypeThreadIndex, "thread-index", CommandCompletions::eNoCompletion, { NULL, false }, "Index into the process' list of threads." }, 9137f941d95SEnrico Granata { eArgTypeThreadName, "thread-name", CommandCompletions::eNoCompletion, { NULL, false }, "The thread's name." }, 914331eff39SJohnny Chen { eArgTypeUnsignedInteger, "unsigned-integer", CommandCompletions::eNoCompletion, { NULL, false }, "An unsigned integer." }, 9157f941d95SEnrico Granata { eArgTypeUnixSignal, "unix-signal", CommandCompletions::eNoCompletion, { NULL, false }, "A valid Unix signal name or number (e.g. SIGKILL, KILL or 9)." }, 9167f941d95SEnrico Granata { eArgTypeVarName, "variable-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a variable in your program." }, 9177f941d95SEnrico Granata { eArgTypeValue, "value", CommandCompletions::eNoCompletion, { NULL, false }, "A value could be anything, depending on where and how it is used." }, 9187f941d95SEnrico Granata { eArgTypeWidth, "width", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." }, 9197f941d95SEnrico Granata { eArgTypeNone, "none", CommandCompletions::eNoCompletion, { NULL, false }, "No help available for this." }, 920b1d7529eSJohnny 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." }, 921de753464SJohnny Chen { eArgTypeWatchpointID, "watchpt-id", CommandCompletions::eNoCompletion, { NULL, false }, "Watchpoint IDs are positive integers." }, 922de753464SJohnny Chen { eArgTypeWatchpointIDRange, "watchpt-id-list", CommandCompletions::eNoCompletion, { NULL, false }, "For example, '1-3' or '1 to 3'." }, 923887062aeSJohnny Chen { eArgTypeWatchType, "watch-type", CommandCompletions::eNoCompletion, { NULL, false }, "Specify the type for a watchpoint." } 924e139cf23SCaroline Tice }; 925e139cf23SCaroline Tice 926e139cf23SCaroline Tice const CommandObject::ArgumentTableEntry* 927e139cf23SCaroline Tice CommandObject::GetArgumentTable () 928e139cf23SCaroline Tice { 9299d0402b1SGreg Clayton // If this assertion fires, then the table above is out of date with the CommandArgumentType enumeration 9309d0402b1SGreg Clayton assert ((sizeof (CommandObject::g_arguments_data) / sizeof (CommandObject::ArgumentTableEntry)) == eArgTypeLastArg); 931e139cf23SCaroline Tice return CommandObject::g_arguments_data; 932e139cf23SCaroline Tice } 933e139cf23SCaroline Tice 934e139cf23SCaroline Tice 935