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" 2730fdc8d8SChris Lattner #include "lldb/Target/Process.h" 2830fdc8d8SChris Lattner #include "lldb/Target/Target.h" 295713a05bSZachary Turner #include "lldb/Utility/FileSpec.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 43a449698cSZachary Turner CommandObject::CommandObject(CommandInterpreter &interpreter, llvm::StringRef name, 44a449698cSZachary Turner llvm::StringRef help, llvm::StringRef syntax, uint32_t flags) 45a449698cSZachary Turner : m_interpreter(interpreter), m_cmd_name(name), 46b9c1b51eSKate Stone m_cmd_help_short(), m_cmd_help_long(), m_cmd_syntax(), m_flags(flags), 47b9c1b51eSKate Stone m_arguments(), m_deprecated_command_override_callback(nullptr), 48b9c1b51eSKate Stone m_command_override_callback(nullptr), m_command_override_baton(nullptr) { 4930fdc8d8SChris Lattner m_cmd_help_short = help; 5030fdc8d8SChris Lattner m_cmd_syntax = syntax; 5130fdc8d8SChris Lattner } 5230fdc8d8SChris Lattner 53b9c1b51eSKate Stone CommandObject::~CommandObject() {} 5430fdc8d8SChris Lattner 55442f6530SZachary Turner llvm::StringRef CommandObject::GetHelp() { return m_cmd_help_short; } 5630fdc8d8SChris Lattner 57442f6530SZachary Turner llvm::StringRef CommandObject::GetHelpLong() { return m_cmd_help_long; } 5830fdc8d8SChris Lattner 59442f6530SZachary Turner llvm::StringRef CommandObject::GetSyntax() { 607cff7d46SEugene Zemtsov if (!m_cmd_syntax.empty()) 61442f6530SZachary Turner return m_cmd_syntax; 62442f6530SZachary Turner 63e139cf23SCaroline Tice StreamString syntax_str; 64442f6530SZachary Turner syntax_str.PutCString(GetCommandName()); 65442f6530SZachary Turner 66bef55ac8SEnrico Granata if (!IsDashDashCommand() && GetOptions() != nullptr) 67442f6530SZachary Turner syntax_str.PutCString(" <cmd-options>"); 68442f6530SZachary Turner 69442f6530SZachary Turner if (!m_arguments.empty()) { 70442f6530SZachary Turner syntax_str.PutCString(" "); 71442f6530SZachary Turner 72b9c1b51eSKate Stone if (!IsDashDashCommand() && WantsRawCommandString() && GetOptions() && 73b9c1b51eSKate Stone GetOptions()->NumCommandOptions()) 74442f6530SZachary Turner syntax_str.PutCString("-- "); 75e139cf23SCaroline Tice GetFormattedCommandArguments(syntax_str); 76e139cf23SCaroline Tice } 77c156427dSZachary Turner m_cmd_syntax = syntax_str.GetString(); 78e139cf23SCaroline Tice 79442f6530SZachary Turner return m_cmd_syntax; 8030fdc8d8SChris Lattner } 8130fdc8d8SChris Lattner 82a449698cSZachary Turner llvm::StringRef CommandObject::GetCommandName() const { return m_cmd_name; } 8330fdc8d8SChris Lattner 84442f6530SZachary Turner void CommandObject::SetCommandName(llvm::StringRef name) { m_cmd_name = name; } 8530fdc8d8SChris Lattner 86442f6530SZachary Turner void CommandObject::SetHelp(llvm::StringRef str) { m_cmd_help_short = str; } 876f79bb2dSEnrico Granata 88442f6530SZachary Turner void CommandObject::SetHelpLong(llvm::StringRef str) { m_cmd_help_long = str; } 8999f0b8f9SEnrico Granata 90442f6530SZachary Turner void CommandObject::SetSyntax(llvm::StringRef str) { m_cmd_syntax = str; } 9130fdc8d8SChris Lattner 92b9c1b51eSKate Stone Options *CommandObject::GetOptions() { 9330fdc8d8SChris Lattner // By default commands don't have options unless this virtual function 9430fdc8d8SChris Lattner // is overridden by base classes. 95d78c9576SEd Maste return nullptr; 9630fdc8d8SChris Lattner } 9730fdc8d8SChris Lattner 98b9c1b51eSKate Stone bool CommandObject::ParseOptions(Args &args, CommandReturnObject &result) { 9930fdc8d8SChris Lattner // See if the subclass has options? 10030fdc8d8SChris Lattner Options *options = GetOptions(); 101b9c1b51eSKate Stone if (options != nullptr) { 10297206d57SZachary Turner Status error; 103e1cfbc79STodd Fiala 104e1cfbc79STodd Fiala auto exe_ctx = GetCommandInterpreter().GetExecutionContext(); 105e1cfbc79STodd Fiala options->NotifyOptionParsingStarting(&exe_ctx); 10630fdc8d8SChris Lattner 107b9c1b51eSKate Stone // ParseOptions calls getopt_long_only, which always skips the zero'th item 108b9c1b51eSKate Stone // in the array and starts at position 1, 10930fdc8d8SChris Lattner // so we need to push a dummy value into position zero. 1105c725f3aSZachary Turner args.Unshift(llvm::StringRef("dummy_string")); 111e1cfbc79STodd Fiala const bool require_validation = true; 112e1cfbc79STodd Fiala error = args.ParseOptions(*options, &exe_ctx, 113e1cfbc79STodd Fiala GetCommandInterpreter().GetPlatform(true), 114e1cfbc79STodd Fiala require_validation); 11530fdc8d8SChris Lattner 11630fdc8d8SChris Lattner // The "dummy_string" will have already been removed by ParseOptions, 11730fdc8d8SChris Lattner // so no need to remove it. 11830fdc8d8SChris Lattner 119f6b8b581SGreg Clayton if (error.Success()) 120e1cfbc79STodd Fiala error = options->NotifyOptionParsingFinished(&exe_ctx); 121f6b8b581SGreg Clayton 122b9c1b51eSKate Stone if (error.Success()) { 123f6b8b581SGreg Clayton if (options->VerifyOptions(result)) 124f6b8b581SGreg Clayton return true; 125b9c1b51eSKate Stone } else { 12630fdc8d8SChris Lattner const char *error_cstr = error.AsCString(); 127b9c1b51eSKate Stone if (error_cstr) { 12830fdc8d8SChris Lattner // We got an error string, lets use that 12986edbf41SGreg Clayton result.AppendError(error_cstr); 130b9c1b51eSKate Stone } else { 13130fdc8d8SChris Lattner // No error string, output the usage information into result 132b9c1b51eSKate Stone options->GenerateOptionUsage( 133b9c1b51eSKate Stone result.GetErrorStream(), this, 134b9c1b51eSKate Stone GetCommandInterpreter().GetDebugger().GetTerminalWidth()); 13530fdc8d8SChris Lattner } 136f6b8b581SGreg Clayton } 13730fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 13830fdc8d8SChris Lattner return false; 13930fdc8d8SChris Lattner } 14030fdc8d8SChris Lattner return true; 14130fdc8d8SChris Lattner } 14230fdc8d8SChris Lattner 143b9c1b51eSKate Stone bool CommandObject::CheckRequirements(CommandReturnObject &result) { 144f9fc609fSGreg Clayton #ifdef LLDB_CONFIGURATION_DEBUG 145f9fc609fSGreg Clayton // Nothing should be stored in m_exe_ctx between running commands as m_exe_ctx 146f9fc609fSGreg Clayton // has shared pointers to the target, process, thread and frame and we don't 147f9fc609fSGreg Clayton // want any CommandObject instances to keep any of these objects around 148f9fc609fSGreg Clayton // longer than for a single command. Every command should call 149f9fc609fSGreg Clayton // CommandObject::Cleanup() after it has completed 150f9fc609fSGreg Clayton assert(m_exe_ctx.GetTargetPtr() == NULL); 151f9fc609fSGreg Clayton assert(m_exe_ctx.GetProcessPtr() == NULL); 152f9fc609fSGreg Clayton assert(m_exe_ctx.GetThreadPtr() == NULL); 153f9fc609fSGreg Clayton assert(m_exe_ctx.GetFramePtr() == NULL); 154f9fc609fSGreg Clayton #endif 155f9fc609fSGreg Clayton 156f9fc609fSGreg Clayton // Lock down the interpreter's execution context prior to running the 157f9fc609fSGreg Clayton // command so we guarantee the selected target, process, thread and frame 158f9fc609fSGreg Clayton // can't go away during the execution 159f9fc609fSGreg Clayton m_exe_ctx = m_interpreter.GetExecutionContext(); 160f9fc609fSGreg Clayton 161f9fc609fSGreg Clayton const uint32_t flags = GetFlags().Get(); 162b9c1b51eSKate Stone if (flags & (eCommandRequiresTarget | eCommandRequiresProcess | 163b9c1b51eSKate Stone eCommandRequiresThread | eCommandRequiresFrame | 164b9c1b51eSKate Stone eCommandTryTargetAPILock)) { 165f9fc609fSGreg Clayton 166b9c1b51eSKate Stone if ((flags & eCommandRequiresTarget) && !m_exe_ctx.HasTargetScope()) { 167f9fc609fSGreg Clayton result.AppendError(GetInvalidTargetDescription()); 168f9fc609fSGreg Clayton return false; 169f9fc609fSGreg Clayton } 170f9fc609fSGreg Clayton 171b9c1b51eSKate Stone if ((flags & eCommandRequiresProcess) && !m_exe_ctx.HasProcessScope()) { 172e59b0d2cSJason Molenda if (!m_exe_ctx.HasTargetScope()) 173e59b0d2cSJason Molenda result.AppendError(GetInvalidTargetDescription()); 174e59b0d2cSJason Molenda else 175f9fc609fSGreg Clayton result.AppendError(GetInvalidProcessDescription()); 176f9fc609fSGreg Clayton return false; 177f9fc609fSGreg Clayton } 178f9fc609fSGreg Clayton 179b9c1b51eSKate Stone if ((flags & eCommandRequiresThread) && !m_exe_ctx.HasThreadScope()) { 180e59b0d2cSJason Molenda if (!m_exe_ctx.HasTargetScope()) 181e59b0d2cSJason Molenda result.AppendError(GetInvalidTargetDescription()); 182e59b0d2cSJason Molenda else if (!m_exe_ctx.HasProcessScope()) 183e59b0d2cSJason Molenda result.AppendError(GetInvalidProcessDescription()); 184e59b0d2cSJason Molenda else 185f9fc609fSGreg Clayton result.AppendError(GetInvalidThreadDescription()); 186f9fc609fSGreg Clayton return false; 187f9fc609fSGreg Clayton } 188f9fc609fSGreg Clayton 189b9c1b51eSKate Stone if ((flags & eCommandRequiresFrame) && !m_exe_ctx.HasFrameScope()) { 190e59b0d2cSJason Molenda if (!m_exe_ctx.HasTargetScope()) 191e59b0d2cSJason Molenda result.AppendError(GetInvalidTargetDescription()); 192e59b0d2cSJason Molenda else if (!m_exe_ctx.HasProcessScope()) 193e59b0d2cSJason Molenda result.AppendError(GetInvalidProcessDescription()); 194e59b0d2cSJason Molenda else if (!m_exe_ctx.HasThreadScope()) 195e59b0d2cSJason Molenda result.AppendError(GetInvalidThreadDescription()); 196e59b0d2cSJason Molenda else 197f9fc609fSGreg Clayton result.AppendError(GetInvalidFrameDescription()); 198f9fc609fSGreg Clayton return false; 199f9fc609fSGreg Clayton } 200f9fc609fSGreg Clayton 201b9c1b51eSKate Stone if ((flags & eCommandRequiresRegContext) && 202b9c1b51eSKate Stone (m_exe_ctx.GetRegisterContext() == nullptr)) { 203f9fc609fSGreg Clayton result.AppendError(GetInvalidRegContextDescription()); 204f9fc609fSGreg Clayton return false; 205f9fc609fSGreg Clayton } 206f9fc609fSGreg Clayton 207b9c1b51eSKate Stone if (flags & eCommandTryTargetAPILock) { 208f9fc609fSGreg Clayton Target *target = m_exe_ctx.GetTargetPtr(); 209f9fc609fSGreg Clayton if (target) 210b9c1b51eSKate Stone m_api_locker = 211b9c1b51eSKate Stone std::unique_lock<std::recursive_mutex>(target->GetAPIMutex()); 212f9fc609fSGreg Clayton } 213f9fc609fSGreg Clayton } 214f9fc609fSGreg Clayton 215b9c1b51eSKate Stone if (GetFlags().AnySet(eCommandProcessMustBeLaunched | 216b9c1b51eSKate Stone eCommandProcessMustBePaused)) { 217c14ee32dSGreg Clayton Process *process = m_interpreter.GetExecutionContext().GetProcessPtr(); 218b9c1b51eSKate Stone if (process == nullptr) { 219b8e8a5f3SJim Ingham // A process that is not running is considered paused. 220b9c1b51eSKate Stone if (GetFlags().Test(eCommandProcessMustBeLaunched)) { 22130fdc8d8SChris Lattner result.AppendError("Process must exist."); 22230fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 22330fdc8d8SChris Lattner return false; 22430fdc8d8SChris Lattner } 225b9c1b51eSKate Stone } else { 22630fdc8d8SChris Lattner StateType state = process->GetState(); 227b9c1b51eSKate Stone switch (state) { 2287a5388bfSGreg Clayton case eStateInvalid: 22930fdc8d8SChris Lattner case eStateSuspended: 23030fdc8d8SChris Lattner case eStateCrashed: 23130fdc8d8SChris Lattner case eStateStopped: 23230fdc8d8SChris Lattner break; 23330fdc8d8SChris Lattner 234b766a73dSGreg Clayton case eStateConnected: 235b766a73dSGreg Clayton case eStateAttaching: 236b766a73dSGreg Clayton case eStateLaunching: 23730fdc8d8SChris Lattner case eStateDetached: 23830fdc8d8SChris Lattner case eStateExited: 23930fdc8d8SChris Lattner case eStateUnloaded: 240b9c1b51eSKate Stone if (GetFlags().Test(eCommandProcessMustBeLaunched)) { 24130fdc8d8SChris Lattner result.AppendError("Process must be launched."); 24230fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 24330fdc8d8SChris Lattner return false; 24430fdc8d8SChris Lattner } 24530fdc8d8SChris Lattner break; 24630fdc8d8SChris Lattner 24730fdc8d8SChris Lattner case eStateRunning: 24830fdc8d8SChris Lattner case eStateStepping: 249b9c1b51eSKate Stone if (GetFlags().Test(eCommandProcessMustBePaused)) { 250b9c1b51eSKate Stone result.AppendError("Process is running. Use 'process interrupt' to " 251b9c1b51eSKate Stone "pause execution."); 25230fdc8d8SChris Lattner result.SetStatus(eReturnStatusFailed); 25330fdc8d8SChris Lattner return false; 25430fdc8d8SChris Lattner } 25530fdc8d8SChris Lattner } 25630fdc8d8SChris Lattner } 257b766a73dSGreg Clayton } 2585a988416SJim Ingham return true; 25930fdc8d8SChris Lattner } 26030fdc8d8SChris Lattner 261b9c1b51eSKate Stone void CommandObject::Cleanup() { 262f9fc609fSGreg Clayton m_exe_ctx.Clear(); 263bb19a13cSSaleem Abdulrasool if (m_api_locker.owns_lock()) 264bb19a13cSSaleem Abdulrasool m_api_locker.unlock(); 265f9fc609fSGreg Clayton } 266f9fc609fSGreg Clayton 267b9c1b51eSKate Stone int CommandObject::HandleCompletion(Args &input, int &cursor_index, 26830fdc8d8SChris Lattner int &cursor_char_position, 26930fdc8d8SChris Lattner int match_start_point, 27030fdc8d8SChris Lattner int max_return_elements, 271b9c1b51eSKate Stone bool &word_complete, StringList &matches) { 272e171da5cSBruce Mitchener // Default implementation of WantsCompletion() is !WantsRawCommandString(). 2736561d15dSJohnny Chen // Subclasses who want raw command string but desire, for example, 2746561d15dSJohnny Chen // argument completion should override WantsCompletion() to return true, 2756561d15dSJohnny Chen // instead. 276b9c1b51eSKate Stone if (WantsRawCommandString() && !WantsCompletion()) { 277b9c1b51eSKate Stone // FIXME: Abstract telling the completion to insert the completion 278b9c1b51eSKate Stone // character. 27930fdc8d8SChris Lattner matches.Clear(); 28030fdc8d8SChris Lattner return -1; 281b9c1b51eSKate Stone } else { 28230fdc8d8SChris Lattner // Can we do anything generic with the options? 28330fdc8d8SChris Lattner Options *cur_options = GetOptions(); 28430fdc8d8SChris Lattner CommandReturnObject result; 28530fdc8d8SChris Lattner OptionElementVector opt_element_vector; 28630fdc8d8SChris Lattner 287b9c1b51eSKate Stone if (cur_options != nullptr) { 28830fdc8d8SChris Lattner // Re-insert the dummy command name string which will have been 28930fdc8d8SChris Lattner // stripped off: 2905c725f3aSZachary Turner input.Unshift(llvm::StringRef("dummy-string")); 29130fdc8d8SChris Lattner cursor_index++; 29230fdc8d8SChris Lattner 293b9c1b51eSKate Stone // I stick an element on the end of the input, because if the last element 294ecbb0bb1SZachary Turner // is option that requires an argument, getopt_long_only will freak out. 29530fdc8d8SChris Lattner 296ecbb0bb1SZachary Turner input.AppendArgument(llvm::StringRef("<FAKE-VALUE>")); 29730fdc8d8SChris Lattner 298b9c1b51eSKate Stone input.ParseArgsForCompletion(*cur_options, opt_element_vector, 299b9c1b51eSKate Stone cursor_index); 30030fdc8d8SChris Lattner 30130fdc8d8SChris Lattner input.DeleteArgumentAtIndex(input.GetArgumentCount() - 1); 30230fdc8d8SChris Lattner 30330fdc8d8SChris Lattner bool handled_by_options; 304b9c1b51eSKate Stone handled_by_options = cur_options->HandleOptionCompletion( 305b9c1b51eSKate Stone input, opt_element_vector, cursor_index, cursor_char_position, 306b9c1b51eSKate Stone match_start_point, max_return_elements, GetCommandInterpreter(), 307b9c1b51eSKate Stone word_complete, matches); 30830fdc8d8SChris Lattner if (handled_by_options) 30930fdc8d8SChris Lattner return matches.GetSize(); 31030fdc8d8SChris Lattner } 31130fdc8d8SChris Lattner 31230fdc8d8SChris Lattner // If we got here, the last word is not an option or an option argument. 313b9c1b51eSKate Stone return HandleArgumentCompletion( 314b9c1b51eSKate Stone input, cursor_index, cursor_char_position, opt_element_vector, 315b9c1b51eSKate Stone match_start_point, max_return_elements, word_complete, matches); 31630fdc8d8SChris Lattner } 31730fdc8d8SChris Lattner } 31830fdc8d8SChris Lattner 31998896839SZachary Turner bool CommandObject::HelpTextContainsWord(llvm::StringRef search_word, 320d033e1ceSEnrico Granata bool search_short_help, 321d033e1ceSEnrico Granata bool search_long_help, 322d033e1ceSEnrico Granata bool search_syntax, 323b9c1b51eSKate Stone bool search_options) { 32430fdc8d8SChris Lattner std::string options_usage_help; 32530fdc8d8SChris Lattner 32630fdc8d8SChris Lattner bool found_word = false; 32730fdc8d8SChris Lattner 328442f6530SZachary Turner llvm::StringRef short_help = GetHelp(); 329442f6530SZachary Turner llvm::StringRef long_help = GetHelpLong(); 330442f6530SZachary Turner llvm::StringRef syntax_help = GetSyntax(); 33130fdc8d8SChris Lattner 332442f6530SZachary Turner if (search_short_help && short_help.contains_lower(search_word)) 33330fdc8d8SChris Lattner found_word = true; 334442f6530SZachary Turner else if (search_long_help && long_help.contains_lower(search_word)) 33530fdc8d8SChris Lattner found_word = true; 336442f6530SZachary Turner else if (search_syntax && syntax_help.contains_lower(search_word)) 33730fdc8d8SChris Lattner found_word = true; 33830fdc8d8SChris Lattner 339b9c1b51eSKate Stone if (!found_word && search_options && GetOptions() != nullptr) { 34030fdc8d8SChris Lattner StreamString usage_help; 341b9c1b51eSKate Stone GetOptions()->GenerateOptionUsage( 342b9c1b51eSKate Stone usage_help, this, 343b9c1b51eSKate Stone GetCommandInterpreter().GetDebugger().GetTerminalWidth()); 34498896839SZachary Turner if (!usage_help.Empty()) { 34598896839SZachary Turner llvm::StringRef usage_text = usage_help.GetString(); 34698896839SZachary Turner if (usage_text.contains_lower(search_word)) 34730fdc8d8SChris Lattner found_word = true; 34830fdc8d8SChris Lattner } 34930fdc8d8SChris Lattner } 35030fdc8d8SChris Lattner 35130fdc8d8SChris Lattner return found_word; 35230fdc8d8SChris Lattner } 353e139cf23SCaroline Tice 354b9c1b51eSKate Stone int CommandObject::GetNumArgumentEntries() { return m_arguments.size(); } 355e139cf23SCaroline Tice 356e139cf23SCaroline Tice CommandObject::CommandArgumentEntry * 357b9c1b51eSKate Stone CommandObject::GetArgumentEntryAtIndex(int idx) { 3583985c8c6SSaleem Abdulrasool if (static_cast<size_t>(idx) < m_arguments.size()) 359e139cf23SCaroline Tice return &(m_arguments[idx]); 360e139cf23SCaroline Tice 361d78c9576SEd Maste return nullptr; 362e139cf23SCaroline Tice } 363e139cf23SCaroline Tice 364d7e6a4f2SVince Harron const CommandObject::ArgumentTableEntry * 365b9c1b51eSKate Stone CommandObject::FindArgumentDataByType(CommandArgumentType arg_type) { 366e139cf23SCaroline Tice const ArgumentTableEntry *table = CommandObject::GetArgumentTable(); 367e139cf23SCaroline Tice 368e139cf23SCaroline Tice for (int i = 0; i < eArgTypeLastArg; ++i) 369e139cf23SCaroline Tice if (table[i].arg_type == arg_type) 370d7e6a4f2SVince Harron return &(table[i]); 371e139cf23SCaroline Tice 372d78c9576SEd Maste return nullptr; 373e139cf23SCaroline Tice } 374e139cf23SCaroline Tice 375b9c1b51eSKate Stone void CommandObject::GetArgumentHelp(Stream &str, CommandArgumentType arg_type, 376b9c1b51eSKate Stone CommandInterpreter &interpreter) { 377e139cf23SCaroline Tice const ArgumentTableEntry *table = CommandObject::GetArgumentTable(); 378d7e6a4f2SVince Harron const ArgumentTableEntry *entry = &(table[arg_type]); 379e139cf23SCaroline Tice 380b9c1b51eSKate Stone // The table is *supposed* to be kept in arg_type order, but someone *could* 381b9c1b51eSKate Stone // have messed it up... 382e139cf23SCaroline Tice 383e139cf23SCaroline Tice if (entry->arg_type != arg_type) 384e139cf23SCaroline Tice entry = CommandObject::FindArgumentDataByType(arg_type); 385e139cf23SCaroline Tice 386e139cf23SCaroline Tice if (!entry) 387e139cf23SCaroline Tice return; 388e139cf23SCaroline Tice 389e139cf23SCaroline Tice StreamString name_str; 390e139cf23SCaroline Tice name_str.Printf("<%s>", entry->arg_name); 391e139cf23SCaroline Tice 392b9c1b51eSKate Stone if (entry->help_function) { 393e0038717SZachary Turner llvm::StringRef help_text = entry->help_function(); 394b9c1b51eSKate Stone if (!entry->help_function.self_formatting) { 395c156427dSZachary Turner interpreter.OutputFormattedHelpText(str, name_str.GetString(), "--", 396b9c1b51eSKate Stone help_text, name_str.GetSize()); 397b9c1b51eSKate Stone } else { 398c156427dSZachary Turner interpreter.OutputHelpText(str, name_str.GetString(), "--", help_text, 39982a7d983SEnrico Granata name_str.GetSize()); 40082a7d983SEnrico Granata } 401b9c1b51eSKate Stone } else 402c156427dSZachary Turner interpreter.OutputFormattedHelpText(str, name_str.GetString(), "--", 403b9c1b51eSKate Stone entry->help_text, name_str.GetSize()); 404e139cf23SCaroline Tice } 405e139cf23SCaroline Tice 406b9c1b51eSKate Stone const char *CommandObject::GetArgumentName(CommandArgumentType arg_type) { 407b9c1b51eSKate Stone const ArgumentTableEntry *entry = 408b9c1b51eSKate Stone &(CommandObject::GetArgumentTable()[arg_type]); 409deaab222SCaroline Tice 410b9c1b51eSKate Stone // The table is *supposed* to be kept in arg_type order, but someone *could* 411b9c1b51eSKate Stone // have messed it up... 412deaab222SCaroline Tice 413deaab222SCaroline Tice if (entry->arg_type != arg_type) 414deaab222SCaroline Tice entry = CommandObject::FindArgumentDataByType(arg_type); 415deaab222SCaroline Tice 416e6acf355SJohnny Chen if (entry) 417deaab222SCaroline Tice return entry->arg_name; 418e6acf355SJohnny Chen 419c156427dSZachary Turner return nullptr; 420e139cf23SCaroline Tice } 421e139cf23SCaroline Tice 422b9c1b51eSKate Stone bool CommandObject::IsPairType(ArgumentRepetitionType arg_repeat_type) { 423b9c1b51eSKate Stone if ((arg_repeat_type == eArgRepeatPairPlain) || 424b9c1b51eSKate Stone (arg_repeat_type == eArgRepeatPairOptional) || 425b9c1b51eSKate Stone (arg_repeat_type == eArgRepeatPairPlus) || 426b9c1b51eSKate Stone (arg_repeat_type == eArgRepeatPairStar) || 427b9c1b51eSKate Stone (arg_repeat_type == eArgRepeatPairRange) || 428b9c1b51eSKate Stone (arg_repeat_type == eArgRepeatPairRangeOptional)) 429405fe67fSCaroline Tice return true; 430405fe67fSCaroline Tice 431405fe67fSCaroline Tice return false; 432405fe67fSCaroline Tice } 433405fe67fSCaroline Tice 43434ddc8dbSJohnny Chen static CommandObject::CommandArgumentEntry 435b9c1b51eSKate Stone OptSetFiltered(uint32_t opt_set_mask, 436b9c1b51eSKate Stone CommandObject::CommandArgumentEntry &cmd_arg_entry) { 43734ddc8dbSJohnny Chen CommandObject::CommandArgumentEntry ret_val; 43834ddc8dbSJohnny Chen for (unsigned i = 0; i < cmd_arg_entry.size(); ++i) 43934ddc8dbSJohnny Chen if (opt_set_mask & cmd_arg_entry[i].arg_opt_set_association) 44034ddc8dbSJohnny Chen ret_val.push_back(cmd_arg_entry[i]); 44134ddc8dbSJohnny Chen return ret_val; 44234ddc8dbSJohnny Chen } 44334ddc8dbSJohnny Chen 44434ddc8dbSJohnny Chen // Default parameter value of opt_set_mask is LLDB_OPT_SET_ALL, which means take 44534ddc8dbSJohnny Chen // all the argument data into account. On rare cases where some argument sticks 44634ddc8dbSJohnny Chen // with certain option sets, this function returns the option set filtered args. 447b9c1b51eSKate Stone void CommandObject::GetFormattedCommandArguments(Stream &str, 448b9c1b51eSKate Stone uint32_t opt_set_mask) { 449e139cf23SCaroline Tice int num_args = m_arguments.size(); 450b9c1b51eSKate Stone for (int i = 0; i < num_args; ++i) { 451e139cf23SCaroline Tice if (i > 0) 452e139cf23SCaroline Tice str.Printf(" "); 45334ddc8dbSJohnny Chen CommandArgumentEntry arg_entry = 454b9c1b51eSKate Stone opt_set_mask == LLDB_OPT_SET_ALL 455b9c1b51eSKate Stone ? m_arguments[i] 45634ddc8dbSJohnny Chen : OptSetFiltered(opt_set_mask, m_arguments[i]); 457e139cf23SCaroline Tice int num_alternatives = arg_entry.size(); 458405fe67fSCaroline Tice 459b9c1b51eSKate Stone if ((num_alternatives == 2) && IsPairType(arg_entry[0].arg_repetition)) { 460405fe67fSCaroline Tice const char *first_name = GetArgumentName(arg_entry[0].arg_type); 461405fe67fSCaroline Tice const char *second_name = GetArgumentName(arg_entry[1].arg_type); 462b9c1b51eSKate Stone switch (arg_entry[0].arg_repetition) { 463405fe67fSCaroline Tice case eArgRepeatPairPlain: 464405fe67fSCaroline Tice str.Printf("<%s> <%s>", first_name, second_name); 465405fe67fSCaroline Tice break; 466405fe67fSCaroline Tice case eArgRepeatPairOptional: 467405fe67fSCaroline Tice str.Printf("[<%s> <%s>]", first_name, second_name); 468405fe67fSCaroline Tice break; 469405fe67fSCaroline Tice case eArgRepeatPairPlus: 470b9c1b51eSKate Stone str.Printf("<%s> <%s> [<%s> <%s> [...]]", first_name, second_name, 471b9c1b51eSKate Stone first_name, second_name); 472405fe67fSCaroline Tice break; 473405fe67fSCaroline Tice case eArgRepeatPairStar: 474b9c1b51eSKate Stone str.Printf("[<%s> <%s> [<%s> <%s> [...]]]", first_name, second_name, 475b9c1b51eSKate Stone first_name, second_name); 476405fe67fSCaroline Tice break; 477405fe67fSCaroline Tice case eArgRepeatPairRange: 478b9c1b51eSKate Stone str.Printf("<%s_1> <%s_1> ... <%s_n> <%s_n>", first_name, second_name, 479b9c1b51eSKate Stone first_name, second_name); 480405fe67fSCaroline Tice break; 481405fe67fSCaroline Tice case eArgRepeatPairRangeOptional: 482b9c1b51eSKate Stone str.Printf("[<%s_1> <%s_1> ... <%s_n> <%s_n>]", first_name, second_name, 483b9c1b51eSKate Stone first_name, second_name); 484405fe67fSCaroline Tice break; 485b9c1b51eSKate Stone // Explicitly test for all the rest of the cases, so if new types get 486b9c1b51eSKate Stone // added we will notice the 487ca1176aaSCaroline Tice // missing case statement(s). 488ca1176aaSCaroline Tice case eArgRepeatPlain: 489ca1176aaSCaroline Tice case eArgRepeatOptional: 490ca1176aaSCaroline Tice case eArgRepeatPlus: 491ca1176aaSCaroline Tice case eArgRepeatStar: 492ca1176aaSCaroline Tice case eArgRepeatRange: 493b9c1b51eSKate Stone // These should not be reached, as they should fail the IsPairType test 494b9c1b51eSKate Stone // above. 495ca1176aaSCaroline Tice break; 496405fe67fSCaroline Tice } 497b9c1b51eSKate Stone } else { 498e139cf23SCaroline Tice StreamString names; 499b9c1b51eSKate Stone for (int j = 0; j < num_alternatives; ++j) { 500e139cf23SCaroline Tice if (j > 0) 501e139cf23SCaroline Tice names.Printf(" | "); 502e139cf23SCaroline Tice names.Printf("%s", GetArgumentName(arg_entry[j].arg_type)); 503e139cf23SCaroline Tice } 504c156427dSZachary Turner 505c156427dSZachary Turner std::string name_str = names.GetString(); 506b9c1b51eSKate Stone switch (arg_entry[0].arg_repetition) { 507e139cf23SCaroline Tice case eArgRepeatPlain: 508c156427dSZachary Turner str.Printf("<%s>", name_str.c_str()); 509e139cf23SCaroline Tice break; 510e139cf23SCaroline Tice case eArgRepeatPlus: 511c156427dSZachary Turner str.Printf("<%s> [<%s> [...]]", name_str.c_str(), name_str.c_str()); 512e139cf23SCaroline Tice break; 513e139cf23SCaroline Tice case eArgRepeatStar: 514c156427dSZachary Turner str.Printf("[<%s> [<%s> [...]]]", name_str.c_str(), name_str.c_str()); 515e139cf23SCaroline Tice break; 516e139cf23SCaroline Tice case eArgRepeatOptional: 517c156427dSZachary Turner str.Printf("[<%s>]", name_str.c_str()); 518e139cf23SCaroline Tice break; 519405fe67fSCaroline Tice case eArgRepeatRange: 520c156427dSZachary Turner str.Printf("<%s_1> .. <%s_n>", name_str.c_str(), name_str.c_str()); 521ca1176aaSCaroline Tice break; 522b9c1b51eSKate Stone // Explicitly test for all the rest of the cases, so if new types get 523b9c1b51eSKate Stone // added we will notice the 524ca1176aaSCaroline Tice // missing case statement(s). 525ca1176aaSCaroline Tice case eArgRepeatPairPlain: 526ca1176aaSCaroline Tice case eArgRepeatPairOptional: 527ca1176aaSCaroline Tice case eArgRepeatPairPlus: 528ca1176aaSCaroline Tice case eArgRepeatPairStar: 529ca1176aaSCaroline Tice case eArgRepeatPairRange: 530ca1176aaSCaroline Tice case eArgRepeatPairRangeOptional: 531b9c1b51eSKate Stone // These should not be hit, as they should pass the IsPairType test 532b9c1b51eSKate Stone // above, and control should 533ca1176aaSCaroline Tice // have gone into the other branch of the if statement. 534ca1176aaSCaroline Tice break; 535405fe67fSCaroline Tice } 536e139cf23SCaroline Tice } 537e139cf23SCaroline Tice } 538e139cf23SCaroline Tice } 539e139cf23SCaroline Tice 54014f6b2c0SZachary Turner CommandArgumentType 54114f6b2c0SZachary Turner CommandObject::LookupArgumentName(llvm::StringRef arg_name) { 542e139cf23SCaroline Tice CommandArgumentType return_type = eArgTypeLastArg; 543e139cf23SCaroline Tice 54414f6b2c0SZachary Turner arg_name = arg_name.ltrim('<').rtrim('>'); 545e139cf23SCaroline Tice 546331eff39SJohnny Chen const ArgumentTableEntry *table = GetArgumentTable(); 547e139cf23SCaroline Tice for (int i = 0; i < eArgTypeLastArg; ++i) 54814f6b2c0SZachary Turner if (arg_name == table[i].arg_name) 549e139cf23SCaroline Tice return_type = g_arguments_data[i].arg_type; 550e139cf23SCaroline Tice 551e139cf23SCaroline Tice return return_type; 552e139cf23SCaroline Tice } 553e139cf23SCaroline Tice 554e0038717SZachary Turner static llvm::StringRef RegisterNameHelpTextCallback() { 555b9c1b51eSKate Stone return "Register names can be specified using the architecture specific " 556b9c1b51eSKate Stone "names. " 557b9c1b51eSKate Stone "They can also be specified using generic names. Not all generic " 558b9c1b51eSKate Stone "entities have " 559b9c1b51eSKate Stone "registers backing them on all architectures. When they don't the " 560b9c1b51eSKate Stone "generic name " 56184c7bd74SJim Ingham "will return an error.\n" 562931e674aSJim Ingham "The generic names defined in lldb are:\n" 563931e674aSJim Ingham "\n" 564931e674aSJim Ingham "pc - program counter register\n" 565931e674aSJim Ingham "ra - return address register\n" 566931e674aSJim Ingham "fp - frame pointer register\n" 567931e674aSJim Ingham "sp - stack pointer register\n" 56884c7bd74SJim Ingham "flags - the flags register\n" 569931e674aSJim Ingham "arg{1-6} - integer argument passing registers.\n"; 570931e674aSJim Ingham } 571931e674aSJim Ingham 572e0038717SZachary Turner static llvm::StringRef BreakpointIDHelpTextCallback() { 5737428a18cSKate Stone return "Breakpoints are identified using major and minor numbers; the major " 574b9c1b51eSKate Stone "number corresponds to the single entity that was created with a " 575b9c1b51eSKate Stone "'breakpoint " 576b9c1b51eSKate Stone "set' command; the minor numbers correspond to all the locations that " 577b9c1b51eSKate Stone "were " 578b9c1b51eSKate Stone "actually found/set based on the major breakpoint. A full breakpoint " 579b9c1b51eSKate Stone "ID might " 580b9c1b51eSKate Stone "look like 3.14, meaning the 14th location set for the 3rd " 581b9c1b51eSKate Stone "breakpoint. You " 582b9c1b51eSKate Stone "can specify all the locations of a breakpoint by just indicating the " 583b9c1b51eSKate Stone "major " 584b9c1b51eSKate Stone "breakpoint number. A valid breakpoint ID consists either of just the " 585b9c1b51eSKate Stone "major " 586b9c1b51eSKate Stone "number, or the major number followed by a dot and the location " 587b9c1b51eSKate Stone "number (e.g. " 5887428a18cSKate Stone "3 or 3.2 could both be valid breakpoint IDs.)"; 589e139cf23SCaroline Tice } 590e139cf23SCaroline Tice 591e0038717SZachary Turner static llvm::StringRef BreakpointIDRangeHelpTextCallback() { 592b9c1b51eSKate Stone return "A 'breakpoint ID list' is a manner of specifying multiple " 593b9c1b51eSKate Stone "breakpoints. " 594b9c1b51eSKate Stone "This can be done through several mechanisms. The easiest way is to " 595b9c1b51eSKate Stone "just " 5967428a18cSKate Stone "enter a space-separated list of breakpoint IDs. To specify all the " 59786edbf41SGreg Clayton "breakpoint locations under a major breakpoint, you can use the major " 598b9c1b51eSKate Stone "breakpoint number followed by '.*', eg. '5.*' means all the " 599b9c1b51eSKate Stone "locations under " 60086edbf41SGreg Clayton "breakpoint 5. You can also indicate a range of breakpoints by using " 601b9c1b51eSKate Stone "<start-bp-id> - <end-bp-id>. The start-bp-id and end-bp-id for a " 602b9c1b51eSKate Stone "range can " 603b9c1b51eSKate Stone "be any valid breakpoint IDs. It is not legal, however, to specify a " 604b9c1b51eSKate Stone "range " 605b9c1b51eSKate Stone "using specific locations that cross major breakpoint numbers. I.e. " 606b9c1b51eSKate Stone "3.2 - 3.7" 60786edbf41SGreg Clayton " is legal; 2 - 5 is legal; but 3.2 - 4.4 is not legal."; 60886edbf41SGreg Clayton } 60986edbf41SGreg Clayton 610e0038717SZachary Turner static llvm::StringRef BreakpointNameHelpTextCallback() { 611b9c1b51eSKate Stone return "A name that can be added to a breakpoint when it is created, or " 612b9c1b51eSKate Stone "later " 6135e09c8c3SJim Ingham "on with the \"breakpoint name add\" command. " 614b9c1b51eSKate Stone "Breakpoint names can be used to specify breakpoints in all the " 615b9c1b51eSKate Stone "places breakpoint IDs " 616b9c1b51eSKate Stone "and breakpoint ID ranges can be used. As such they provide a " 617b9c1b51eSKate Stone "convenient way to group breakpoints, " 618b9c1b51eSKate Stone "and to operate on breakpoints you create without having to track the " 619b9c1b51eSKate Stone "breakpoint number. " 620b9c1b51eSKate Stone "Note, the attributes you set when using a breakpoint name in a " 621b9c1b51eSKate Stone "breakpoint command don't " 622b9c1b51eSKate Stone "adhere to the name, but instead are set individually on all the " 623b9c1b51eSKate Stone "breakpoints currently tagged with that " 6247428a18cSKate Stone "name. Future breakpoints " 625b9c1b51eSKate Stone "tagged with that name will not pick up the attributes previously " 626b9c1b51eSKate Stone "given using that name. " 627b9c1b51eSKate Stone "In order to distinguish breakpoint names from breakpoint IDs and " 628b9c1b51eSKate Stone "ranges, " 629b9c1b51eSKate Stone "names must start with a letter from a-z or A-Z and cannot contain " 630b9c1b51eSKate Stone "spaces, \".\" or \"-\". " 631b9c1b51eSKate Stone "Also, breakpoint names can only be applied to breakpoints, not to " 632b9c1b51eSKate Stone "breakpoint locations."; 6335e09c8c3SJim Ingham } 6345e09c8c3SJim Ingham 635e0038717SZachary Turner static llvm::StringRef GDBFormatHelpTextCallback() { 636b9c1b51eSKate Stone return "A GDB format consists of a repeat count, a format letter and a size " 637b9c1b51eSKate Stone "letter. " 638b9c1b51eSKate Stone "The repeat count is optional and defaults to 1. The format letter is " 639b9c1b51eSKate Stone "optional " 640b9c1b51eSKate Stone "and defaults to the previous format that was used. The size letter " 641b9c1b51eSKate Stone "is optional " 642f91381e8SGreg Clayton "and defaults to the previous size that was used.\n" 643f91381e8SGreg Clayton "\n" 644f91381e8SGreg Clayton "Format letters include:\n" 645f91381e8SGreg Clayton "o - octal\n" 646f91381e8SGreg Clayton "x - hexadecimal\n" 647f91381e8SGreg Clayton "d - decimal\n" 648f91381e8SGreg Clayton "u - unsigned decimal\n" 649f91381e8SGreg Clayton "t - binary\n" 650f91381e8SGreg Clayton "f - float\n" 651f91381e8SGreg Clayton "a - address\n" 652f91381e8SGreg Clayton "i - instruction\n" 653f91381e8SGreg Clayton "c - char\n" 654f91381e8SGreg Clayton "s - string\n" 655f91381e8SGreg Clayton "T - OSType\n" 656f91381e8SGreg Clayton "A - float as hex\n" 657f91381e8SGreg Clayton "\n" 658f91381e8SGreg Clayton "Size letters include:\n" 659f91381e8SGreg Clayton "b - 1 byte (byte)\n" 660f91381e8SGreg Clayton "h - 2 bytes (halfword)\n" 661f91381e8SGreg Clayton "w - 4 bytes (word)\n" 662f91381e8SGreg Clayton "g - 8 bytes (giant)\n" 663f91381e8SGreg Clayton "\n" 664f91381e8SGreg Clayton "Example formats:\n" 665f91381e8SGreg Clayton "32xb - show 32 1 byte hexadecimal integer values\n" 666f91381e8SGreg Clayton "16xh - show 16 2 byte hexadecimal integer values\n" 667b9c1b51eSKate Stone "64 - show 64 2 byte hexadecimal integer values (format and size " 668b9c1b51eSKate Stone "from the last format)\n" 669b9c1b51eSKate Stone "dw - show 1 4 byte decimal integer value\n"; 670e139cf23SCaroline Tice } 671e139cf23SCaroline Tice 672e0038717SZachary Turner static llvm::StringRef FormatHelpTextCallback() { 673e0038717SZachary Turner static std::string help_text; 67482a7d983SEnrico Granata 675e0038717SZachary Turner if (!help_text.empty()) 676e0038717SZachary Turner return help_text; 67782a7d983SEnrico Granata 6780a3958e0SEnrico Granata StreamString sstr; 679b9c1b51eSKate Stone sstr << "One of the format names (or one-character names) that can be used " 680b9c1b51eSKate Stone "to show a variable's value:\n"; 681b9c1b51eSKate Stone for (Format f = eFormatDefault; f < kNumFormats; f = Format(f + 1)) { 68282a7d983SEnrico Granata if (f != eFormatDefault) 68382a7d983SEnrico Granata sstr.PutChar('\n'); 68482a7d983SEnrico Granata 6850a3958e0SEnrico Granata char format_char = FormatManager::GetFormatAsFormatChar(f); 6860a3958e0SEnrico Granata if (format_char) 6870a3958e0SEnrico Granata sstr.Printf("'%c' or ", format_char); 6880a3958e0SEnrico Granata 68982a7d983SEnrico Granata sstr.Printf("\"%s\"", FormatManager::GetFormatAsCString(f)); 6900a3958e0SEnrico Granata } 6910a3958e0SEnrico Granata 6920a3958e0SEnrico Granata sstr.Flush(); 6930a3958e0SEnrico Granata 694e0038717SZachary Turner help_text = sstr.GetString(); 6950a3958e0SEnrico Granata 696e0038717SZachary Turner return help_text; 6970a3958e0SEnrico Granata } 6980a3958e0SEnrico Granata 699e0038717SZachary Turner static llvm::StringRef LanguageTypeHelpTextCallback() { 700e0038717SZachary Turner static std::string help_text; 701d9477397SSean Callanan 702e0038717SZachary Turner if (!help_text.empty()) 703e0038717SZachary Turner return help_text; 704d9477397SSean Callanan 705d9477397SSean Callanan StreamString sstr; 706d9477397SSean Callanan sstr << "One of the following languages:\n"; 707d9477397SSean Callanan 7080e0984eeSJim Ingham Language::PrintAllLanguages(sstr, " ", "\n"); 709d9477397SSean Callanan 710d9477397SSean Callanan sstr.Flush(); 711d9477397SSean Callanan 712e0038717SZachary Turner help_text = sstr.GetString(); 713d9477397SSean Callanan 714e0038717SZachary Turner return help_text; 715d9477397SSean Callanan } 716d9477397SSean Callanan 717e0038717SZachary Turner static llvm::StringRef SummaryStringHelpTextCallback() { 718b9c1b51eSKate Stone return "A summary string is a way to extract information from variables in " 719b9c1b51eSKate Stone "order to present them using a summary.\n" 720b9c1b51eSKate Stone "Summary strings contain static text, variables, scopes and control " 721b9c1b51eSKate Stone "sequences:\n" 722b9c1b51eSKate Stone " - Static text can be any sequence of non-special characters, i.e. " 723b9c1b51eSKate Stone "anything but '{', '}', '$', or '\\'.\n" 724b9c1b51eSKate Stone " - Variables are sequences of characters beginning with ${, ending " 725b9c1b51eSKate Stone "with } and that contain symbols in the format described below.\n" 726b9c1b51eSKate Stone " - Scopes are any sequence of text between { and }. Anything " 727b9c1b51eSKate Stone "included in a scope will only appear in the output summary if there " 728b9c1b51eSKate Stone "were no errors.\n" 729b9c1b51eSKate Stone " - Control sequences are the usual C/C++ '\\a', '\\n', ..., plus " 730b9c1b51eSKate Stone "'\\$', '\\{' and '\\}'.\n" 731b9c1b51eSKate Stone "A summary string works by copying static text verbatim, turning " 732b9c1b51eSKate Stone "control sequences into their character counterpart, expanding " 733b9c1b51eSKate Stone "variables and trying to expand scopes.\n" 734b9c1b51eSKate Stone "A variable is expanded by giving it a value other than its textual " 735b9c1b51eSKate Stone "representation, and the way this is done depends on what comes after " 736b9c1b51eSKate Stone "the ${ marker.\n" 737b9c1b51eSKate Stone "The most common sequence if ${var followed by an expression path, " 738b9c1b51eSKate Stone "which is the text one would type to access a member of an aggregate " 739b9c1b51eSKate Stone "types, given a variable of that type" 740b9c1b51eSKate Stone " (e.g. if type T has a member named x, which has a member named y, " 741b9c1b51eSKate Stone "and if t is of type T, the expression path would be .x.y and the way " 742b9c1b51eSKate Stone "to fit that into a summary string would be" 743b9c1b51eSKate Stone " ${var.x.y}). You can also use ${*var followed by an expression path " 744b9c1b51eSKate Stone "and in that case the object referred by the path will be " 745b9c1b51eSKate Stone "dereferenced before being displayed." 746b9c1b51eSKate Stone " If the object is not a pointer, doing so will cause an error. For " 747b9c1b51eSKate Stone "additional details on expression paths, you can type 'help " 748b9c1b51eSKate Stone "expr-path'. \n" 749b9c1b51eSKate Stone "By default, summary strings attempt to display the summary for any " 750b9c1b51eSKate Stone "variable they reference, and if that fails the value. If neither can " 751b9c1b51eSKate Stone "be shown, nothing is displayed." 752b9c1b51eSKate Stone "In a summary string, you can also use an array index [n], or a " 753b9c1b51eSKate Stone "slice-like range [n-m]. This can have two different meanings " 754b9c1b51eSKate Stone "depending on what kind of object the expression" 75582a7d983SEnrico Granata " path refers to:\n" 756b9c1b51eSKate Stone " - if it is a scalar type (any basic type like int, float, ...) the " 757b9c1b51eSKate Stone "expression is a bitfield, i.e. the bits indicated by the indexing " 758b9c1b51eSKate Stone "operator are extracted out of the number" 75982a7d983SEnrico Granata " and displayed as an individual variable\n" 760b9c1b51eSKate Stone " - if it is an array or pointer the array items indicated by the " 761b9c1b51eSKate Stone "indexing operator are shown as the result of the variable. if the " 762b9c1b51eSKate Stone "expression is an array, real array items are" 763b9c1b51eSKate Stone " printed; if it is a pointer, the pointer-as-array syntax is used to " 764b9c1b51eSKate Stone "obtain the values (this means, the latter case can have no range " 765b9c1b51eSKate Stone "checking)\n" 766b9c1b51eSKate Stone "If you are trying to display an array for which the size is known, " 767b9c1b51eSKate Stone "you can also use [] instead of giving an exact range. This has the " 768b9c1b51eSKate Stone "effect of showing items 0 thru size - 1.\n" 769b9c1b51eSKate Stone "Additionally, a variable can contain an (optional) format code, as " 770b9c1b51eSKate Stone "in ${var.x.y%code}, where code can be any of the valid formats " 771b9c1b51eSKate Stone "described in 'help format', or one of the" 7729128ee2fSEnrico Granata " special symbols only allowed as part of a variable:\n" 7739128ee2fSEnrico Granata " %V: show the value of the object by default\n" 7749128ee2fSEnrico Granata " %S: show the summary of the object by default\n" 775b9c1b51eSKate Stone " %@: show the runtime-provided object description (for " 776b9c1b51eSKate Stone "Objective-C, it calls NSPrintForDebugger; for C/C++ it does " 777b9c1b51eSKate Stone "nothing)\n" 778b9c1b51eSKate Stone " %L: show the location of the object (memory address or a " 779b9c1b51eSKate Stone "register name)\n" 7809128ee2fSEnrico Granata " %#: show the number of children of the object\n" 7819128ee2fSEnrico Granata " %T: show the type of the object\n" 782b9c1b51eSKate Stone "Another variable that you can use in summary strings is ${svar . " 783b9c1b51eSKate Stone "This sequence works exactly like ${var, including the fact that " 784b9c1b51eSKate Stone "${*svar is an allowed sequence, but uses" 785b9c1b51eSKate Stone " the object's synthetic children provider instead of the actual " 786b9c1b51eSKate Stone "objects. For instance, if you are using STL synthetic children " 787b9c1b51eSKate Stone "providers, the following summary string would" 7889128ee2fSEnrico Granata " count the number of actual elements stored in an std::list:\n" 7899128ee2fSEnrico Granata "type summary add -s \"${svar%#}\" -x \"std::list<\""; 7909128ee2fSEnrico Granata } 7919128ee2fSEnrico Granata 792e0038717SZachary Turner static llvm::StringRef ExprPathHelpTextCallback() { 793b9c1b51eSKate Stone return "An expression path is the sequence of symbols that is used in C/C++ " 794b9c1b51eSKate Stone "to access a member variable of an aggregate object (class).\n" 7959128ee2fSEnrico Granata "For instance, given a class:\n" 7969128ee2fSEnrico Granata " class foo {\n" 7979128ee2fSEnrico Granata " int a;\n" 7989128ee2fSEnrico Granata " int b; .\n" 7999128ee2fSEnrico Granata " foo* next;\n" 8009128ee2fSEnrico Granata " };\n" 801b9c1b51eSKate Stone "the expression to read item b in the item pointed to by next for foo " 802b9c1b51eSKate Stone "aFoo would be aFoo.next->b.\n" 803b9c1b51eSKate Stone "Given that aFoo could just be any object of type foo, the string " 804b9c1b51eSKate Stone "'.next->b' is the expression path, because it can be attached to any " 805b9c1b51eSKate Stone "foo instance to achieve the effect.\n" 806b9c1b51eSKate Stone "Expression paths in LLDB include dot (.) and arrow (->) operators, " 807b9c1b51eSKate Stone "and most commands using expression paths have ways to also accept " 808b9c1b51eSKate Stone "the star (*) operator.\n" 809b9c1b51eSKate Stone "The meaning of these operators is the same as the usual one given to " 810b9c1b51eSKate Stone "them by the C/C++ standards.\n" 811b9c1b51eSKate Stone "LLDB also has support for indexing ([ ]) in expression paths, and " 812b9c1b51eSKate Stone "extends the traditional meaning of the square brackets operator to " 813b9c1b51eSKate Stone "allow bitfield extraction:\n" 814b9c1b51eSKate Stone "for objects of native types (int, float, char, ...) saying '[n-m]' " 815b9c1b51eSKate Stone "as an expression path (where n and m are any positive integers, e.g. " 816b9c1b51eSKate Stone "[3-5]) causes LLDB to extract" 817b9c1b51eSKate Stone " bits n thru m from the value of the variable. If n == m, [n] is " 818b9c1b51eSKate Stone "also allowed as a shortcut syntax. For arrays and pointers, " 819b9c1b51eSKate Stone "expression paths can only contain one index" 820b9c1b51eSKate Stone " and the meaning of the operation is the same as the one defined by " 821b9c1b51eSKate Stone "C/C++ (item extraction). Some commands extend bitfield-like syntax " 822b9c1b51eSKate Stone "for arrays and pointers with the" 823b9c1b51eSKate Stone " meaning of array slicing (taking elements n thru m inside the array " 824b9c1b51eSKate Stone "or pointed-to memory)."; 8250a3958e0SEnrico Granata } 8260a3958e0SEnrico Granata 827b9c1b51eSKate Stone void CommandObject::FormatLongHelpText(Stream &output_strm, 828442f6530SZachary Turner llvm::StringRef long_help) { 829ea671fbdSKate Stone CommandInterpreter &interpreter = GetCommandInterpreter(); 830ea671fbdSKate Stone std::stringstream lineStream(long_help); 831ea671fbdSKate Stone std::string line; 832ea671fbdSKate Stone while (std::getline(lineStream, line)) { 833ea671fbdSKate Stone if (line.empty()) { 834ea671fbdSKate Stone output_strm << "\n"; 835ea671fbdSKate Stone continue; 836ea671fbdSKate Stone } 837ea671fbdSKate Stone size_t result = line.find_first_not_of(" \t"); 838ea671fbdSKate Stone if (result == std::string::npos) { 839ea671fbdSKate Stone result = 0; 840ea671fbdSKate Stone } 841ea671fbdSKate Stone std::string whitespace_prefix = line.substr(0, result); 842ea671fbdSKate Stone std::string remainder = line.substr(result); 843b9c1b51eSKate Stone interpreter.OutputFormattedHelpText(output_strm, whitespace_prefix.c_str(), 844b9c1b51eSKate Stone remainder.c_str()); 845ea671fbdSKate Stone } 846ea671fbdSKate Stone } 847ea671fbdSKate Stone 848b9c1b51eSKate Stone void CommandObject::GenerateHelpText(CommandReturnObject &result) { 8499b62d1d5SEnrico Granata GenerateHelpText(result.GetOutputStream()); 8509b62d1d5SEnrico Granata 8519b62d1d5SEnrico Granata result.SetStatus(eReturnStatusSuccessFinishNoResult); 8529b62d1d5SEnrico Granata } 8539b62d1d5SEnrico Granata 854b9c1b51eSKate Stone void CommandObject::GenerateHelpText(Stream &output_strm) { 8559b62d1d5SEnrico Granata CommandInterpreter &interpreter = GetCommandInterpreter(); 856b9c1b51eSKate Stone if (WantsRawCommandString()) { 8579b62d1d5SEnrico Granata std::string help_text(GetHelp()); 8587428a18cSKate Stone help_text.append(" Expects 'raw' input (see 'help raw-input'.)"); 859b9c1b51eSKate Stone interpreter.OutputFormattedHelpText(output_strm, "", "", help_text.c_str(), 860b9c1b51eSKate Stone 1); 861b9c1b51eSKate Stone } else 8629b62d1d5SEnrico Granata interpreter.OutputFormattedHelpText(output_strm, "", "", GetHelp(), 1); 86303c9f364SZachary Turner output_strm << "\nSyntax: " << GetSyntax() << "\n"; 8647428a18cSKate Stone Options *options = GetOptions(); 865b9c1b51eSKate Stone if (options != nullptr) { 866b9c1b51eSKate Stone options->GenerateOptionUsage( 867b9c1b51eSKate Stone output_strm, this, 868b9c1b51eSKate Stone GetCommandInterpreter().GetDebugger().GetTerminalWidth()); 8697428a18cSKate Stone } 870442f6530SZachary Turner llvm::StringRef long_help = GetHelpLong(); 871442f6530SZachary Turner if (!long_help.empty()) { 872ea671fbdSKate Stone FormatLongHelpText(output_strm, long_help); 8737428a18cSKate Stone } 874b9c1b51eSKate Stone if (!IsDashDashCommand() && options && options->NumCommandOptions() > 0) { 875b9c1b51eSKate Stone if (WantsRawCommandString() && !WantsCompletion()) { 876b9c1b51eSKate Stone // Emit the message about using ' -- ' between the end of the command 877b9c1b51eSKate Stone // options and the raw input 878b9c1b51eSKate Stone // conditionally, i.e., only if the command object does not want 879b9c1b51eSKate Stone // completion. 8807428a18cSKate Stone interpreter.OutputFormattedHelpText( 8817428a18cSKate Stone output_strm, "", "", 882b9c1b51eSKate Stone "\nImportant Note: Because this command takes 'raw' input, if you " 883b9c1b51eSKate Stone "use any command options" 884b9c1b51eSKate Stone " you must use ' -- ' between the end of the command options and the " 885b9c1b51eSKate Stone "beginning of the raw input.", 8867428a18cSKate Stone 1); 887b9c1b51eSKate Stone } else if (GetNumArgumentEntries() > 0) { 888b9c1b51eSKate Stone // Also emit a warning about using "--" in case you are using a command 889b9c1b51eSKate Stone // that takes options and arguments. 8907428a18cSKate Stone interpreter.OutputFormattedHelpText( 891b9c1b51eSKate Stone output_strm, "", "", 892b9c1b51eSKate Stone "\nThis command takes options and free-form arguments. If your " 893b9c1b51eSKate Stone "arguments resemble" 894b9c1b51eSKate Stone " option specifiers (i.e., they start with a - or --), you must use " 895b9c1b51eSKate Stone "' -- ' between" 8967428a18cSKate Stone " the end of the command options and the beginning of the arguments.", 8977428a18cSKate Stone 1); 8989b62d1d5SEnrico Granata } 8999b62d1d5SEnrico Granata } 900bfb75e9bSEnrico Granata } 9019b62d1d5SEnrico Granata 902b9c1b51eSKate Stone void CommandObject::AddIDsArgumentData(CommandArgumentEntry &arg, 903b9c1b51eSKate Stone CommandArgumentType ID, 904b9c1b51eSKate Stone CommandArgumentType IDRange) { 905184d7a72SJohnny Chen CommandArgumentData id_arg; 906184d7a72SJohnny Chen CommandArgumentData id_range_arg; 907184d7a72SJohnny Chen 908b9c1b51eSKate Stone // Create the first variant for the first (and only) argument for this 909b9c1b51eSKate Stone // command. 910de753464SJohnny Chen id_arg.arg_type = ID; 911184d7a72SJohnny Chen id_arg.arg_repetition = eArgRepeatOptional; 912184d7a72SJohnny Chen 913b9c1b51eSKate Stone // Create the second variant for the first (and only) argument for this 914b9c1b51eSKate Stone // command. 915de753464SJohnny Chen id_range_arg.arg_type = IDRange; 916184d7a72SJohnny Chen id_range_arg.arg_repetition = eArgRepeatOptional; 917184d7a72SJohnny Chen 918b9c1b51eSKate Stone // The first (and only) argument for this command could be either an id or an 919b9c1b51eSKate Stone // id_range. 920184d7a72SJohnny Chen // Push both variants into the entry for the first argument for this command. 921184d7a72SJohnny Chen arg.push_back(id_arg); 922184d7a72SJohnny Chen arg.push_back(id_range_arg); 923184d7a72SJohnny Chen } 924184d7a72SJohnny Chen 925b9c1b51eSKate Stone const char *CommandObject::GetArgumentTypeAsCString( 926b9c1b51eSKate Stone const lldb::CommandArgumentType arg_type) { 927b9c1b51eSKate Stone assert(arg_type < eArgTypeLastArg && 928b9c1b51eSKate Stone "Invalid argument type passed to GetArgumentTypeAsCString"); 9299d0402b1SGreg Clayton return g_arguments_data[arg_type].arg_name; 9309d0402b1SGreg Clayton } 9319d0402b1SGreg Clayton 932b9c1b51eSKate Stone const char *CommandObject::GetArgumentDescriptionAsCString( 933b9c1b51eSKate Stone const lldb::CommandArgumentType arg_type) { 934b9c1b51eSKate Stone assert(arg_type < eArgTypeLastArg && 935b9c1b51eSKate Stone "Invalid argument type passed to GetArgumentDescriptionAsCString"); 9369d0402b1SGreg Clayton return g_arguments_data[arg_type].help_text; 9379d0402b1SGreg Clayton } 9389d0402b1SGreg Clayton 939b9c1b51eSKate Stone Target *CommandObject::GetDummyTarget() { 940893c932aSJim Ingham return m_interpreter.GetDebugger().GetDummyTarget(); 941893c932aSJim Ingham } 942893c932aSJim Ingham 943b9c1b51eSKate Stone Target *CommandObject::GetSelectedOrDummyTarget(bool prefer_dummy) { 94433df7cd3SJim Ingham return m_interpreter.GetDebugger().GetSelectedOrDummyTarget(prefer_dummy); 945893c932aSJim Ingham } 946893c932aSJim Ingham 947b9c1b51eSKate Stone Thread *CommandObject::GetDefaultThread() { 9488d94ba0fSJim Ingham Thread *thread_to_use = m_exe_ctx.GetThreadPtr(); 9498d94ba0fSJim Ingham if (thread_to_use) 9508d94ba0fSJim Ingham return thread_to_use; 9518d94ba0fSJim Ingham 9528d94ba0fSJim Ingham Process *process = m_exe_ctx.GetProcessPtr(); 953b9c1b51eSKate Stone if (!process) { 9548d94ba0fSJim Ingham Target *target = m_exe_ctx.GetTargetPtr(); 955b9c1b51eSKate Stone if (!target) { 9568d94ba0fSJim Ingham target = m_interpreter.GetDebugger().GetSelectedTarget().get(); 9578d94ba0fSJim Ingham } 9588d94ba0fSJim Ingham if (target) 9598d94ba0fSJim Ingham process = target->GetProcessSP().get(); 9608d94ba0fSJim Ingham } 9618d94ba0fSJim Ingham 9628d94ba0fSJim Ingham if (process) 9638d94ba0fSJim Ingham return process->GetThreadList().GetSelectedThread().get(); 9648d94ba0fSJim Ingham else 9658d94ba0fSJim Ingham return nullptr; 9668d94ba0fSJim Ingham } 9678d94ba0fSJim Ingham 968b9c1b51eSKate Stone bool CommandObjectParsed::Execute(const char *args_string, 969b9c1b51eSKate Stone CommandReturnObject &result) { 9705a988416SJim Ingham bool handled = false; 9715a988416SJim Ingham Args cmd_args(args_string); 972b9c1b51eSKate Stone if (HasOverrideCallback()) { 9735a988416SJim Ingham Args full_args(GetCommandName()); 9745a988416SJim Ingham full_args.AppendArguments(cmd_args); 975b9c1b51eSKate Stone handled = 976b9c1b51eSKate Stone InvokeOverrideCallback(full_args.GetConstArgumentVector(), result); 9775a988416SJim Ingham } 978b9c1b51eSKate Stone if (!handled) { 97997d2c401SZachary Turner for (auto entry : llvm::enumerate(cmd_args.entries())) { 9804eb8449dSZachary Turner if (!entry.value().ref.empty() && entry.value().ref.front() == '`') { 981b9c1b51eSKate Stone cmd_args.ReplaceArgumentAtIndex( 9824eb8449dSZachary Turner entry.index(), 9834eb8449dSZachary Turner m_interpreter.ProcessEmbeddedScriptCommands(entry.value().c_str())); 98497d2c401SZachary Turner } 9855a988416SJim Ingham } 9865a988416SJim Ingham 987b9c1b51eSKate Stone if (CheckRequirements(result)) { 988b9c1b51eSKate Stone if (ParseOptions(cmd_args, result)) { 989b9c1b51eSKate Stone // Call the command-specific version of 'Execute', passing it the 990b9c1b51eSKate Stone // already processed arguments. 9915a988416SJim Ingham handled = DoExecute(cmd_args, result); 9925a988416SJim Ingham } 993f9fc609fSGreg Clayton } 994f9fc609fSGreg Clayton 995f9fc609fSGreg Clayton Cleanup(); 996f9fc609fSGreg Clayton } 9975a988416SJim Ingham return handled; 9985a988416SJim Ingham } 9995a988416SJim Ingham 1000b9c1b51eSKate Stone bool CommandObjectRaw::Execute(const char *args_string, 1001b9c1b51eSKate Stone CommandReturnObject &result) { 10025a988416SJim Ingham bool handled = false; 1003b9c1b51eSKate Stone if (HasOverrideCallback()) { 10045a988416SJim Ingham std::string full_command(GetCommandName()); 10055a988416SJim Ingham full_command += ' '; 10065a988416SJim Ingham full_command += args_string; 1007d78c9576SEd Maste const char *argv[2] = {nullptr, nullptr}; 10085a988416SJim Ingham argv[0] = full_command.c_str(); 10093b652621SJim Ingham handled = InvokeOverrideCallback(argv, result); 10105a988416SJim Ingham } 1011b9c1b51eSKate Stone if (!handled) { 1012f9fc609fSGreg Clayton if (CheckRequirements(result)) 10135a988416SJim Ingham handled = DoExecute(args_string, result); 1014f9fc609fSGreg Clayton 1015f9fc609fSGreg Clayton Cleanup(); 10165a988416SJim Ingham } 10175a988416SJim Ingham return handled; 10185a988416SJim Ingham } 10195a988416SJim Ingham 1020e0038717SZachary Turner static llvm::StringRef arch_helper() { 1021d70b14eaSGreg Clayton static StreamString g_archs_help; 1022b9c1b51eSKate Stone if (g_archs_help.Empty()) { 1023ca7835c6SJohnny Chen StringList archs; 10244aa8753cSZachary Turner ArchSpec::AutoComplete(llvm::StringRef(), archs); 1025d70b14eaSGreg Clayton g_archs_help.Printf("These are the supported architecture names:\n"); 1026797a1b37SJohnny Chen archs.Join("\n", g_archs_help); 1027d70b14eaSGreg Clayton } 1028e0038717SZachary Turner return g_archs_help.GetString(); 1029ca7835c6SJohnny Chen } 1030ca7835c6SJohnny Chen 10317428a18cSKate Stone CommandObject::ArgumentTableEntry CommandObject::g_arguments_data[] = { 10327428a18cSKate Stone // clang-format off 1033d78c9576SEd Maste { eArgTypeAddress, "address", CommandCompletions::eNoCompletion, { nullptr, false }, "A valid address in the target program's execution space." }, 1034d78c9576SEd Maste { eArgTypeAddressOrExpression, "address-expression", CommandCompletions::eNoCompletion, { nullptr, false }, "An expression that resolves to an address." }, 1035d78c9576SEd Maste { eArgTypeAliasName, "alias-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of an abbreviation (alias) for a debugger command." }, 1036d78c9576SEd 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.)" }, 1037ca7835c6SJohnny Chen { eArgTypeArchitecture, "arch", CommandCompletions::eArchitectureCompletion, { arch_helper, true }, "The architecture name, e.g. i386 or x86_64." }, 1038d78c9576SEd Maste { eArgTypeBoolean, "boolean", CommandCompletions::eNoCompletion, { nullptr, false }, "A Boolean value: 'true' or 'false'" }, 1039d78c9576SEd Maste { eArgTypeBreakpointID, "breakpt-id", CommandCompletions::eNoCompletion, { BreakpointIDHelpTextCallback, false }, nullptr }, 1040d78c9576SEd Maste { eArgTypeBreakpointIDRange, "breakpt-id-list", CommandCompletions::eNoCompletion, { BreakpointIDRangeHelpTextCallback, false }, nullptr }, 10415e09c8c3SJim Ingham { eArgTypeBreakpointName, "breakpoint-name", CommandCompletions::eNoCompletion, { BreakpointNameHelpTextCallback, false }, nullptr }, 1042d78c9576SEd Maste { eArgTypeByteSize, "byte-size", CommandCompletions::eNoCompletion, { nullptr, false }, "Number of bytes to use." }, 1043d78c9576SEd Maste { eArgTypeClassName, "class-name", CommandCompletions::eNoCompletion, { nullptr, false }, "Then name of a class from the debug information in the program." }, 1044d78c9576SEd Maste { eArgTypeCommandName, "cmd-name", CommandCompletions::eNoCompletion, { nullptr, false }, "A debugger command (may be multiple words), without any options or arguments." }, 1045d78c9576SEd Maste { eArgTypeCount, "count", CommandCompletions::eNoCompletion, { nullptr, false }, "An unsigned integer." }, 1046d78c9576SEd Maste { eArgTypeDirectoryName, "directory", CommandCompletions::eDiskDirectoryCompletion, { nullptr, false }, "A directory name." }, 1047d78c9576SEd 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" }, 1048d78c9576SEd Maste { eArgTypeDescriptionVerbosity, "description-verbosity", CommandCompletions::eNoCompletion, { nullptr, false }, "How verbose the output of 'po' should be." }, 1049d78c9576SEd Maste { eArgTypeEndAddress, "end-address", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, 1050d78c9576SEd Maste { eArgTypeExpression, "expr", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, 1051d78c9576SEd Maste { eArgTypeExpressionPath, "expr-path", CommandCompletions::eNoCompletion, { ExprPathHelpTextCallback, true }, nullptr }, 1052d78c9576SEd 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] ]" }, 1053d78c9576SEd Maste { eArgTypeFilename, "filename", CommandCompletions::eDiskFileCompletion, { nullptr, false }, "The name of a file (can include path)." }, 1054d78c9576SEd Maste { eArgTypeFormat, "format", CommandCompletions::eNoCompletion, { FormatHelpTextCallback, true }, nullptr }, 1055d78c9576SEd Maste { eArgTypeFrameIndex, "frame-index", CommandCompletions::eNoCompletion, { nullptr, false }, "Index into a thread's list of frames." }, 1056d78c9576SEd Maste { eArgTypeFullName, "fullname", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, 1057d78c9576SEd Maste { eArgTypeFunctionName, "function-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a function." }, 1058d78c9576SEd Maste { eArgTypeFunctionOrSymbol, "function-or-symbol", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a function or symbol." }, 1059d78c9576SEd Maste { eArgTypeGDBFormat, "gdb-format", CommandCompletions::eNoCompletion, { GDBFormatHelpTextCallback, true }, nullptr }, 1060735152e3SEnrico Granata { eArgTypeHelpText, "help-text", CommandCompletions::eNoCompletion, { nullptr, false }, "Text to be used as help for some other entity in LLDB" }, 1061d78c9576SEd Maste { eArgTypeIndex, "index", CommandCompletions::eNoCompletion, { nullptr, false }, "An index into a list." }, 10627a67ee26SEnrico Granata { eArgTypeLanguage, "source-language", CommandCompletions::eNoCompletion, { LanguageTypeHelpTextCallback, true }, nullptr }, 1063d78c9576SEd Maste { eArgTypeLineNum, "linenum", CommandCompletions::eNoCompletion, { nullptr, false }, "Line number in a source file." }, 1064d78c9576SEd 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." }, 1065d78c9576SEd 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)." }, 1066d78c9576SEd Maste { eArgTypeMethod, "method", CommandCompletions::eNoCompletion, { nullptr, false }, "A C++ method name." }, 1067d78c9576SEd Maste { eArgTypeName, "name", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, 1068d78c9576SEd Maste { eArgTypeNewPathPrefix, "new-path-prefix", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, 1069d78c9576SEd Maste { eArgTypeNumLines, "num-lines", CommandCompletions::eNoCompletion, { nullptr, false }, "The number of lines to use." }, 1070d78c9576SEd Maste { eArgTypeNumberPerLine, "number-per-line", CommandCompletions::eNoCompletion, { nullptr, false }, "The number of items per line to display." }, 1071d78c9576SEd Maste { eArgTypeOffset, "offset", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, 1072d78c9576SEd Maste { eArgTypeOldPathPrefix, "old-path-prefix", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, 1073d78c9576SEd Maste { eArgTypeOneLiner, "one-line-command", CommandCompletions::eNoCompletion, { nullptr, false }, "A command that is entered as a single line of text." }, 1074d78c9576SEd Maste { eArgTypePath, "path", CommandCompletions::eDiskFileCompletion, { nullptr, false }, "Path." }, 1075d78c9576SEd Maste { eArgTypePermissionsNumber, "perms-numeric", CommandCompletions::eNoCompletion, { nullptr, false }, "Permissions given as an octal number (e.g. 755)." }, 1076d78c9576SEd Maste { eArgTypePermissionsString, "perms=string", CommandCompletions::eNoCompletion, { nullptr, false }, "Permissions given as a string value (e.g. rw-r-xr--)." }, 1077d78c9576SEd Maste { eArgTypePid, "pid", CommandCompletions::eNoCompletion, { nullptr, false }, "The process ID number." }, 1078d78c9576SEd Maste { eArgTypePlugin, "plugin", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, 1079d78c9576SEd Maste { eArgTypeProcessName, "process-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of the process." }, 1080d78c9576SEd Maste { eArgTypePythonClass, "python-class", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a Python class." }, 1081d78c9576SEd Maste { eArgTypePythonFunction, "python-function", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a Python function." }, 1082d78c9576SEd Maste { eArgTypePythonScript, "python-script", CommandCompletions::eNoCompletion, { nullptr, false }, "Source code written in Python." }, 1083d78c9576SEd Maste { eArgTypeQueueName, "queue-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of the thread queue." }, 1084d78c9576SEd Maste { eArgTypeRegisterName, "register-name", CommandCompletions::eNoCompletion, { RegisterNameHelpTextCallback, true }, nullptr }, 1085d78c9576SEd Maste { eArgTypeRegularExpression, "regular-expression", CommandCompletions::eNoCompletion, { nullptr, false }, "A regular expression." }, 1086d78c9576SEd Maste { eArgTypeRunArgs, "run-args", CommandCompletions::eNoCompletion, { nullptr, false }, "Arguments to be passed to the target program when it starts executing." }, 1087d78c9576SEd Maste { eArgTypeRunMode, "run-mode", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, 1088d78c9576SEd Maste { eArgTypeScriptedCommandSynchronicity, "script-cmd-synchronicity", CommandCompletions::eNoCompletion, { nullptr, false }, "The synchronicity to use to run scripted commands with regard to LLDB event system." }, 1089d78c9576SEd Maste { eArgTypeScriptLang, "script-language", CommandCompletions::eNoCompletion, { nullptr, false }, "The scripting language to be used for script-based commands. Currently only Python is valid." }, 10907428a18cSKate Stone { eArgTypeSearchWord, "search-word", CommandCompletions::eNoCompletion, { nullptr, false }, "Any word of interest for search purposes." }, 1091d78c9576SEd Maste { eArgTypeSelector, "selector", CommandCompletions::eNoCompletion, { nullptr, false }, "An Objective-C selector name." }, 1092d78c9576SEd 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)." }, 1093d78c9576SEd 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)." }, 1094d78c9576SEd Maste { eArgTypeSettingPrefix, "setting-prefix", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a settable internal debugger variable up to a dot ('.'), e.g. 'target.process.'" }, 1095d78c9576SEd 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." }, 1096d78c9576SEd Maste { eArgTypeShlibName, "shlib-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a shared library." }, 1097d78c9576SEd Maste { eArgTypeSourceFile, "source-file", CommandCompletions::eSourceFileCompletion, { nullptr, false }, "The name of a source file.." }, 1098d78c9576SEd Maste { eArgTypeSortOrder, "sort-order", CommandCompletions::eNoCompletion, { nullptr, false }, "Specify a sort order when dumping lists." }, 1099d78c9576SEd Maste { eArgTypeStartAddress, "start-address", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, 1100d78c9576SEd Maste { eArgTypeSummaryString, "summary-string", CommandCompletions::eNoCompletion, { SummaryStringHelpTextCallback, true }, nullptr }, 1101d78c9576SEd Maste { eArgTypeSymbol, "symbol", CommandCompletions::eSymbolCompletion, { nullptr, false }, "Any symbol name (function name, variable, argument, etc.)" }, 1102d78c9576SEd Maste { eArgTypeThreadID, "thread-id", CommandCompletions::eNoCompletion, { nullptr, false }, "Thread ID number." }, 1103d78c9576SEd Maste { eArgTypeThreadIndex, "thread-index", CommandCompletions::eNoCompletion, { nullptr, false }, "Index into the process' list of threads." }, 1104d78c9576SEd Maste { eArgTypeThreadName, "thread-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The thread's name." }, 1105a72b31c7SJim Ingham { eArgTypeTypeName, "type-name", CommandCompletions::eNoCompletion, { nullptr, false }, "A type name." }, 1106d78c9576SEd Maste { eArgTypeUnsignedInteger, "unsigned-integer", CommandCompletions::eNoCompletion, { nullptr, false }, "An unsigned integer." }, 1107d78c9576SEd Maste { eArgTypeUnixSignal, "unix-signal", CommandCompletions::eNoCompletion, { nullptr, false }, "A valid Unix signal name or number (e.g. SIGKILL, KILL or 9)." }, 1108d78c9576SEd Maste { eArgTypeVarName, "variable-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a variable in your program." }, 1109d78c9576SEd Maste { eArgTypeValue, "value", CommandCompletions::eNoCompletion, { nullptr, false }, "A value could be anything, depending on where and how it is used." }, 1110d78c9576SEd Maste { eArgTypeWidth, "width", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." }, 1111d78c9576SEd Maste { eArgTypeNone, "none", CommandCompletions::eNoCompletion, { nullptr, false }, "No help available for this." }, 1112d78c9576SEd 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." }, 1113d78c9576SEd Maste { eArgTypeWatchpointID, "watchpt-id", CommandCompletions::eNoCompletion, { nullptr, false }, "Watchpoint IDs are positive integers." }, 1114d78c9576SEd Maste { eArgTypeWatchpointIDRange, "watchpt-id-list", CommandCompletions::eNoCompletion, { nullptr, false }, "For example, '1-3' or '1 to 3'." }, 11157428a18cSKate Stone { eArgTypeWatchType, "watch-type", CommandCompletions::eNoCompletion, { nullptr, false }, "Specify the type for a watchpoint." }, 1116*b842f2ecSJim Ingham { 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." }, 1117*b842f2ecSJim Ingham { eArgTypeCommand, "command", CommandCompletions::eNoCompletion, { nullptr, false }, "An LLDB Command line command." } 11187428a18cSKate Stone // clang-format on 1119e139cf23SCaroline Tice }; 1120e139cf23SCaroline Tice 1121b9c1b51eSKate Stone const CommandObject::ArgumentTableEntry *CommandObject::GetArgumentTable() { 1122b9c1b51eSKate Stone // If this assertion fires, then the table above is out of date with the 1123b9c1b51eSKate Stone // CommandArgumentType enumeration 1124b9c1b51eSKate Stone assert((sizeof(CommandObject::g_arguments_data) / 1125b9c1b51eSKate Stone sizeof(CommandObject::ArgumentTableEntry)) == eArgTypeLastArg); 1126e139cf23SCaroline Tice return CommandObject::g_arguments_data; 1127e139cf23SCaroline Tice } 1128