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 <map> 13b9c1b51eSKate Stone #include <sstream> 14b9c1b51eSKate Stone #include <string> 1530fdc8d8SChris Lattner 1630fdc8d8SChris Lattner #include <ctype.h> 17b9c1b51eSKate Stone #include <stdlib.h> 1830fdc8d8SChris Lattner 1930fdc8d8SChris Lattner #include "lldb/Core/Address.h" 20ca7835c6SJohnny Chen #include "lldb/Core/ArchSpec.h" 2140af72e1SJim Ingham #include "lldb/Interpreter/Options.h" 2230fdc8d8SChris Lattner 2330fdc8d8SChris Lattner // These are for the Sourcename completers. 2430fdc8d8SChris Lattner // FIXME: Make a separate file for the completers. 2530fdc8d8SChris Lattner #include "lldb/Core/FileSpecList.h" 26a78bd7ffSZachary Turner #include "lldb/DataFormatters/FormatManager.h" 27b9c1b51eSKate Stone #include "lldb/Host/FileSpec.h" 2830fdc8d8SChris Lattner #include "lldb/Target/Process.h" 2930fdc8d8SChris Lattner #include "lldb/Target/Target.h" 3030fdc8d8SChris Lattner 310e0984eeSJim Ingham #include "lldb/Target/Language.h" 320e0984eeSJim Ingham 3330fdc8d8SChris Lattner #include "lldb/Interpreter/CommandInterpreter.h" 3430fdc8d8SChris Lattner #include "lldb/Interpreter/CommandReturnObject.h" 3530fdc8d8SChris Lattner 3630fdc8d8SChris Lattner using namespace lldb; 3730fdc8d8SChris Lattner using namespace lldb_private; 3830fdc8d8SChris Lattner 3930fdc8d8SChris Lattner //------------------------------------------------------------------------- 4030fdc8d8SChris Lattner // CommandObject 4130fdc8d8SChris Lattner //------------------------------------------------------------------------- 4230fdc8d8SChris Lattner 43b9c1b51eSKate Stone CommandObject::CommandObject(CommandInterpreter &interpreter, const char *name, 44b9c1b51eSKate Stone const char *help, const char *syntax, 45b9c1b51eSKate Stone uint32_t flags) 46b9c1b51eSKate Stone : m_interpreter(interpreter), m_cmd_name(name ? name : ""), 47b9c1b51eSKate Stone m_cmd_help_short(), m_cmd_help_long(), m_cmd_syntax(), m_flags(flags), 48b9c1b51eSKate Stone m_arguments(), m_deprecated_command_override_callback(nullptr), 49b9c1b51eSKate Stone m_command_override_callback(nullptr), m_command_override_baton(nullptr) { 5030fdc8d8SChris Lattner if (help && help[0]) 5130fdc8d8SChris Lattner m_cmd_help_short = help; 5230fdc8d8SChris Lattner if (syntax && syntax[0]) 5330fdc8d8SChris Lattner m_cmd_syntax = syntax; 5430fdc8d8SChris Lattner } 5530fdc8d8SChris Lattner 56b9c1b51eSKate Stone CommandObject::~CommandObject() {} 5730fdc8d8SChris Lattner 58b9c1b51eSKate Stone const char *CommandObject::GetHelp() { return m_cmd_help_short.c_str(); } 5930fdc8d8SChris Lattner 60b9c1b51eSKate Stone const char *CommandObject::GetHelpLong() { return m_cmd_help_long.c_str(); } 6130fdc8d8SChris Lattner 62b9c1b51eSKate Stone const char *CommandObject::GetSyntax() { 63b9c1b51eSKate Stone if (m_cmd_syntax.length() == 0) { 64e139cf23SCaroline Tice StreamString syntax_str; 65e139cf23SCaroline Tice syntax_str.Printf("%s", GetCommandName()); 66bef55ac8SEnrico Granata if (!IsDashDashCommand() && GetOptions() != nullptr) 67e139cf23SCaroline Tice syntax_str.Printf(" <cmd-options>"); 68b9c1b51eSKate Stone if (m_arguments.size() > 0) { 69e139cf23SCaroline Tice syntax_str.Printf(" "); 70b9c1b51eSKate Stone if (!IsDashDashCommand() && WantsRawCommandString() && GetOptions() && 71b9c1b51eSKate Stone GetOptions()->NumCommandOptions()) 72a4c6ad19SSean Callanan syntax_str.Printf("-- "); 73e139cf23SCaroline Tice GetFormattedCommandArguments(syntax_str); 74e139cf23SCaroline Tice } 75e139cf23SCaroline Tice m_cmd_syntax = syntax_str.GetData(); 76e139cf23SCaroline Tice } 77e139cf23SCaroline Tice 7830fdc8d8SChris Lattner return m_cmd_syntax.c_str(); 7930fdc8d8SChris Lattner } 8030fdc8d8SChris Lattner 81b9c1b51eSKate Stone const char *CommandObject::GetCommandName() { return m_cmd_name.c_str(); } 8230fdc8d8SChris Lattner 83b9c1b51eSKate Stone void CommandObject::SetCommandName(const char *name) { m_cmd_name = name; } 8430fdc8d8SChris Lattner 85b9c1b51eSKate Stone void CommandObject::SetHelp(const char *cstr) { 86bfb75e9bSEnrico Granata if (cstr) 8730fdc8d8SChris Lattner m_cmd_help_short = cstr; 88bfb75e9bSEnrico Granata else 89bfb75e9bSEnrico Granata m_cmd_help_short.assign(""); 906f79bb2dSEnrico Granata } 916f79bb2dSEnrico Granata 92b9c1b51eSKate Stone void CommandObject::SetHelpLong(const char *cstr) { 93bfb75e9bSEnrico Granata if (cstr) 9430fdc8d8SChris Lattner m_cmd_help_long = cstr; 95bfb75e9bSEnrico Granata else 96bfb75e9bSEnrico Granata m_cmd_help_long.assign(""); 9799f0b8f9SEnrico Granata } 9899f0b8f9SEnrico Granata 99b9c1b51eSKate Stone void CommandObject::SetSyntax(const char *cstr) { m_cmd_syntax = cstr; } 10030fdc8d8SChris Lattner 101b9c1b51eSKate Stone Options *CommandObject::GetOptions() { 10230fdc8d8SChris Lattner // By default commands don't have options unless this virtual function 10330fdc8d8SChris Lattner // is overridden by base classes. 104d78c9576SEd Maste return nullptr; 10530fdc8d8SChris Lattner } 10630fdc8d8SChris Lattner 107b9c1b51eSKate Stone bool CommandObject::ParseOptions(Args &args, CommandReturnObject &result) { 10830fdc8d8SChris Lattner // See if the subclass has options? 10930fdc8d8SChris Lattner Options *options = GetOptions(); 110b9c1b51eSKate Stone if (options != nullptr) { 11130fdc8d8SChris Lattner Error error; 112e1cfbc79STodd Fiala 113e1cfbc79STodd Fiala auto exe_ctx = GetCommandInterpreter().GetExecutionContext(); 114e1cfbc79STodd Fiala options->NotifyOptionParsingStarting(&exe_ctx); 11530fdc8d8SChris Lattner 116b9c1b51eSKate Stone // ParseOptions calls getopt_long_only, which always skips the zero'th item 117b9c1b51eSKate Stone // in the array and starts at position 1, 11830fdc8d8SChris Lattner // so we need to push a dummy value into position zero. 11930fdc8d8SChris Lattner args.Unshift("dummy_string"); 120e1cfbc79STodd Fiala const bool require_validation = true; 121e1cfbc79STodd Fiala error = args.ParseOptions(*options, &exe_ctx, 122e1cfbc79STodd Fiala GetCommandInterpreter().GetPlatform(true), 123e1cfbc79STodd Fiala require_validation); 12430fdc8d8SChris Lattner 12530fdc8d8SChris Lattner // The "dummy_string" will have already been removed by ParseOptions, 12630fdc8d8SChris Lattner // so no need to remove it. 12730fdc8d8SChris Lattner 128f6b8b581SGreg Clayton if (error.Success()) 129e1cfbc79STodd Fiala error = options->NotifyOptionParsingFinished(&exe_ctx); 130f6b8b581SGreg Clayton 131b9c1b51eSKate Stone if (error.Success()) { 132f6b8b581SGreg Clayton if (options->VerifyOptions(result)) 133f6b8b581SGreg Clayton return true; 134b9c1b51eSKate Stone } else { 13530fdc8d8SChris Lattner const char *error_cstr = error.AsCString(); 136b9c1b51eSKate Stone if (error_cstr) { 13730fdc8d8SChris Lattner // We got an error string, lets use that 13886edbf41SGreg Clayton result.AppendError(error_cstr); 139b9c1b51eSKate Stone } else { 14030fdc8d8SChris Lattner // No error string, output the usage information into result 141b9c1b51eSKate Stone options->GenerateOptionUsage( 142b9c1b51eSKate Stone result.GetErrorStream(), this, 143b9c1b51eSKate Stone GetCommandInterpreter().GetDebugger().GetTerminalWidth()); 14430fdc8d8SChris Lattner } 145f6b8b581SGreg Clayton } 14630fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 14730fdc8d8SChris Lattner return false; 14830fdc8d8SChris Lattner } 14930fdc8d8SChris Lattner return true; 15030fdc8d8SChris Lattner } 15130fdc8d8SChris Lattner 152b9c1b51eSKate Stone bool CommandObject::CheckRequirements(CommandReturnObject &result) { 153f9fc609fSGreg Clayton #ifdef LLDB_CONFIGURATION_DEBUG 154f9fc609fSGreg Clayton // Nothing should be stored in m_exe_ctx between running commands as m_exe_ctx 155f9fc609fSGreg Clayton // has shared pointers to the target, process, thread and frame and we don't 156f9fc609fSGreg Clayton // want any CommandObject instances to keep any of these objects around 157f9fc609fSGreg Clayton // longer than for a single command. Every command should call 158f9fc609fSGreg Clayton // CommandObject::Cleanup() after it has completed 159f9fc609fSGreg Clayton assert(m_exe_ctx.GetTargetPtr() == NULL); 160f9fc609fSGreg Clayton assert(m_exe_ctx.GetProcessPtr() == NULL); 161f9fc609fSGreg Clayton assert(m_exe_ctx.GetThreadPtr() == NULL); 162f9fc609fSGreg Clayton assert(m_exe_ctx.GetFramePtr() == NULL); 163f9fc609fSGreg Clayton #endif 164f9fc609fSGreg Clayton 165f9fc609fSGreg Clayton // Lock down the interpreter's execution context prior to running the 166f9fc609fSGreg Clayton // command so we guarantee the selected target, process, thread and frame 167f9fc609fSGreg Clayton // can't go away during the execution 168f9fc609fSGreg Clayton m_exe_ctx = m_interpreter.GetExecutionContext(); 169f9fc609fSGreg Clayton 170f9fc609fSGreg Clayton const uint32_t flags = GetFlags().Get(); 171b9c1b51eSKate Stone if (flags & (eCommandRequiresTarget | eCommandRequiresProcess | 172b9c1b51eSKate Stone eCommandRequiresThread | eCommandRequiresFrame | 173b9c1b51eSKate Stone eCommandTryTargetAPILock)) { 174f9fc609fSGreg Clayton 175b9c1b51eSKate Stone if ((flags & eCommandRequiresTarget) && !m_exe_ctx.HasTargetScope()) { 176f9fc609fSGreg Clayton result.AppendError(GetInvalidTargetDescription()); 177f9fc609fSGreg Clayton return false; 178f9fc609fSGreg Clayton } 179f9fc609fSGreg Clayton 180b9c1b51eSKate Stone if ((flags & eCommandRequiresProcess) && !m_exe_ctx.HasProcessScope()) { 181e59b0d2cSJason Molenda if (!m_exe_ctx.HasTargetScope()) 182e59b0d2cSJason Molenda result.AppendError(GetInvalidTargetDescription()); 183e59b0d2cSJason Molenda else 184f9fc609fSGreg Clayton result.AppendError(GetInvalidProcessDescription()); 185f9fc609fSGreg Clayton return false; 186f9fc609fSGreg Clayton } 187f9fc609fSGreg Clayton 188b9c1b51eSKate Stone if ((flags & eCommandRequiresThread) && !m_exe_ctx.HasThreadScope()) { 189e59b0d2cSJason Molenda if (!m_exe_ctx.HasTargetScope()) 190e59b0d2cSJason Molenda result.AppendError(GetInvalidTargetDescription()); 191e59b0d2cSJason Molenda else if (!m_exe_ctx.HasProcessScope()) 192e59b0d2cSJason Molenda result.AppendError(GetInvalidProcessDescription()); 193e59b0d2cSJason Molenda else 194f9fc609fSGreg Clayton result.AppendError(GetInvalidThreadDescription()); 195f9fc609fSGreg Clayton return false; 196f9fc609fSGreg Clayton } 197f9fc609fSGreg Clayton 198b9c1b51eSKate Stone if ((flags & eCommandRequiresFrame) && !m_exe_ctx.HasFrameScope()) { 199e59b0d2cSJason Molenda if (!m_exe_ctx.HasTargetScope()) 200e59b0d2cSJason Molenda result.AppendError(GetInvalidTargetDescription()); 201e59b0d2cSJason Molenda else if (!m_exe_ctx.HasProcessScope()) 202e59b0d2cSJason Molenda result.AppendError(GetInvalidProcessDescription()); 203e59b0d2cSJason Molenda else if (!m_exe_ctx.HasThreadScope()) 204e59b0d2cSJason Molenda result.AppendError(GetInvalidThreadDescription()); 205e59b0d2cSJason Molenda else 206f9fc609fSGreg Clayton result.AppendError(GetInvalidFrameDescription()); 207f9fc609fSGreg Clayton return false; 208f9fc609fSGreg Clayton } 209f9fc609fSGreg Clayton 210b9c1b51eSKate Stone if ((flags & eCommandRequiresRegContext) && 211b9c1b51eSKate Stone (m_exe_ctx.GetRegisterContext() == nullptr)) { 212f9fc609fSGreg Clayton result.AppendError(GetInvalidRegContextDescription()); 213f9fc609fSGreg Clayton return false; 214f9fc609fSGreg Clayton } 215f9fc609fSGreg Clayton 216b9c1b51eSKate Stone if (flags & eCommandTryTargetAPILock) { 217f9fc609fSGreg Clayton Target *target = m_exe_ctx.GetTargetPtr(); 218f9fc609fSGreg Clayton if (target) 219b9c1b51eSKate Stone m_api_locker = 220b9c1b51eSKate Stone std::unique_lock<std::recursive_mutex>(target->GetAPIMutex()); 221f9fc609fSGreg Clayton } 222f9fc609fSGreg Clayton } 223f9fc609fSGreg Clayton 224b9c1b51eSKate Stone if (GetFlags().AnySet(eCommandProcessMustBeLaunched | 225b9c1b51eSKate Stone eCommandProcessMustBePaused)) { 226c14ee32dSGreg Clayton Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); 227b9c1b51eSKate Stone if (process == nullptr) { 228b8e8a5f3SJim Ingham // A process that is not running is considered paused. 229b9c1b51eSKate Stone if (GetFlags().Test(eCommandProcessMustBeLaunched)) { 23030fdc8d8SChris Lattner result.AppendError("Process must exist."); 23130fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 23230fdc8d8SChris Lattner return false; 23330fdc8d8SChris Lattner } 234b9c1b51eSKate Stone } else { 23530fdc8d8SChris Lattner StateType state = process->GetState(); 236b9c1b51eSKate Stone switch (state) { 2377a5388bfSGreg Clayton case eStateInvalid: 23830fdc8d8SChris Lattner case eStateSuspended: 23930fdc8d8SChris Lattner case eStateCrashed: 24030fdc8d8SChris Lattner case eStateStopped: 24130fdc8d8SChris Lattner break; 24230fdc8d8SChris Lattner 243b766a73dSGreg Clayton case eStateConnected: 244b766a73dSGreg Clayton case eStateAttaching: 245b766a73dSGreg Clayton case eStateLaunching: 24630fdc8d8SChris Lattner case eStateDetached: 24730fdc8d8SChris Lattner case eStateExited: 24830fdc8d8SChris Lattner case eStateUnloaded: 249b9c1b51eSKate Stone if (GetFlags().Test(eCommandProcessMustBeLaunched)) { 25030fdc8d8SChris Lattner result.AppendError("Process must be launched."); 25130fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 25230fdc8d8SChris Lattner return false; 25330fdc8d8SChris Lattner } 25430fdc8d8SChris Lattner break; 25530fdc8d8SChris Lattner 25630fdc8d8SChris Lattner case eStateRunning: 25730fdc8d8SChris Lattner case eStateStepping: 258b9c1b51eSKate Stone if (GetFlags().Test(eCommandProcessMustBePaused)) { 259b9c1b51eSKate Stone result.AppendError("Process is running. Use 'process interrupt' to " 260b9c1b51eSKate Stone "pause execution."); 26130fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 26230fdc8d8SChris Lattner return false; 26330fdc8d8SChris Lattner } 26430fdc8d8SChris Lattner } 26530fdc8d8SChris Lattner } 266b766a73dSGreg Clayton } 2675a988416SJim Ingham return true; 26830fdc8d8SChris Lattner } 26930fdc8d8SChris Lattner 270b9c1b51eSKate Stone void CommandObject::Cleanup() { 271f9fc609fSGreg Clayton m_exe_ctx.Clear(); 272bb19a13cSSaleem Abdulrasool if (m_api_locker.owns_lock()) 273bb19a13cSSaleem Abdulrasool m_api_locker.unlock(); 274f9fc609fSGreg Clayton } 275f9fc609fSGreg Clayton 276b9c1b51eSKate Stone int CommandObject::HandleCompletion(Args &input, int &cursor_index, 27730fdc8d8SChris Lattner int &cursor_char_position, 27830fdc8d8SChris Lattner int match_start_point, 27930fdc8d8SChris Lattner int max_return_elements, 280b9c1b51eSKate Stone bool &word_complete, StringList &matches) { 281e171da5cSBruce Mitchener // Default implementation of WantsCompletion() is !WantsRawCommandString(). 2826561d15dSJohnny Chen // Subclasses who want raw command string but desire, for example, 2836561d15dSJohnny Chen // argument completion should override WantsCompletion() to return true, 2846561d15dSJohnny Chen // instead. 285b9c1b51eSKate Stone if (WantsRawCommandString() && !WantsCompletion()) { 286b9c1b51eSKate Stone // FIXME: Abstract telling the completion to insert the completion 287b9c1b51eSKate Stone // character. 28830fdc8d8SChris Lattner matches.Clear(); 28930fdc8d8SChris Lattner return -1; 290b9c1b51eSKate Stone } else { 29130fdc8d8SChris Lattner // Can we do anything generic with the options? 29230fdc8d8SChris Lattner Options *cur_options = GetOptions(); 29330fdc8d8SChris Lattner CommandReturnObject result; 29430fdc8d8SChris Lattner OptionElementVector opt_element_vector; 29530fdc8d8SChris Lattner 296b9c1b51eSKate Stone if (cur_options != nullptr) { 29730fdc8d8SChris Lattner // Re-insert the dummy command name string which will have been 29830fdc8d8SChris Lattner // stripped off: 29930fdc8d8SChris Lattner input.Unshift("dummy-string"); 30030fdc8d8SChris Lattner cursor_index++; 30130fdc8d8SChris Lattner 302b9c1b51eSKate Stone // I stick an element on the end of the input, because if the last element 303*ecbb0bb1SZachary Turner // is option that requires an argument, getopt_long_only will freak out. 30430fdc8d8SChris Lattner 305*ecbb0bb1SZachary Turner input.AppendArgument(llvm::StringRef("<FAKE-VALUE>")); 30630fdc8d8SChris Lattner 307b9c1b51eSKate Stone input.ParseArgsForCompletion(*cur_options, opt_element_vector, 308b9c1b51eSKate Stone cursor_index); 30930fdc8d8SChris Lattner 31030fdc8d8SChris Lattner input.DeleteArgumentAtIndex(input.GetArgumentCount() - 1); 31130fdc8d8SChris Lattner 31230fdc8d8SChris Lattner bool handled_by_options; 313b9c1b51eSKate Stone handled_by_options = cur_options->HandleOptionCompletion( 314b9c1b51eSKate Stone input, opt_element_vector, cursor_index, cursor_char_position, 315b9c1b51eSKate Stone match_start_point, max_return_elements, GetCommandInterpreter(), 316b9c1b51eSKate Stone word_complete, matches); 31730fdc8d8SChris Lattner if (handled_by_options) 31830fdc8d8SChris Lattner return matches.GetSize(); 31930fdc8d8SChris Lattner } 32030fdc8d8SChris Lattner 32130fdc8d8SChris Lattner // If we got here, the last word is not an option or an option argument. 322b9c1b51eSKate Stone return HandleArgumentCompletion( 323b9c1b51eSKate Stone input, cursor_index, cursor_char_position, opt_element_vector, 324b9c1b51eSKate Stone match_start_point, max_return_elements, word_complete, matches); 32530fdc8d8SChris Lattner } 32630fdc8d8SChris Lattner } 32730fdc8d8SChris Lattner 328b9c1b51eSKate Stone bool CommandObject::HelpTextContainsWord(const char *search_word, 329d033e1ceSEnrico Granata bool search_short_help, 330d033e1ceSEnrico Granata bool search_long_help, 331d033e1ceSEnrico Granata bool search_syntax, 332b9c1b51eSKate Stone bool search_options) { 33330fdc8d8SChris Lattner std::string options_usage_help; 33430fdc8d8SChris Lattner 33530fdc8d8SChris Lattner bool found_word = false; 33630fdc8d8SChris Lattner 337998255bfSGreg Clayton const char *short_help = GetHelp(); 338998255bfSGreg Clayton const char *long_help = GetHelpLong(); 339998255bfSGreg Clayton const char *syntax_help = GetSyntax(); 34030fdc8d8SChris Lattner 341d033e1ceSEnrico Granata if (search_short_help && short_help && strcasestr(short_help, search_word)) 34230fdc8d8SChris Lattner found_word = true; 343d033e1ceSEnrico Granata else if (search_long_help && long_help && strcasestr(long_help, search_word)) 34430fdc8d8SChris Lattner found_word = true; 345d033e1ceSEnrico Granata else if (search_syntax && syntax_help && strcasestr(syntax_help, search_word)) 34630fdc8d8SChris Lattner found_word = true; 34730fdc8d8SChris Lattner 348b9c1b51eSKate Stone if (!found_word && search_options && GetOptions() != nullptr) { 34930fdc8d8SChris Lattner StreamString usage_help; 350b9c1b51eSKate Stone GetOptions()->GenerateOptionUsage( 351b9c1b51eSKate Stone usage_help, this, 352b9c1b51eSKate Stone GetCommandInterpreter().GetDebugger().GetTerminalWidth()); 353b9c1b51eSKate Stone if (usage_help.GetSize() > 0) { 35430fdc8d8SChris Lattner const char *usage_text = usage_help.GetData(); 3554b6fbf37SCaroline Tice if (strcasestr(usage_text, search_word)) 35630fdc8d8SChris Lattner found_word = true; 35730fdc8d8SChris Lattner } 35830fdc8d8SChris Lattner } 35930fdc8d8SChris Lattner 36030fdc8d8SChris Lattner return found_word; 36130fdc8d8SChris Lattner } 362e139cf23SCaroline Tice 363b9c1b51eSKate Stone int CommandObject::GetNumArgumentEntries() { return m_arguments.size(); } 364e139cf23SCaroline Tice 365e139cf23SCaroline Tice CommandObject::CommandArgumentEntry * 366b9c1b51eSKate Stone CommandObject::GetArgumentEntryAtIndex(int idx) { 3673985c8c6SSaleem Abdulrasool if (static_cast<size_t>(idx) < m_arguments.size()) 368e139cf23SCaroline Tice return &(m_arguments[idx]); 369e139cf23SCaroline Tice 370d78c9576SEd Maste return nullptr; 371e139cf23SCaroline Tice } 372e139cf23SCaroline Tice 373d7e6a4f2SVince Harron const CommandObject::ArgumentTableEntry * 374b9c1b51eSKate Stone CommandObject::FindArgumentDataByType(CommandArgumentType arg_type) { 375e139cf23SCaroline Tice const ArgumentTableEntry *table = CommandObject::GetArgumentTable(); 376e139cf23SCaroline Tice 377e139cf23SCaroline Tice for (int i = 0; i < eArgTypeLastArg; ++i) 378e139cf23SCaroline Tice if (table[i].arg_type == arg_type) 379d7e6a4f2SVince Harron return &(table[i]); 380e139cf23SCaroline Tice 381d78c9576SEd Maste return nullptr; 382e139cf23SCaroline Tice } 383e139cf23SCaroline Tice 384b9c1b51eSKate Stone void CommandObject::GetArgumentHelp(Stream &str, CommandArgumentType arg_type, 385b9c1b51eSKate Stone CommandInterpreter &interpreter) { 386e139cf23SCaroline Tice const ArgumentTableEntry *table = CommandObject::GetArgumentTable(); 387d7e6a4f2SVince Harron const ArgumentTableEntry *entry = &(table[arg_type]); 388e139cf23SCaroline Tice 389b9c1b51eSKate Stone // The table is *supposed* to be kept in arg_type order, but someone *could* 390b9c1b51eSKate Stone // have messed it up... 391e139cf23SCaroline Tice 392e139cf23SCaroline Tice if (entry->arg_type != arg_type) 393e139cf23SCaroline Tice entry = CommandObject::FindArgumentDataByType(arg_type); 394e139cf23SCaroline Tice 395e139cf23SCaroline Tice if (!entry) 396e139cf23SCaroline Tice return; 397e139cf23SCaroline Tice 398e139cf23SCaroline Tice StreamString name_str; 399e139cf23SCaroline Tice name_str.Printf("<%s>", entry->arg_name); 400e139cf23SCaroline Tice 401b9c1b51eSKate Stone if (entry->help_function) { 402fc7a7f3bSEnrico Granata const char *help_text = entry->help_function(); 403b9c1b51eSKate Stone if (!entry->help_function.self_formatting) { 404b9c1b51eSKate Stone interpreter.OutputFormattedHelpText(str, name_str.GetData(), "--", 405b9c1b51eSKate Stone help_text, name_str.GetSize()); 406b9c1b51eSKate Stone } else { 40782a7d983SEnrico Granata interpreter.OutputHelpText(str, name_str.GetData(), "--", help_text, 40882a7d983SEnrico Granata name_str.GetSize()); 40982a7d983SEnrico Granata } 410b9c1b51eSKate Stone } else 411b9c1b51eSKate Stone interpreter.OutputFormattedHelpText(str, name_str.GetData(), "--", 412b9c1b51eSKate Stone entry->help_text, name_str.GetSize()); 413e139cf23SCaroline Tice } 414e139cf23SCaroline Tice 415b9c1b51eSKate Stone const char *CommandObject::GetArgumentName(CommandArgumentType arg_type) { 416b9c1b51eSKate Stone const ArgumentTableEntry *entry = 417b9c1b51eSKate Stone &(CommandObject::GetArgumentTable()[arg_type]); 418deaab222SCaroline Tice 419b9c1b51eSKate Stone // The table is *supposed* to be kept in arg_type order, but someone *could* 420b9c1b51eSKate Stone // have messed it up... 421deaab222SCaroline Tice 422deaab222SCaroline Tice if (entry->arg_type != arg_type) 423deaab222SCaroline Tice entry = CommandObject::FindArgumentDataByType(arg_type); 424deaab222SCaroline Tice 425e6acf355SJohnny Chen if (entry) 426deaab222SCaroline Tice return entry->arg_name; 427e6acf355SJohnny Chen 428e6acf355SJohnny Chen StreamString str; 429e6acf355SJohnny Chen str << "Arg name for type (" << arg_type << ") not in arg table!"; 430e6acf355SJohnny Chen return str.GetData(); 431e139cf23SCaroline Tice } 432e139cf23SCaroline Tice 433b9c1b51eSKate Stone bool CommandObject::IsPairType(ArgumentRepetitionType arg_repeat_type) { 434b9c1b51eSKate Stone if ((arg_repeat_type == eArgRepeatPairPlain) || 435b9c1b51eSKate Stone (arg_repeat_type == eArgRepeatPairOptional) || 436b9c1b51eSKate Stone (arg_repeat_type == eArgRepeatPairPlus) || 437b9c1b51eSKate Stone (arg_repeat_type == eArgRepeatPairStar) || 438b9c1b51eSKate Stone (arg_repeat_type == eArgRepeatPairRange) || 439b9c1b51eSKate Stone (arg_repeat_type == eArgRepeatPairRangeOptional)) 440405fe67fSCaroline Tice return true; 441405fe67fSCaroline Tice 442405fe67fSCaroline Tice return false; 443405fe67fSCaroline Tice } 444405fe67fSCaroline Tice 44534ddc8dbSJohnny Chen static CommandObject::CommandArgumentEntry 446b9c1b51eSKate Stone OptSetFiltered(uint32_t opt_set_mask, 447b9c1b51eSKate Stone CommandObject::CommandArgumentEntry &cmd_arg_entry) { 44834ddc8dbSJohnny Chen CommandObject::CommandArgumentEntry ret_val; 44934ddc8dbSJohnny Chen for (unsigned i = 0; i < cmd_arg_entry.size(); ++i) 45034ddc8dbSJohnny Chen if (opt_set_mask & cmd_arg_entry[i].arg_opt_set_association) 45134ddc8dbSJohnny Chen ret_val.push_back(cmd_arg_entry[i]); 45234ddc8dbSJohnny Chen return ret_val; 45334ddc8dbSJohnny Chen } 45434ddc8dbSJohnny Chen 45534ddc8dbSJohnny Chen // Default parameter value of opt_set_mask is LLDB_OPT_SET_ALL, which means take 45634ddc8dbSJohnny Chen // all the argument data into account. On rare cases where some argument sticks 45734ddc8dbSJohnny Chen // with certain option sets, this function returns the option set filtered args. 458b9c1b51eSKate Stone void CommandObject::GetFormattedCommandArguments(Stream &str, 459b9c1b51eSKate Stone uint32_t opt_set_mask) { 460e139cf23SCaroline Tice int num_args = m_arguments.size(); 461b9c1b51eSKate Stone for (int i = 0; i < num_args; ++i) { 462e139cf23SCaroline Tice if (i > 0) 463e139cf23SCaroline Tice str.Printf(" "); 46434ddc8dbSJohnny Chen CommandArgumentEntry arg_entry = 465b9c1b51eSKate Stone opt_set_mask == LLDB_OPT_SET_ALL 466b9c1b51eSKate Stone ? m_arguments[i] 46734ddc8dbSJohnny Chen : OptSetFiltered(opt_set_mask, m_arguments[i]); 468e139cf23SCaroline Tice int num_alternatives = arg_entry.size(); 469405fe67fSCaroline Tice 470b9c1b51eSKate Stone if ((num_alternatives == 2) && IsPairType(arg_entry[0].arg_repetition)) { 471405fe67fSCaroline Tice const char *first_name = GetArgumentName(arg_entry[0].arg_type); 472405fe67fSCaroline Tice const char *second_name = GetArgumentName(arg_entry[1].arg_type); 473b9c1b51eSKate Stone switch (arg_entry[0].arg_repetition) { 474405fe67fSCaroline Tice case eArgRepeatPairPlain: 475405fe67fSCaroline Tice str.Printf("<%s> <%s>", first_name, second_name); 476405fe67fSCaroline Tice break; 477405fe67fSCaroline Tice case eArgRepeatPairOptional: 478405fe67fSCaroline Tice str.Printf("[<%s> <%s>]", first_name, second_name); 479405fe67fSCaroline Tice break; 480405fe67fSCaroline Tice case eArgRepeatPairPlus: 481b9c1b51eSKate Stone str.Printf("<%s> <%s> [<%s> <%s> [...]]", first_name, second_name, 482b9c1b51eSKate Stone first_name, second_name); 483405fe67fSCaroline Tice break; 484405fe67fSCaroline Tice case eArgRepeatPairStar: 485b9c1b51eSKate Stone str.Printf("[<%s> <%s> [<%s> <%s> [...]]]", first_name, second_name, 486b9c1b51eSKate Stone first_name, second_name); 487405fe67fSCaroline Tice break; 488405fe67fSCaroline Tice case eArgRepeatPairRange: 489b9c1b51eSKate Stone str.Printf("<%s_1> <%s_1> ... <%s_n> <%s_n>", first_name, second_name, 490b9c1b51eSKate Stone first_name, second_name); 491405fe67fSCaroline Tice break; 492405fe67fSCaroline Tice case eArgRepeatPairRangeOptional: 493b9c1b51eSKate Stone str.Printf("[<%s_1> <%s_1> ... <%s_n> <%s_n>]", first_name, second_name, 494b9c1b51eSKate Stone first_name, second_name); 495405fe67fSCaroline Tice break; 496b9c1b51eSKate Stone // Explicitly test for all the rest of the cases, so if new types get 497b9c1b51eSKate Stone // added we will notice the 498ca1176aaSCaroline Tice // missing case statement(s). 499ca1176aaSCaroline Tice case eArgRepeatPlain: 500ca1176aaSCaroline Tice case eArgRepeatOptional: 501ca1176aaSCaroline Tice case eArgRepeatPlus: 502ca1176aaSCaroline Tice case eArgRepeatStar: 503ca1176aaSCaroline Tice case eArgRepeatRange: 504b9c1b51eSKate Stone // These should not be reached, as they should fail the IsPairType test 505b9c1b51eSKate Stone // above. 506ca1176aaSCaroline Tice break; 507405fe67fSCaroline Tice } 508b9c1b51eSKate Stone } else { 509e139cf23SCaroline Tice StreamString names; 510b9c1b51eSKate Stone for (int j = 0; j < num_alternatives; ++j) { 511e139cf23SCaroline Tice if (j > 0) 512e139cf23SCaroline Tice names.Printf(" | "); 513e139cf23SCaroline Tice names.Printf("%s", GetArgumentName(arg_entry[j].arg_type)); 514e139cf23SCaroline Tice } 515b9c1b51eSKate Stone switch (arg_entry[0].arg_repetition) { 516e139cf23SCaroline Tice case eArgRepeatPlain: 517e139cf23SCaroline Tice str.Printf("<%s>", names.GetData()); 518e139cf23SCaroline Tice break; 519e139cf23SCaroline Tice case eArgRepeatPlus: 520e139cf23SCaroline Tice str.Printf("<%s> [<%s> [...]]", names.GetData(), names.GetData()); 521e139cf23SCaroline Tice break; 522e139cf23SCaroline Tice case eArgRepeatStar: 523e139cf23SCaroline Tice str.Printf("[<%s> [<%s> [...]]]", names.GetData(), names.GetData()); 524e139cf23SCaroline Tice break; 525e139cf23SCaroline Tice case eArgRepeatOptional: 526e139cf23SCaroline Tice str.Printf("[<%s>]", names.GetData()); 527e139cf23SCaroline Tice break; 528405fe67fSCaroline Tice case eArgRepeatRange: 529fd54b368SJason Molenda str.Printf("<%s_1> .. <%s_n>", names.GetData(), names.GetData()); 530ca1176aaSCaroline Tice break; 531b9c1b51eSKate Stone // Explicitly test for all the rest of the cases, so if new types get 532b9c1b51eSKate Stone // added we will notice the 533ca1176aaSCaroline Tice // missing case statement(s). 534ca1176aaSCaroline Tice case eArgRepeatPairPlain: 535ca1176aaSCaroline Tice case eArgRepeatPairOptional: 536ca1176aaSCaroline Tice case eArgRepeatPairPlus: 537ca1176aaSCaroline Tice case eArgRepeatPairStar: 538ca1176aaSCaroline Tice case eArgRepeatPairRange: 539ca1176aaSCaroline Tice case eArgRepeatPairRangeOptional: 540b9c1b51eSKate Stone // These should not be hit, as they should pass the IsPairType test 541b9c1b51eSKate Stone // above, and control should 542ca1176aaSCaroline Tice // have gone into the other branch of the if statement. 543ca1176aaSCaroline Tice break; 544405fe67fSCaroline Tice } 545e139cf23SCaroline Tice } 546e139cf23SCaroline Tice } 547e139cf23SCaroline Tice } 548e139cf23SCaroline Tice 549b9c1b51eSKate Stone CommandArgumentType CommandObject::LookupArgumentName(const char *arg_name) { 550e139cf23SCaroline Tice CommandArgumentType return_type = eArgTypeLastArg; 551e139cf23SCaroline Tice 552e139cf23SCaroline Tice std::string arg_name_str(arg_name); 553e139cf23SCaroline Tice size_t len = arg_name_str.length(); 554b9c1b51eSKate Stone if (arg_name[0] == '<' && arg_name[len - 1] == '>') 555e139cf23SCaroline Tice arg_name_str = arg_name_str.substr(1, len - 2); 556e139cf23SCaroline Tice 557331eff39SJohnny Chen const ArgumentTableEntry *table = GetArgumentTable(); 558e139cf23SCaroline Tice for (int i = 0; i < eArgTypeLastArg; ++i) 559331eff39SJohnny Chen if (arg_name_str.compare(table[i].arg_name) == 0) 560e139cf23SCaroline Tice return_type = g_arguments_data[i].arg_type; 561e139cf23SCaroline Tice 562e139cf23SCaroline Tice return return_type; 563e139cf23SCaroline Tice } 564e139cf23SCaroline Tice 565b9c1b51eSKate Stone static const char *RegisterNameHelpTextCallback() { 566b9c1b51eSKate Stone return "Register names can be specified using the architecture specific " 567b9c1b51eSKate Stone "names. " 568b9c1b51eSKate Stone "They can also be specified using generic names. Not all generic " 569b9c1b51eSKate Stone "entities have " 570b9c1b51eSKate Stone "registers backing them on all architectures. When they don't the " 571b9c1b51eSKate Stone "generic name " 57284c7bd74SJim Ingham "will return an error.\n" 573931e674aSJim Ingham "The generic names defined in lldb are:\n" 574931e674aSJim Ingham "\n" 575931e674aSJim Ingham "pc - program counter register\n" 576931e674aSJim Ingham "ra - return address register\n" 577931e674aSJim Ingham "fp - frame pointer register\n" 578931e674aSJim Ingham "sp - stack pointer register\n" 57984c7bd74SJim Ingham "flags - the flags register\n" 580931e674aSJim Ingham "arg{1-6} - integer argument passing registers.\n"; 581931e674aSJim Ingham } 582931e674aSJim Ingham 583b9c1b51eSKate Stone static const char *BreakpointIDHelpTextCallback() { 5847428a18cSKate Stone return "Breakpoints are identified using major and minor numbers; the major " 585b9c1b51eSKate Stone "number corresponds to the single entity that was created with a " 586b9c1b51eSKate Stone "'breakpoint " 587b9c1b51eSKate Stone "set' command; the minor numbers correspond to all the locations that " 588b9c1b51eSKate Stone "were " 589b9c1b51eSKate Stone "actually found/set based on the major breakpoint. A full breakpoint " 590b9c1b51eSKate Stone "ID might " 591b9c1b51eSKate Stone "look like 3.14, meaning the 14th location set for the 3rd " 592b9c1b51eSKate Stone "breakpoint. You " 593b9c1b51eSKate Stone "can specify all the locations of a breakpoint by just indicating the " 594b9c1b51eSKate Stone "major " 595b9c1b51eSKate Stone "breakpoint number. A valid breakpoint ID consists either of just the " 596b9c1b51eSKate Stone "major " 597b9c1b51eSKate Stone "number, or the major number followed by a dot and the location " 598b9c1b51eSKate Stone "number (e.g. " 5997428a18cSKate Stone "3 or 3.2 could both be valid breakpoint IDs.)"; 600e139cf23SCaroline Tice } 601e139cf23SCaroline Tice 602b9c1b51eSKate Stone static const char *BreakpointIDRangeHelpTextCallback() { 603b9c1b51eSKate Stone return "A 'breakpoint ID list' is a manner of specifying multiple " 604b9c1b51eSKate Stone "breakpoints. " 605b9c1b51eSKate Stone "This can be done through several mechanisms. The easiest way is to " 606b9c1b51eSKate Stone "just " 6077428a18cSKate Stone "enter a space-separated list of breakpoint IDs. To specify all the " 60886edbf41SGreg Clayton "breakpoint locations under a major breakpoint, you can use the major " 609b9c1b51eSKate Stone "breakpoint number followed by '.*', eg. '5.*' means all the " 610b9c1b51eSKate Stone "locations under " 61186edbf41SGreg Clayton "breakpoint 5. You can also indicate a range of breakpoints by using " 612b9c1b51eSKate Stone "<start-bp-id> - <end-bp-id>. The start-bp-id and end-bp-id for a " 613b9c1b51eSKate Stone "range can " 614b9c1b51eSKate Stone "be any valid breakpoint IDs. It is not legal, however, to specify a " 615b9c1b51eSKate Stone "range " 616b9c1b51eSKate Stone "using specific locations that cross major breakpoint numbers. I.e. " 617b9c1b51eSKate Stone "3.2 - 3.7" 61886edbf41SGreg Clayton " is legal; 2 - 5 is legal; but 3.2 - 4.4 is not legal."; 61986edbf41SGreg Clayton } 62086edbf41SGreg Clayton 621b9c1b51eSKate Stone static const char *BreakpointNameHelpTextCallback() { 622b9c1b51eSKate Stone return "A name that can be added to a breakpoint when it is created, or " 623b9c1b51eSKate Stone "later " 6245e09c8c3SJim Ingham "on with the \"breakpoint name add\" command. " 625b9c1b51eSKate Stone "Breakpoint names can be used to specify breakpoints in all the " 626b9c1b51eSKate Stone "places breakpoint IDs " 627b9c1b51eSKate Stone "and breakpoint ID ranges can be used. As such they provide a " 628b9c1b51eSKate Stone "convenient way to group breakpoints, " 629b9c1b51eSKate Stone "and to operate on breakpoints you create without having to track the " 630b9c1b51eSKate Stone "breakpoint number. " 631b9c1b51eSKate Stone "Note, the attributes you set when using a breakpoint name in a " 632b9c1b51eSKate Stone "breakpoint command don't " 633b9c1b51eSKate Stone "adhere to the name, but instead are set individually on all the " 634b9c1b51eSKate Stone "breakpoints currently tagged with that " 6357428a18cSKate Stone "name. Future breakpoints " 636b9c1b51eSKate Stone "tagged with that name will not pick up the attributes previously " 637b9c1b51eSKate Stone "given using that name. " 638b9c1b51eSKate Stone "In order to distinguish breakpoint names from breakpoint IDs and " 639b9c1b51eSKate Stone "ranges, " 640b9c1b51eSKate Stone "names must start with a letter from a-z or A-Z and cannot contain " 641b9c1b51eSKate Stone "spaces, \".\" or \"-\". " 642b9c1b51eSKate Stone "Also, breakpoint names can only be applied to breakpoints, not to " 643b9c1b51eSKate Stone "breakpoint locations."; 6445e09c8c3SJim Ingham } 6455e09c8c3SJim Ingham 646b9c1b51eSKate Stone static const char *GDBFormatHelpTextCallback() { 647b9c1b51eSKate Stone return "A GDB format consists of a repeat count, a format letter and a size " 648b9c1b51eSKate Stone "letter. " 649b9c1b51eSKate Stone "The repeat count is optional and defaults to 1. The format letter is " 650b9c1b51eSKate Stone "optional " 651b9c1b51eSKate Stone "and defaults to the previous format that was used. The size letter " 652b9c1b51eSKate Stone "is optional " 653f91381e8SGreg Clayton "and defaults to the previous size that was used.\n" 654f91381e8SGreg Clayton "\n" 655f91381e8SGreg Clayton "Format letters include:\n" 656f91381e8SGreg Clayton "o - octal\n" 657f91381e8SGreg Clayton "x - hexadecimal\n" 658f91381e8SGreg Clayton "d - decimal\n" 659f91381e8SGreg Clayton "u - unsigned decimal\n" 660f91381e8SGreg Clayton "t - binary\n" 661f91381e8SGreg Clayton "f - float\n" 662f91381e8SGreg Clayton "a - address\n" 663f91381e8SGreg Clayton "i - instruction\n" 664f91381e8SGreg Clayton "c - char\n" 665f91381e8SGreg Clayton "s - string\n" 666f91381e8SGreg Clayton "T - OSType\n" 667f91381e8SGreg Clayton "A - float as hex\n" 668f91381e8SGreg Clayton "\n" 669f91381e8SGreg Clayton "Size letters include:\n" 670f91381e8SGreg Clayton "b - 1 byte (byte)\n" 671f91381e8SGreg Clayton "h - 2 bytes (halfword)\n" 672f91381e8SGreg Clayton "w - 4 bytes (word)\n" 673f91381e8SGreg Clayton "g - 8 bytes (giant)\n" 674f91381e8SGreg Clayton "\n" 675f91381e8SGreg Clayton "Example formats:\n" 676f91381e8SGreg Clayton "32xb - show 32 1 byte hexadecimal integer values\n" 677f91381e8SGreg Clayton "16xh - show 16 2 byte hexadecimal integer values\n" 678b9c1b51eSKate Stone "64 - show 64 2 byte hexadecimal integer values (format and size " 679b9c1b51eSKate Stone "from the last format)\n" 680b9c1b51eSKate Stone "dw - show 1 4 byte decimal integer value\n"; 681e139cf23SCaroline Tice } 682e139cf23SCaroline Tice 683b9c1b51eSKate Stone static const char *FormatHelpTextCallback() { 68482a7d983SEnrico Granata 685d78c9576SEd Maste static char *help_text_ptr = nullptr; 68682a7d983SEnrico Granata 68782a7d983SEnrico Granata if (help_text_ptr) 68882a7d983SEnrico Granata return help_text_ptr; 68982a7d983SEnrico Granata 6900a3958e0SEnrico Granata StreamString sstr; 691b9c1b51eSKate Stone sstr << "One of the format names (or one-character names) that can be used " 692b9c1b51eSKate Stone "to show a variable's value:\n"; 693b9c1b51eSKate Stone for (Format f = eFormatDefault; f < kNumFormats; f = Format(f + 1)) { 69482a7d983SEnrico Granata if (f != eFormatDefault) 69582a7d983SEnrico Granata sstr.PutChar('\n'); 69682a7d983SEnrico Granata 6970a3958e0SEnrico Granata char format_char = FormatManager::GetFormatAsFormatChar(f); 6980a3958e0SEnrico Granata if (format_char) 6990a3958e0SEnrico Granata sstr.Printf("'%c' or ", format_char); 7000a3958e0SEnrico Granata 70182a7d983SEnrico Granata sstr.Printf("\"%s\"", FormatManager::GetFormatAsCString(f)); 7020a3958e0SEnrico Granata } 7030a3958e0SEnrico Granata 7040a3958e0SEnrico Granata sstr.Flush(); 7050a3958e0SEnrico Granata 7060a3958e0SEnrico Granata std::string data = sstr.GetString(); 7070a3958e0SEnrico Granata 70882a7d983SEnrico Granata help_text_ptr = new char[data.length() + 1]; 7090a3958e0SEnrico Granata 71082a7d983SEnrico Granata data.copy(help_text_ptr, data.length()); 7110a3958e0SEnrico Granata 71282a7d983SEnrico Granata return help_text_ptr; 7130a3958e0SEnrico Granata } 7140a3958e0SEnrico Granata 715b9c1b51eSKate Stone static const char *LanguageTypeHelpTextCallback() { 716d78c9576SEd Maste static char *help_text_ptr = nullptr; 717d9477397SSean Callanan 718d9477397SSean Callanan if (help_text_ptr) 719d9477397SSean Callanan return help_text_ptr; 720d9477397SSean Callanan 721d9477397SSean Callanan StreamString sstr; 722d9477397SSean Callanan sstr << "One of the following languages:\n"; 723d9477397SSean Callanan 7240e0984eeSJim Ingham Language::PrintAllLanguages(sstr, " ", "\n"); 725d9477397SSean Callanan 726d9477397SSean Callanan sstr.Flush(); 727d9477397SSean Callanan 728d9477397SSean Callanan std::string data = sstr.GetString(); 729d9477397SSean Callanan 730d9477397SSean Callanan help_text_ptr = new char[data.length() + 1]; 731d9477397SSean Callanan 732d9477397SSean Callanan data.copy(help_text_ptr, data.length()); 733d9477397SSean Callanan 734d9477397SSean Callanan return help_text_ptr; 735d9477397SSean Callanan } 736d9477397SSean Callanan 737b9c1b51eSKate Stone static const char *SummaryStringHelpTextCallback() { 738b9c1b51eSKate Stone return "A summary string is a way to extract information from variables in " 739b9c1b51eSKate Stone "order to present them using a summary.\n" 740b9c1b51eSKate Stone "Summary strings contain static text, variables, scopes and control " 741b9c1b51eSKate Stone "sequences:\n" 742b9c1b51eSKate Stone " - Static text can be any sequence of non-special characters, i.e. " 743b9c1b51eSKate Stone "anything but '{', '}', '$', or '\\'.\n" 744b9c1b51eSKate Stone " - Variables are sequences of characters beginning with ${, ending " 745b9c1b51eSKate Stone "with } and that contain symbols in the format described below.\n" 746b9c1b51eSKate Stone " - Scopes are any sequence of text between { and }. Anything " 747b9c1b51eSKate Stone "included in a scope will only appear in the output summary if there " 748b9c1b51eSKate Stone "were no errors.\n" 749b9c1b51eSKate Stone " - Control sequences are the usual C/C++ '\\a', '\\n', ..., plus " 750b9c1b51eSKate Stone "'\\$', '\\{' and '\\}'.\n" 751b9c1b51eSKate Stone "A summary string works by copying static text verbatim, turning " 752b9c1b51eSKate Stone "control sequences into their character counterpart, expanding " 753b9c1b51eSKate Stone "variables and trying to expand scopes.\n" 754b9c1b51eSKate Stone "A variable is expanded by giving it a value other than its textual " 755b9c1b51eSKate Stone "representation, and the way this is done depends on what comes after " 756b9c1b51eSKate Stone "the ${ marker.\n" 757b9c1b51eSKate Stone "The most common sequence if ${var followed by an expression path, " 758b9c1b51eSKate Stone "which is the text one would type to access a member of an aggregate " 759b9c1b51eSKate Stone "types, given a variable of that type" 760b9c1b51eSKate Stone " (e.g. if type T has a member named x, which has a member named y, " 761b9c1b51eSKate Stone "and if t is of type T, the expression path would be .x.y and the way " 762b9c1b51eSKate Stone "to fit that into a summary string would be" 763b9c1b51eSKate Stone " ${var.x.y}). You can also use ${*var followed by an expression path " 764b9c1b51eSKate Stone "and in that case the object referred by the path will be " 765b9c1b51eSKate Stone "dereferenced before being displayed." 766b9c1b51eSKate Stone " If the object is not a pointer, doing so will cause an error. For " 767b9c1b51eSKate Stone "additional details on expression paths, you can type 'help " 768b9c1b51eSKate Stone "expr-path'. \n" 769b9c1b51eSKate Stone "By default, summary strings attempt to display the summary for any " 770b9c1b51eSKate Stone "variable they reference, and if that fails the value. If neither can " 771b9c1b51eSKate Stone "be shown, nothing is displayed." 772b9c1b51eSKate Stone "In a summary string, you can also use an array index [n], or a " 773b9c1b51eSKate Stone "slice-like range [n-m]. This can have two different meanings " 774b9c1b51eSKate Stone "depending on what kind of object the expression" 77582a7d983SEnrico Granata " path refers to:\n" 776b9c1b51eSKate Stone " - if it is a scalar type (any basic type like int, float, ...) the " 777b9c1b51eSKate Stone "expression is a bitfield, i.e. the bits indicated by the indexing " 778b9c1b51eSKate Stone "operator are extracted out of the number" 77982a7d983SEnrico Granata " and displayed as an individual variable\n" 780b9c1b51eSKate Stone " - if it is an array or pointer the array items indicated by the " 781b9c1b51eSKate Stone "indexing operator are shown as the result of the variable. if the " 782b9c1b51eSKate Stone "expression is an array, real array items are" 783b9c1b51eSKate Stone " printed; if it is a pointer, the pointer-as-array syntax is used to " 784b9c1b51eSKate Stone "obtain the values (this means, the latter case can have no range " 785b9c1b51eSKate Stone "checking)\n" 786b9c1b51eSKate Stone "If you are trying to display an array for which the size is known, " 787b9c1b51eSKate Stone "you can also use [] instead of giving an exact range. This has the " 788b9c1b51eSKate Stone "effect of showing items 0 thru size - 1.\n" 789b9c1b51eSKate Stone "Additionally, a variable can contain an (optional) format code, as " 790b9c1b51eSKate Stone "in ${var.x.y%code}, where code can be any of the valid formats " 791b9c1b51eSKate Stone "described in 'help format', or one of the" 7929128ee2fSEnrico Granata " special symbols only allowed as part of a variable:\n" 7939128ee2fSEnrico Granata " %V: show the value of the object by default\n" 7949128ee2fSEnrico Granata " %S: show the summary of the object by default\n" 795b9c1b51eSKate Stone " %@: show the runtime-provided object description (for " 796b9c1b51eSKate Stone "Objective-C, it calls NSPrintForDebugger; for C/C++ it does " 797b9c1b51eSKate Stone "nothing)\n" 798b9c1b51eSKate Stone " %L: show the location of the object (memory address or a " 799b9c1b51eSKate Stone "register name)\n" 8009128ee2fSEnrico Granata " %#: show the number of children of the object\n" 8019128ee2fSEnrico Granata " %T: show the type of the object\n" 802b9c1b51eSKate Stone "Another variable that you can use in summary strings is ${svar . " 803b9c1b51eSKate Stone "This sequence works exactly like ${var, including the fact that " 804b9c1b51eSKate Stone "${*svar is an allowed sequence, but uses" 805b9c1b51eSKate Stone " the object's synthetic children provider instead of the actual " 806b9c1b51eSKate Stone "objects. For instance, if you are using STL synthetic children " 807b9c1b51eSKate Stone "providers, the following summary string would" 8089128ee2fSEnrico Granata " count the number of actual elements stored in an std::list:\n" 8099128ee2fSEnrico Granata "type summary add -s \"${svar%#}\" -x \"std::list<\""; 8109128ee2fSEnrico Granata } 8119128ee2fSEnrico Granata 812b9c1b51eSKate Stone static const char *ExprPathHelpTextCallback() { 813b9c1b51eSKate Stone return "An expression path is the sequence of symbols that is used in C/C++ " 814b9c1b51eSKate Stone "to access a member variable of an aggregate object (class).\n" 8159128ee2fSEnrico Granata "For instance, given a class:\n" 8169128ee2fSEnrico Granata " class foo {\n" 8179128ee2fSEnrico Granata " int a;\n" 8189128ee2fSEnrico Granata " int b; .\n" 8199128ee2fSEnrico Granata " foo* next;\n" 8209128ee2fSEnrico Granata " };\n" 821b9c1b51eSKate Stone "the expression to read item b in the item pointed to by next for foo " 822b9c1b51eSKate Stone "aFoo would be aFoo.next->b.\n" 823b9c1b51eSKate Stone "Given that aFoo could just be any object of type foo, the string " 824b9c1b51eSKate Stone "'.next->b' is the expression path, because it can be attached to any " 825b9c1b51eSKate Stone "foo instance to achieve the effect.\n" 826b9c1b51eSKate Stone "Expression paths in LLDB include dot (.) and arrow (->) operators, " 827b9c1b51eSKate Stone "and most commands using expression paths have ways to also accept " 828b9c1b51eSKate Stone "the star (*) operator.\n" 829b9c1b51eSKate Stone "The meaning of these operators is the same as the usual one given to " 830b9c1b51eSKate Stone "them by the C/C++ standards.\n" 831b9c1b51eSKate Stone "LLDB also has support for indexing ([ ]) in expression paths, and " 832b9c1b51eSKate Stone "extends the traditional meaning of the square brackets operator to " 833b9c1b51eSKate Stone "allow bitfield extraction:\n" 834b9c1b51eSKate Stone "for objects of native types (int, float, char, ...) saying '[n-m]' " 835b9c1b51eSKate Stone "as an expression path (where n and m are any positive integers, e.g. " 836b9c1b51eSKate Stone "[3-5]) causes LLDB to extract" 837b9c1b51eSKate Stone " bits n thru m from the value of the variable. If n == m, [n] is " 838b9c1b51eSKate Stone "also allowed as a shortcut syntax. For arrays and pointers, " 839b9c1b51eSKate Stone "expression paths can only contain one index" 840b9c1b51eSKate Stone " and the meaning of the operation is the same as the one defined by " 841b9c1b51eSKate Stone "C/C++ (item extraction). Some commands extend bitfield-like syntax " 842b9c1b51eSKate Stone "for arrays and pointers with the" 843b9c1b51eSKate Stone " meaning of array slicing (taking elements n thru m inside the array " 844b9c1b51eSKate Stone "or pointed-to memory)."; 8450a3958e0SEnrico Granata } 8460a3958e0SEnrico Granata 847b9c1b51eSKate Stone void CommandObject::FormatLongHelpText(Stream &output_strm, 848b9c1b51eSKate Stone const char *long_help) { 849ea671fbdSKate Stone CommandInterpreter &interpreter = GetCommandInterpreter(); 850ea671fbdSKate Stone std::stringstream lineStream(long_help); 851ea671fbdSKate Stone std::string line; 852ea671fbdSKate Stone while (std::getline(lineStream, line)) { 853ea671fbdSKate Stone if (line.empty()) { 854ea671fbdSKate Stone output_strm << "\n"; 855ea671fbdSKate Stone continue; 856ea671fbdSKate Stone } 857ea671fbdSKate Stone size_t result = line.find_first_not_of(" \t"); 858ea671fbdSKate Stone if (result == std::string::npos) { 859ea671fbdSKate Stone result = 0; 860ea671fbdSKate Stone } 861ea671fbdSKate Stone std::string whitespace_prefix = line.substr(0, result); 862ea671fbdSKate Stone std::string remainder = line.substr(result); 863b9c1b51eSKate Stone interpreter.OutputFormattedHelpText(output_strm, whitespace_prefix.c_str(), 864b9c1b51eSKate Stone remainder.c_str()); 865ea671fbdSKate Stone } 866ea671fbdSKate Stone } 867ea671fbdSKate Stone 868b9c1b51eSKate Stone void CommandObject::GenerateHelpText(CommandReturnObject &result) { 8699b62d1d5SEnrico Granata GenerateHelpText(result.GetOutputStream()); 8709b62d1d5SEnrico Granata 8719b62d1d5SEnrico Granata result.SetStatus(eReturnStatusSuccessFinishNoResult); 8729b62d1d5SEnrico Granata } 8739b62d1d5SEnrico Granata 874b9c1b51eSKate Stone void CommandObject::GenerateHelpText(Stream &output_strm) { 8759b62d1d5SEnrico Granata CommandInterpreter &interpreter = GetCommandInterpreter(); 876b9c1b51eSKate Stone if (WantsRawCommandString()) { 8779b62d1d5SEnrico Granata std::string help_text(GetHelp()); 8787428a18cSKate Stone help_text.append(" Expects 'raw' input (see 'help raw-input'.)"); 879b9c1b51eSKate Stone interpreter.OutputFormattedHelpText(output_strm, "", "", help_text.c_str(), 880b9c1b51eSKate Stone 1); 881b9c1b51eSKate Stone } else 8829b62d1d5SEnrico Granata interpreter.OutputFormattedHelpText(output_strm, "", "", GetHelp(), 1); 8839b62d1d5SEnrico Granata output_strm.Printf("\nSyntax: %s\n", GetSyntax()); 8847428a18cSKate Stone Options *options = GetOptions(); 885b9c1b51eSKate Stone if (options != nullptr) { 886b9c1b51eSKate Stone options->GenerateOptionUsage( 887b9c1b51eSKate Stone output_strm, this, 888b9c1b51eSKate Stone GetCommandInterpreter().GetDebugger().GetTerminalWidth()); 8897428a18cSKate Stone } 8909b62d1d5SEnrico Granata const char *long_help = GetHelpLong(); 891b9c1b51eSKate Stone if ((long_help != nullptr) && (strlen(long_help) > 0)) { 892ea671fbdSKate Stone FormatLongHelpText(output_strm, long_help); 8937428a18cSKate Stone } 894b9c1b51eSKate Stone if (!IsDashDashCommand() && options && options->NumCommandOptions() > 0) { 895b9c1b51eSKate Stone if (WantsRawCommandString() && !WantsCompletion()) { 896b9c1b51eSKate Stone // Emit the message about using ' -- ' between the end of the command 897b9c1b51eSKate Stone // options and the raw input 898b9c1b51eSKate Stone // conditionally, i.e., only if the command object does not want 899b9c1b51eSKate Stone // completion. 9007428a18cSKate Stone interpreter.OutputFormattedHelpText( 9017428a18cSKate Stone output_strm, "", "", 902b9c1b51eSKate Stone "\nImportant Note: Because this command takes 'raw' input, if you " 903b9c1b51eSKate Stone "use any command options" 904b9c1b51eSKate Stone " you must use ' -- ' between the end of the command options and the " 905b9c1b51eSKate Stone "beginning of the raw input.", 9067428a18cSKate Stone 1); 907b9c1b51eSKate Stone } else if (GetNumArgumentEntries() > 0) { 908b9c1b51eSKate Stone // Also emit a warning about using "--" in case you are using a command 909b9c1b51eSKate Stone // that takes options and arguments. 9107428a18cSKate Stone interpreter.OutputFormattedHelpText( 911b9c1b51eSKate Stone output_strm, "", "", 912b9c1b51eSKate Stone "\nThis command takes options and free-form arguments. If your " 913b9c1b51eSKate Stone "arguments resemble" 914b9c1b51eSKate Stone " option specifiers (i.e., they start with a - or --), you must use " 915b9c1b51eSKate Stone "' -- ' between" 9167428a18cSKate Stone " the end of the command options and the beginning of the arguments.", 9177428a18cSKate Stone 1); 9189b62d1d5SEnrico Granata } 9199b62d1d5SEnrico Granata } 920bfb75e9bSEnrico Granata } 9219b62d1d5SEnrico Granata 922b9c1b51eSKate Stone void CommandObject::AddIDsArgumentData(CommandArgumentEntry &arg, 923b9c1b51eSKate Stone CommandArgumentType ID, 924b9c1b51eSKate Stone CommandArgumentType IDRange) { 925184d7a72SJohnny Chen CommandArgumentData id_arg; 926184d7a72SJohnny Chen CommandArgumentData id_range_arg; 927184d7a72SJohnny Chen 928b9c1b51eSKate Stone // Create the first variant for the first (and only) argument for this 929b9c1b51eSKate Stone // command. 930de753464SJohnny Chen id_arg.arg_type = ID; 931184d7a72SJohnny Chen id_arg.arg_repetition = eArgRepeatOptional; 932184d7a72SJohnny Chen 933b9c1b51eSKate Stone // Create the second variant for the first (and only) argument for this 934b9c1b51eSKate Stone // command. 935de753464SJohnny Chen id_range_arg.arg_type = IDRange; 936184d7a72SJohnny Chen id_range_arg.arg_repetition = eArgRepeatOptional; 937184d7a72SJohnny Chen 938b9c1b51eSKate Stone // The first (and only) argument for this command could be either an id or an 939b9c1b51eSKate Stone // id_range. 940184d7a72SJohnny Chen // Push both variants into the entry for the first argument for this command. 941184d7a72SJohnny Chen arg.push_back(id_arg); 942184d7a72SJohnny Chen arg.push_back(id_range_arg); 943184d7a72SJohnny Chen } 944184d7a72SJohnny Chen 945b9c1b51eSKate Stone const char *CommandObject::GetArgumentTypeAsCString( 946b9c1b51eSKate Stone const lldb::CommandArgumentType arg_type) { 947b9c1b51eSKate Stone assert(arg_type < eArgTypeLastArg && 948b9c1b51eSKate Stone "Invalid argument type passed to GetArgumentTypeAsCString"); 9499d0402b1SGreg Clayton return g_arguments_data[arg_type].arg_name; 9509d0402b1SGreg Clayton } 9519d0402b1SGreg Clayton 952b9c1b51eSKate Stone const char *CommandObject::GetArgumentDescriptionAsCString( 953b9c1b51eSKate Stone const lldb::CommandArgumentType arg_type) { 954b9c1b51eSKate Stone assert(arg_type < eArgTypeLastArg && 955b9c1b51eSKate Stone "Invalid argument type passed to GetArgumentDescriptionAsCString"); 9569d0402b1SGreg Clayton return g_arguments_data[arg_type].help_text; 9579d0402b1SGreg Clayton } 9589d0402b1SGreg Clayton 959b9c1b51eSKate Stone Target *CommandObject::GetDummyTarget() { 960893c932aSJim Ingham return m_interpreter.GetDebugger().GetDummyTarget(); 961893c932aSJim Ingham } 962893c932aSJim Ingham 963b9c1b51eSKate Stone Target *CommandObject::GetSelectedOrDummyTarget(bool prefer_dummy) { 96433df7cd3SJim Ingham return m_interpreter.GetDebugger().GetSelectedOrDummyTarget(prefer_dummy); 965893c932aSJim Ingham } 966893c932aSJim Ingham 967b9c1b51eSKate Stone Thread *CommandObject::GetDefaultThread() { 9688d94ba0fSJim Ingham Thread *thread_to_use = m_exe_ctx.GetThreadPtr(); 9698d94ba0fSJim Ingham if (thread_to_use) 9708d94ba0fSJim Ingham return thread_to_use; 9718d94ba0fSJim Ingham 9728d94ba0fSJim Ingham Process *process = m_exe_ctx.GetProcessPtr(); 973b9c1b51eSKate Stone if (!process) { 9748d94ba0fSJim Ingham Target *target = m_exe_ctx.GetTargetPtr(); 975b9c1b51eSKate Stone if (!target) { 9768d94ba0fSJim Ingham target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 9778d94ba0fSJim Ingham } 9788d94ba0fSJim Ingham if (target) 9798d94ba0fSJim Ingham process = target->GetProcessSP().get(); 9808d94ba0fSJim Ingham } 9818d94ba0fSJim Ingham 9828d94ba0fSJim Ingham if (process) 9838d94ba0fSJim Ingham return process->GetThreadList().GetSelectedThread().get(); 9848d94ba0fSJim Ingham else 9858d94ba0fSJim Ingham return nullptr; 9868d94ba0fSJim Ingham } 9878d94ba0fSJim Ingham 988b9c1b51eSKate Stone bool CommandObjectParsed::Execute(const char *args_string, 989b9c1b51eSKate Stone CommandReturnObject &result) { 9905a988416SJim Ingham bool handled = false; 9915a988416SJim Ingham Args cmd_args(args_string); 992b9c1b51eSKate Stone if (HasOverrideCallback()) { 9935a988416SJim Ingham Args full_args(GetCommandName()); 9945a988416SJim Ingham full_args.AppendArguments(cmd_args); 995b9c1b51eSKate Stone handled = 996b9c1b51eSKate Stone InvokeOverrideCallback(full_args.GetConstArgumentVector(), result); 9975a988416SJim Ingham } 998b9c1b51eSKate Stone if (!handled) { 999b9c1b51eSKate Stone for (size_t i = 0; i < cmd_args.GetArgumentCount(); ++i) { 10005a988416SJim Ingham const char *tmp_str = cmd_args.GetArgumentAtIndex(i); 10015a988416SJim Ingham if (tmp_str[0] == '`') // back-quote 1002b9c1b51eSKate Stone cmd_args.ReplaceArgumentAtIndex( 1003*ecbb0bb1SZachary Turner i, llvm::StringRef::withNullAsEmpty( 1004*ecbb0bb1SZachary Turner m_interpreter.ProcessEmbeddedScriptCommands(tmp_str))); 10055a988416SJim Ingham } 10065a988416SJim Ingham 1007b9c1b51eSKate Stone if (CheckRequirements(result)) { 1008b9c1b51eSKate Stone if (ParseOptions(cmd_args, result)) { 1009b9c1b51eSKate Stone // Call the command-specific version of 'Execute', passing it the 1010b9c1b51eSKate Stone // already processed arguments. 10115a988416SJim Ingham handled = DoExecute(cmd_args, result); 10125a988416SJim Ingham } 1013f9fc609fSGreg Clayton } 1014f9fc609fSGreg Clayton 1015f9fc609fSGreg Clayton Cleanup(); 1016f9fc609fSGreg Clayton } 10175a988416SJim Ingham return handled; 10185a988416SJim Ingham } 10195a988416SJim Ingham 1020b9c1b51eSKate Stone bool CommandObjectRaw::Execute(const char *args_string, 1021b9c1b51eSKate Stone CommandReturnObject &result) { 10225a988416SJim Ingham bool handled = false; 1023b9c1b51eSKate Stone if (HasOverrideCallback()) { 10245a988416SJim Ingham std::string full_command(GetCommandName()); 10255a988416SJim Ingham full_command += ' '; 10265a988416SJim Ingham full_command += args_string; 1027d78c9576SEd Maste const char *argv[2] = {nullptr, nullptr}; 10285a988416SJim Ingham argv[0] = full_command.c_str(); 10293b652621SJim Ingham handled = InvokeOverrideCallback(argv, result); 10305a988416SJim Ingham } 1031b9c1b51eSKate Stone if (!handled) { 1032f9fc609fSGreg Clayton if (CheckRequirements(result)) 10335a988416SJim Ingham handled = DoExecute(args_string, result); 1034f9fc609fSGreg Clayton 1035f9fc609fSGreg Clayton Cleanup(); 10365a988416SJim Ingham } 10375a988416SJim Ingham return handled; 10385a988416SJim Ingham } 10395a988416SJim Ingham 1040b9c1b51eSKate Stone static const char *arch_helper() { 1041d70b14eaSGreg Clayton static StreamString g_archs_help; 1042b9c1b51eSKate Stone if (g_archs_help.Empty()) { 1043ca7835c6SJohnny Chen StringList archs; 1044d78c9576SEd Maste ArchSpec::AutoComplete(nullptr, archs); 1045d70b14eaSGreg Clayton g_archs_help.Printf("These are the supported architecture names:\n"); 1046797a1b37SJohnny Chen archs.Join("\n", g_archs_help); 1047d70b14eaSGreg Clayton } 1048d70b14eaSGreg Clayton return g_archs_help.GetData(); 1049ca7835c6SJohnny Chen } 1050ca7835c6SJohnny Chen 10517428a18cSKate Stone CommandObject::ArgumentTableEntry CommandObject::g_arguments_data[] = { 10527428a18cSKate Stone // clang-format off 1053d78c9576SEd Maste { eArgTypeAddress, "address", CommandCompletions::eNoCompletion, { nullptr, false }, "A valid address in the target program's execution space." }, 1054d78c9576SEd Maste { eArgTypeAddressOrExpression, "address-expression", CommandCompletions::eNoCompletion, { nullptr, false }, "An expression that resolves to an address." }, 1055d78c9576SEd Maste { eArgTypeAliasName, "alias-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of an abbreviation (alias) for a debugger command." }, 1056d78c9576SEd Maste { eArgTypeAliasOptions, "options-for-aliased-command", CommandCompletions::eNoCompletion, { nullptr, false }, "Command options to be used as part of an alias (abbreviation) definition. (See 'help commands alias' for more information.)" }, 1057ca7835c6SJohnny Chen { eArgTypeArchitecture, "arch", CommandCompletions::eArchitectureCompletion, { arch_helper, true }, "The architecture name, e.g. i386 or x86_64." }, 1058d78c9576SEd Maste { eArgTypeBoolean, "boolean", CommandCompletions::eNoCompletion, { nullptr, false }, "A Boolean value: 'true' or 'false'" }, 1059d78c9576SEd Maste { eArgTypeBreakpointID, "breakpt-id", CommandCompletions::eNoCompletion, { BreakpointIDHelpTextCallback, false }, nullptr }, 1060d78c9576SEd Maste { eArgTypeBreakpointIDRange, "breakpt-id-list", CommandCompletions::eNoCompletion, { BreakpointIDRangeHelpTextCallback, false }, nullptr }, 10615e09c8c3SJim Ingham { eArgTypeBreakpointName, "breakpoint-name", CommandCompletions::eNoCompletion, { BreakpointNameHelpTextCallback, false }, nullptr }, 1062d78c9576SEd Maste { eArgTypeByteSize, "byte-size", CommandCompletions::eNoCompletion, { nullptr, false }, "Number of bytes to use." }, 1063d78c9576SEd Maste { eArgTypeClassName, "class-name", CommandCompletions::eNoCompletion, { nullptr, false }, "Then name of a class from the debug information in the program." }, 1064d78c9576SEd Maste { eArgTypeCommandName, "cmd-name", CommandCompletions::eNoCompletion, { nullptr, false }, "A debugger command (may be multiple words), without any options or arguments." }, 1065d78c9576SEd Maste { eArgTypeCount, "count", CommandCompletions::eNoCompletion, { nullptr, false }, "An unsigned integer." }, 1066d78c9576SEd Maste { eArgTypeDirectoryName, "directory", CommandCompletions::eDiskDirectoryCompletion, { nullptr, false }, "A directory name." }, 1067d78c9576SEd Maste { eArgTypeDisassemblyFlavor, "disassembly-flavor", CommandCompletions::eNoCompletion, { nullptr, false }, "A disassembly flavor recognized by your disassembly plugin. Currently the only valid options are \"att\" and \"intel\" for Intel targets" }, 1068d78c9576SEd Maste { eArgTypeDescriptionVerbosity, "description-verbosity", CommandCompletions::eNoCompletion, { nullptr, false }, "How verbose the output of 'po' should be." }, 1069d78c9576SEd Maste { eArgTypeEndAddress, "end-address", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, 1070d78c9576SEd Maste { eArgTypeExpression, "expr", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, 1071d78c9576SEd Maste { eArgTypeExpressionPath, "expr-path", CommandCompletions::eNoCompletion, { ExprPathHelpTextCallback, true }, nullptr }, 1072d78c9576SEd Maste { eArgTypeExprFormat, "expression-format", CommandCompletions::eNoCompletion, { nullptr, false }, "[ [bool|b] | [bin] | [char|c] | [oct|o] | [dec|i|d|u] | [hex|x] | [float|f] | [cstr|s] ]" }, 1073d78c9576SEd Maste { eArgTypeFilename, "filename", CommandCompletions::eDiskFileCompletion, { nullptr, false }, "The name of a file (can include path)." }, 1074d78c9576SEd Maste { eArgTypeFormat, "format", CommandCompletions::eNoCompletion, { FormatHelpTextCallback, true }, nullptr }, 1075d78c9576SEd Maste { eArgTypeFrameIndex, "frame-index", CommandCompletions::eNoCompletion, { nullptr, false }, "Index into a thread's list of frames." }, 1076d78c9576SEd Maste { eArgTypeFullName, "fullname", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, 1077d78c9576SEd Maste { eArgTypeFunctionName, "function-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a function." }, 1078d78c9576SEd Maste { eArgTypeFunctionOrSymbol, "function-or-symbol", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a function or symbol." }, 1079d78c9576SEd Maste { eArgTypeGDBFormat, "gdb-format", CommandCompletions::eNoCompletion, { GDBFormatHelpTextCallback, true }, nullptr }, 1080735152e3SEnrico Granata { eArgTypeHelpText, "help-text", CommandCompletions::eNoCompletion, { nullptr, false }, "Text to be used as help for some other entity in LLDB" }, 1081d78c9576SEd Maste { eArgTypeIndex, "index", CommandCompletions::eNoCompletion, { nullptr, false }, "An index into a list." }, 10827a67ee26SEnrico Granata { eArgTypeLanguage, "source-language", CommandCompletions::eNoCompletion, { LanguageTypeHelpTextCallback, true }, nullptr }, 1083d78c9576SEd Maste { eArgTypeLineNum, "linenum", CommandCompletions::eNoCompletion, { nullptr, false }, "Line number in a source file." }, 1084d78c9576SEd Maste { eArgTypeLogCategory, "log-category", CommandCompletions::eNoCompletion, { nullptr, 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." }, 1085d78c9576SEd Maste { eArgTypeLogChannel, "log-channel", CommandCompletions::eNoCompletion, { nullptr, 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)." }, 1086d78c9576SEd Maste { eArgTypeMethod, "method", CommandCompletions::eNoCompletion, { nullptr, false }, "A C++ method name." }, 1087d78c9576SEd Maste { eArgTypeName, "name", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, 1088d78c9576SEd Maste { eArgTypeNewPathPrefix, "new-path-prefix", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, 1089d78c9576SEd Maste { eArgTypeNumLines, "num-lines", CommandCompletions::eNoCompletion, { nullptr, false }, "The number of lines to use." }, 1090d78c9576SEd Maste { eArgTypeNumberPerLine, "number-per-line", CommandCompletions::eNoCompletion, { nullptr, false }, "The number of items per line to display." }, 1091d78c9576SEd Maste { eArgTypeOffset, "offset", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, 1092d78c9576SEd Maste { eArgTypeOldPathPrefix, "old-path-prefix", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, 1093d78c9576SEd Maste { eArgTypeOneLiner, "one-line-command", CommandCompletions::eNoCompletion, { nullptr, false }, "A command that is entered as a single line of text." }, 1094d78c9576SEd Maste { eArgTypePath, "path", CommandCompletions::eDiskFileCompletion, { nullptr, false }, "Path." }, 1095d78c9576SEd Maste { eArgTypePermissionsNumber, "perms-numeric", CommandCompletions::eNoCompletion, { nullptr, false }, "Permissions given as an octal number (e.g. 755)." }, 1096d78c9576SEd Maste { eArgTypePermissionsString, "perms=string", CommandCompletions::eNoCompletion, { nullptr, false }, "Permissions given as a string value (e.g. rw-r-xr--)." }, 1097d78c9576SEd Maste { eArgTypePid, "pid", CommandCompletions::eNoCompletion, { nullptr, false }, "The process ID number." }, 1098d78c9576SEd Maste { eArgTypePlugin, "plugin", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, 1099d78c9576SEd Maste { eArgTypeProcessName, "process-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of the process." }, 1100d78c9576SEd Maste { eArgTypePythonClass, "python-class", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a Python class." }, 1101d78c9576SEd Maste { eArgTypePythonFunction, "python-function", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a Python function." }, 1102d78c9576SEd Maste { eArgTypePythonScript, "python-script", CommandCompletions::eNoCompletion, { nullptr, false }, "Source code written in Python." }, 1103d78c9576SEd Maste { eArgTypeQueueName, "queue-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of the thread queue." }, 1104d78c9576SEd Maste { eArgTypeRegisterName, "register-name", CommandCompletions::eNoCompletion, { RegisterNameHelpTextCallback, true }, nullptr }, 1105d78c9576SEd Maste { eArgTypeRegularExpression, "regular-expression", CommandCompletions::eNoCompletion, { nullptr, false }, "A regular expression." }, 1106d78c9576SEd Maste { eArgTypeRunArgs, "run-args", CommandCompletions::eNoCompletion, { nullptr, false }, "Arguments to be passed to the target program when it starts executing." }, 1107d78c9576SEd Maste { eArgTypeRunMode, "run-mode", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, 1108d78c9576SEd Maste { eArgTypeScriptedCommandSynchronicity, "script-cmd-synchronicity", CommandCompletions::eNoCompletion, { nullptr, false }, "The synchronicity to use to run scripted commands with regard to LLDB event system." }, 1109d78c9576SEd Maste { eArgTypeScriptLang, "script-language", CommandCompletions::eNoCompletion, { nullptr, false }, "The scripting language to be used for script-based commands. Currently only Python is valid." }, 11107428a18cSKate Stone { eArgTypeSearchWord, "search-word", CommandCompletions::eNoCompletion, { nullptr, false }, "Any word of interest for search purposes." }, 1111d78c9576SEd Maste { eArgTypeSelector, "selector", CommandCompletions::eNoCompletion, { nullptr, false }, "An Objective-C selector name." }, 1112d78c9576SEd Maste { eArgTypeSettingIndex, "setting-index", CommandCompletions::eNoCompletion, { nullptr, false }, "An index into a settings variable that is an array (try 'settings list' to see all the possible settings variables and their types)." }, 1113d78c9576SEd Maste { eArgTypeSettingKey, "setting-key", CommandCompletions::eNoCompletion, { nullptr, false }, "A key into a settings variables that is a dictionary (try 'settings list' to see all the possible settings variables and their types)." }, 1114d78c9576SEd Maste { eArgTypeSettingPrefix, "setting-prefix", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a settable internal debugger variable up to a dot ('.'), e.g. 'target.process.'" }, 1115d78c9576SEd Maste { eArgTypeSettingVariableName, "setting-variable-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a settable internal debugger variable. Type 'settings list' to see a complete list of such variables." }, 1116d78c9576SEd Maste { eArgTypeShlibName, "shlib-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a shared library." }, 1117d78c9576SEd Maste { eArgTypeSourceFile, "source-file", CommandCompletions::eSourceFileCompletion, { nullptr, false }, "The name of a source file.." }, 1118d78c9576SEd Maste { eArgTypeSortOrder, "sort-order", CommandCompletions::eNoCompletion, { nullptr, false }, "Specify a sort order when dumping lists." }, 1119d78c9576SEd Maste { eArgTypeStartAddress, "start-address", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, 1120d78c9576SEd Maste { eArgTypeSummaryString, "summary-string", CommandCompletions::eNoCompletion, { SummaryStringHelpTextCallback, true }, nullptr }, 1121d78c9576SEd Maste { eArgTypeSymbol, "symbol", CommandCompletions::eSymbolCompletion, { nullptr, false }, "Any symbol name (function name, variable, argument, etc.)" }, 1122d78c9576SEd Maste { eArgTypeThreadID, "thread-id", CommandCompletions::eNoCompletion, { nullptr, false }, "Thread ID number." }, 1123d78c9576SEd Maste { eArgTypeThreadIndex, "thread-index", CommandCompletions::eNoCompletion, { nullptr, false }, "Index into the process' list of threads." }, 1124d78c9576SEd Maste { eArgTypeThreadName, "thread-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The thread's name." }, 1125a72b31c7SJim Ingham { eArgTypeTypeName, "type-name", CommandCompletions::eNoCompletion, { nullptr, false }, "A type name." }, 1126d78c9576SEd Maste { eArgTypeUnsignedInteger, "unsigned-integer", CommandCompletions::eNoCompletion, { nullptr, false }, "An unsigned integer." }, 1127d78c9576SEd Maste { eArgTypeUnixSignal, "unix-signal", CommandCompletions::eNoCompletion, { nullptr, false }, "A valid Unix signal name or number (e.g. SIGKILL, KILL or 9)." }, 1128d78c9576SEd Maste { eArgTypeVarName, "variable-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a variable in your program." }, 1129d78c9576SEd Maste { eArgTypeValue, "value", CommandCompletions::eNoCompletion, { nullptr, false }, "A value could be anything, depending on where and how it is used." }, 1130d78c9576SEd Maste { eArgTypeWidth, "width", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, 1131d78c9576SEd Maste { eArgTypeNone, "none", CommandCompletions::eNoCompletion, { nullptr, false }, "No help available for this." }, 1132d78c9576SEd Maste { eArgTypePlatform, "platform-name", CommandCompletions::ePlatformPluginCompletion, { nullptr, false }, "The name of an installed platform plug-in . Type 'platform list' to see a complete list of installed platforms." }, 1133d78c9576SEd Maste { eArgTypeWatchpointID, "watchpt-id", CommandCompletions::eNoCompletion, { nullptr, false }, "Watchpoint IDs are positive integers." }, 1134d78c9576SEd Maste { eArgTypeWatchpointIDRange, "watchpt-id-list", CommandCompletions::eNoCompletion, { nullptr, false }, "For example, '1-3' or '1 to 3'." }, 11357428a18cSKate Stone { eArgTypeWatchType, "watch-type", CommandCompletions::eNoCompletion, { nullptr, false }, "Specify the type for a watchpoint." }, 11367428a18cSKate Stone { eArgRawInput, "raw-input", CommandCompletions::eNoCompletion, { nullptr, false }, "Free-form text passed to a command without prior interpretation, allowing spaces without requiring quotes. To pass arguments and free form text put two dashes ' -- ' between the last argument and any raw input." } 11377428a18cSKate Stone // clang-format on 1138e139cf23SCaroline Tice }; 1139e139cf23SCaroline Tice 1140b9c1b51eSKate Stone const CommandObject::ArgumentTableEntry *CommandObject::GetArgumentTable() { 1141b9c1b51eSKate Stone // If this assertion fires, then the table above is out of date with the 1142b9c1b51eSKate Stone // CommandArgumentType enumeration 1143b9c1b51eSKate Stone assert((sizeof(CommandObject::g_arguments_data) / 1144b9c1b51eSKate Stone sizeof(CommandObject::ArgumentTableEntry)) == eArgTypeLastArg); 1145e139cf23SCaroline Tice return CommandObject::g_arguments_data; 1146e139cf23SCaroline Tice } 1147