1ac7ddfbfSEd Maste //===-- CommandObject.cpp ---------------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste //                     The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste 
10ac7ddfbfSEd Maste #include "lldb/Interpreter/CommandObject.h"
11ac7ddfbfSEd Maste 
12ac7ddfbfSEd Maste #include <map>
13435933ddSDimitry Andric #include <sstream>
14435933ddSDimitry Andric #include <string>
15ac7ddfbfSEd Maste 
16ac7ddfbfSEd Maste #include <ctype.h>
17435933ddSDimitry Andric #include <stdlib.h>
18ac7ddfbfSEd Maste 
19ac7ddfbfSEd Maste #include "lldb/Core/Address.h"
20ac7ddfbfSEd Maste #include "lldb/Interpreter/Options.h"
21acac075bSDimitry Andric #include "lldb/Utility/ArchSpec.h"
22ac7ddfbfSEd Maste 
23ac7ddfbfSEd Maste // These are for the Sourcename completers.
24ac7ddfbfSEd Maste // FIXME: Make a separate file for the completers.
25ac7ddfbfSEd Maste #include "lldb/Core/FileSpecList.h"
261c3bbb01SEd Maste #include "lldb/DataFormatters/FormatManager.h"
27ac7ddfbfSEd Maste #include "lldb/Target/Process.h"
28ac7ddfbfSEd Maste #include "lldb/Target/Target.h"
29f678e45dSDimitry Andric #include "lldb/Utility/FileSpec.h"
30ac7ddfbfSEd Maste 
319f2f44ceSEd Maste #include "lldb/Target/Language.h"
329f2f44ceSEd Maste 
33ac7ddfbfSEd Maste #include "lldb/Interpreter/CommandInterpreter.h"
34ac7ddfbfSEd Maste #include "lldb/Interpreter/CommandReturnObject.h"
35ac7ddfbfSEd Maste 
36ac7ddfbfSEd Maste using namespace lldb;
37ac7ddfbfSEd Maste using namespace lldb_private;
38ac7ddfbfSEd Maste 
39ac7ddfbfSEd Maste //-------------------------------------------------------------------------
40ac7ddfbfSEd Maste // CommandObject
41ac7ddfbfSEd Maste //-------------------------------------------------------------------------
42ac7ddfbfSEd Maste 
CommandObject(CommandInterpreter & interpreter,llvm::StringRef name,llvm::StringRef help,llvm::StringRef syntax,uint32_t flags)43435933ddSDimitry Andric CommandObject::CommandObject(CommandInterpreter &interpreter, llvm::StringRef name,
44435933ddSDimitry Andric   llvm::StringRef help, llvm::StringRef syntax, uint32_t flags)
45435933ddSDimitry Andric     : m_interpreter(interpreter), m_cmd_name(name),
46435933ddSDimitry Andric       m_cmd_help_short(), m_cmd_help_long(), m_cmd_syntax(), m_flags(flags),
47435933ddSDimitry Andric       m_arguments(), m_deprecated_command_override_callback(nullptr),
48435933ddSDimitry Andric       m_command_override_callback(nullptr), m_command_override_baton(nullptr) {
49ac7ddfbfSEd Maste   m_cmd_help_short = help;
50ac7ddfbfSEd Maste   m_cmd_syntax = syntax;
51ac7ddfbfSEd Maste }
52ac7ddfbfSEd Maste 
~CommandObject()53435933ddSDimitry Andric CommandObject::~CommandObject() {}
54ac7ddfbfSEd Maste 
GetHelp()55435933ddSDimitry Andric llvm::StringRef CommandObject::GetHelp() { return m_cmd_help_short; }
56ac7ddfbfSEd Maste 
GetHelpLong()57435933ddSDimitry Andric llvm::StringRef CommandObject::GetHelpLong() { return m_cmd_help_long; }
58ac7ddfbfSEd Maste 
GetSyntax()59435933ddSDimitry Andric llvm::StringRef CommandObject::GetSyntax() {
60acac075bSDimitry Andric   if (!m_cmd_syntax.empty())
61435933ddSDimitry Andric     return m_cmd_syntax;
62435933ddSDimitry Andric 
63ac7ddfbfSEd Maste   StreamString syntax_str;
64435933ddSDimitry Andric   syntax_str.PutCString(GetCommandName());
65435933ddSDimitry Andric 
664bb0738eSEd Maste   if (!IsDashDashCommand() && GetOptions() != nullptr)
67435933ddSDimitry Andric     syntax_str.PutCString(" <cmd-options>");
68435933ddSDimitry Andric 
69435933ddSDimitry Andric   if (!m_arguments.empty()) {
70435933ddSDimitry Andric     syntax_str.PutCString(" ");
71435933ddSDimitry Andric 
72435933ddSDimitry Andric     if (!IsDashDashCommand() && WantsRawCommandString() && GetOptions() &&
73435933ddSDimitry Andric         GetOptions()->NumCommandOptions())
74435933ddSDimitry Andric       syntax_str.PutCString("-- ");
75ac7ddfbfSEd Maste     GetFormattedCommandArguments(syntax_str);
76ac7ddfbfSEd Maste   }
77435933ddSDimitry Andric   m_cmd_syntax = syntax_str.GetString();
78435933ddSDimitry Andric 
79435933ddSDimitry Andric   return m_cmd_syntax;
80ac7ddfbfSEd Maste }
81ac7ddfbfSEd Maste 
GetCommandName() const82435933ddSDimitry Andric llvm::StringRef CommandObject::GetCommandName() const { return m_cmd_name; }
83ac7ddfbfSEd Maste 
SetCommandName(llvm::StringRef name)84435933ddSDimitry Andric void CommandObject::SetCommandName(llvm::StringRef name) { m_cmd_name = name; }
85ac7ddfbfSEd Maste 
SetHelp(llvm::StringRef str)86435933ddSDimitry Andric void CommandObject::SetHelp(llvm::StringRef str) { m_cmd_help_short = str; }
87ac7ddfbfSEd Maste 
SetHelpLong(llvm::StringRef str)88435933ddSDimitry Andric void CommandObject::SetHelpLong(llvm::StringRef str) { m_cmd_help_long = str; }
891c3bbb01SEd Maste 
SetSyntax(llvm::StringRef str)90435933ddSDimitry Andric void CommandObject::SetSyntax(llvm::StringRef str) { m_cmd_syntax = str; }
91ac7ddfbfSEd Maste 
GetOptions()92435933ddSDimitry Andric Options *CommandObject::GetOptions() {
934ba319b5SDimitry Andric   // By default commands don't have options unless this virtual function is
944ba319b5SDimitry Andric   // overridden by base classes.
950127ef0fSEd Maste   return nullptr;
96ac7ddfbfSEd Maste }
97ac7ddfbfSEd Maste 
ParseOptions(Args & args,CommandReturnObject & result)98435933ddSDimitry Andric bool CommandObject::ParseOptions(Args &args, CommandReturnObject &result) {
99ac7ddfbfSEd Maste   // See if the subclass has options?
100ac7ddfbfSEd Maste   Options *options = GetOptions();
101435933ddSDimitry Andric   if (options != nullptr) {
1025517e702SDimitry Andric     Status error;
103ac7ddfbfSEd Maste 
104435933ddSDimitry Andric     auto exe_ctx = GetCommandInterpreter().GetExecutionContext();
105435933ddSDimitry Andric     options->NotifyOptionParsingStarting(&exe_ctx);
106435933ddSDimitry Andric 
107435933ddSDimitry Andric     const bool require_validation = true;
1084ba319b5SDimitry Andric     llvm::Expected<Args> args_or = options->Parse(
1094ba319b5SDimitry Andric         args, &exe_ctx, GetCommandInterpreter().GetPlatform(true),
110435933ddSDimitry Andric         require_validation);
111ac7ddfbfSEd Maste 
1124ba319b5SDimitry Andric     if (args_or) {
1134ba319b5SDimitry Andric       args = std::move(*args_or);
114435933ddSDimitry Andric       error = options->NotifyOptionParsingFinished(&exe_ctx);
1154ba319b5SDimitry Andric     } else
1164ba319b5SDimitry Andric       error = args_or.takeError();
117ac7ddfbfSEd Maste 
118435933ddSDimitry Andric     if (error.Success()) {
119ac7ddfbfSEd Maste       if (options->VerifyOptions(result))
120ac7ddfbfSEd Maste         return true;
121435933ddSDimitry Andric     } else {
122ac7ddfbfSEd Maste       const char *error_cstr = error.AsCString();
123435933ddSDimitry Andric       if (error_cstr) {
124ac7ddfbfSEd Maste         // We got an error string, lets use that
125ac7ddfbfSEd Maste         result.AppendError(error_cstr);
126435933ddSDimitry Andric       } else {
127ac7ddfbfSEd Maste         // No error string, output the usage information into result
128435933ddSDimitry Andric         options->GenerateOptionUsage(
129435933ddSDimitry Andric             result.GetErrorStream(), this,
130435933ddSDimitry Andric             GetCommandInterpreter().GetDebugger().GetTerminalWidth());
131ac7ddfbfSEd Maste       }
132ac7ddfbfSEd Maste     }
133ac7ddfbfSEd Maste     result.SetStatus(eReturnStatusFailed);
134ac7ddfbfSEd Maste     return false;
135ac7ddfbfSEd Maste   }
136ac7ddfbfSEd Maste   return true;
137ac7ddfbfSEd Maste }
138ac7ddfbfSEd Maste 
CheckRequirements(CommandReturnObject & result)139435933ddSDimitry Andric bool CommandObject::CheckRequirements(CommandReturnObject &result) {
140ac7ddfbfSEd Maste #ifdef LLDB_CONFIGURATION_DEBUG
1414ba319b5SDimitry Andric   // Nothing should be stored in m_exe_ctx between running commands as
1424ba319b5SDimitry Andric   // m_exe_ctx has shared pointers to the target, process, thread and frame and
1434ba319b5SDimitry Andric   // we don't want any CommandObject instances to keep any of these objects
1444ba319b5SDimitry Andric   // around longer than for a single command. Every command should call
145ac7ddfbfSEd Maste   // CommandObject::Cleanup() after it has completed
146ac7ddfbfSEd Maste   assert(m_exe_ctx.GetTargetPtr() == NULL);
147ac7ddfbfSEd Maste   assert(m_exe_ctx.GetProcessPtr() == NULL);
148ac7ddfbfSEd Maste   assert(m_exe_ctx.GetThreadPtr() == NULL);
149ac7ddfbfSEd Maste   assert(m_exe_ctx.GetFramePtr() == NULL);
150ac7ddfbfSEd Maste #endif
151ac7ddfbfSEd Maste 
1524ba319b5SDimitry Andric   // Lock down the interpreter's execution context prior to running the command
1534ba319b5SDimitry Andric   // so we guarantee the selected target, process, thread and frame can't go
1544ba319b5SDimitry Andric   // away during the execution
155ac7ddfbfSEd Maste   m_exe_ctx = m_interpreter.GetExecutionContext();
156ac7ddfbfSEd Maste 
157ac7ddfbfSEd Maste   const uint32_t flags = GetFlags().Get();
158435933ddSDimitry Andric   if (flags & (eCommandRequiresTarget | eCommandRequiresProcess |
159435933ddSDimitry Andric                eCommandRequiresThread | eCommandRequiresFrame |
160435933ddSDimitry Andric                eCommandTryTargetAPILock)) {
161ac7ddfbfSEd Maste 
162435933ddSDimitry Andric     if ((flags & eCommandRequiresTarget) && !m_exe_ctx.HasTargetScope()) {
163ac7ddfbfSEd Maste       result.AppendError(GetInvalidTargetDescription());
164ac7ddfbfSEd Maste       return false;
165ac7ddfbfSEd Maste     }
166ac7ddfbfSEd Maste 
167435933ddSDimitry Andric     if ((flags & eCommandRequiresProcess) && !m_exe_ctx.HasProcessScope()) {
1687aa51b79SEd Maste       if (!m_exe_ctx.HasTargetScope())
1697aa51b79SEd Maste         result.AppendError(GetInvalidTargetDescription());
1707aa51b79SEd Maste       else
171ac7ddfbfSEd Maste         result.AppendError(GetInvalidProcessDescription());
172ac7ddfbfSEd Maste       return false;
173ac7ddfbfSEd Maste     }
174ac7ddfbfSEd Maste 
175435933ddSDimitry Andric     if ((flags & eCommandRequiresThread) && !m_exe_ctx.HasThreadScope()) {
1767aa51b79SEd Maste       if (!m_exe_ctx.HasTargetScope())
1777aa51b79SEd Maste         result.AppendError(GetInvalidTargetDescription());
1787aa51b79SEd Maste       else if (!m_exe_ctx.HasProcessScope())
1797aa51b79SEd Maste         result.AppendError(GetInvalidProcessDescription());
1807aa51b79SEd Maste       else
181ac7ddfbfSEd Maste         result.AppendError(GetInvalidThreadDescription());
182ac7ddfbfSEd Maste       return false;
183ac7ddfbfSEd Maste     }
184ac7ddfbfSEd Maste 
185435933ddSDimitry Andric     if ((flags & eCommandRequiresFrame) && !m_exe_ctx.HasFrameScope()) {
1867aa51b79SEd Maste       if (!m_exe_ctx.HasTargetScope())
1877aa51b79SEd Maste         result.AppendError(GetInvalidTargetDescription());
1887aa51b79SEd Maste       else if (!m_exe_ctx.HasProcessScope())
1897aa51b79SEd Maste         result.AppendError(GetInvalidProcessDescription());
1907aa51b79SEd Maste       else if (!m_exe_ctx.HasThreadScope())
1917aa51b79SEd Maste         result.AppendError(GetInvalidThreadDescription());
1927aa51b79SEd Maste       else
193ac7ddfbfSEd Maste         result.AppendError(GetInvalidFrameDescription());
194ac7ddfbfSEd Maste       return false;
195ac7ddfbfSEd Maste     }
196ac7ddfbfSEd Maste 
197435933ddSDimitry Andric     if ((flags & eCommandRequiresRegContext) &&
198435933ddSDimitry Andric         (m_exe_ctx.GetRegisterContext() == nullptr)) {
199ac7ddfbfSEd Maste       result.AppendError(GetInvalidRegContextDescription());
200ac7ddfbfSEd Maste       return false;
201ac7ddfbfSEd Maste     }
202ac7ddfbfSEd Maste 
203435933ddSDimitry Andric     if (flags & eCommandTryTargetAPILock) {
204ac7ddfbfSEd Maste       Target *target = m_exe_ctx.GetTargetPtr();
205ac7ddfbfSEd Maste       if (target)
206435933ddSDimitry Andric         m_api_locker =
207435933ddSDimitry Andric             std::unique_lock<std::recursive_mutex>(target->GetAPIMutex());
208ac7ddfbfSEd Maste     }
209ac7ddfbfSEd Maste   }
210ac7ddfbfSEd Maste 
211435933ddSDimitry Andric   if (GetFlags().AnySet(eCommandProcessMustBeLaunched |
212435933ddSDimitry Andric                         eCommandProcessMustBePaused)) {
213ac7ddfbfSEd Maste     Process *process = m_interpreter.GetExecutionContext().GetProcessPtr();
214435933ddSDimitry Andric     if (process == nullptr) {
215ac7ddfbfSEd Maste       // A process that is not running is considered paused.
216435933ddSDimitry Andric       if (GetFlags().Test(eCommandProcessMustBeLaunched)) {
217ac7ddfbfSEd Maste         result.AppendError("Process must exist.");
218ac7ddfbfSEd Maste         result.SetStatus(eReturnStatusFailed);
219ac7ddfbfSEd Maste         return false;
220ac7ddfbfSEd Maste       }
221435933ddSDimitry Andric     } else {
222ac7ddfbfSEd Maste       StateType state = process->GetState();
223435933ddSDimitry Andric       switch (state) {
224ac7ddfbfSEd Maste       case eStateInvalid:
225ac7ddfbfSEd Maste       case eStateSuspended:
226ac7ddfbfSEd Maste       case eStateCrashed:
227ac7ddfbfSEd Maste       case eStateStopped:
228ac7ddfbfSEd Maste         break;
229ac7ddfbfSEd Maste 
230ac7ddfbfSEd Maste       case eStateConnected:
231ac7ddfbfSEd Maste       case eStateAttaching:
232ac7ddfbfSEd Maste       case eStateLaunching:
233ac7ddfbfSEd Maste       case eStateDetached:
234ac7ddfbfSEd Maste       case eStateExited:
235ac7ddfbfSEd Maste       case eStateUnloaded:
236435933ddSDimitry Andric         if (GetFlags().Test(eCommandProcessMustBeLaunched)) {
237ac7ddfbfSEd Maste           result.AppendError("Process must be launched.");
238ac7ddfbfSEd Maste           result.SetStatus(eReturnStatusFailed);
239ac7ddfbfSEd Maste           return false;
240ac7ddfbfSEd Maste         }
241ac7ddfbfSEd Maste         break;
242ac7ddfbfSEd Maste 
243ac7ddfbfSEd Maste       case eStateRunning:
244ac7ddfbfSEd Maste       case eStateStepping:
245435933ddSDimitry Andric         if (GetFlags().Test(eCommandProcessMustBePaused)) {
246435933ddSDimitry Andric           result.AppendError("Process is running.  Use 'process interrupt' to "
247435933ddSDimitry Andric                              "pause execution.");
248ac7ddfbfSEd Maste           result.SetStatus(eReturnStatusFailed);
249ac7ddfbfSEd Maste           return false;
250ac7ddfbfSEd Maste         }
251ac7ddfbfSEd Maste       }
252ac7ddfbfSEd Maste     }
253ac7ddfbfSEd Maste   }
254ac7ddfbfSEd Maste   return true;
255ac7ddfbfSEd Maste }
256ac7ddfbfSEd Maste 
Cleanup()257435933ddSDimitry Andric void CommandObject::Cleanup() {
258ac7ddfbfSEd Maste   m_exe_ctx.Clear();
2594bb0738eSEd Maste   if (m_api_locker.owns_lock())
2604bb0738eSEd Maste     m_api_locker.unlock();
261ac7ddfbfSEd Maste }
262ac7ddfbfSEd Maste 
HandleCompletion(CompletionRequest & request)2634ba319b5SDimitry Andric int CommandObject::HandleCompletion(CompletionRequest &request) {
2649f2f44ceSEd Maste   // Default implementation of WantsCompletion() is !WantsRawCommandString().
2654ba319b5SDimitry Andric   // Subclasses who want raw command string but desire, for example, argument
2664ba319b5SDimitry Andric   // completion should override WantsCompletion() to return true, instead.
267435933ddSDimitry Andric   if (WantsRawCommandString() && !WantsCompletion()) {
268435933ddSDimitry Andric     // FIXME: Abstract telling the completion to insert the completion
269435933ddSDimitry Andric     // character.
270ac7ddfbfSEd Maste     return -1;
271435933ddSDimitry Andric   } else {
272ac7ddfbfSEd Maste     // Can we do anything generic with the options?
273ac7ddfbfSEd Maste     Options *cur_options = GetOptions();
274ac7ddfbfSEd Maste     CommandReturnObject result;
275ac7ddfbfSEd Maste     OptionElementVector opt_element_vector;
276ac7ddfbfSEd Maste 
277435933ddSDimitry Andric     if (cur_options != nullptr) {
2784ba319b5SDimitry Andric       opt_element_vector = cur_options->ParseForCompletion(
2794ba319b5SDimitry Andric           request.GetParsedLine(), request.GetCursorIndex());
280ac7ddfbfSEd Maste 
2814ba319b5SDimitry Andric       bool handled_by_options = cur_options->HandleOptionCompletion(
2824ba319b5SDimitry Andric           request, opt_element_vector, GetCommandInterpreter());
283ac7ddfbfSEd Maste       if (handled_by_options)
2844ba319b5SDimitry Andric         return request.GetNumberOfMatches();
285ac7ddfbfSEd Maste     }
286ac7ddfbfSEd Maste 
287ac7ddfbfSEd Maste     // If we got here, the last word is not an option or an option argument.
2884ba319b5SDimitry Andric     return HandleArgumentCompletion(request, opt_element_vector);
289ac7ddfbfSEd Maste   }
290ac7ddfbfSEd Maste }
291ac7ddfbfSEd Maste 
HelpTextContainsWord(llvm::StringRef search_word,bool search_short_help,bool search_long_help,bool search_syntax,bool search_options)292435933ddSDimitry Andric bool CommandObject::HelpTextContainsWord(llvm::StringRef search_word,
2934bb0738eSEd Maste                                          bool search_short_help,
2944bb0738eSEd Maste                                          bool search_long_help,
2954bb0738eSEd Maste                                          bool search_syntax,
296435933ddSDimitry Andric                                          bool search_options) {
297ac7ddfbfSEd Maste   std::string options_usage_help;
298ac7ddfbfSEd Maste 
299ac7ddfbfSEd Maste   bool found_word = false;
300ac7ddfbfSEd Maste 
301435933ddSDimitry Andric   llvm::StringRef short_help = GetHelp();
302435933ddSDimitry Andric   llvm::StringRef long_help = GetHelpLong();
303435933ddSDimitry Andric   llvm::StringRef syntax_help = GetSyntax();
304ac7ddfbfSEd Maste 
305435933ddSDimitry Andric   if (search_short_help && short_help.contains_lower(search_word))
306ac7ddfbfSEd Maste     found_word = true;
307435933ddSDimitry Andric   else if (search_long_help && long_help.contains_lower(search_word))
308ac7ddfbfSEd Maste     found_word = true;
309435933ddSDimitry Andric   else if (search_syntax && syntax_help.contains_lower(search_word))
310ac7ddfbfSEd Maste     found_word = true;
311ac7ddfbfSEd Maste 
312435933ddSDimitry Andric   if (!found_word && search_options && GetOptions() != nullptr) {
313ac7ddfbfSEd Maste     StreamString usage_help;
314435933ddSDimitry Andric     GetOptions()->GenerateOptionUsage(
315435933ddSDimitry Andric         usage_help, this,
316435933ddSDimitry Andric         GetCommandInterpreter().GetDebugger().GetTerminalWidth());
317435933ddSDimitry Andric     if (!usage_help.Empty()) {
318435933ddSDimitry Andric       llvm::StringRef usage_text = usage_help.GetString();
319435933ddSDimitry Andric       if (usage_text.contains_lower(search_word))
320ac7ddfbfSEd Maste         found_word = true;
321ac7ddfbfSEd Maste     }
322ac7ddfbfSEd Maste   }
323ac7ddfbfSEd Maste 
324ac7ddfbfSEd Maste   return found_word;
325ac7ddfbfSEd Maste }
326ac7ddfbfSEd Maste 
ParseOptionsAndNotify(Args & args,CommandReturnObject & result,OptionGroupOptions & group_options,ExecutionContext & exe_ctx)3274ba319b5SDimitry Andric bool CommandObject::ParseOptionsAndNotify(Args &args,
3284ba319b5SDimitry Andric                                           CommandReturnObject &result,
3294ba319b5SDimitry Andric                                           OptionGroupOptions &group_options,
3304ba319b5SDimitry Andric                                           ExecutionContext &exe_ctx) {
3314ba319b5SDimitry Andric   if (!ParseOptions(args, result))
3324ba319b5SDimitry Andric     return false;
3334ba319b5SDimitry Andric 
3344ba319b5SDimitry Andric   Status error(group_options.NotifyOptionParsingFinished(&exe_ctx));
3354ba319b5SDimitry Andric   if (error.Fail()) {
3364ba319b5SDimitry Andric     result.AppendError(error.AsCString());
3374ba319b5SDimitry Andric     result.SetStatus(eReturnStatusFailed);
3384ba319b5SDimitry Andric     return false;
3394ba319b5SDimitry Andric   }
3404ba319b5SDimitry Andric   return true;
3414ba319b5SDimitry Andric }
3424ba319b5SDimitry Andric 
GetNumArgumentEntries()343435933ddSDimitry Andric int CommandObject::GetNumArgumentEntries() { return m_arguments.size(); }
344ac7ddfbfSEd Maste 
345ac7ddfbfSEd Maste CommandObject::CommandArgumentEntry *
GetArgumentEntryAtIndex(int idx)346435933ddSDimitry Andric CommandObject::GetArgumentEntryAtIndex(int idx) {
3470127ef0fSEd Maste   if (static_cast<size_t>(idx) < m_arguments.size())
348ac7ddfbfSEd Maste     return &(m_arguments[idx]);
349ac7ddfbfSEd Maste 
3500127ef0fSEd Maste   return nullptr;
351ac7ddfbfSEd Maste }
352ac7ddfbfSEd Maste 
3531c3bbb01SEd Maste const CommandObject::ArgumentTableEntry *
FindArgumentDataByType(CommandArgumentType arg_type)354435933ddSDimitry Andric CommandObject::FindArgumentDataByType(CommandArgumentType arg_type) {
355ac7ddfbfSEd Maste   const ArgumentTableEntry *table = CommandObject::GetArgumentTable();
356ac7ddfbfSEd Maste 
357ac7ddfbfSEd Maste   for (int i = 0; i < eArgTypeLastArg; ++i)
358ac7ddfbfSEd Maste     if (table[i].arg_type == arg_type)
3591c3bbb01SEd Maste       return &(table[i]);
360ac7ddfbfSEd Maste 
3610127ef0fSEd Maste   return nullptr;
362ac7ddfbfSEd Maste }
363ac7ddfbfSEd Maste 
GetArgumentHelp(Stream & str,CommandArgumentType arg_type,CommandInterpreter & interpreter)364435933ddSDimitry Andric void CommandObject::GetArgumentHelp(Stream &str, CommandArgumentType arg_type,
365435933ddSDimitry Andric                                     CommandInterpreter &interpreter) {
366ac7ddfbfSEd Maste   const ArgumentTableEntry *table = CommandObject::GetArgumentTable();
3671c3bbb01SEd Maste   const ArgumentTableEntry *entry = &(table[arg_type]);
368ac7ddfbfSEd Maste 
369435933ddSDimitry Andric   // The table is *supposed* to be kept in arg_type order, but someone *could*
370435933ddSDimitry Andric   // have messed it up...
371ac7ddfbfSEd Maste 
372ac7ddfbfSEd Maste   if (entry->arg_type != arg_type)
373ac7ddfbfSEd Maste     entry = CommandObject::FindArgumentDataByType(arg_type);
374ac7ddfbfSEd Maste 
375ac7ddfbfSEd Maste   if (!entry)
376ac7ddfbfSEd Maste     return;
377ac7ddfbfSEd Maste 
378ac7ddfbfSEd Maste   StreamString name_str;
379ac7ddfbfSEd Maste   name_str.Printf("<%s>", entry->arg_name);
380ac7ddfbfSEd Maste 
381435933ddSDimitry Andric   if (entry->help_function) {
382435933ddSDimitry Andric     llvm::StringRef help_text = entry->help_function();
383435933ddSDimitry Andric     if (!entry->help_function.self_formatting) {
384435933ddSDimitry Andric       interpreter.OutputFormattedHelpText(str, name_str.GetString(), "--",
385435933ddSDimitry Andric                                           help_text, name_str.GetSize());
386435933ddSDimitry Andric     } else {
387435933ddSDimitry Andric       interpreter.OutputHelpText(str, name_str.GetString(), "--", help_text,
388ac7ddfbfSEd Maste                                  name_str.GetSize());
389ac7ddfbfSEd Maste     }
390435933ddSDimitry Andric   } else
391435933ddSDimitry Andric     interpreter.OutputFormattedHelpText(str, name_str.GetString(), "--",
392435933ddSDimitry Andric                                         entry->help_text, name_str.GetSize());
393ac7ddfbfSEd Maste }
394ac7ddfbfSEd Maste 
GetArgumentName(CommandArgumentType arg_type)395435933ddSDimitry Andric const char *CommandObject::GetArgumentName(CommandArgumentType arg_type) {
396435933ddSDimitry Andric   const ArgumentTableEntry *entry =
397435933ddSDimitry Andric       &(CommandObject::GetArgumentTable()[arg_type]);
398ac7ddfbfSEd Maste 
399435933ddSDimitry Andric   // The table is *supposed* to be kept in arg_type order, but someone *could*
400435933ddSDimitry Andric   // have messed it up...
401ac7ddfbfSEd Maste 
402ac7ddfbfSEd Maste   if (entry->arg_type != arg_type)
403ac7ddfbfSEd Maste     entry = CommandObject::FindArgumentDataByType(arg_type);
404ac7ddfbfSEd Maste 
405ac7ddfbfSEd Maste   if (entry)
406ac7ddfbfSEd Maste     return entry->arg_name;
407ac7ddfbfSEd Maste 
408435933ddSDimitry Andric   return nullptr;
409ac7ddfbfSEd Maste }
410ac7ddfbfSEd Maste 
IsPairType(ArgumentRepetitionType arg_repeat_type)411435933ddSDimitry Andric bool CommandObject::IsPairType(ArgumentRepetitionType arg_repeat_type) {
412*b5893f02SDimitry Andric   return (arg_repeat_type == eArgRepeatPairPlain) ||
413435933ddSDimitry Andric          (arg_repeat_type == eArgRepeatPairOptional) ||
414435933ddSDimitry Andric          (arg_repeat_type == eArgRepeatPairPlus) ||
415435933ddSDimitry Andric          (arg_repeat_type == eArgRepeatPairStar) ||
416435933ddSDimitry Andric          (arg_repeat_type == eArgRepeatPairRange) ||
417*b5893f02SDimitry Andric          (arg_repeat_type == eArgRepeatPairRangeOptional);
418ac7ddfbfSEd Maste }
419ac7ddfbfSEd Maste 
420ac7ddfbfSEd Maste static CommandObject::CommandArgumentEntry
OptSetFiltered(uint32_t opt_set_mask,CommandObject::CommandArgumentEntry & cmd_arg_entry)421435933ddSDimitry Andric OptSetFiltered(uint32_t opt_set_mask,
422435933ddSDimitry Andric                CommandObject::CommandArgumentEntry &cmd_arg_entry) {
423ac7ddfbfSEd Maste   CommandObject::CommandArgumentEntry ret_val;
424ac7ddfbfSEd Maste   for (unsigned i = 0; i < cmd_arg_entry.size(); ++i)
425ac7ddfbfSEd Maste     if (opt_set_mask & cmd_arg_entry[i].arg_opt_set_association)
426ac7ddfbfSEd Maste       ret_val.push_back(cmd_arg_entry[i]);
427ac7ddfbfSEd Maste   return ret_val;
428ac7ddfbfSEd Maste }
429ac7ddfbfSEd Maste 
4304ba319b5SDimitry Andric // Default parameter value of opt_set_mask is LLDB_OPT_SET_ALL, which means
4314ba319b5SDimitry Andric // take all the argument data into account.  On rare cases where some argument
4324ba319b5SDimitry Andric // sticks with certain option sets, this function returns the option set
4334ba319b5SDimitry Andric // filtered args.
GetFormattedCommandArguments(Stream & str,uint32_t opt_set_mask)434435933ddSDimitry Andric void CommandObject::GetFormattedCommandArguments(Stream &str,
435435933ddSDimitry Andric                                                  uint32_t opt_set_mask) {
436ac7ddfbfSEd Maste   int num_args = m_arguments.size();
437435933ddSDimitry Andric   for (int i = 0; i < num_args; ++i) {
438ac7ddfbfSEd Maste     if (i > 0)
439ac7ddfbfSEd Maste       str.Printf(" ");
440ac7ddfbfSEd Maste     CommandArgumentEntry arg_entry =
441435933ddSDimitry Andric         opt_set_mask == LLDB_OPT_SET_ALL
442435933ddSDimitry Andric             ? m_arguments[i]
443ac7ddfbfSEd Maste             : OptSetFiltered(opt_set_mask, m_arguments[i]);
444ac7ddfbfSEd Maste     int num_alternatives = arg_entry.size();
445ac7ddfbfSEd Maste 
446435933ddSDimitry Andric     if ((num_alternatives == 2) && IsPairType(arg_entry[0].arg_repetition)) {
447ac7ddfbfSEd Maste       const char *first_name = GetArgumentName(arg_entry[0].arg_type);
448ac7ddfbfSEd Maste       const char *second_name = GetArgumentName(arg_entry[1].arg_type);
449435933ddSDimitry Andric       switch (arg_entry[0].arg_repetition) {
450ac7ddfbfSEd Maste       case eArgRepeatPairPlain:
451ac7ddfbfSEd Maste         str.Printf("<%s> <%s>", first_name, second_name);
452ac7ddfbfSEd Maste         break;
453ac7ddfbfSEd Maste       case eArgRepeatPairOptional:
454ac7ddfbfSEd Maste         str.Printf("[<%s> <%s>]", first_name, second_name);
455ac7ddfbfSEd Maste         break;
456ac7ddfbfSEd Maste       case eArgRepeatPairPlus:
457435933ddSDimitry Andric         str.Printf("<%s> <%s> [<%s> <%s> [...]]", first_name, second_name,
458435933ddSDimitry Andric                    first_name, second_name);
459ac7ddfbfSEd Maste         break;
460ac7ddfbfSEd Maste       case eArgRepeatPairStar:
461435933ddSDimitry Andric         str.Printf("[<%s> <%s> [<%s> <%s> [...]]]", first_name, second_name,
462435933ddSDimitry Andric                    first_name, second_name);
463ac7ddfbfSEd Maste         break;
464ac7ddfbfSEd Maste       case eArgRepeatPairRange:
465435933ddSDimitry Andric         str.Printf("<%s_1> <%s_1> ... <%s_n> <%s_n>", first_name, second_name,
466435933ddSDimitry Andric                    first_name, second_name);
467ac7ddfbfSEd Maste         break;
468ac7ddfbfSEd Maste       case eArgRepeatPairRangeOptional:
469435933ddSDimitry Andric         str.Printf("[<%s_1> <%s_1> ... <%s_n> <%s_n>]", first_name, second_name,
470435933ddSDimitry Andric                    first_name, second_name);
471ac7ddfbfSEd Maste         break;
472435933ddSDimitry Andric       // Explicitly test for all the rest of the cases, so if new types get
4734ba319b5SDimitry Andric       // added we will notice the missing case statement(s).
474ac7ddfbfSEd Maste       case eArgRepeatPlain:
475ac7ddfbfSEd Maste       case eArgRepeatOptional:
476ac7ddfbfSEd Maste       case eArgRepeatPlus:
477ac7ddfbfSEd Maste       case eArgRepeatStar:
478ac7ddfbfSEd Maste       case eArgRepeatRange:
479435933ddSDimitry Andric         // These should not be reached, as they should fail the IsPairType test
480435933ddSDimitry Andric         // above.
481ac7ddfbfSEd Maste         break;
482ac7ddfbfSEd Maste       }
483435933ddSDimitry Andric     } else {
484ac7ddfbfSEd Maste       StreamString names;
485435933ddSDimitry Andric       for (int j = 0; j < num_alternatives; ++j) {
486ac7ddfbfSEd Maste         if (j > 0)
487ac7ddfbfSEd Maste           names.Printf(" | ");
488ac7ddfbfSEd Maste         names.Printf("%s", GetArgumentName(arg_entry[j].arg_type));
489ac7ddfbfSEd Maste       }
490435933ddSDimitry Andric 
491435933ddSDimitry Andric       std::string name_str = names.GetString();
492435933ddSDimitry Andric       switch (arg_entry[0].arg_repetition) {
493ac7ddfbfSEd Maste       case eArgRepeatPlain:
494435933ddSDimitry Andric         str.Printf("<%s>", name_str.c_str());
495ac7ddfbfSEd Maste         break;
496ac7ddfbfSEd Maste       case eArgRepeatPlus:
497435933ddSDimitry Andric         str.Printf("<%s> [<%s> [...]]", name_str.c_str(), name_str.c_str());
498ac7ddfbfSEd Maste         break;
499ac7ddfbfSEd Maste       case eArgRepeatStar:
500435933ddSDimitry Andric         str.Printf("[<%s> [<%s> [...]]]", name_str.c_str(), name_str.c_str());
501ac7ddfbfSEd Maste         break;
502ac7ddfbfSEd Maste       case eArgRepeatOptional:
503435933ddSDimitry Andric         str.Printf("[<%s>]", name_str.c_str());
504ac7ddfbfSEd Maste         break;
505ac7ddfbfSEd Maste       case eArgRepeatRange:
506435933ddSDimitry Andric         str.Printf("<%s_1> .. <%s_n>", name_str.c_str(), name_str.c_str());
507ac7ddfbfSEd Maste         break;
508435933ddSDimitry Andric       // Explicitly test for all the rest of the cases, so if new types get
5094ba319b5SDimitry Andric       // added we will notice the missing case statement(s).
510ac7ddfbfSEd Maste       case eArgRepeatPairPlain:
511ac7ddfbfSEd Maste       case eArgRepeatPairOptional:
512ac7ddfbfSEd Maste       case eArgRepeatPairPlus:
513ac7ddfbfSEd Maste       case eArgRepeatPairStar:
514ac7ddfbfSEd Maste       case eArgRepeatPairRange:
515ac7ddfbfSEd Maste       case eArgRepeatPairRangeOptional:
516435933ddSDimitry Andric         // These should not be hit, as they should pass the IsPairType test
5174ba319b5SDimitry Andric         // above, and control should have gone into the other branch of the if
5184ba319b5SDimitry Andric         // statement.
519ac7ddfbfSEd Maste         break;
520ac7ddfbfSEd Maste       }
521ac7ddfbfSEd Maste     }
522ac7ddfbfSEd Maste   }
523ac7ddfbfSEd Maste }
524ac7ddfbfSEd Maste 
525ac7ddfbfSEd Maste CommandArgumentType
LookupArgumentName(llvm::StringRef arg_name)526435933ddSDimitry Andric CommandObject::LookupArgumentName(llvm::StringRef arg_name) {
527ac7ddfbfSEd Maste   CommandArgumentType return_type = eArgTypeLastArg;
528ac7ddfbfSEd Maste 
529435933ddSDimitry Andric   arg_name = arg_name.ltrim('<').rtrim('>');
530ac7ddfbfSEd Maste 
531ac7ddfbfSEd Maste   const ArgumentTableEntry *table = GetArgumentTable();
532ac7ddfbfSEd Maste   for (int i = 0; i < eArgTypeLastArg; ++i)
533435933ddSDimitry Andric     if (arg_name == table[i].arg_name)
534ac7ddfbfSEd Maste       return_type = g_arguments_data[i].arg_type;
535ac7ddfbfSEd Maste 
536ac7ddfbfSEd Maste   return return_type;
537ac7ddfbfSEd Maste }
538ac7ddfbfSEd Maste 
RegisterNameHelpTextCallback()539435933ddSDimitry Andric static llvm::StringRef RegisterNameHelpTextCallback() {
540435933ddSDimitry Andric   return "Register names can be specified using the architecture specific "
541435933ddSDimitry Andric          "names.  "
542435933ddSDimitry Andric          "They can also be specified using generic names.  Not all generic "
543435933ddSDimitry Andric          "entities have "
544435933ddSDimitry Andric          "registers backing them on all architectures.  When they don't the "
545435933ddSDimitry Andric          "generic name "
546ac7ddfbfSEd Maste          "will return an error.\n"
547ac7ddfbfSEd Maste          "The generic names defined in lldb are:\n"
548ac7ddfbfSEd Maste          "\n"
549ac7ddfbfSEd Maste          "pc       - program counter register\n"
550ac7ddfbfSEd Maste          "ra       - return address register\n"
551ac7ddfbfSEd Maste          "fp       - frame pointer register\n"
552ac7ddfbfSEd Maste          "sp       - stack pointer register\n"
553ac7ddfbfSEd Maste          "flags    - the flags register\n"
554ac7ddfbfSEd Maste          "arg{1-6} - integer argument passing registers.\n";
555ac7ddfbfSEd Maste }
556ac7ddfbfSEd Maste 
BreakpointIDHelpTextCallback()557435933ddSDimitry Andric static llvm::StringRef BreakpointIDHelpTextCallback() {
5584bb0738eSEd Maste   return "Breakpoints are identified using major and minor numbers; the major "
559435933ddSDimitry Andric          "number corresponds to the single entity that was created with a "
560435933ddSDimitry Andric          "'breakpoint "
561435933ddSDimitry Andric          "set' command; the minor numbers correspond to all the locations that "
562435933ddSDimitry Andric          "were "
563435933ddSDimitry Andric          "actually found/set based on the major breakpoint.  A full breakpoint "
564435933ddSDimitry Andric          "ID might "
565435933ddSDimitry Andric          "look like 3.14, meaning the 14th location set for the 3rd "
566435933ddSDimitry Andric          "breakpoint.  You "
567435933ddSDimitry Andric          "can specify all the locations of a breakpoint by just indicating the "
568435933ddSDimitry Andric          "major "
569435933ddSDimitry Andric          "breakpoint number. A valid breakpoint ID consists either of just the "
570435933ddSDimitry Andric          "major "
571435933ddSDimitry Andric          "number, or the major number followed by a dot and the location "
572435933ddSDimitry Andric          "number (e.g. "
5734bb0738eSEd Maste          "3 or 3.2 could both be valid breakpoint IDs.)";
574ac7ddfbfSEd Maste }
575ac7ddfbfSEd Maste 
BreakpointIDRangeHelpTextCallback()576435933ddSDimitry Andric static llvm::StringRef BreakpointIDRangeHelpTextCallback() {
577435933ddSDimitry Andric   return "A 'breakpoint ID list' is a manner of specifying multiple "
578435933ddSDimitry Andric          "breakpoints. "
579435933ddSDimitry Andric          "This can be done through several mechanisms.  The easiest way is to "
580435933ddSDimitry Andric          "just "
5814bb0738eSEd Maste          "enter a space-separated list of breakpoint IDs.  To specify all the "
582ac7ddfbfSEd Maste          "breakpoint locations under a major breakpoint, you can use the major "
583435933ddSDimitry Andric          "breakpoint number followed by '.*', eg. '5.*' means all the "
584435933ddSDimitry Andric          "locations under "
585ac7ddfbfSEd Maste          "breakpoint 5.  You can also indicate a range of breakpoints by using "
586435933ddSDimitry Andric          "<start-bp-id> - <end-bp-id>.  The start-bp-id and end-bp-id for a "
587435933ddSDimitry Andric          "range can "
588435933ddSDimitry Andric          "be any valid breakpoint IDs.  It is not legal, however, to specify a "
589435933ddSDimitry Andric          "range "
590435933ddSDimitry Andric          "using specific locations that cross major breakpoint numbers.  I.e. "
591435933ddSDimitry Andric          "3.2 - 3.7"
592ac7ddfbfSEd Maste          " is legal; 2 - 5 is legal; but 3.2 - 4.4 is not legal.";
593ac7ddfbfSEd Maste }
594ac7ddfbfSEd Maste 
BreakpointNameHelpTextCallback()595435933ddSDimitry Andric static llvm::StringRef BreakpointNameHelpTextCallback() {
596435933ddSDimitry Andric   return "A name that can be added to a breakpoint when it is created, or "
597435933ddSDimitry Andric          "later "
5987aa51b79SEd Maste          "on with the \"breakpoint name add\" command.  "
599435933ddSDimitry Andric          "Breakpoint names can be used to specify breakpoints in all the "
600435933ddSDimitry Andric          "places breakpoint IDs "
601435933ddSDimitry Andric          "and breakpoint ID ranges can be used.  As such they provide a "
602435933ddSDimitry Andric          "convenient way to group breakpoints, "
603435933ddSDimitry Andric          "and to operate on breakpoints you create without having to track the "
604435933ddSDimitry Andric          "breakpoint number.  "
605435933ddSDimitry Andric          "Note, the attributes you set when using a breakpoint name in a "
606435933ddSDimitry Andric          "breakpoint command don't "
607435933ddSDimitry Andric          "adhere to the name, but instead are set individually on all the "
608435933ddSDimitry Andric          "breakpoints currently tagged with that "
6094bb0738eSEd Maste          "name.  Future breakpoints "
610435933ddSDimitry Andric          "tagged with that name will not pick up the attributes previously "
611435933ddSDimitry Andric          "given using that name.  "
612435933ddSDimitry Andric          "In order to distinguish breakpoint names from breakpoint IDs and "
613435933ddSDimitry Andric          "ranges, "
614435933ddSDimitry Andric          "names must start with a letter from a-z or A-Z and cannot contain "
615435933ddSDimitry Andric          "spaces, \".\" or \"-\".  "
616435933ddSDimitry Andric          "Also, breakpoint names can only be applied to breakpoints, not to "
617435933ddSDimitry Andric          "breakpoint locations.";
6187aa51b79SEd Maste }
6197aa51b79SEd Maste 
GDBFormatHelpTextCallback()620435933ddSDimitry Andric static llvm::StringRef GDBFormatHelpTextCallback() {
621435933ddSDimitry Andric   return "A GDB format consists of a repeat count, a format letter and a size "
622435933ddSDimitry Andric          "letter. "
623435933ddSDimitry Andric          "The repeat count is optional and defaults to 1. The format letter is "
624435933ddSDimitry Andric          "optional "
625435933ddSDimitry Andric          "and defaults to the previous format that was used. The size letter "
626435933ddSDimitry Andric          "is optional "
627ac7ddfbfSEd Maste          "and defaults to the previous size that was used.\n"
628ac7ddfbfSEd Maste          "\n"
629ac7ddfbfSEd Maste          "Format letters include:\n"
630ac7ddfbfSEd Maste          "o - octal\n"
631ac7ddfbfSEd Maste          "x - hexadecimal\n"
632ac7ddfbfSEd Maste          "d - decimal\n"
633ac7ddfbfSEd Maste          "u - unsigned decimal\n"
634ac7ddfbfSEd Maste          "t - binary\n"
635ac7ddfbfSEd Maste          "f - float\n"
636ac7ddfbfSEd Maste          "a - address\n"
637ac7ddfbfSEd Maste          "i - instruction\n"
638ac7ddfbfSEd Maste          "c - char\n"
639ac7ddfbfSEd Maste          "s - string\n"
640ac7ddfbfSEd Maste          "T - OSType\n"
641ac7ddfbfSEd Maste          "A - float as hex\n"
642ac7ddfbfSEd Maste          "\n"
643ac7ddfbfSEd Maste          "Size letters include:\n"
644ac7ddfbfSEd Maste          "b - 1 byte  (byte)\n"
645ac7ddfbfSEd Maste          "h - 2 bytes (halfword)\n"
646ac7ddfbfSEd Maste          "w - 4 bytes (word)\n"
647ac7ddfbfSEd Maste          "g - 8 bytes (giant)\n"
648ac7ddfbfSEd Maste          "\n"
649ac7ddfbfSEd Maste          "Example formats:\n"
650ac7ddfbfSEd Maste          "32xb - show 32 1 byte hexadecimal integer values\n"
651ac7ddfbfSEd Maste          "16xh - show 16 2 byte hexadecimal integer values\n"
652435933ddSDimitry Andric          "64   - show 64 2 byte hexadecimal integer values (format and size "
653435933ddSDimitry Andric          "from the last format)\n"
654435933ddSDimitry Andric          "dw   - show 1 4 byte decimal integer value\n";
655ac7ddfbfSEd Maste }
656ac7ddfbfSEd Maste 
FormatHelpTextCallback()657435933ddSDimitry Andric static llvm::StringRef FormatHelpTextCallback() {
658435933ddSDimitry Andric   static std::string help_text;
659ac7ddfbfSEd Maste 
660435933ddSDimitry Andric   if (!help_text.empty())
661435933ddSDimitry Andric     return help_text;
662ac7ddfbfSEd Maste 
663ac7ddfbfSEd Maste   StreamString sstr;
664435933ddSDimitry Andric   sstr << "One of the format names (or one-character names) that can be used "
665435933ddSDimitry Andric           "to show a variable's value:\n";
666435933ddSDimitry Andric   for (Format f = eFormatDefault; f < kNumFormats; f = Format(f + 1)) {
667ac7ddfbfSEd Maste     if (f != eFormatDefault)
668ac7ddfbfSEd Maste       sstr.PutChar('\n');
669ac7ddfbfSEd Maste 
670ac7ddfbfSEd Maste     char format_char = FormatManager::GetFormatAsFormatChar(f);
671ac7ddfbfSEd Maste     if (format_char)
672ac7ddfbfSEd Maste       sstr.Printf("'%c' or ", format_char);
673ac7ddfbfSEd Maste 
674ac7ddfbfSEd Maste     sstr.Printf("\"%s\"", FormatManager::GetFormatAsCString(f));
675ac7ddfbfSEd Maste   }
676ac7ddfbfSEd Maste 
677ac7ddfbfSEd Maste   sstr.Flush();
678ac7ddfbfSEd Maste 
679435933ddSDimitry Andric   help_text = sstr.GetString();
680ac7ddfbfSEd Maste 
681435933ddSDimitry Andric   return help_text;
682ac7ddfbfSEd Maste }
683ac7ddfbfSEd Maste 
LanguageTypeHelpTextCallback()684435933ddSDimitry Andric static llvm::StringRef LanguageTypeHelpTextCallback() {
685435933ddSDimitry Andric   static std::string help_text;
686ac7ddfbfSEd Maste 
687435933ddSDimitry Andric   if (!help_text.empty())
688435933ddSDimitry Andric     return help_text;
689ac7ddfbfSEd Maste 
690ac7ddfbfSEd Maste   StreamString sstr;
691ac7ddfbfSEd Maste   sstr << "One of the following languages:\n";
692ac7ddfbfSEd Maste 
6939f2f44ceSEd Maste   Language::PrintAllLanguages(sstr, "  ", "\n");
694ac7ddfbfSEd Maste 
695ac7ddfbfSEd Maste   sstr.Flush();
696ac7ddfbfSEd Maste 
697435933ddSDimitry Andric   help_text = sstr.GetString();
698ac7ddfbfSEd Maste 
699435933ddSDimitry Andric   return help_text;
700ac7ddfbfSEd Maste }
701ac7ddfbfSEd Maste 
SummaryStringHelpTextCallback()702435933ddSDimitry Andric static llvm::StringRef SummaryStringHelpTextCallback() {
703435933ddSDimitry Andric   return "A summary string is a way to extract information from variables in "
704435933ddSDimitry Andric          "order to present them using a summary.\n"
705435933ddSDimitry Andric          "Summary strings contain static text, variables, scopes and control "
706435933ddSDimitry Andric          "sequences:\n"
707435933ddSDimitry Andric          "  - Static text can be any sequence of non-special characters, i.e. "
708435933ddSDimitry Andric          "anything but '{', '}', '$', or '\\'.\n"
709435933ddSDimitry Andric          "  - Variables are sequences of characters beginning with ${, ending "
710435933ddSDimitry Andric          "with } and that contain symbols in the format described below.\n"
711435933ddSDimitry Andric          "  - Scopes are any sequence of text between { and }. Anything "
712435933ddSDimitry Andric          "included in a scope will only appear in the output summary if there "
713435933ddSDimitry Andric          "were no errors.\n"
714435933ddSDimitry Andric          "  - Control sequences are the usual C/C++ '\\a', '\\n', ..., plus "
715435933ddSDimitry Andric          "'\\$', '\\{' and '\\}'.\n"
716435933ddSDimitry Andric          "A summary string works by copying static text verbatim, turning "
717435933ddSDimitry Andric          "control sequences into their character counterpart, expanding "
718435933ddSDimitry Andric          "variables and trying to expand scopes.\n"
719435933ddSDimitry Andric          "A variable is expanded by giving it a value other than its textual "
720435933ddSDimitry Andric          "representation, and the way this is done depends on what comes after "
721435933ddSDimitry Andric          "the ${ marker.\n"
722435933ddSDimitry Andric          "The most common sequence if ${var followed by an expression path, "
723435933ddSDimitry Andric          "which is the text one would type to access a member of an aggregate "
724435933ddSDimitry Andric          "types, given a variable of that type"
725435933ddSDimitry Andric          " (e.g. if type T has a member named x, which has a member named y, "
726435933ddSDimitry Andric          "and if t is of type T, the expression path would be .x.y and the way "
727435933ddSDimitry Andric          "to fit that into a summary string would be"
728435933ddSDimitry Andric          " ${var.x.y}). You can also use ${*var followed by an expression path "
729435933ddSDimitry Andric          "and in that case the object referred by the path will be "
730435933ddSDimitry Andric          "dereferenced before being displayed."
731435933ddSDimitry Andric          " If the object is not a pointer, doing so will cause an error. For "
732435933ddSDimitry Andric          "additional details on expression paths, you can type 'help "
733435933ddSDimitry Andric          "expr-path'. \n"
734435933ddSDimitry Andric          "By default, summary strings attempt to display the summary for any "
735435933ddSDimitry Andric          "variable they reference, and if that fails the value. If neither can "
736435933ddSDimitry Andric          "be shown, nothing is displayed."
737435933ddSDimitry Andric          "In a summary string, you can also use an array index [n], or a "
738435933ddSDimitry Andric          "slice-like range [n-m]. This can have two different meanings "
739435933ddSDimitry Andric          "depending on what kind of object the expression"
740ac7ddfbfSEd Maste          " path refers to:\n"
741435933ddSDimitry Andric          "  - if it is a scalar type (any basic type like int, float, ...) the "
742435933ddSDimitry Andric          "expression is a bitfield, i.e. the bits indicated by the indexing "
743435933ddSDimitry Andric          "operator are extracted out of the number"
744ac7ddfbfSEd Maste          " and displayed as an individual variable\n"
745435933ddSDimitry Andric          "  - if it is an array or pointer the array items indicated by the "
746435933ddSDimitry Andric          "indexing operator are shown as the result of the variable. if the "
747435933ddSDimitry Andric          "expression is an array, real array items are"
748435933ddSDimitry Andric          " printed; if it is a pointer, the pointer-as-array syntax is used to "
749435933ddSDimitry Andric          "obtain the values (this means, the latter case can have no range "
750435933ddSDimitry Andric          "checking)\n"
751435933ddSDimitry Andric          "If you are trying to display an array for which the size is known, "
752435933ddSDimitry Andric          "you can also use [] instead of giving an exact range. This has the "
753435933ddSDimitry Andric          "effect of showing items 0 thru size - 1.\n"
754435933ddSDimitry Andric          "Additionally, a variable can contain an (optional) format code, as "
755435933ddSDimitry Andric          "in ${var.x.y%code}, where code can be any of the valid formats "
756435933ddSDimitry Andric          "described in 'help format', or one of the"
757ac7ddfbfSEd Maste          " special symbols only allowed as part of a variable:\n"
758ac7ddfbfSEd Maste          "    %V: show the value of the object by default\n"
759ac7ddfbfSEd Maste          "    %S: show the summary of the object by default\n"
760435933ddSDimitry Andric          "    %@: show the runtime-provided object description (for "
761435933ddSDimitry Andric          "Objective-C, it calls NSPrintForDebugger; for C/C++ it does "
762435933ddSDimitry Andric          "nothing)\n"
763435933ddSDimitry Andric          "    %L: show the location of the object (memory address or a "
764435933ddSDimitry Andric          "register name)\n"
765ac7ddfbfSEd Maste          "    %#: show the number of children of the object\n"
766ac7ddfbfSEd Maste          "    %T: show the type of the object\n"
767435933ddSDimitry Andric          "Another variable that you can use in summary strings is ${svar . "
768435933ddSDimitry Andric          "This sequence works exactly like ${var, including the fact that "
769435933ddSDimitry Andric          "${*svar is an allowed sequence, but uses"
770435933ddSDimitry Andric          " the object's synthetic children provider instead of the actual "
771435933ddSDimitry Andric          "objects. For instance, if you are using STL synthetic children "
772435933ddSDimitry Andric          "providers, the following summary string would"
773ac7ddfbfSEd Maste          " count the number of actual elements stored in an std::list:\n"
774ac7ddfbfSEd Maste          "type summary add -s \"${svar%#}\" -x \"std::list<\"";
775ac7ddfbfSEd Maste }
776ac7ddfbfSEd Maste 
ExprPathHelpTextCallback()777435933ddSDimitry Andric static llvm::StringRef ExprPathHelpTextCallback() {
778435933ddSDimitry Andric   return "An expression path is the sequence of symbols that is used in C/C++ "
779435933ddSDimitry Andric          "to access a member variable of an aggregate object (class).\n"
780ac7ddfbfSEd Maste          "For instance, given a class:\n"
781ac7ddfbfSEd Maste          "  class foo {\n"
782ac7ddfbfSEd Maste          "      int a;\n"
783ac7ddfbfSEd Maste          "      int b; .\n"
784ac7ddfbfSEd Maste          "      foo* next;\n"
785ac7ddfbfSEd Maste          "  };\n"
786435933ddSDimitry Andric          "the expression to read item b in the item pointed to by next for foo "
787435933ddSDimitry Andric          "aFoo would be aFoo.next->b.\n"
788435933ddSDimitry Andric          "Given that aFoo could just be any object of type foo, the string "
789435933ddSDimitry Andric          "'.next->b' is the expression path, because it can be attached to any "
790435933ddSDimitry Andric          "foo instance to achieve the effect.\n"
791435933ddSDimitry Andric          "Expression paths in LLDB include dot (.) and arrow (->) operators, "
792435933ddSDimitry Andric          "and most commands using expression paths have ways to also accept "
793435933ddSDimitry Andric          "the star (*) operator.\n"
794435933ddSDimitry Andric          "The meaning of these operators is the same as the usual one given to "
795435933ddSDimitry Andric          "them by the C/C++ standards.\n"
796435933ddSDimitry Andric          "LLDB also has support for indexing ([ ]) in expression paths, and "
797435933ddSDimitry Andric          "extends the traditional meaning of the square brackets operator to "
798435933ddSDimitry Andric          "allow bitfield extraction:\n"
799435933ddSDimitry Andric          "for objects of native types (int, float, char, ...) saying '[n-m]' "
800435933ddSDimitry Andric          "as an expression path (where n and m are any positive integers, e.g. "
801435933ddSDimitry Andric          "[3-5]) causes LLDB to extract"
802435933ddSDimitry Andric          " bits n thru m from the value of the variable. If n == m, [n] is "
803435933ddSDimitry Andric          "also allowed as a shortcut syntax. For arrays and pointers, "
804435933ddSDimitry Andric          "expression paths can only contain one index"
805435933ddSDimitry Andric          " and the meaning of the operation is the same as the one defined by "
806435933ddSDimitry Andric          "C/C++ (item extraction). Some commands extend bitfield-like syntax "
807435933ddSDimitry Andric          "for arrays and pointers with the"
808435933ddSDimitry Andric          " meaning of array slicing (taking elements n thru m inside the array "
809435933ddSDimitry Andric          "or pointed-to memory).";
810ac7ddfbfSEd Maste }
811ac7ddfbfSEd Maste 
FormatLongHelpText(Stream & output_strm,llvm::StringRef long_help)812435933ddSDimitry Andric void CommandObject::FormatLongHelpText(Stream &output_strm,
813435933ddSDimitry Andric                                        llvm::StringRef long_help) {
814b91a7dfcSDimitry Andric   CommandInterpreter &interpreter = GetCommandInterpreter();
815b91a7dfcSDimitry Andric   std::stringstream lineStream(long_help);
816b91a7dfcSDimitry Andric   std::string line;
817b91a7dfcSDimitry Andric   while (std::getline(lineStream, line)) {
818b91a7dfcSDimitry Andric     if (line.empty()) {
819b91a7dfcSDimitry Andric       output_strm << "\n";
820b91a7dfcSDimitry Andric       continue;
821b91a7dfcSDimitry Andric     }
822b91a7dfcSDimitry Andric     size_t result = line.find_first_not_of(" \t");
823b91a7dfcSDimitry Andric     if (result == std::string::npos) {
824b91a7dfcSDimitry Andric       result = 0;
825b91a7dfcSDimitry Andric     }
826b91a7dfcSDimitry Andric     std::string whitespace_prefix = line.substr(0, result);
827b91a7dfcSDimitry Andric     std::string remainder = line.substr(result);
828435933ddSDimitry Andric     interpreter.OutputFormattedHelpText(output_strm, whitespace_prefix.c_str(),
829435933ddSDimitry Andric                                         remainder.c_str());
830b91a7dfcSDimitry Andric   }
831b91a7dfcSDimitry Andric }
832b91a7dfcSDimitry Andric 
GenerateHelpText(CommandReturnObject & result)833435933ddSDimitry Andric void CommandObject::GenerateHelpText(CommandReturnObject &result) {
834ac7ddfbfSEd Maste   GenerateHelpText(result.GetOutputStream());
835ac7ddfbfSEd Maste 
836ac7ddfbfSEd Maste   result.SetStatus(eReturnStatusSuccessFinishNoResult);
837ac7ddfbfSEd Maste }
838ac7ddfbfSEd Maste 
GenerateHelpText(Stream & output_strm)839435933ddSDimitry Andric void CommandObject::GenerateHelpText(Stream &output_strm) {
840ac7ddfbfSEd Maste   CommandInterpreter &interpreter = GetCommandInterpreter();
841435933ddSDimitry Andric   if (WantsRawCommandString()) {
842ac7ddfbfSEd Maste     std::string help_text(GetHelp());
8434bb0738eSEd Maste     help_text.append("  Expects 'raw' input (see 'help raw-input'.)");
844435933ddSDimitry Andric     interpreter.OutputFormattedHelpText(output_strm, "", "", help_text.c_str(),
845435933ddSDimitry Andric                                         1);
846435933ddSDimitry Andric   } else
847ac7ddfbfSEd Maste     interpreter.OutputFormattedHelpText(output_strm, "", "", GetHelp(), 1);
848435933ddSDimitry Andric   output_strm << "\nSyntax: " << GetSyntax() << "\n";
8494bb0738eSEd Maste   Options *options = GetOptions();
850435933ddSDimitry Andric   if (options != nullptr) {
851435933ddSDimitry Andric     options->GenerateOptionUsage(
852435933ddSDimitry Andric         output_strm, this,
853435933ddSDimitry Andric         GetCommandInterpreter().GetDebugger().GetTerminalWidth());
8544bb0738eSEd Maste   }
855435933ddSDimitry Andric   llvm::StringRef long_help = GetHelpLong();
856435933ddSDimitry Andric   if (!long_help.empty()) {
857b91a7dfcSDimitry Andric     FormatLongHelpText(output_strm, long_help);
8584bb0738eSEd Maste   }
859435933ddSDimitry Andric   if (!IsDashDashCommand() && options && options->NumCommandOptions() > 0) {
860435933ddSDimitry Andric     if (WantsRawCommandString() && !WantsCompletion()) {
861435933ddSDimitry Andric       // Emit the message about using ' -- ' between the end of the command
8624ba319b5SDimitry Andric       // options and the raw input conditionally, i.e., only if the command
8634ba319b5SDimitry Andric       // object does not want completion.
8644bb0738eSEd Maste       interpreter.OutputFormattedHelpText(
8654bb0738eSEd Maste           output_strm, "", "",
866435933ddSDimitry Andric           "\nImportant Note: Because this command takes 'raw' input, if you "
867435933ddSDimitry Andric           "use any command options"
868435933ddSDimitry Andric           " you must use ' -- ' between the end of the command options and the "
869435933ddSDimitry Andric           "beginning of the raw input.",
8704bb0738eSEd Maste           1);
871435933ddSDimitry Andric     } else if (GetNumArgumentEntries() > 0) {
872435933ddSDimitry Andric       // Also emit a warning about using "--" in case you are using a command
873435933ddSDimitry Andric       // that takes options and arguments.
8744bb0738eSEd Maste       interpreter.OutputFormattedHelpText(
875435933ddSDimitry Andric           output_strm, "", "",
876435933ddSDimitry Andric           "\nThis command takes options and free-form arguments.  If your "
877435933ddSDimitry Andric           "arguments resemble"
878435933ddSDimitry Andric           " option specifiers (i.e., they start with a - or --), you must use "
879435933ddSDimitry Andric           "' -- ' between"
8804bb0738eSEd Maste           " the end of the command options and the beginning of the arguments.",
8814bb0738eSEd Maste           1);
882ac7ddfbfSEd Maste     }
883ac7ddfbfSEd Maste   }
884ac7ddfbfSEd Maste }
885ac7ddfbfSEd Maste 
AddIDsArgumentData(CommandArgumentEntry & arg,CommandArgumentType ID,CommandArgumentType IDRange)886435933ddSDimitry Andric void CommandObject::AddIDsArgumentData(CommandArgumentEntry &arg,
887435933ddSDimitry Andric                                        CommandArgumentType ID,
888435933ddSDimitry Andric                                        CommandArgumentType IDRange) {
889ac7ddfbfSEd Maste   CommandArgumentData id_arg;
890ac7ddfbfSEd Maste   CommandArgumentData id_range_arg;
891ac7ddfbfSEd Maste 
892435933ddSDimitry Andric   // Create the first variant for the first (and only) argument for this
893435933ddSDimitry Andric   // command.
894ac7ddfbfSEd Maste   id_arg.arg_type = ID;
895ac7ddfbfSEd Maste   id_arg.arg_repetition = eArgRepeatOptional;
896ac7ddfbfSEd Maste 
897435933ddSDimitry Andric   // Create the second variant for the first (and only) argument for this
898435933ddSDimitry Andric   // command.
899ac7ddfbfSEd Maste   id_range_arg.arg_type = IDRange;
900ac7ddfbfSEd Maste   id_range_arg.arg_repetition = eArgRepeatOptional;
901ac7ddfbfSEd Maste 
902435933ddSDimitry Andric   // The first (and only) argument for this command could be either an id or an
9034ba319b5SDimitry Andric   // id_range. Push both variants into the entry for the first argument for
9044ba319b5SDimitry Andric   // this command.
905ac7ddfbfSEd Maste   arg.push_back(id_arg);
906ac7ddfbfSEd Maste   arg.push_back(id_range_arg);
907ac7ddfbfSEd Maste }
908ac7ddfbfSEd Maste 
GetArgumentTypeAsCString(const lldb::CommandArgumentType arg_type)909435933ddSDimitry Andric const char *CommandObject::GetArgumentTypeAsCString(
910435933ddSDimitry Andric     const lldb::CommandArgumentType arg_type) {
911435933ddSDimitry Andric   assert(arg_type < eArgTypeLastArg &&
912435933ddSDimitry Andric          "Invalid argument type passed to GetArgumentTypeAsCString");
913ac7ddfbfSEd Maste   return g_arguments_data[arg_type].arg_name;
914ac7ddfbfSEd Maste }
915ac7ddfbfSEd Maste 
GetArgumentDescriptionAsCString(const lldb::CommandArgumentType arg_type)916435933ddSDimitry Andric const char *CommandObject::GetArgumentDescriptionAsCString(
917435933ddSDimitry Andric     const lldb::CommandArgumentType arg_type) {
918435933ddSDimitry Andric   assert(arg_type < eArgTypeLastArg &&
919435933ddSDimitry Andric          "Invalid argument type passed to GetArgumentDescriptionAsCString");
920ac7ddfbfSEd Maste   return g_arguments_data[arg_type].help_text;
921ac7ddfbfSEd Maste }
922ac7ddfbfSEd Maste 
GetDummyTarget()923435933ddSDimitry Andric Target *CommandObject::GetDummyTarget() {
9247aa51b79SEd Maste   return m_interpreter.GetDebugger().GetDummyTarget();
9257aa51b79SEd Maste }
9267aa51b79SEd Maste 
GetSelectedOrDummyTarget(bool prefer_dummy)927435933ddSDimitry Andric Target *CommandObject::GetSelectedOrDummyTarget(bool prefer_dummy) {
9287aa51b79SEd Maste   return m_interpreter.GetDebugger().GetSelectedOrDummyTarget(prefer_dummy);
9297aa51b79SEd Maste }
9307aa51b79SEd Maste 
GetDefaultThread()931435933ddSDimitry Andric Thread *CommandObject::GetDefaultThread() {
9324bb0738eSEd Maste   Thread *thread_to_use = m_exe_ctx.GetThreadPtr();
9334bb0738eSEd Maste   if (thread_to_use)
9344bb0738eSEd Maste     return thread_to_use;
9354bb0738eSEd Maste 
9364bb0738eSEd Maste   Process *process = m_exe_ctx.GetProcessPtr();
937435933ddSDimitry Andric   if (!process) {
9384bb0738eSEd Maste     Target *target = m_exe_ctx.GetTargetPtr();
939435933ddSDimitry Andric     if (!target) {
9404bb0738eSEd Maste       target = m_interpreter.GetDebugger().GetSelectedTarget().get();
9414bb0738eSEd Maste     }
9424bb0738eSEd Maste     if (target)
9434bb0738eSEd Maste       process = target->GetProcessSP().get();
9444bb0738eSEd Maste   }
9454bb0738eSEd Maste 
9464bb0738eSEd Maste   if (process)
9474bb0738eSEd Maste     return process->GetThreadList().GetSelectedThread().get();
9484bb0738eSEd Maste   else
9494bb0738eSEd Maste     return nullptr;
9504bb0738eSEd Maste }
9514bb0738eSEd Maste 
Execute(const char * args_string,CommandReturnObject & result)952435933ddSDimitry Andric bool CommandObjectParsed::Execute(const char *args_string,
953435933ddSDimitry Andric                                   CommandReturnObject &result) {
954ac7ddfbfSEd Maste   bool handled = false;
955ac7ddfbfSEd Maste   Args cmd_args(args_string);
956435933ddSDimitry Andric   if (HasOverrideCallback()) {
957ac7ddfbfSEd Maste     Args full_args(GetCommandName());
958ac7ddfbfSEd Maste     full_args.AppendArguments(cmd_args);
959435933ddSDimitry Andric     handled =
960435933ddSDimitry Andric         InvokeOverrideCallback(full_args.GetConstArgumentVector(), result);
961ac7ddfbfSEd Maste   }
962435933ddSDimitry Andric   if (!handled) {
963435933ddSDimitry Andric     for (auto entry : llvm::enumerate(cmd_args.entries())) {
964f678e45dSDimitry Andric       if (!entry.value().ref.empty() && entry.value().ref.front() == '`') {
965435933ddSDimitry Andric         cmd_args.ReplaceArgumentAtIndex(
966f678e45dSDimitry Andric             entry.index(),
967f678e45dSDimitry Andric             m_interpreter.ProcessEmbeddedScriptCommands(entry.value().c_str()));
968435933ddSDimitry Andric       }
969ac7ddfbfSEd Maste     }
970ac7ddfbfSEd Maste 
971435933ddSDimitry Andric     if (CheckRequirements(result)) {
972435933ddSDimitry Andric       if (ParseOptions(cmd_args, result)) {
973435933ddSDimitry Andric         // Call the command-specific version of 'Execute', passing it the
974435933ddSDimitry Andric         // already processed arguments.
975ac7ddfbfSEd Maste         handled = DoExecute(cmd_args, result);
976ac7ddfbfSEd Maste       }
977ac7ddfbfSEd Maste     }
978ac7ddfbfSEd Maste 
979ac7ddfbfSEd Maste     Cleanup();
980ac7ddfbfSEd Maste   }
981ac7ddfbfSEd Maste   return handled;
982ac7ddfbfSEd Maste }
983ac7ddfbfSEd Maste 
Execute(const char * args_string,CommandReturnObject & result)984435933ddSDimitry Andric bool CommandObjectRaw::Execute(const char *args_string,
985435933ddSDimitry Andric                                CommandReturnObject &result) {
986ac7ddfbfSEd Maste   bool handled = false;
987435933ddSDimitry Andric   if (HasOverrideCallback()) {
988ac7ddfbfSEd Maste     std::string full_command(GetCommandName());
989ac7ddfbfSEd Maste     full_command += ' ';
990ac7ddfbfSEd Maste     full_command += args_string;
9910127ef0fSEd Maste     const char *argv[2] = {nullptr, nullptr};
992ac7ddfbfSEd Maste     argv[0] = full_command.c_str();
9930127ef0fSEd Maste     handled = InvokeOverrideCallback(argv, result);
994ac7ddfbfSEd Maste   }
995435933ddSDimitry Andric   if (!handled) {
996ac7ddfbfSEd Maste     if (CheckRequirements(result))
997ac7ddfbfSEd Maste       handled = DoExecute(args_string, result);
998ac7ddfbfSEd Maste 
999ac7ddfbfSEd Maste     Cleanup();
1000ac7ddfbfSEd Maste   }
1001ac7ddfbfSEd Maste   return handled;
1002ac7ddfbfSEd Maste }
1003ac7ddfbfSEd Maste 
arch_helper()1004435933ddSDimitry Andric static llvm::StringRef arch_helper() {
1005ac7ddfbfSEd Maste   static StreamString g_archs_help;
1006435933ddSDimitry Andric   if (g_archs_help.Empty()) {
1007ac7ddfbfSEd Maste     StringList archs;
10084ba319b5SDimitry Andric 
10094ba319b5SDimitry Andric     ArchSpec::ListSupportedArchNames(archs);
1010ac7ddfbfSEd Maste     g_archs_help.Printf("These are the supported architecture names:\n");
1011ac7ddfbfSEd Maste     archs.Join("\n", g_archs_help);
1012ac7ddfbfSEd Maste   }
1013435933ddSDimitry Andric   return g_archs_help.GetString();
1014ac7ddfbfSEd Maste }
1015ac7ddfbfSEd Maste 
10164bb0738eSEd Maste CommandObject::ArgumentTableEntry CommandObject::g_arguments_data[] = {
10174bb0738eSEd Maste     // clang-format off
10180127ef0fSEd Maste     { eArgTypeAddress, "address", CommandCompletions::eNoCompletion, { nullptr, false }, "A valid address in the target program's execution space." },
10190127ef0fSEd Maste     { eArgTypeAddressOrExpression, "address-expression", CommandCompletions::eNoCompletion, { nullptr, false }, "An expression that resolves to an address." },
10200127ef0fSEd Maste     { eArgTypeAliasName, "alias-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of an abbreviation (alias) for a debugger command." },
10210127ef0fSEd 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.)" },
1022ac7ddfbfSEd Maste     { eArgTypeArchitecture, "arch", CommandCompletions::eArchitectureCompletion, { arch_helper, true }, "The architecture name, e.g. i386 or x86_64." },
10230127ef0fSEd Maste     { eArgTypeBoolean, "boolean", CommandCompletions::eNoCompletion, { nullptr, false }, "A Boolean value: 'true' or 'false'" },
10240127ef0fSEd Maste     { eArgTypeBreakpointID, "breakpt-id", CommandCompletions::eNoCompletion, { BreakpointIDHelpTextCallback, false }, nullptr },
10250127ef0fSEd Maste     { eArgTypeBreakpointIDRange, "breakpt-id-list", CommandCompletions::eNoCompletion, { BreakpointIDRangeHelpTextCallback, false }, nullptr },
10267aa51b79SEd Maste     { eArgTypeBreakpointName, "breakpoint-name", CommandCompletions::eNoCompletion, { BreakpointNameHelpTextCallback, false }, nullptr },
10270127ef0fSEd Maste     { eArgTypeByteSize, "byte-size", CommandCompletions::eNoCompletion, { nullptr, false }, "Number of bytes to use." },
10280127ef0fSEd Maste     { eArgTypeClassName, "class-name", CommandCompletions::eNoCompletion, { nullptr, false }, "Then name of a class from the debug information in the program." },
10290127ef0fSEd Maste     { eArgTypeCommandName, "cmd-name", CommandCompletions::eNoCompletion, { nullptr, false }, "A debugger command (may be multiple words), without any options or arguments." },
10300127ef0fSEd Maste     { eArgTypeCount, "count", CommandCompletions::eNoCompletion, { nullptr, false }, "An unsigned integer." },
10310127ef0fSEd Maste     { eArgTypeDirectoryName, "directory", CommandCompletions::eDiskDirectoryCompletion, { nullptr, false }, "A directory name." },
10320127ef0fSEd 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" },
10330127ef0fSEd Maste     { eArgTypeDescriptionVerbosity, "description-verbosity", CommandCompletions::eNoCompletion, { nullptr, false }, "How verbose the output of 'po' should be." },
10340127ef0fSEd Maste     { eArgTypeEndAddress, "end-address", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
10350127ef0fSEd Maste     { eArgTypeExpression, "expr", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
10360127ef0fSEd Maste     { eArgTypeExpressionPath, "expr-path", CommandCompletions::eNoCompletion, { ExprPathHelpTextCallback, true }, nullptr },
10370127ef0fSEd 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] ]" },
10380127ef0fSEd Maste     { eArgTypeFilename, "filename", CommandCompletions::eDiskFileCompletion, { nullptr, false }, "The name of a file (can include path)." },
10390127ef0fSEd Maste     { eArgTypeFormat, "format", CommandCompletions::eNoCompletion, { FormatHelpTextCallback, true }, nullptr },
10400127ef0fSEd Maste     { eArgTypeFrameIndex, "frame-index", CommandCompletions::eNoCompletion, { nullptr, false }, "Index into a thread's list of frames." },
10410127ef0fSEd Maste     { eArgTypeFullName, "fullname", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
10420127ef0fSEd Maste     { eArgTypeFunctionName, "function-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a function." },
10430127ef0fSEd Maste     { eArgTypeFunctionOrSymbol, "function-or-symbol", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a function or symbol." },
10440127ef0fSEd Maste     { eArgTypeGDBFormat, "gdb-format", CommandCompletions::eNoCompletion, { GDBFormatHelpTextCallback, true }, nullptr },
10457aa51b79SEd Maste     { eArgTypeHelpText, "help-text", CommandCompletions::eNoCompletion, { nullptr, false }, "Text to be used as help for some other entity in LLDB" },
10460127ef0fSEd Maste     { eArgTypeIndex, "index", CommandCompletions::eNoCompletion, { nullptr, false }, "An index into a list." },
10474bb0738eSEd Maste     { eArgTypeLanguage, "source-language", CommandCompletions::eNoCompletion, { LanguageTypeHelpTextCallback, true }, nullptr },
10480127ef0fSEd Maste     { eArgTypeLineNum, "linenum", CommandCompletions::eNoCompletion, { nullptr, false }, "Line number in a source file." },
10490127ef0fSEd 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." },
10500127ef0fSEd 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)." },
10510127ef0fSEd Maste     { eArgTypeMethod, "method", CommandCompletions::eNoCompletion, { nullptr, false }, "A C++ method name." },
10520127ef0fSEd Maste     { eArgTypeName, "name", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
10530127ef0fSEd Maste     { eArgTypeNewPathPrefix, "new-path-prefix", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
10540127ef0fSEd Maste     { eArgTypeNumLines, "num-lines", CommandCompletions::eNoCompletion, { nullptr, false }, "The number of lines to use." },
10550127ef0fSEd Maste     { eArgTypeNumberPerLine, "number-per-line", CommandCompletions::eNoCompletion, { nullptr, false }, "The number of items per line to display." },
10560127ef0fSEd Maste     { eArgTypeOffset, "offset", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
10570127ef0fSEd Maste     { eArgTypeOldPathPrefix, "old-path-prefix", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
10580127ef0fSEd Maste     { eArgTypeOneLiner, "one-line-command", CommandCompletions::eNoCompletion, { nullptr, false }, "A command that is entered as a single line of text." },
10590127ef0fSEd Maste     { eArgTypePath, "path", CommandCompletions::eDiskFileCompletion, { nullptr, false }, "Path." },
10600127ef0fSEd Maste     { eArgTypePermissionsNumber, "perms-numeric", CommandCompletions::eNoCompletion, { nullptr, false }, "Permissions given as an octal number (e.g. 755)." },
10610127ef0fSEd Maste     { eArgTypePermissionsString, "perms=string", CommandCompletions::eNoCompletion, { nullptr, false }, "Permissions given as a string value (e.g. rw-r-xr--)." },
10620127ef0fSEd Maste     { eArgTypePid, "pid", CommandCompletions::eNoCompletion, { nullptr, false }, "The process ID number." },
10630127ef0fSEd Maste     { eArgTypePlugin, "plugin", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
10640127ef0fSEd Maste     { eArgTypeProcessName, "process-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of the process." },
10650127ef0fSEd Maste     { eArgTypePythonClass, "python-class", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a Python class." },
10660127ef0fSEd Maste     { eArgTypePythonFunction, "python-function", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a Python function." },
10670127ef0fSEd Maste     { eArgTypePythonScript, "python-script", CommandCompletions::eNoCompletion, { nullptr, false }, "Source code written in Python." },
10680127ef0fSEd Maste     { eArgTypeQueueName, "queue-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of the thread queue." },
10690127ef0fSEd Maste     { eArgTypeRegisterName, "register-name", CommandCompletions::eNoCompletion, { RegisterNameHelpTextCallback, true }, nullptr },
10700127ef0fSEd Maste     { eArgTypeRegularExpression, "regular-expression", CommandCompletions::eNoCompletion, { nullptr, false }, "A regular expression." },
10710127ef0fSEd Maste     { eArgTypeRunArgs, "run-args", CommandCompletions::eNoCompletion, { nullptr, false }, "Arguments to be passed to the target program when it starts executing." },
10720127ef0fSEd Maste     { eArgTypeRunMode, "run-mode", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
10730127ef0fSEd Maste     { eArgTypeScriptedCommandSynchronicity, "script-cmd-synchronicity", CommandCompletions::eNoCompletion, { nullptr, false }, "The synchronicity to use to run scripted commands with regard to LLDB event system." },
10740127ef0fSEd Maste     { eArgTypeScriptLang, "script-language", CommandCompletions::eNoCompletion, { nullptr, false }, "The scripting language to be used for script-based commands.  Currently only Python is valid." },
10754bb0738eSEd Maste     { eArgTypeSearchWord, "search-word", CommandCompletions::eNoCompletion, { nullptr, false }, "Any word of interest for search purposes." },
10760127ef0fSEd Maste     { eArgTypeSelector, "selector", CommandCompletions::eNoCompletion, { nullptr, false }, "An Objective-C selector name." },
10770127ef0fSEd 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)." },
10780127ef0fSEd 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)." },
10790127ef0fSEd Maste     { eArgTypeSettingPrefix, "setting-prefix", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a settable internal debugger variable up to a dot ('.'), e.g. 'target.process.'" },
10800127ef0fSEd 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." },
10810127ef0fSEd Maste     { eArgTypeShlibName, "shlib-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a shared library." },
10820127ef0fSEd Maste     { eArgTypeSourceFile, "source-file", CommandCompletions::eSourceFileCompletion, { nullptr, false }, "The name of a source file.." },
10830127ef0fSEd Maste     { eArgTypeSortOrder, "sort-order", CommandCompletions::eNoCompletion, { nullptr, false }, "Specify a sort order when dumping lists." },
10840127ef0fSEd Maste     { eArgTypeStartAddress, "start-address", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
10850127ef0fSEd Maste     { eArgTypeSummaryString, "summary-string", CommandCompletions::eNoCompletion, { SummaryStringHelpTextCallback, true }, nullptr },
10860127ef0fSEd Maste     { eArgTypeSymbol, "symbol", CommandCompletions::eSymbolCompletion, { nullptr, false }, "Any symbol name (function name, variable, argument, etc.)" },
10870127ef0fSEd Maste     { eArgTypeThreadID, "thread-id", CommandCompletions::eNoCompletion, { nullptr, false }, "Thread ID number." },
10880127ef0fSEd Maste     { eArgTypeThreadIndex, "thread-index", CommandCompletions::eNoCompletion, { nullptr, false }, "Index into the process' list of threads." },
10890127ef0fSEd Maste     { eArgTypeThreadName, "thread-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The thread's name." },
10901c3bbb01SEd Maste     { eArgTypeTypeName, "type-name", CommandCompletions::eNoCompletion, { nullptr, false }, "A type name." },
10910127ef0fSEd Maste     { eArgTypeUnsignedInteger, "unsigned-integer", CommandCompletions::eNoCompletion, { nullptr, false }, "An unsigned integer." },
10920127ef0fSEd Maste     { eArgTypeUnixSignal, "unix-signal", CommandCompletions::eNoCompletion, { nullptr, false }, "A valid Unix signal name or number (e.g. SIGKILL, KILL or 9)." },
10930127ef0fSEd Maste     { eArgTypeVarName, "variable-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a variable in your program." },
10940127ef0fSEd Maste     { eArgTypeValue, "value", CommandCompletions::eNoCompletion, { nullptr, false }, "A value could be anything, depending on where and how it is used." },
10950127ef0fSEd Maste     { eArgTypeWidth, "width", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
10960127ef0fSEd Maste     { eArgTypeNone, "none", CommandCompletions::eNoCompletion, { nullptr, false }, "No help available for this." },
10970127ef0fSEd 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." },
10980127ef0fSEd Maste     { eArgTypeWatchpointID, "watchpt-id", CommandCompletions::eNoCompletion, { nullptr, false }, "Watchpoint IDs are positive integers." },
10990127ef0fSEd Maste     { eArgTypeWatchpointIDRange, "watchpt-id-list", CommandCompletions::eNoCompletion, { nullptr, false }, "For example, '1-3' or '1 to 3'." },
11004bb0738eSEd Maste     { eArgTypeWatchType, "watch-type", CommandCompletions::eNoCompletion, { nullptr, false }, "Specify the type for a watchpoint." },
1101acac075bSDimitry 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." },
1102acac075bSDimitry Andric     { eArgTypeCommand, "command", CommandCompletions::eNoCompletion, { nullptr, false }, "An LLDB Command line command." }
11034bb0738eSEd Maste     // clang-format on
1104ac7ddfbfSEd Maste };
1105ac7ddfbfSEd Maste 
GetArgumentTable()1106435933ddSDimitry Andric const CommandObject::ArgumentTableEntry *CommandObject::GetArgumentTable() {
1107435933ddSDimitry Andric   // If this assertion fires, then the table above is out of date with the
1108435933ddSDimitry Andric   // CommandArgumentType enumeration
1109435933ddSDimitry Andric   assert((sizeof(CommandObject::g_arguments_data) /
1110435933ddSDimitry Andric           sizeof(CommandObject::ArgumentTableEntry)) == eArgTypeLastArg);
1111ac7ddfbfSEd Maste   return CommandObject::g_arguments_data;
1112ac7ddfbfSEd Maste }
1113