15ffd83dbSDimitry Andric //===-- CommandObject.cpp -------------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric
90b57cec5SDimitry Andric #include "lldb/Interpreter/CommandObject.h"
100b57cec5SDimitry Andric
110b57cec5SDimitry Andric #include <map>
120b57cec5SDimitry Andric #include <sstream>
130b57cec5SDimitry Andric #include <string>
140b57cec5SDimitry Andric
15*5f7ddb14SDimitry Andric #include <cctype>
16*5f7ddb14SDimitry Andric #include <cstdlib>
170b57cec5SDimitry Andric
180b57cec5SDimitry Andric #include "lldb/Core/Address.h"
190b57cec5SDimitry Andric #include "lldb/Interpreter/Options.h"
200b57cec5SDimitry Andric #include "lldb/Utility/ArchSpec.h"
215ffd83dbSDimitry Andric #include "llvm/ADT/ScopeExit.h"
220b57cec5SDimitry Andric
230b57cec5SDimitry Andric // These are for the Sourcename completers.
240b57cec5SDimitry Andric // FIXME: Make a separate file for the completers.
250b57cec5SDimitry Andric #include "lldb/Core/FileSpecList.h"
260b57cec5SDimitry Andric #include "lldb/DataFormatters/FormatManager.h"
270b57cec5SDimitry Andric #include "lldb/Target/Process.h"
280b57cec5SDimitry Andric #include "lldb/Target/Target.h"
290b57cec5SDimitry Andric #include "lldb/Utility/FileSpec.h"
300b57cec5SDimitry Andric
310b57cec5SDimitry Andric #include "lldb/Target/Language.h"
320b57cec5SDimitry Andric
330b57cec5SDimitry Andric #include "lldb/Interpreter/CommandInterpreter.h"
340b57cec5SDimitry Andric #include "lldb/Interpreter/CommandReturnObject.h"
350b57cec5SDimitry Andric
360b57cec5SDimitry Andric using namespace lldb;
370b57cec5SDimitry Andric using namespace lldb_private;
380b57cec5SDimitry Andric
390b57cec5SDimitry Andric // CommandObject
400b57cec5SDimitry Andric
CommandObject(CommandInterpreter & interpreter,llvm::StringRef name,llvm::StringRef help,llvm::StringRef syntax,uint32_t flags)415ffd83dbSDimitry Andric CommandObject::CommandObject(CommandInterpreter &interpreter,
425ffd83dbSDimitry Andric llvm::StringRef name, llvm::StringRef help,
435ffd83dbSDimitry Andric llvm::StringRef syntax, uint32_t flags)
445ffd83dbSDimitry Andric : m_interpreter(interpreter), m_cmd_name(std::string(name)),
45*5f7ddb14SDimitry Andric m_flags(flags), m_deprecated_command_override_callback(nullptr),
460b57cec5SDimitry Andric m_command_override_callback(nullptr), m_command_override_baton(nullptr) {
475ffd83dbSDimitry Andric m_cmd_help_short = std::string(help);
485ffd83dbSDimitry Andric m_cmd_syntax = std::string(syntax);
490b57cec5SDimitry Andric }
500b57cec5SDimitry Andric
GetDebugger()510b57cec5SDimitry Andric Debugger &CommandObject::GetDebugger() { return m_interpreter.GetDebugger(); }
520b57cec5SDimitry Andric
GetHelp()530b57cec5SDimitry Andric llvm::StringRef CommandObject::GetHelp() { return m_cmd_help_short; }
540b57cec5SDimitry Andric
GetHelpLong()550b57cec5SDimitry Andric llvm::StringRef CommandObject::GetHelpLong() { return m_cmd_help_long; }
560b57cec5SDimitry Andric
GetSyntax()570b57cec5SDimitry Andric llvm::StringRef CommandObject::GetSyntax() {
580b57cec5SDimitry Andric if (!m_cmd_syntax.empty())
590b57cec5SDimitry Andric return m_cmd_syntax;
600b57cec5SDimitry Andric
610b57cec5SDimitry Andric StreamString syntax_str;
620b57cec5SDimitry Andric syntax_str.PutCString(GetCommandName());
630b57cec5SDimitry Andric
640b57cec5SDimitry Andric if (!IsDashDashCommand() && GetOptions() != nullptr)
650b57cec5SDimitry Andric syntax_str.PutCString(" <cmd-options>");
660b57cec5SDimitry Andric
670b57cec5SDimitry Andric if (!m_arguments.empty()) {
680b57cec5SDimitry Andric syntax_str.PutCString(" ");
690b57cec5SDimitry Andric
700b57cec5SDimitry Andric if (!IsDashDashCommand() && WantsRawCommandString() && GetOptions() &&
710b57cec5SDimitry Andric GetOptions()->NumCommandOptions())
720b57cec5SDimitry Andric syntax_str.PutCString("-- ");
730b57cec5SDimitry Andric GetFormattedCommandArguments(syntax_str);
740b57cec5SDimitry Andric }
755ffd83dbSDimitry Andric m_cmd_syntax = std::string(syntax_str.GetString());
760b57cec5SDimitry Andric
770b57cec5SDimitry Andric return m_cmd_syntax;
780b57cec5SDimitry Andric }
790b57cec5SDimitry Andric
GetCommandName() const800b57cec5SDimitry Andric llvm::StringRef CommandObject::GetCommandName() const { return m_cmd_name; }
810b57cec5SDimitry Andric
SetCommandName(llvm::StringRef name)825ffd83dbSDimitry Andric void CommandObject::SetCommandName(llvm::StringRef name) {
835ffd83dbSDimitry Andric m_cmd_name = std::string(name);
845ffd83dbSDimitry Andric }
850b57cec5SDimitry Andric
SetHelp(llvm::StringRef str)865ffd83dbSDimitry Andric void CommandObject::SetHelp(llvm::StringRef str) {
875ffd83dbSDimitry Andric m_cmd_help_short = std::string(str);
885ffd83dbSDimitry Andric }
890b57cec5SDimitry Andric
SetHelpLong(llvm::StringRef str)905ffd83dbSDimitry Andric void CommandObject::SetHelpLong(llvm::StringRef str) {
915ffd83dbSDimitry Andric m_cmd_help_long = std::string(str);
925ffd83dbSDimitry Andric }
930b57cec5SDimitry Andric
SetSyntax(llvm::StringRef str)945ffd83dbSDimitry Andric void CommandObject::SetSyntax(llvm::StringRef str) {
955ffd83dbSDimitry Andric m_cmd_syntax = std::string(str);
965ffd83dbSDimitry Andric }
970b57cec5SDimitry Andric
GetOptions()980b57cec5SDimitry Andric Options *CommandObject::GetOptions() {
990b57cec5SDimitry Andric // By default commands don't have options unless this virtual function is
1000b57cec5SDimitry Andric // overridden by base classes.
1010b57cec5SDimitry Andric return nullptr;
1020b57cec5SDimitry Andric }
1030b57cec5SDimitry Andric
ParseOptions(Args & args,CommandReturnObject & result)1040b57cec5SDimitry Andric bool CommandObject::ParseOptions(Args &args, CommandReturnObject &result) {
1050b57cec5SDimitry Andric // See if the subclass has options?
1060b57cec5SDimitry Andric Options *options = GetOptions();
1070b57cec5SDimitry Andric if (options != nullptr) {
1080b57cec5SDimitry Andric Status error;
1090b57cec5SDimitry Andric
1100b57cec5SDimitry Andric auto exe_ctx = GetCommandInterpreter().GetExecutionContext();
1110b57cec5SDimitry Andric options->NotifyOptionParsingStarting(&exe_ctx);
1120b57cec5SDimitry Andric
1130b57cec5SDimitry Andric const bool require_validation = true;
1140b57cec5SDimitry Andric llvm::Expected<Args> args_or = options->Parse(
1150b57cec5SDimitry Andric args, &exe_ctx, GetCommandInterpreter().GetPlatform(true),
1160b57cec5SDimitry Andric require_validation);
1170b57cec5SDimitry Andric
1180b57cec5SDimitry Andric if (args_or) {
1190b57cec5SDimitry Andric args = std::move(*args_or);
1200b57cec5SDimitry Andric error = options->NotifyOptionParsingFinished(&exe_ctx);
1210b57cec5SDimitry Andric } else
1220b57cec5SDimitry Andric error = args_or.takeError();
1230b57cec5SDimitry Andric
1240b57cec5SDimitry Andric if (error.Success()) {
1250b57cec5SDimitry Andric if (options->VerifyOptions(result))
1260b57cec5SDimitry Andric return true;
1270b57cec5SDimitry Andric } else {
1280b57cec5SDimitry Andric const char *error_cstr = error.AsCString();
1290b57cec5SDimitry Andric if (error_cstr) {
1300b57cec5SDimitry Andric // We got an error string, lets use that
1310b57cec5SDimitry Andric result.AppendError(error_cstr);
1320b57cec5SDimitry Andric } else {
1330b57cec5SDimitry Andric // No error string, output the usage information into result
1340b57cec5SDimitry Andric options->GenerateOptionUsage(
1350b57cec5SDimitry Andric result.GetErrorStream(), this,
1360b57cec5SDimitry Andric GetCommandInterpreter().GetDebugger().GetTerminalWidth());
1370b57cec5SDimitry Andric }
1380b57cec5SDimitry Andric }
1390b57cec5SDimitry Andric result.SetStatus(eReturnStatusFailed);
1400b57cec5SDimitry Andric return false;
1410b57cec5SDimitry Andric }
1420b57cec5SDimitry Andric return true;
1430b57cec5SDimitry Andric }
1440b57cec5SDimitry Andric
CheckRequirements(CommandReturnObject & result)1450b57cec5SDimitry Andric bool CommandObject::CheckRequirements(CommandReturnObject &result) {
1460b57cec5SDimitry Andric // Nothing should be stored in m_exe_ctx between running commands as
1470b57cec5SDimitry Andric // m_exe_ctx has shared pointers to the target, process, thread and frame and
1480b57cec5SDimitry Andric // we don't want any CommandObject instances to keep any of these objects
1490b57cec5SDimitry Andric // around longer than for a single command. Every command should call
1500b57cec5SDimitry Andric // CommandObject::Cleanup() after it has completed.
1510b57cec5SDimitry Andric assert(!m_exe_ctx.GetTargetPtr());
1520b57cec5SDimitry Andric assert(!m_exe_ctx.GetProcessPtr());
1530b57cec5SDimitry Andric assert(!m_exe_ctx.GetThreadPtr());
1540b57cec5SDimitry Andric assert(!m_exe_ctx.GetFramePtr());
1550b57cec5SDimitry Andric
1560b57cec5SDimitry Andric // Lock down the interpreter's execution context prior to running the command
1570b57cec5SDimitry Andric // so we guarantee the selected target, process, thread and frame can't go
1580b57cec5SDimitry Andric // away during the execution
1590b57cec5SDimitry Andric m_exe_ctx = m_interpreter.GetExecutionContext();
1600b57cec5SDimitry Andric
1610b57cec5SDimitry Andric const uint32_t flags = GetFlags().Get();
1620b57cec5SDimitry Andric if (flags & (eCommandRequiresTarget | eCommandRequiresProcess |
1630b57cec5SDimitry Andric eCommandRequiresThread | eCommandRequiresFrame |
1640b57cec5SDimitry Andric eCommandTryTargetAPILock)) {
1650b57cec5SDimitry Andric
1660b57cec5SDimitry Andric if ((flags & eCommandRequiresTarget) && !m_exe_ctx.HasTargetScope()) {
1670b57cec5SDimitry Andric result.AppendError(GetInvalidTargetDescription());
1680b57cec5SDimitry Andric return false;
1690b57cec5SDimitry Andric }
1700b57cec5SDimitry Andric
1710b57cec5SDimitry Andric if ((flags & eCommandRequiresProcess) && !m_exe_ctx.HasProcessScope()) {
1720b57cec5SDimitry Andric if (!m_exe_ctx.HasTargetScope())
1730b57cec5SDimitry Andric result.AppendError(GetInvalidTargetDescription());
1740b57cec5SDimitry Andric else
1750b57cec5SDimitry Andric result.AppendError(GetInvalidProcessDescription());
1760b57cec5SDimitry Andric return false;
1770b57cec5SDimitry Andric }
1780b57cec5SDimitry Andric
1790b57cec5SDimitry Andric if ((flags & eCommandRequiresThread) && !m_exe_ctx.HasThreadScope()) {
1800b57cec5SDimitry Andric if (!m_exe_ctx.HasTargetScope())
1810b57cec5SDimitry Andric result.AppendError(GetInvalidTargetDescription());
1820b57cec5SDimitry Andric else if (!m_exe_ctx.HasProcessScope())
1830b57cec5SDimitry Andric result.AppendError(GetInvalidProcessDescription());
1840b57cec5SDimitry Andric else
1850b57cec5SDimitry Andric result.AppendError(GetInvalidThreadDescription());
1860b57cec5SDimitry Andric return false;
1870b57cec5SDimitry Andric }
1880b57cec5SDimitry Andric
1890b57cec5SDimitry Andric if ((flags & eCommandRequiresFrame) && !m_exe_ctx.HasFrameScope()) {
1900b57cec5SDimitry Andric if (!m_exe_ctx.HasTargetScope())
1910b57cec5SDimitry Andric result.AppendError(GetInvalidTargetDescription());
1920b57cec5SDimitry Andric else if (!m_exe_ctx.HasProcessScope())
1930b57cec5SDimitry Andric result.AppendError(GetInvalidProcessDescription());
1940b57cec5SDimitry Andric else if (!m_exe_ctx.HasThreadScope())
1950b57cec5SDimitry Andric result.AppendError(GetInvalidThreadDescription());
1960b57cec5SDimitry Andric else
1970b57cec5SDimitry Andric result.AppendError(GetInvalidFrameDescription());
1980b57cec5SDimitry Andric return false;
1990b57cec5SDimitry Andric }
2000b57cec5SDimitry Andric
2010b57cec5SDimitry Andric if ((flags & eCommandRequiresRegContext) &&
2020b57cec5SDimitry Andric (m_exe_ctx.GetRegisterContext() == nullptr)) {
2030b57cec5SDimitry Andric result.AppendError(GetInvalidRegContextDescription());
2040b57cec5SDimitry Andric return false;
2050b57cec5SDimitry Andric }
2060b57cec5SDimitry Andric
2070b57cec5SDimitry Andric if (flags & eCommandTryTargetAPILock) {
2080b57cec5SDimitry Andric Target *target = m_exe_ctx.GetTargetPtr();
2090b57cec5SDimitry Andric if (target)
2100b57cec5SDimitry Andric m_api_locker =
2110b57cec5SDimitry Andric std::unique_lock<std::recursive_mutex>(target->GetAPIMutex());
2120b57cec5SDimitry Andric }
2130b57cec5SDimitry Andric }
2140b57cec5SDimitry Andric
2150b57cec5SDimitry Andric if (GetFlags().AnySet(eCommandProcessMustBeLaunched |
2160b57cec5SDimitry Andric eCommandProcessMustBePaused)) {
2170b57cec5SDimitry Andric Process *process = m_interpreter.GetExecutionContext().GetProcessPtr();
2180b57cec5SDimitry Andric if (process == nullptr) {
2190b57cec5SDimitry Andric // A process that is not running is considered paused.
2200b57cec5SDimitry Andric if (GetFlags().Test(eCommandProcessMustBeLaunched)) {
2210b57cec5SDimitry Andric result.AppendError("Process must exist.");
2220b57cec5SDimitry Andric return false;
2230b57cec5SDimitry Andric }
2240b57cec5SDimitry Andric } else {
2250b57cec5SDimitry Andric StateType state = process->GetState();
2260b57cec5SDimitry Andric switch (state) {
2270b57cec5SDimitry Andric case eStateInvalid:
2280b57cec5SDimitry Andric case eStateSuspended:
2290b57cec5SDimitry Andric case eStateCrashed:
2300b57cec5SDimitry Andric case eStateStopped:
2310b57cec5SDimitry Andric break;
2320b57cec5SDimitry Andric
2330b57cec5SDimitry Andric case eStateConnected:
2340b57cec5SDimitry Andric case eStateAttaching:
2350b57cec5SDimitry Andric case eStateLaunching:
2360b57cec5SDimitry Andric case eStateDetached:
2370b57cec5SDimitry Andric case eStateExited:
2380b57cec5SDimitry Andric case eStateUnloaded:
2390b57cec5SDimitry Andric if (GetFlags().Test(eCommandProcessMustBeLaunched)) {
2400b57cec5SDimitry Andric result.AppendError("Process must be launched.");
2410b57cec5SDimitry Andric return false;
2420b57cec5SDimitry Andric }
2430b57cec5SDimitry Andric break;
2440b57cec5SDimitry Andric
2450b57cec5SDimitry Andric case eStateRunning:
2460b57cec5SDimitry Andric case eStateStepping:
2470b57cec5SDimitry Andric if (GetFlags().Test(eCommandProcessMustBePaused)) {
2480b57cec5SDimitry Andric result.AppendError("Process is running. Use 'process interrupt' to "
2490b57cec5SDimitry Andric "pause execution.");
2500b57cec5SDimitry Andric return false;
2510b57cec5SDimitry Andric }
2520b57cec5SDimitry Andric }
2530b57cec5SDimitry Andric }
2540b57cec5SDimitry Andric }
255af732203SDimitry Andric
256af732203SDimitry Andric if (GetFlags().Test(eCommandProcessMustBeTraced)) {
257af732203SDimitry Andric Target *target = m_exe_ctx.GetTargetPtr();
258af732203SDimitry Andric if (target && !target->GetTrace()) {
259*5f7ddb14SDimitry Andric result.AppendError("Process is not being traced.");
260af732203SDimitry Andric return false;
261af732203SDimitry Andric }
262af732203SDimitry Andric }
263af732203SDimitry Andric
2640b57cec5SDimitry Andric return true;
2650b57cec5SDimitry Andric }
2660b57cec5SDimitry Andric
Cleanup()2670b57cec5SDimitry Andric void CommandObject::Cleanup() {
2680b57cec5SDimitry Andric m_exe_ctx.Clear();
2690b57cec5SDimitry Andric if (m_api_locker.owns_lock())
2700b57cec5SDimitry Andric m_api_locker.unlock();
2710b57cec5SDimitry Andric }
2720b57cec5SDimitry Andric
HandleCompletion(CompletionRequest & request)2739dba64beSDimitry Andric void CommandObject::HandleCompletion(CompletionRequest &request) {
2745ffd83dbSDimitry Andric
2755ffd83dbSDimitry Andric m_exe_ctx = m_interpreter.GetExecutionContext();
2765ffd83dbSDimitry Andric auto reset_ctx = llvm::make_scope_exit([this]() { Cleanup(); });
2775ffd83dbSDimitry Andric
2780b57cec5SDimitry Andric // Default implementation of WantsCompletion() is !WantsRawCommandString().
2790b57cec5SDimitry Andric // Subclasses who want raw command string but desire, for example, argument
2800b57cec5SDimitry Andric // completion should override WantsCompletion() to return true, instead.
2810b57cec5SDimitry Andric if (WantsRawCommandString() && !WantsCompletion()) {
2820b57cec5SDimitry Andric // FIXME: Abstract telling the completion to insert the completion
2830b57cec5SDimitry Andric // character.
2849dba64beSDimitry Andric return;
2850b57cec5SDimitry Andric } else {
2860b57cec5SDimitry Andric // Can we do anything generic with the options?
2870b57cec5SDimitry Andric Options *cur_options = GetOptions();
2885ffd83dbSDimitry Andric CommandReturnObject result(m_interpreter.GetDebugger().GetUseColor());
2890b57cec5SDimitry Andric OptionElementVector opt_element_vector;
2900b57cec5SDimitry Andric
2910b57cec5SDimitry Andric if (cur_options != nullptr) {
2920b57cec5SDimitry Andric opt_element_vector = cur_options->ParseForCompletion(
2930b57cec5SDimitry Andric request.GetParsedLine(), request.GetCursorIndex());
2940b57cec5SDimitry Andric
2950b57cec5SDimitry Andric bool handled_by_options = cur_options->HandleOptionCompletion(
2960b57cec5SDimitry Andric request, opt_element_vector, GetCommandInterpreter());
2970b57cec5SDimitry Andric if (handled_by_options)
2989dba64beSDimitry Andric return;
2990b57cec5SDimitry Andric }
3000b57cec5SDimitry Andric
3010b57cec5SDimitry Andric // If we got here, the last word is not an option or an option argument.
3029dba64beSDimitry Andric HandleArgumentCompletion(request, opt_element_vector);
3030b57cec5SDimitry Andric }
3040b57cec5SDimitry Andric }
3050b57cec5SDimitry Andric
HelpTextContainsWord(llvm::StringRef search_word,bool search_short_help,bool search_long_help,bool search_syntax,bool search_options)3060b57cec5SDimitry Andric bool CommandObject::HelpTextContainsWord(llvm::StringRef search_word,
3070b57cec5SDimitry Andric bool search_short_help,
3080b57cec5SDimitry Andric bool search_long_help,
3090b57cec5SDimitry Andric bool search_syntax,
3100b57cec5SDimitry Andric bool search_options) {
3110b57cec5SDimitry Andric std::string options_usage_help;
3120b57cec5SDimitry Andric
3130b57cec5SDimitry Andric bool found_word = false;
3140b57cec5SDimitry Andric
3150b57cec5SDimitry Andric llvm::StringRef short_help = GetHelp();
3160b57cec5SDimitry Andric llvm::StringRef long_help = GetHelpLong();
3170b57cec5SDimitry Andric llvm::StringRef syntax_help = GetSyntax();
3180b57cec5SDimitry Andric
319*5f7ddb14SDimitry Andric if (search_short_help && short_help.contains_insensitive(search_word))
3200b57cec5SDimitry Andric found_word = true;
321*5f7ddb14SDimitry Andric else if (search_long_help && long_help.contains_insensitive(search_word))
3220b57cec5SDimitry Andric found_word = true;
323*5f7ddb14SDimitry Andric else if (search_syntax && syntax_help.contains_insensitive(search_word))
3240b57cec5SDimitry Andric found_word = true;
3250b57cec5SDimitry Andric
3260b57cec5SDimitry Andric if (!found_word && search_options && GetOptions() != nullptr) {
3270b57cec5SDimitry Andric StreamString usage_help;
3280b57cec5SDimitry Andric GetOptions()->GenerateOptionUsage(
3290b57cec5SDimitry Andric usage_help, this,
3300b57cec5SDimitry Andric GetCommandInterpreter().GetDebugger().GetTerminalWidth());
3310b57cec5SDimitry Andric if (!usage_help.Empty()) {
3320b57cec5SDimitry Andric llvm::StringRef usage_text = usage_help.GetString();
333*5f7ddb14SDimitry Andric if (usage_text.contains_insensitive(search_word))
3340b57cec5SDimitry Andric found_word = true;
3350b57cec5SDimitry Andric }
3360b57cec5SDimitry Andric }
3370b57cec5SDimitry Andric
3380b57cec5SDimitry Andric return found_word;
3390b57cec5SDimitry Andric }
3400b57cec5SDimitry Andric
ParseOptionsAndNotify(Args & args,CommandReturnObject & result,OptionGroupOptions & group_options,ExecutionContext & exe_ctx)3410b57cec5SDimitry Andric bool CommandObject::ParseOptionsAndNotify(Args &args,
3420b57cec5SDimitry Andric CommandReturnObject &result,
3430b57cec5SDimitry Andric OptionGroupOptions &group_options,
3440b57cec5SDimitry Andric ExecutionContext &exe_ctx) {
3450b57cec5SDimitry Andric if (!ParseOptions(args, result))
3460b57cec5SDimitry Andric return false;
3470b57cec5SDimitry Andric
3480b57cec5SDimitry Andric Status error(group_options.NotifyOptionParsingFinished(&exe_ctx));
3490b57cec5SDimitry Andric if (error.Fail()) {
3500b57cec5SDimitry Andric result.AppendError(error.AsCString());
3510b57cec5SDimitry Andric return false;
3520b57cec5SDimitry Andric }
3530b57cec5SDimitry Andric return true;
3540b57cec5SDimitry Andric }
3550b57cec5SDimitry Andric
GetNumArgumentEntries()3560b57cec5SDimitry Andric int CommandObject::GetNumArgumentEntries() { return m_arguments.size(); }
3570b57cec5SDimitry Andric
3580b57cec5SDimitry Andric CommandObject::CommandArgumentEntry *
GetArgumentEntryAtIndex(int idx)3590b57cec5SDimitry Andric CommandObject::GetArgumentEntryAtIndex(int idx) {
3600b57cec5SDimitry Andric if (static_cast<size_t>(idx) < m_arguments.size())
3610b57cec5SDimitry Andric return &(m_arguments[idx]);
3620b57cec5SDimitry Andric
3630b57cec5SDimitry Andric return nullptr;
3640b57cec5SDimitry Andric }
3650b57cec5SDimitry Andric
3660b57cec5SDimitry Andric const CommandObject::ArgumentTableEntry *
FindArgumentDataByType(CommandArgumentType arg_type)3670b57cec5SDimitry Andric CommandObject::FindArgumentDataByType(CommandArgumentType arg_type) {
3680b57cec5SDimitry Andric const ArgumentTableEntry *table = CommandObject::GetArgumentTable();
3690b57cec5SDimitry Andric
3700b57cec5SDimitry Andric for (int i = 0; i < eArgTypeLastArg; ++i)
3710b57cec5SDimitry Andric if (table[i].arg_type == arg_type)
3720b57cec5SDimitry Andric return &(table[i]);
3730b57cec5SDimitry Andric
3740b57cec5SDimitry Andric return nullptr;
3750b57cec5SDimitry Andric }
3760b57cec5SDimitry Andric
GetArgumentHelp(Stream & str,CommandArgumentType arg_type,CommandInterpreter & interpreter)3770b57cec5SDimitry Andric void CommandObject::GetArgumentHelp(Stream &str, CommandArgumentType arg_type,
3780b57cec5SDimitry Andric CommandInterpreter &interpreter) {
3790b57cec5SDimitry Andric const ArgumentTableEntry *table = CommandObject::GetArgumentTable();
3800b57cec5SDimitry Andric const ArgumentTableEntry *entry = &(table[arg_type]);
3810b57cec5SDimitry Andric
3820b57cec5SDimitry Andric // The table is *supposed* to be kept in arg_type order, but someone *could*
3830b57cec5SDimitry Andric // have messed it up...
3840b57cec5SDimitry Andric
3850b57cec5SDimitry Andric if (entry->arg_type != arg_type)
3860b57cec5SDimitry Andric entry = CommandObject::FindArgumentDataByType(arg_type);
3870b57cec5SDimitry Andric
3880b57cec5SDimitry Andric if (!entry)
3890b57cec5SDimitry Andric return;
3900b57cec5SDimitry Andric
3910b57cec5SDimitry Andric StreamString name_str;
3920b57cec5SDimitry Andric name_str.Printf("<%s>", entry->arg_name);
3930b57cec5SDimitry Andric
3940b57cec5SDimitry Andric if (entry->help_function) {
3950b57cec5SDimitry Andric llvm::StringRef help_text = entry->help_function();
3960b57cec5SDimitry Andric if (!entry->help_function.self_formatting) {
3970b57cec5SDimitry Andric interpreter.OutputFormattedHelpText(str, name_str.GetString(), "--",
3980b57cec5SDimitry Andric help_text, name_str.GetSize());
3990b57cec5SDimitry Andric } else {
4000b57cec5SDimitry Andric interpreter.OutputHelpText(str, name_str.GetString(), "--", help_text,
4010b57cec5SDimitry Andric name_str.GetSize());
4020b57cec5SDimitry Andric }
4030b57cec5SDimitry Andric } else
4040b57cec5SDimitry Andric interpreter.OutputFormattedHelpText(str, name_str.GetString(), "--",
4050b57cec5SDimitry Andric entry->help_text, name_str.GetSize());
4060b57cec5SDimitry Andric }
4070b57cec5SDimitry Andric
GetArgumentName(CommandArgumentType arg_type)4080b57cec5SDimitry Andric const char *CommandObject::GetArgumentName(CommandArgumentType arg_type) {
4090b57cec5SDimitry Andric const ArgumentTableEntry *entry =
4100b57cec5SDimitry Andric &(CommandObject::GetArgumentTable()[arg_type]);
4110b57cec5SDimitry Andric
4120b57cec5SDimitry Andric // The table is *supposed* to be kept in arg_type order, but someone *could*
4130b57cec5SDimitry Andric // have messed it up...
4140b57cec5SDimitry Andric
4150b57cec5SDimitry Andric if (entry->arg_type != arg_type)
4160b57cec5SDimitry Andric entry = CommandObject::FindArgumentDataByType(arg_type);
4170b57cec5SDimitry Andric
4180b57cec5SDimitry Andric if (entry)
4190b57cec5SDimitry Andric return entry->arg_name;
4200b57cec5SDimitry Andric
4210b57cec5SDimitry Andric return nullptr;
4220b57cec5SDimitry Andric }
4230b57cec5SDimitry Andric
IsPairType(ArgumentRepetitionType arg_repeat_type)4240b57cec5SDimitry Andric bool CommandObject::IsPairType(ArgumentRepetitionType arg_repeat_type) {
4250b57cec5SDimitry Andric return (arg_repeat_type == eArgRepeatPairPlain) ||
4260b57cec5SDimitry Andric (arg_repeat_type == eArgRepeatPairOptional) ||
4270b57cec5SDimitry Andric (arg_repeat_type == eArgRepeatPairPlus) ||
4280b57cec5SDimitry Andric (arg_repeat_type == eArgRepeatPairStar) ||
4290b57cec5SDimitry Andric (arg_repeat_type == eArgRepeatPairRange) ||
4300b57cec5SDimitry Andric (arg_repeat_type == eArgRepeatPairRangeOptional);
4310b57cec5SDimitry Andric }
4320b57cec5SDimitry Andric
4330b57cec5SDimitry Andric static CommandObject::CommandArgumentEntry
OptSetFiltered(uint32_t opt_set_mask,CommandObject::CommandArgumentEntry & cmd_arg_entry)4340b57cec5SDimitry Andric OptSetFiltered(uint32_t opt_set_mask,
4350b57cec5SDimitry Andric CommandObject::CommandArgumentEntry &cmd_arg_entry) {
4360b57cec5SDimitry Andric CommandObject::CommandArgumentEntry ret_val;
4370b57cec5SDimitry Andric for (unsigned i = 0; i < cmd_arg_entry.size(); ++i)
4380b57cec5SDimitry Andric if (opt_set_mask & cmd_arg_entry[i].arg_opt_set_association)
4390b57cec5SDimitry Andric ret_val.push_back(cmd_arg_entry[i]);
4400b57cec5SDimitry Andric return ret_val;
4410b57cec5SDimitry Andric }
4420b57cec5SDimitry Andric
4430b57cec5SDimitry Andric // Default parameter value of opt_set_mask is LLDB_OPT_SET_ALL, which means
4440b57cec5SDimitry Andric // take all the argument data into account. On rare cases where some argument
4450b57cec5SDimitry Andric // sticks with certain option sets, this function returns the option set
4460b57cec5SDimitry Andric // filtered args.
GetFormattedCommandArguments(Stream & str,uint32_t opt_set_mask)4470b57cec5SDimitry Andric void CommandObject::GetFormattedCommandArguments(Stream &str,
4480b57cec5SDimitry Andric uint32_t opt_set_mask) {
4490b57cec5SDimitry Andric int num_args = m_arguments.size();
4500b57cec5SDimitry Andric for (int i = 0; i < num_args; ++i) {
4510b57cec5SDimitry Andric if (i > 0)
4520b57cec5SDimitry Andric str.Printf(" ");
4530b57cec5SDimitry Andric CommandArgumentEntry arg_entry =
4540b57cec5SDimitry Andric opt_set_mask == LLDB_OPT_SET_ALL
4550b57cec5SDimitry Andric ? m_arguments[i]
4560b57cec5SDimitry Andric : OptSetFiltered(opt_set_mask, m_arguments[i]);
4570b57cec5SDimitry Andric int num_alternatives = arg_entry.size();
4580b57cec5SDimitry Andric
4590b57cec5SDimitry Andric if ((num_alternatives == 2) && IsPairType(arg_entry[0].arg_repetition)) {
4600b57cec5SDimitry Andric const char *first_name = GetArgumentName(arg_entry[0].arg_type);
4610b57cec5SDimitry Andric const char *second_name = GetArgumentName(arg_entry[1].arg_type);
4620b57cec5SDimitry Andric switch (arg_entry[0].arg_repetition) {
4630b57cec5SDimitry Andric case eArgRepeatPairPlain:
4640b57cec5SDimitry Andric str.Printf("<%s> <%s>", first_name, second_name);
4650b57cec5SDimitry Andric break;
4660b57cec5SDimitry Andric case eArgRepeatPairOptional:
4670b57cec5SDimitry Andric str.Printf("[<%s> <%s>]", first_name, second_name);
4680b57cec5SDimitry Andric break;
4690b57cec5SDimitry Andric case eArgRepeatPairPlus:
4700b57cec5SDimitry Andric str.Printf("<%s> <%s> [<%s> <%s> [...]]", first_name, second_name,
4710b57cec5SDimitry Andric first_name, second_name);
4720b57cec5SDimitry Andric break;
4730b57cec5SDimitry Andric case eArgRepeatPairStar:
4740b57cec5SDimitry Andric str.Printf("[<%s> <%s> [<%s> <%s> [...]]]", first_name, second_name,
4750b57cec5SDimitry Andric first_name, second_name);
4760b57cec5SDimitry Andric break;
4770b57cec5SDimitry Andric case eArgRepeatPairRange:
4780b57cec5SDimitry Andric str.Printf("<%s_1> <%s_1> ... <%s_n> <%s_n>", first_name, second_name,
4790b57cec5SDimitry Andric first_name, second_name);
4800b57cec5SDimitry Andric break;
4810b57cec5SDimitry Andric case eArgRepeatPairRangeOptional:
4820b57cec5SDimitry Andric str.Printf("[<%s_1> <%s_1> ... <%s_n> <%s_n>]", first_name, second_name,
4830b57cec5SDimitry Andric first_name, second_name);
4840b57cec5SDimitry Andric break;
4850b57cec5SDimitry Andric // Explicitly test for all the rest of the cases, so if new types get
4860b57cec5SDimitry Andric // added we will notice the missing case statement(s).
4870b57cec5SDimitry Andric case eArgRepeatPlain:
4880b57cec5SDimitry Andric case eArgRepeatOptional:
4890b57cec5SDimitry Andric case eArgRepeatPlus:
4900b57cec5SDimitry Andric case eArgRepeatStar:
4910b57cec5SDimitry Andric case eArgRepeatRange:
4920b57cec5SDimitry Andric // These should not be reached, as they should fail the IsPairType test
4930b57cec5SDimitry Andric // above.
4940b57cec5SDimitry Andric break;
4950b57cec5SDimitry Andric }
4960b57cec5SDimitry Andric } else {
4970b57cec5SDimitry Andric StreamString names;
4980b57cec5SDimitry Andric for (int j = 0; j < num_alternatives; ++j) {
4990b57cec5SDimitry Andric if (j > 0)
5000b57cec5SDimitry Andric names.Printf(" | ");
5010b57cec5SDimitry Andric names.Printf("%s", GetArgumentName(arg_entry[j].arg_type));
5020b57cec5SDimitry Andric }
5030b57cec5SDimitry Andric
5045ffd83dbSDimitry Andric std::string name_str = std::string(names.GetString());
5050b57cec5SDimitry Andric switch (arg_entry[0].arg_repetition) {
5060b57cec5SDimitry Andric case eArgRepeatPlain:
5070b57cec5SDimitry Andric str.Printf("<%s>", name_str.c_str());
5080b57cec5SDimitry Andric break;
5090b57cec5SDimitry Andric case eArgRepeatPlus:
5100b57cec5SDimitry Andric str.Printf("<%s> [<%s> [...]]", name_str.c_str(), name_str.c_str());
5110b57cec5SDimitry Andric break;
5120b57cec5SDimitry Andric case eArgRepeatStar:
5130b57cec5SDimitry Andric str.Printf("[<%s> [<%s> [...]]]", name_str.c_str(), name_str.c_str());
5140b57cec5SDimitry Andric break;
5150b57cec5SDimitry Andric case eArgRepeatOptional:
5160b57cec5SDimitry Andric str.Printf("[<%s>]", name_str.c_str());
5170b57cec5SDimitry Andric break;
5180b57cec5SDimitry Andric case eArgRepeatRange:
5190b57cec5SDimitry Andric str.Printf("<%s_1> .. <%s_n>", name_str.c_str(), name_str.c_str());
5200b57cec5SDimitry Andric break;
5210b57cec5SDimitry Andric // Explicitly test for all the rest of the cases, so if new types get
5220b57cec5SDimitry Andric // added we will notice the missing case statement(s).
5230b57cec5SDimitry Andric case eArgRepeatPairPlain:
5240b57cec5SDimitry Andric case eArgRepeatPairOptional:
5250b57cec5SDimitry Andric case eArgRepeatPairPlus:
5260b57cec5SDimitry Andric case eArgRepeatPairStar:
5270b57cec5SDimitry Andric case eArgRepeatPairRange:
5280b57cec5SDimitry Andric case eArgRepeatPairRangeOptional:
5290b57cec5SDimitry Andric // These should not be hit, as they should pass the IsPairType test
5300b57cec5SDimitry Andric // above, and control should have gone into the other branch of the if
5310b57cec5SDimitry Andric // statement.
5320b57cec5SDimitry Andric break;
5330b57cec5SDimitry Andric }
5340b57cec5SDimitry Andric }
5350b57cec5SDimitry Andric }
5360b57cec5SDimitry Andric }
5370b57cec5SDimitry Andric
5380b57cec5SDimitry Andric CommandArgumentType
LookupArgumentName(llvm::StringRef arg_name)5390b57cec5SDimitry Andric CommandObject::LookupArgumentName(llvm::StringRef arg_name) {
5400b57cec5SDimitry Andric CommandArgumentType return_type = eArgTypeLastArg;
5410b57cec5SDimitry Andric
5420b57cec5SDimitry Andric arg_name = arg_name.ltrim('<').rtrim('>');
5430b57cec5SDimitry Andric
5440b57cec5SDimitry Andric const ArgumentTableEntry *table = GetArgumentTable();
5450b57cec5SDimitry Andric for (int i = 0; i < eArgTypeLastArg; ++i)
5460b57cec5SDimitry Andric if (arg_name == table[i].arg_name)
5470b57cec5SDimitry Andric return_type = g_arguments_data[i].arg_type;
5480b57cec5SDimitry Andric
5490b57cec5SDimitry Andric return return_type;
5500b57cec5SDimitry Andric }
5510b57cec5SDimitry Andric
RegisterNameHelpTextCallback()5520b57cec5SDimitry Andric static llvm::StringRef RegisterNameHelpTextCallback() {
5530b57cec5SDimitry Andric return "Register names can be specified using the architecture specific "
5540b57cec5SDimitry Andric "names. "
5550b57cec5SDimitry Andric "They can also be specified using generic names. Not all generic "
5560b57cec5SDimitry Andric "entities have "
5570b57cec5SDimitry Andric "registers backing them on all architectures. When they don't the "
5580b57cec5SDimitry Andric "generic name "
5590b57cec5SDimitry Andric "will return an error.\n"
5600b57cec5SDimitry Andric "The generic names defined in lldb are:\n"
5610b57cec5SDimitry Andric "\n"
5620b57cec5SDimitry Andric "pc - program counter register\n"
5630b57cec5SDimitry Andric "ra - return address register\n"
5640b57cec5SDimitry Andric "fp - frame pointer register\n"
5650b57cec5SDimitry Andric "sp - stack pointer register\n"
5660b57cec5SDimitry Andric "flags - the flags register\n"
5670b57cec5SDimitry Andric "arg{1-6} - integer argument passing registers.\n";
5680b57cec5SDimitry Andric }
5690b57cec5SDimitry Andric
BreakpointIDHelpTextCallback()5700b57cec5SDimitry Andric static llvm::StringRef BreakpointIDHelpTextCallback() {
5710b57cec5SDimitry Andric return "Breakpoints are identified using major and minor numbers; the major "
5720b57cec5SDimitry Andric "number corresponds to the single entity that was created with a "
5730b57cec5SDimitry Andric "'breakpoint "
5740b57cec5SDimitry Andric "set' command; the minor numbers correspond to all the locations that "
5750b57cec5SDimitry Andric "were "
5760b57cec5SDimitry Andric "actually found/set based on the major breakpoint. A full breakpoint "
5770b57cec5SDimitry Andric "ID might "
5780b57cec5SDimitry Andric "look like 3.14, meaning the 14th location set for the 3rd "
5790b57cec5SDimitry Andric "breakpoint. You "
5800b57cec5SDimitry Andric "can specify all the locations of a breakpoint by just indicating the "
5810b57cec5SDimitry Andric "major "
5820b57cec5SDimitry Andric "breakpoint number. A valid breakpoint ID consists either of just the "
5830b57cec5SDimitry Andric "major "
5840b57cec5SDimitry Andric "number, or the major number followed by a dot and the location "
5850b57cec5SDimitry Andric "number (e.g. "
5860b57cec5SDimitry Andric "3 or 3.2 could both be valid breakpoint IDs.)";
5870b57cec5SDimitry Andric }
5880b57cec5SDimitry Andric
BreakpointIDRangeHelpTextCallback()5890b57cec5SDimitry Andric static llvm::StringRef BreakpointIDRangeHelpTextCallback() {
5900b57cec5SDimitry Andric return "A 'breakpoint ID list' is a manner of specifying multiple "
5910b57cec5SDimitry Andric "breakpoints. "
5920b57cec5SDimitry Andric "This can be done through several mechanisms. The easiest way is to "
5930b57cec5SDimitry Andric "just "
5940b57cec5SDimitry Andric "enter a space-separated list of breakpoint IDs. To specify all the "
5950b57cec5SDimitry Andric "breakpoint locations under a major breakpoint, you can use the major "
5960b57cec5SDimitry Andric "breakpoint number followed by '.*', eg. '5.*' means all the "
5970b57cec5SDimitry Andric "locations under "
5980b57cec5SDimitry Andric "breakpoint 5. You can also indicate a range of breakpoints by using "
5990b57cec5SDimitry Andric "<start-bp-id> - <end-bp-id>. The start-bp-id and end-bp-id for a "
6000b57cec5SDimitry Andric "range can "
6010b57cec5SDimitry Andric "be any valid breakpoint IDs. It is not legal, however, to specify a "
6020b57cec5SDimitry Andric "range "
6030b57cec5SDimitry Andric "using specific locations that cross major breakpoint numbers. I.e. "
6040b57cec5SDimitry Andric "3.2 - 3.7"
6050b57cec5SDimitry Andric " is legal; 2 - 5 is legal; but 3.2 - 4.4 is not legal.";
6060b57cec5SDimitry Andric }
6070b57cec5SDimitry Andric
BreakpointNameHelpTextCallback()6080b57cec5SDimitry Andric static llvm::StringRef BreakpointNameHelpTextCallback() {
6090b57cec5SDimitry Andric return "A name that can be added to a breakpoint when it is created, or "
6100b57cec5SDimitry Andric "later "
6110b57cec5SDimitry Andric "on with the \"breakpoint name add\" command. "
6120b57cec5SDimitry Andric "Breakpoint names can be used to specify breakpoints in all the "
6130b57cec5SDimitry Andric "places breakpoint IDs "
6140b57cec5SDimitry Andric "and breakpoint ID ranges can be used. As such they provide a "
6150b57cec5SDimitry Andric "convenient way to group breakpoints, "
6160b57cec5SDimitry Andric "and to operate on breakpoints you create without having to track the "
6170b57cec5SDimitry Andric "breakpoint number. "
6180b57cec5SDimitry Andric "Note, the attributes you set when using a breakpoint name in a "
6190b57cec5SDimitry Andric "breakpoint command don't "
6200b57cec5SDimitry Andric "adhere to the name, but instead are set individually on all the "
6210b57cec5SDimitry Andric "breakpoints currently tagged with that "
6220b57cec5SDimitry Andric "name. Future breakpoints "
6230b57cec5SDimitry Andric "tagged with that name will not pick up the attributes previously "
6240b57cec5SDimitry Andric "given using that name. "
6250b57cec5SDimitry Andric "In order to distinguish breakpoint names from breakpoint IDs and "
6260b57cec5SDimitry Andric "ranges, "
6270b57cec5SDimitry Andric "names must start with a letter from a-z or A-Z and cannot contain "
6280b57cec5SDimitry Andric "spaces, \".\" or \"-\". "
6290b57cec5SDimitry Andric "Also, breakpoint names can only be applied to breakpoints, not to "
6300b57cec5SDimitry Andric "breakpoint locations.";
6310b57cec5SDimitry Andric }
6320b57cec5SDimitry Andric
GDBFormatHelpTextCallback()6330b57cec5SDimitry Andric static llvm::StringRef GDBFormatHelpTextCallback() {
6340b57cec5SDimitry Andric return "A GDB format consists of a repeat count, a format letter and a size "
6350b57cec5SDimitry Andric "letter. "
6360b57cec5SDimitry Andric "The repeat count is optional and defaults to 1. The format letter is "
6370b57cec5SDimitry Andric "optional "
6380b57cec5SDimitry Andric "and defaults to the previous format that was used. The size letter "
6390b57cec5SDimitry Andric "is optional "
6400b57cec5SDimitry Andric "and defaults to the previous size that was used.\n"
6410b57cec5SDimitry Andric "\n"
6420b57cec5SDimitry Andric "Format letters include:\n"
6430b57cec5SDimitry Andric "o - octal\n"
6440b57cec5SDimitry Andric "x - hexadecimal\n"
6450b57cec5SDimitry Andric "d - decimal\n"
6460b57cec5SDimitry Andric "u - unsigned decimal\n"
6470b57cec5SDimitry Andric "t - binary\n"
6480b57cec5SDimitry Andric "f - float\n"
6490b57cec5SDimitry Andric "a - address\n"
6500b57cec5SDimitry Andric "i - instruction\n"
6510b57cec5SDimitry Andric "c - char\n"
6520b57cec5SDimitry Andric "s - string\n"
6530b57cec5SDimitry Andric "T - OSType\n"
6540b57cec5SDimitry Andric "A - float as hex\n"
6550b57cec5SDimitry Andric "\n"
6560b57cec5SDimitry Andric "Size letters include:\n"
6570b57cec5SDimitry Andric "b - 1 byte (byte)\n"
6580b57cec5SDimitry Andric "h - 2 bytes (halfword)\n"
6590b57cec5SDimitry Andric "w - 4 bytes (word)\n"
6600b57cec5SDimitry Andric "g - 8 bytes (giant)\n"
6610b57cec5SDimitry Andric "\n"
6620b57cec5SDimitry Andric "Example formats:\n"
6630b57cec5SDimitry Andric "32xb - show 32 1 byte hexadecimal integer values\n"
6640b57cec5SDimitry Andric "16xh - show 16 2 byte hexadecimal integer values\n"
6650b57cec5SDimitry Andric "64 - show 64 2 byte hexadecimal integer values (format and size "
6660b57cec5SDimitry Andric "from the last format)\n"
6670b57cec5SDimitry Andric "dw - show 1 4 byte decimal integer value\n";
6680b57cec5SDimitry Andric }
6690b57cec5SDimitry Andric
FormatHelpTextCallback()6700b57cec5SDimitry Andric static llvm::StringRef FormatHelpTextCallback() {
6710b57cec5SDimitry Andric static std::string help_text;
6720b57cec5SDimitry Andric
6730b57cec5SDimitry Andric if (!help_text.empty())
6740b57cec5SDimitry Andric return help_text;
6750b57cec5SDimitry Andric
6760b57cec5SDimitry Andric StreamString sstr;
6770b57cec5SDimitry Andric sstr << "One of the format names (or one-character names) that can be used "
6780b57cec5SDimitry Andric "to show a variable's value:\n";
6790b57cec5SDimitry Andric for (Format f = eFormatDefault; f < kNumFormats; f = Format(f + 1)) {
6800b57cec5SDimitry Andric if (f != eFormatDefault)
6810b57cec5SDimitry Andric sstr.PutChar('\n');
6820b57cec5SDimitry Andric
6830b57cec5SDimitry Andric char format_char = FormatManager::GetFormatAsFormatChar(f);
6840b57cec5SDimitry Andric if (format_char)
6850b57cec5SDimitry Andric sstr.Printf("'%c' or ", format_char);
6860b57cec5SDimitry Andric
6870b57cec5SDimitry Andric sstr.Printf("\"%s\"", FormatManager::GetFormatAsCString(f));
6880b57cec5SDimitry Andric }
6890b57cec5SDimitry Andric
6900b57cec5SDimitry Andric sstr.Flush();
6910b57cec5SDimitry Andric
6925ffd83dbSDimitry Andric help_text = std::string(sstr.GetString());
6930b57cec5SDimitry Andric
6940b57cec5SDimitry Andric return help_text;
6950b57cec5SDimitry Andric }
6960b57cec5SDimitry Andric
LanguageTypeHelpTextCallback()6970b57cec5SDimitry Andric static llvm::StringRef LanguageTypeHelpTextCallback() {
6980b57cec5SDimitry Andric static std::string help_text;
6990b57cec5SDimitry Andric
7000b57cec5SDimitry Andric if (!help_text.empty())
7010b57cec5SDimitry Andric return help_text;
7020b57cec5SDimitry Andric
7030b57cec5SDimitry Andric StreamString sstr;
7040b57cec5SDimitry Andric sstr << "One of the following languages:\n";
7050b57cec5SDimitry Andric
7060b57cec5SDimitry Andric Language::PrintAllLanguages(sstr, " ", "\n");
7070b57cec5SDimitry Andric
7080b57cec5SDimitry Andric sstr.Flush();
7090b57cec5SDimitry Andric
7105ffd83dbSDimitry Andric help_text = std::string(sstr.GetString());
7110b57cec5SDimitry Andric
7120b57cec5SDimitry Andric return help_text;
7130b57cec5SDimitry Andric }
7140b57cec5SDimitry Andric
SummaryStringHelpTextCallback()7150b57cec5SDimitry Andric static llvm::StringRef SummaryStringHelpTextCallback() {
7160b57cec5SDimitry Andric return "A summary string is a way to extract information from variables in "
7170b57cec5SDimitry Andric "order to present them using a summary.\n"
7180b57cec5SDimitry Andric "Summary strings contain static text, variables, scopes and control "
7190b57cec5SDimitry Andric "sequences:\n"
7200b57cec5SDimitry Andric " - Static text can be any sequence of non-special characters, i.e. "
7210b57cec5SDimitry Andric "anything but '{', '}', '$', or '\\'.\n"
7220b57cec5SDimitry Andric " - Variables are sequences of characters beginning with ${, ending "
7230b57cec5SDimitry Andric "with } and that contain symbols in the format described below.\n"
7240b57cec5SDimitry Andric " - Scopes are any sequence of text between { and }. Anything "
7250b57cec5SDimitry Andric "included in a scope will only appear in the output summary if there "
7260b57cec5SDimitry Andric "were no errors.\n"
7270b57cec5SDimitry Andric " - Control sequences are the usual C/C++ '\\a', '\\n', ..., plus "
7280b57cec5SDimitry Andric "'\\$', '\\{' and '\\}'.\n"
7290b57cec5SDimitry Andric "A summary string works by copying static text verbatim, turning "
7300b57cec5SDimitry Andric "control sequences into their character counterpart, expanding "
7310b57cec5SDimitry Andric "variables and trying to expand scopes.\n"
7320b57cec5SDimitry Andric "A variable is expanded by giving it a value other than its textual "
7330b57cec5SDimitry Andric "representation, and the way this is done depends on what comes after "
7340b57cec5SDimitry Andric "the ${ marker.\n"
7350b57cec5SDimitry Andric "The most common sequence if ${var followed by an expression path, "
7360b57cec5SDimitry Andric "which is the text one would type to access a member of an aggregate "
7370b57cec5SDimitry Andric "types, given a variable of that type"
7380b57cec5SDimitry Andric " (e.g. if type T has a member named x, which has a member named y, "
7390b57cec5SDimitry Andric "and if t is of type T, the expression path would be .x.y and the way "
7400b57cec5SDimitry Andric "to fit that into a summary string would be"
7410b57cec5SDimitry Andric " ${var.x.y}). You can also use ${*var followed by an expression path "
7420b57cec5SDimitry Andric "and in that case the object referred by the path will be "
7430b57cec5SDimitry Andric "dereferenced before being displayed."
7440b57cec5SDimitry Andric " If the object is not a pointer, doing so will cause an error. For "
7450b57cec5SDimitry Andric "additional details on expression paths, you can type 'help "
7460b57cec5SDimitry Andric "expr-path'. \n"
7470b57cec5SDimitry Andric "By default, summary strings attempt to display the summary for any "
7480b57cec5SDimitry Andric "variable they reference, and if that fails the value. If neither can "
7490b57cec5SDimitry Andric "be shown, nothing is displayed."
7500b57cec5SDimitry Andric "In a summary string, you can also use an array index [n], or a "
7510b57cec5SDimitry Andric "slice-like range [n-m]. This can have two different meanings "
7520b57cec5SDimitry Andric "depending on what kind of object the expression"
7530b57cec5SDimitry Andric " path refers to:\n"
7540b57cec5SDimitry Andric " - if it is a scalar type (any basic type like int, float, ...) the "
7550b57cec5SDimitry Andric "expression is a bitfield, i.e. the bits indicated by the indexing "
7560b57cec5SDimitry Andric "operator are extracted out of the number"
7570b57cec5SDimitry Andric " and displayed as an individual variable\n"
7580b57cec5SDimitry Andric " - if it is an array or pointer the array items indicated by the "
7590b57cec5SDimitry Andric "indexing operator are shown as the result of the variable. if the "
7600b57cec5SDimitry Andric "expression is an array, real array items are"
7610b57cec5SDimitry Andric " printed; if it is a pointer, the pointer-as-array syntax is used to "
7620b57cec5SDimitry Andric "obtain the values (this means, the latter case can have no range "
7630b57cec5SDimitry Andric "checking)\n"
7640b57cec5SDimitry Andric "If you are trying to display an array for which the size is known, "
7650b57cec5SDimitry Andric "you can also use [] instead of giving an exact range. This has the "
7660b57cec5SDimitry Andric "effect of showing items 0 thru size - 1.\n"
7670b57cec5SDimitry Andric "Additionally, a variable can contain an (optional) format code, as "
7680b57cec5SDimitry Andric "in ${var.x.y%code}, where code can be any of the valid formats "
7690b57cec5SDimitry Andric "described in 'help format', or one of the"
7700b57cec5SDimitry Andric " special symbols only allowed as part of a variable:\n"
7710b57cec5SDimitry Andric " %V: show the value of the object by default\n"
7720b57cec5SDimitry Andric " %S: show the summary of the object by default\n"
7730b57cec5SDimitry Andric " %@: show the runtime-provided object description (for "
7740b57cec5SDimitry Andric "Objective-C, it calls NSPrintForDebugger; for C/C++ it does "
7750b57cec5SDimitry Andric "nothing)\n"
7760b57cec5SDimitry Andric " %L: show the location of the object (memory address or a "
7770b57cec5SDimitry Andric "register name)\n"
7780b57cec5SDimitry Andric " %#: show the number of children of the object\n"
7790b57cec5SDimitry Andric " %T: show the type of the object\n"
7800b57cec5SDimitry Andric "Another variable that you can use in summary strings is ${svar . "
7810b57cec5SDimitry Andric "This sequence works exactly like ${var, including the fact that "
7820b57cec5SDimitry Andric "${*svar is an allowed sequence, but uses"
7830b57cec5SDimitry Andric " the object's synthetic children provider instead of the actual "
7840b57cec5SDimitry Andric "objects. For instance, if you are using STL synthetic children "
7850b57cec5SDimitry Andric "providers, the following summary string would"
7860b57cec5SDimitry Andric " count the number of actual elements stored in an std::list:\n"
7870b57cec5SDimitry Andric "type summary add -s \"${svar%#}\" -x \"std::list<\"";
7880b57cec5SDimitry Andric }
7890b57cec5SDimitry Andric
ExprPathHelpTextCallback()7900b57cec5SDimitry Andric static llvm::StringRef ExprPathHelpTextCallback() {
7910b57cec5SDimitry Andric return "An expression path is the sequence of symbols that is used in C/C++ "
7920b57cec5SDimitry Andric "to access a member variable of an aggregate object (class).\n"
7930b57cec5SDimitry Andric "For instance, given a class:\n"
7940b57cec5SDimitry Andric " class foo {\n"
7950b57cec5SDimitry Andric " int a;\n"
7960b57cec5SDimitry Andric " int b; .\n"
7970b57cec5SDimitry Andric " foo* next;\n"
7980b57cec5SDimitry Andric " };\n"
7990b57cec5SDimitry Andric "the expression to read item b in the item pointed to by next for foo "
8000b57cec5SDimitry Andric "aFoo would be aFoo.next->b.\n"
8010b57cec5SDimitry Andric "Given that aFoo could just be any object of type foo, the string "
8020b57cec5SDimitry Andric "'.next->b' is the expression path, because it can be attached to any "
8030b57cec5SDimitry Andric "foo instance to achieve the effect.\n"
8040b57cec5SDimitry Andric "Expression paths in LLDB include dot (.) and arrow (->) operators, "
8050b57cec5SDimitry Andric "and most commands using expression paths have ways to also accept "
8060b57cec5SDimitry Andric "the star (*) operator.\n"
8070b57cec5SDimitry Andric "The meaning of these operators is the same as the usual one given to "
8080b57cec5SDimitry Andric "them by the C/C++ standards.\n"
8090b57cec5SDimitry Andric "LLDB also has support for indexing ([ ]) in expression paths, and "
8100b57cec5SDimitry Andric "extends the traditional meaning of the square brackets operator to "
8110b57cec5SDimitry Andric "allow bitfield extraction:\n"
8120b57cec5SDimitry Andric "for objects of native types (int, float, char, ...) saying '[n-m]' "
8130b57cec5SDimitry Andric "as an expression path (where n and m are any positive integers, e.g. "
8140b57cec5SDimitry Andric "[3-5]) causes LLDB to extract"
8150b57cec5SDimitry Andric " bits n thru m from the value of the variable. If n == m, [n] is "
8160b57cec5SDimitry Andric "also allowed as a shortcut syntax. For arrays and pointers, "
8170b57cec5SDimitry Andric "expression paths can only contain one index"
8180b57cec5SDimitry Andric " and the meaning of the operation is the same as the one defined by "
8190b57cec5SDimitry Andric "C/C++ (item extraction). Some commands extend bitfield-like syntax "
8200b57cec5SDimitry Andric "for arrays and pointers with the"
8210b57cec5SDimitry Andric " meaning of array slicing (taking elements n thru m inside the array "
8220b57cec5SDimitry Andric "or pointed-to memory).";
8230b57cec5SDimitry Andric }
8240b57cec5SDimitry Andric
FormatLongHelpText(Stream & output_strm,llvm::StringRef long_help)8250b57cec5SDimitry Andric void CommandObject::FormatLongHelpText(Stream &output_strm,
8260b57cec5SDimitry Andric llvm::StringRef long_help) {
8270b57cec5SDimitry Andric CommandInterpreter &interpreter = GetCommandInterpreter();
8285ffd83dbSDimitry Andric std::stringstream lineStream{std::string(long_help)};
8290b57cec5SDimitry Andric std::string line;
8300b57cec5SDimitry Andric while (std::getline(lineStream, line)) {
8310b57cec5SDimitry Andric if (line.empty()) {
8320b57cec5SDimitry Andric output_strm << "\n";
8330b57cec5SDimitry Andric continue;
8340b57cec5SDimitry Andric }
8350b57cec5SDimitry Andric size_t result = line.find_first_not_of(" \t");
8360b57cec5SDimitry Andric if (result == std::string::npos) {
8370b57cec5SDimitry Andric result = 0;
8380b57cec5SDimitry Andric }
8390b57cec5SDimitry Andric std::string whitespace_prefix = line.substr(0, result);
8400b57cec5SDimitry Andric std::string remainder = line.substr(result);
8415ffd83dbSDimitry Andric interpreter.OutputFormattedHelpText(output_strm, whitespace_prefix,
8425ffd83dbSDimitry Andric remainder);
8430b57cec5SDimitry Andric }
8440b57cec5SDimitry Andric }
8450b57cec5SDimitry Andric
GenerateHelpText(CommandReturnObject & result)8460b57cec5SDimitry Andric void CommandObject::GenerateHelpText(CommandReturnObject &result) {
8470b57cec5SDimitry Andric GenerateHelpText(result.GetOutputStream());
8480b57cec5SDimitry Andric
8490b57cec5SDimitry Andric result.SetStatus(eReturnStatusSuccessFinishNoResult);
8500b57cec5SDimitry Andric }
8510b57cec5SDimitry Andric
GenerateHelpText(Stream & output_strm)8520b57cec5SDimitry Andric void CommandObject::GenerateHelpText(Stream &output_strm) {
8530b57cec5SDimitry Andric CommandInterpreter &interpreter = GetCommandInterpreter();
8540b57cec5SDimitry Andric std::string help_text(GetHelp());
8555ffd83dbSDimitry Andric if (WantsRawCommandString()) {
8560b57cec5SDimitry Andric help_text.append(" Expects 'raw' input (see 'help raw-input'.)");
8575ffd83dbSDimitry Andric }
8585ffd83dbSDimitry Andric interpreter.OutputFormattedHelpText(output_strm, "", help_text);
8590b57cec5SDimitry Andric output_strm << "\nSyntax: " << GetSyntax() << "\n";
8600b57cec5SDimitry Andric Options *options = GetOptions();
8610b57cec5SDimitry Andric if (options != nullptr) {
8620b57cec5SDimitry Andric options->GenerateOptionUsage(
8630b57cec5SDimitry Andric output_strm, this,
8640b57cec5SDimitry Andric GetCommandInterpreter().GetDebugger().GetTerminalWidth());
8650b57cec5SDimitry Andric }
8660b57cec5SDimitry Andric llvm::StringRef long_help = GetHelpLong();
8670b57cec5SDimitry Andric if (!long_help.empty()) {
8680b57cec5SDimitry Andric FormatLongHelpText(output_strm, long_help);
8690b57cec5SDimitry Andric }
8700b57cec5SDimitry Andric if (!IsDashDashCommand() && options && options->NumCommandOptions() > 0) {
8710b57cec5SDimitry Andric if (WantsRawCommandString() && !WantsCompletion()) {
8720b57cec5SDimitry Andric // Emit the message about using ' -- ' between the end of the command
8730b57cec5SDimitry Andric // options and the raw input conditionally, i.e., only if the command
8740b57cec5SDimitry Andric // object does not want completion.
8750b57cec5SDimitry Andric interpreter.OutputFormattedHelpText(
8760b57cec5SDimitry Andric output_strm, "", "",
8770b57cec5SDimitry Andric "\nImportant Note: Because this command takes 'raw' input, if you "
8780b57cec5SDimitry Andric "use any command options"
8790b57cec5SDimitry Andric " you must use ' -- ' between the end of the command options and the "
8800b57cec5SDimitry Andric "beginning of the raw input.",
8810b57cec5SDimitry Andric 1);
8820b57cec5SDimitry Andric } else if (GetNumArgumentEntries() > 0) {
8830b57cec5SDimitry Andric // Also emit a warning about using "--" in case you are using a command
8840b57cec5SDimitry Andric // that takes options and arguments.
8850b57cec5SDimitry Andric interpreter.OutputFormattedHelpText(
8860b57cec5SDimitry Andric output_strm, "", "",
8870b57cec5SDimitry Andric "\nThis command takes options and free-form arguments. If your "
8880b57cec5SDimitry Andric "arguments resemble"
8890b57cec5SDimitry Andric " option specifiers (i.e., they start with a - or --), you must use "
8900b57cec5SDimitry Andric "' -- ' between"
8910b57cec5SDimitry Andric " the end of the command options and the beginning of the arguments.",
8920b57cec5SDimitry Andric 1);
8930b57cec5SDimitry Andric }
8940b57cec5SDimitry Andric }
8950b57cec5SDimitry Andric }
8960b57cec5SDimitry Andric
AddIDsArgumentData(CommandArgumentEntry & arg,CommandArgumentType ID,CommandArgumentType IDRange)8970b57cec5SDimitry Andric void CommandObject::AddIDsArgumentData(CommandArgumentEntry &arg,
8980b57cec5SDimitry Andric CommandArgumentType ID,
8990b57cec5SDimitry Andric CommandArgumentType IDRange) {
9000b57cec5SDimitry Andric CommandArgumentData id_arg;
9010b57cec5SDimitry Andric CommandArgumentData id_range_arg;
9020b57cec5SDimitry Andric
9030b57cec5SDimitry Andric // Create the first variant for the first (and only) argument for this
9040b57cec5SDimitry Andric // command.
9050b57cec5SDimitry Andric id_arg.arg_type = ID;
9060b57cec5SDimitry Andric id_arg.arg_repetition = eArgRepeatOptional;
9070b57cec5SDimitry Andric
9080b57cec5SDimitry Andric // Create the second variant for the first (and only) argument for this
9090b57cec5SDimitry Andric // command.
9100b57cec5SDimitry Andric id_range_arg.arg_type = IDRange;
9110b57cec5SDimitry Andric id_range_arg.arg_repetition = eArgRepeatOptional;
9120b57cec5SDimitry Andric
9130b57cec5SDimitry Andric // The first (and only) argument for this command could be either an id or an
9140b57cec5SDimitry Andric // id_range. Push both variants into the entry for the first argument for
9150b57cec5SDimitry Andric // this command.
9160b57cec5SDimitry Andric arg.push_back(id_arg);
9170b57cec5SDimitry Andric arg.push_back(id_range_arg);
9180b57cec5SDimitry Andric }
9190b57cec5SDimitry Andric
GetArgumentTypeAsCString(const lldb::CommandArgumentType arg_type)9200b57cec5SDimitry Andric const char *CommandObject::GetArgumentTypeAsCString(
9210b57cec5SDimitry Andric const lldb::CommandArgumentType arg_type) {
9220b57cec5SDimitry Andric assert(arg_type < eArgTypeLastArg &&
9230b57cec5SDimitry Andric "Invalid argument type passed to GetArgumentTypeAsCString");
9240b57cec5SDimitry Andric return g_arguments_data[arg_type].arg_name;
9250b57cec5SDimitry Andric }
9260b57cec5SDimitry Andric
GetArgumentDescriptionAsCString(const lldb::CommandArgumentType arg_type)9270b57cec5SDimitry Andric const char *CommandObject::GetArgumentDescriptionAsCString(
9280b57cec5SDimitry Andric const lldb::CommandArgumentType arg_type) {
9290b57cec5SDimitry Andric assert(arg_type < eArgTypeLastArg &&
9300b57cec5SDimitry Andric "Invalid argument type passed to GetArgumentDescriptionAsCString");
9310b57cec5SDimitry Andric return g_arguments_data[arg_type].help_text;
9320b57cec5SDimitry Andric }
9330b57cec5SDimitry Andric
GetDummyTarget()9349dba64beSDimitry Andric Target &CommandObject::GetDummyTarget() {
935af732203SDimitry Andric return m_interpreter.GetDebugger().GetDummyTarget();
9360b57cec5SDimitry Andric }
9370b57cec5SDimitry Andric
GetSelectedOrDummyTarget(bool prefer_dummy)9389dba64beSDimitry Andric Target &CommandObject::GetSelectedOrDummyTarget(bool prefer_dummy) {
939af732203SDimitry Andric return m_interpreter.GetDebugger().GetSelectedOrDummyTarget(prefer_dummy);
9409dba64beSDimitry Andric }
9419dba64beSDimitry Andric
GetSelectedTarget()9429dba64beSDimitry Andric Target &CommandObject::GetSelectedTarget() {
9439dba64beSDimitry Andric assert(m_flags.AnySet(eCommandRequiresTarget | eCommandProcessMustBePaused |
9449dba64beSDimitry Andric eCommandProcessMustBeLaunched | eCommandRequiresFrame |
9459dba64beSDimitry Andric eCommandRequiresThread | eCommandRequiresProcess |
9469dba64beSDimitry Andric eCommandRequiresRegContext) &&
9479dba64beSDimitry Andric "GetSelectedTarget called from object that may have no target");
9489dba64beSDimitry Andric return *m_interpreter.GetDebugger().GetSelectedTarget();
9490b57cec5SDimitry Andric }
9500b57cec5SDimitry Andric
GetDefaultThread()9510b57cec5SDimitry Andric Thread *CommandObject::GetDefaultThread() {
9520b57cec5SDimitry Andric Thread *thread_to_use = m_exe_ctx.GetThreadPtr();
9530b57cec5SDimitry Andric if (thread_to_use)
9540b57cec5SDimitry Andric return thread_to_use;
9550b57cec5SDimitry Andric
9560b57cec5SDimitry Andric Process *process = m_exe_ctx.GetProcessPtr();
9570b57cec5SDimitry Andric if (!process) {
9580b57cec5SDimitry Andric Target *target = m_exe_ctx.GetTargetPtr();
9590b57cec5SDimitry Andric if (!target) {
9600b57cec5SDimitry Andric target = m_interpreter.GetDebugger().GetSelectedTarget().get();
9610b57cec5SDimitry Andric }
9620b57cec5SDimitry Andric if (target)
9630b57cec5SDimitry Andric process = target->GetProcessSP().get();
9640b57cec5SDimitry Andric }
9650b57cec5SDimitry Andric
9660b57cec5SDimitry Andric if (process)
9670b57cec5SDimitry Andric return process->GetThreadList().GetSelectedThread().get();
9680b57cec5SDimitry Andric else
9690b57cec5SDimitry Andric return nullptr;
9700b57cec5SDimitry Andric }
9710b57cec5SDimitry Andric
Execute(const char * args_string,CommandReturnObject & result)9720b57cec5SDimitry Andric bool CommandObjectParsed::Execute(const char *args_string,
9730b57cec5SDimitry Andric CommandReturnObject &result) {
9740b57cec5SDimitry Andric bool handled = false;
9750b57cec5SDimitry Andric Args cmd_args(args_string);
9760b57cec5SDimitry Andric if (HasOverrideCallback()) {
9770b57cec5SDimitry Andric Args full_args(GetCommandName());
9780b57cec5SDimitry Andric full_args.AppendArguments(cmd_args);
9790b57cec5SDimitry Andric handled =
9800b57cec5SDimitry Andric InvokeOverrideCallback(full_args.GetConstArgumentVector(), result);
9810b57cec5SDimitry Andric }
9820b57cec5SDimitry Andric if (!handled) {
9830b57cec5SDimitry Andric for (auto entry : llvm::enumerate(cmd_args.entries())) {
9849dba64beSDimitry Andric if (!entry.value().ref().empty() && entry.value().ref().front() == '`') {
9850b57cec5SDimitry Andric cmd_args.ReplaceArgumentAtIndex(
9860b57cec5SDimitry Andric entry.index(),
9870b57cec5SDimitry Andric m_interpreter.ProcessEmbeddedScriptCommands(entry.value().c_str()));
9880b57cec5SDimitry Andric }
9890b57cec5SDimitry Andric }
9900b57cec5SDimitry Andric
9910b57cec5SDimitry Andric if (CheckRequirements(result)) {
9920b57cec5SDimitry Andric if (ParseOptions(cmd_args, result)) {
9930b57cec5SDimitry Andric // Call the command-specific version of 'Execute', passing it the
9940b57cec5SDimitry Andric // already processed arguments.
9950b57cec5SDimitry Andric handled = DoExecute(cmd_args, result);
9960b57cec5SDimitry Andric }
9970b57cec5SDimitry Andric }
9980b57cec5SDimitry Andric
9990b57cec5SDimitry Andric Cleanup();
10000b57cec5SDimitry Andric }
10010b57cec5SDimitry Andric return handled;
10020b57cec5SDimitry Andric }
10030b57cec5SDimitry Andric
Execute(const char * args_string,CommandReturnObject & result)10040b57cec5SDimitry Andric bool CommandObjectRaw::Execute(const char *args_string,
10050b57cec5SDimitry Andric CommandReturnObject &result) {
10060b57cec5SDimitry Andric bool handled = false;
10070b57cec5SDimitry Andric if (HasOverrideCallback()) {
10080b57cec5SDimitry Andric std::string full_command(GetCommandName());
10090b57cec5SDimitry Andric full_command += ' ';
10100b57cec5SDimitry Andric full_command += args_string;
10110b57cec5SDimitry Andric const char *argv[2] = {nullptr, nullptr};
10120b57cec5SDimitry Andric argv[0] = full_command.c_str();
10130b57cec5SDimitry Andric handled = InvokeOverrideCallback(argv, result);
10140b57cec5SDimitry Andric }
10150b57cec5SDimitry Andric if (!handled) {
10160b57cec5SDimitry Andric if (CheckRequirements(result))
10170b57cec5SDimitry Andric handled = DoExecute(args_string, result);
10180b57cec5SDimitry Andric
10190b57cec5SDimitry Andric Cleanup();
10200b57cec5SDimitry Andric }
10210b57cec5SDimitry Andric return handled;
10220b57cec5SDimitry Andric }
10230b57cec5SDimitry Andric
arch_helper()10240b57cec5SDimitry Andric static llvm::StringRef arch_helper() {
10250b57cec5SDimitry Andric static StreamString g_archs_help;
10260b57cec5SDimitry Andric if (g_archs_help.Empty()) {
10270b57cec5SDimitry Andric StringList archs;
10280b57cec5SDimitry Andric
10290b57cec5SDimitry Andric ArchSpec::ListSupportedArchNames(archs);
10300b57cec5SDimitry Andric g_archs_help.Printf("These are the supported architecture names:\n");
10310b57cec5SDimitry Andric archs.Join("\n", g_archs_help);
10320b57cec5SDimitry Andric }
10330b57cec5SDimitry Andric return g_archs_help.GetString();
10340b57cec5SDimitry Andric }
10350b57cec5SDimitry Andric
10360b57cec5SDimitry Andric CommandObject::ArgumentTableEntry CommandObject::g_arguments_data[] = {
10370b57cec5SDimitry Andric // clang-format off
10380b57cec5SDimitry Andric { eArgTypeAddress, "address", CommandCompletions::eNoCompletion, { nullptr, false }, "A valid address in the target program's execution space." },
10390b57cec5SDimitry Andric { eArgTypeAddressOrExpression, "address-expression", CommandCompletions::eNoCompletion, { nullptr, false }, "An expression that resolves to an address." },
10400b57cec5SDimitry Andric { eArgTypeAliasName, "alias-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of an abbreviation (alias) for a debugger command." },
10410b57cec5SDimitry Andric { 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.)" },
10420b57cec5SDimitry Andric { eArgTypeArchitecture, "arch", CommandCompletions::eArchitectureCompletion, { arch_helper, true }, "The architecture name, e.g. i386 or x86_64." },
10430b57cec5SDimitry Andric { eArgTypeBoolean, "boolean", CommandCompletions::eNoCompletion, { nullptr, false }, "A Boolean value: 'true' or 'false'" },
10440b57cec5SDimitry Andric { eArgTypeBreakpointID, "breakpt-id", CommandCompletions::eNoCompletion, { BreakpointIDHelpTextCallback, false }, nullptr },
10450b57cec5SDimitry Andric { eArgTypeBreakpointIDRange, "breakpt-id-list", CommandCompletions::eNoCompletion, { BreakpointIDRangeHelpTextCallback, false }, nullptr },
1046af732203SDimitry Andric { eArgTypeBreakpointName, "breakpoint-name", CommandCompletions::eBreakpointNameCompletion, { BreakpointNameHelpTextCallback, false }, nullptr },
10470b57cec5SDimitry Andric { eArgTypeByteSize, "byte-size", CommandCompletions::eNoCompletion, { nullptr, false }, "Number of bytes to use." },
10480b57cec5SDimitry Andric { eArgTypeClassName, "class-name", CommandCompletions::eNoCompletion, { nullptr, false }, "Then name of a class from the debug information in the program." },
10490b57cec5SDimitry Andric { eArgTypeCommandName, "cmd-name", CommandCompletions::eNoCompletion, { nullptr, false }, "A debugger command (may be multiple words), without any options or arguments." },
10500b57cec5SDimitry Andric { eArgTypeCount, "count", CommandCompletions::eNoCompletion, { nullptr, false }, "An unsigned integer." },
10510b57cec5SDimitry Andric { eArgTypeDirectoryName, "directory", CommandCompletions::eDiskDirectoryCompletion, { nullptr, false }, "A directory name." },
1052af732203SDimitry Andric { eArgTypeDisassemblyFlavor, "disassembly-flavor", CommandCompletions::eDisassemblyFlavorCompletion, { nullptr, false }, "A disassembly flavor recognized by your disassembly plugin. Currently the only valid options are \"att\" and \"intel\" for Intel targets" },
10530b57cec5SDimitry Andric { eArgTypeDescriptionVerbosity, "description-verbosity", CommandCompletions::eNoCompletion, { nullptr, false }, "How verbose the output of 'po' should be." },
10540b57cec5SDimitry Andric { eArgTypeEndAddress, "end-address", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
10550b57cec5SDimitry Andric { eArgTypeExpression, "expr", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
10560b57cec5SDimitry Andric { eArgTypeExpressionPath, "expr-path", CommandCompletions::eNoCompletion, { ExprPathHelpTextCallback, true }, nullptr },
10570b57cec5SDimitry Andric { eArgTypeExprFormat, "expression-format", CommandCompletions::eNoCompletion, { nullptr, false }, "[ [bool|b] | [bin] | [char|c] | [oct|o] | [dec|i|d|u] | [hex|x] | [float|f] | [cstr|s] ]" },
10580b57cec5SDimitry Andric { eArgTypeFilename, "filename", CommandCompletions::eDiskFileCompletion, { nullptr, false }, "The name of a file (can include path)." },
10590b57cec5SDimitry Andric { eArgTypeFormat, "format", CommandCompletions::eNoCompletion, { FormatHelpTextCallback, true }, nullptr },
1060af732203SDimitry Andric { eArgTypeFrameIndex, "frame-index", CommandCompletions::eFrameIndexCompletion, { nullptr, false }, "Index into a thread's list of frames." },
10610b57cec5SDimitry Andric { eArgTypeFullName, "fullname", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
10620b57cec5SDimitry Andric { eArgTypeFunctionName, "function-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a function." },
10630b57cec5SDimitry Andric { eArgTypeFunctionOrSymbol, "function-or-symbol", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a function or symbol." },
10640b57cec5SDimitry Andric { eArgTypeGDBFormat, "gdb-format", CommandCompletions::eNoCompletion, { GDBFormatHelpTextCallback, true }, nullptr },
10650b57cec5SDimitry Andric { eArgTypeHelpText, "help-text", CommandCompletions::eNoCompletion, { nullptr, false }, "Text to be used as help for some other entity in LLDB" },
10660b57cec5SDimitry Andric { eArgTypeIndex, "index", CommandCompletions::eNoCompletion, { nullptr, false }, "An index into a list." },
1067af732203SDimitry Andric { eArgTypeLanguage, "source-language", CommandCompletions::eTypeLanguageCompletion, { LanguageTypeHelpTextCallback, true }, nullptr },
10680b57cec5SDimitry Andric { eArgTypeLineNum, "linenum", CommandCompletions::eNoCompletion, { nullptr, false }, "Line number in a source file." },
1069af732203SDimitry Andric { eArgTypeFileLineColumn, "linespec", CommandCompletions::eNoCompletion, { nullptr, false }, "A source specifier in the form file:line[:column]" },
10700b57cec5SDimitry Andric { 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." },
10710b57cec5SDimitry Andric { 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)." },
10720b57cec5SDimitry Andric { eArgTypeMethod, "method", CommandCompletions::eNoCompletion, { nullptr, false }, "A C++ method name." },
1073af732203SDimitry Andric { eArgTypeName, "name", CommandCompletions::eTypeCategoryNameCompletion, { nullptr, false }, "Help text goes here." },
10740b57cec5SDimitry Andric { eArgTypeNewPathPrefix, "new-path-prefix", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
10750b57cec5SDimitry Andric { eArgTypeNumLines, "num-lines", CommandCompletions::eNoCompletion, { nullptr, false }, "The number of lines to use." },
10760b57cec5SDimitry Andric { eArgTypeNumberPerLine, "number-per-line", CommandCompletions::eNoCompletion, { nullptr, false }, "The number of items per line to display." },
10770b57cec5SDimitry Andric { eArgTypeOffset, "offset", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
10780b57cec5SDimitry Andric { eArgTypeOldPathPrefix, "old-path-prefix", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
10790b57cec5SDimitry Andric { eArgTypeOneLiner, "one-line-command", CommandCompletions::eNoCompletion, { nullptr, false }, "A command that is entered as a single line of text." },
10800b57cec5SDimitry Andric { eArgTypePath, "path", CommandCompletions::eDiskFileCompletion, { nullptr, false }, "Path." },
10810b57cec5SDimitry Andric { eArgTypePermissionsNumber, "perms-numeric", CommandCompletions::eNoCompletion, { nullptr, false }, "Permissions given as an octal number (e.g. 755)." },
10820b57cec5SDimitry Andric { eArgTypePermissionsString, "perms=string", CommandCompletions::eNoCompletion, { nullptr, false }, "Permissions given as a string value (e.g. rw-r-xr--)." },
1083af732203SDimitry Andric { eArgTypePid, "pid", CommandCompletions::eProcessIDCompletion, { nullptr, false }, "The process ID number." },
10845ffd83dbSDimitry Andric { eArgTypePlugin, "plugin", CommandCompletions::eProcessPluginCompletion, { nullptr, false }, "Help text goes here." },
1085af732203SDimitry Andric { eArgTypeProcessName, "process-name", CommandCompletions::eProcessNameCompletion, { nullptr, false }, "The name of the process." },
10860b57cec5SDimitry Andric { eArgTypePythonClass, "python-class", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a Python class." },
10870b57cec5SDimitry Andric { eArgTypePythonFunction, "python-function", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a Python function." },
10880b57cec5SDimitry Andric { eArgTypePythonScript, "python-script", CommandCompletions::eNoCompletion, { nullptr, false }, "Source code written in Python." },
10890b57cec5SDimitry Andric { eArgTypeQueueName, "queue-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of the thread queue." },
10900b57cec5SDimitry Andric { eArgTypeRegisterName, "register-name", CommandCompletions::eNoCompletion, { RegisterNameHelpTextCallback, true }, nullptr },
10919dba64beSDimitry Andric { eArgTypeRegularExpression, "regular-expression", CommandCompletions::eNoCompletion, { nullptr, false }, "A POSIX-compliant extended regular expression." },
10920b57cec5SDimitry Andric { eArgTypeRunArgs, "run-args", CommandCompletions::eNoCompletion, { nullptr, false }, "Arguments to be passed to the target program when it starts executing." },
10930b57cec5SDimitry Andric { eArgTypeRunMode, "run-mode", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
10940b57cec5SDimitry Andric { eArgTypeScriptedCommandSynchronicity, "script-cmd-synchronicity", CommandCompletions::eNoCompletion, { nullptr, false }, "The synchronicity to use to run scripted commands with regard to LLDB event system." },
10955ffd83dbSDimitry Andric { eArgTypeScriptLang, "script-language", CommandCompletions::eNoCompletion, { nullptr, false }, "The scripting language to be used for script-based commands. Supported languages are python and lua." },
10960b57cec5SDimitry Andric { eArgTypeSearchWord, "search-word", CommandCompletions::eNoCompletion, { nullptr, false }, "Any word of interest for search purposes." },
10970b57cec5SDimitry Andric { eArgTypeSelector, "selector", CommandCompletions::eNoCompletion, { nullptr, false }, "An Objective-C selector name." },
10980b57cec5SDimitry Andric { 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)." },
10990b57cec5SDimitry Andric { 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)." },
11000b57cec5SDimitry Andric { eArgTypeSettingPrefix, "setting-prefix", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a settable internal debugger variable up to a dot ('.'), e.g. 'target.process.'" },
11010b57cec5SDimitry Andric { 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." },
11020b57cec5SDimitry Andric { eArgTypeShlibName, "shlib-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a shared library." },
11030b57cec5SDimitry Andric { eArgTypeSourceFile, "source-file", CommandCompletions::eSourceFileCompletion, { nullptr, false }, "The name of a source file.." },
11040b57cec5SDimitry Andric { eArgTypeSortOrder, "sort-order", CommandCompletions::eNoCompletion, { nullptr, false }, "Specify a sort order when dumping lists." },
11050b57cec5SDimitry Andric { eArgTypeStartAddress, "start-address", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
11060b57cec5SDimitry Andric { eArgTypeSummaryString, "summary-string", CommandCompletions::eNoCompletion, { SummaryStringHelpTextCallback, true }, nullptr },
11070b57cec5SDimitry Andric { eArgTypeSymbol, "symbol", CommandCompletions::eSymbolCompletion, { nullptr, false }, "Any symbol name (function name, variable, argument, etc.)" },
11080b57cec5SDimitry Andric { eArgTypeThreadID, "thread-id", CommandCompletions::eNoCompletion, { nullptr, false }, "Thread ID number." },
11090b57cec5SDimitry Andric { eArgTypeThreadIndex, "thread-index", CommandCompletions::eNoCompletion, { nullptr, false }, "Index into the process' list of threads." },
11100b57cec5SDimitry Andric { eArgTypeThreadName, "thread-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The thread's name." },
11110b57cec5SDimitry Andric { eArgTypeTypeName, "type-name", CommandCompletions::eNoCompletion, { nullptr, false }, "A type name." },
11120b57cec5SDimitry Andric { eArgTypeUnsignedInteger, "unsigned-integer", CommandCompletions::eNoCompletion, { nullptr, false }, "An unsigned integer." },
11130b57cec5SDimitry Andric { eArgTypeUnixSignal, "unix-signal", CommandCompletions::eNoCompletion, { nullptr, false }, "A valid Unix signal name or number (e.g. SIGKILL, KILL or 9)." },
11140b57cec5SDimitry Andric { eArgTypeVarName, "variable-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a variable in your program." },
11150b57cec5SDimitry Andric { eArgTypeValue, "value", CommandCompletions::eNoCompletion, { nullptr, false }, "A value could be anything, depending on where and how it is used." },
11160b57cec5SDimitry Andric { eArgTypeWidth, "width", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
11170b57cec5SDimitry Andric { eArgTypeNone, "none", CommandCompletions::eNoCompletion, { nullptr, false }, "No help available for this." },
11180b57cec5SDimitry Andric { 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." },
11190b57cec5SDimitry Andric { eArgTypeWatchpointID, "watchpt-id", CommandCompletions::eNoCompletion, { nullptr, false }, "Watchpoint IDs are positive integers." },
11200b57cec5SDimitry Andric { eArgTypeWatchpointIDRange, "watchpt-id-list", CommandCompletions::eNoCompletion, { nullptr, false }, "For example, '1-3' or '1 to 3'." },
11210b57cec5SDimitry Andric { eArgTypeWatchType, "watch-type", CommandCompletions::eNoCompletion, { nullptr, false }, "Specify the type for a watchpoint." },
11220b57cec5SDimitry Andric { 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." },
11235ffd83dbSDimitry Andric { eArgTypeCommand, "command", CommandCompletions::eNoCompletion, { nullptr, false }, "An LLDB Command line command." },
1124af732203SDimitry Andric { eArgTypeColumnNum, "column", CommandCompletions::eNoCompletion, { nullptr, false }, "Column number in a source file." },
1125*5f7ddb14SDimitry Andric { eArgTypeModuleUUID, "module-uuid", CommandCompletions::eModuleUUIDCompletion, { nullptr, false }, "A module UUID value." },
1126*5f7ddb14SDimitry Andric { eArgTypeSaveCoreStyle, "corefile-style", CommandCompletions::eNoCompletion, { nullptr, false }, "The type of corefile that lldb will try to create, dependant on this target's capabilities." }
11270b57cec5SDimitry Andric // clang-format on
11280b57cec5SDimitry Andric };
11290b57cec5SDimitry Andric
GetArgumentTable()11300b57cec5SDimitry Andric const CommandObject::ArgumentTableEntry *CommandObject::GetArgumentTable() {
11310b57cec5SDimitry Andric // If this assertion fires, then the table above is out of date with the
11320b57cec5SDimitry Andric // CommandArgumentType enumeration
11330b57cec5SDimitry Andric static_assert((sizeof(CommandObject::g_arguments_data) /
11340b57cec5SDimitry Andric sizeof(CommandObject::ArgumentTableEntry)) == eArgTypeLastArg,
11350b57cec5SDimitry Andric "");
11360b57cec5SDimitry Andric return CommandObject::g_arguments_data;
11370b57cec5SDimitry Andric }
1138