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