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"
2040af72e1SJim Ingham #include "lldb/Interpreter/Options.h"
215f19b907SPavel Labath #include "lldb/Utility/ArchSpec.h"
2230fdc8d8SChris Lattner 
2330fdc8d8SChris Lattner // These are for the Sourcename completers.
2430fdc8d8SChris Lattner // FIXME: Make a separate file for the completers.
2530fdc8d8SChris Lattner #include "lldb/Core/FileSpecList.h"
26a78bd7ffSZachary Turner #include "lldb/DataFormatters/FormatManager.h"
2730fdc8d8SChris Lattner #include "lldb/Target/Process.h"
2830fdc8d8SChris Lattner #include "lldb/Target/Target.h"
295713a05bSZachary Turner #include "lldb/Utility/FileSpec.h"
3030fdc8d8SChris Lattner 
310e0984eeSJim Ingham #include "lldb/Target/Language.h"
320e0984eeSJim Ingham 
3330fdc8d8SChris Lattner #include "lldb/Interpreter/CommandInterpreter.h"
3430fdc8d8SChris Lattner #include "lldb/Interpreter/CommandReturnObject.h"
3530fdc8d8SChris Lattner 
3630fdc8d8SChris Lattner using namespace lldb;
3730fdc8d8SChris Lattner using namespace lldb_private;
3830fdc8d8SChris Lattner 
3930fdc8d8SChris Lattner //-------------------------------------------------------------------------
4030fdc8d8SChris Lattner // CommandObject
4130fdc8d8SChris Lattner //-------------------------------------------------------------------------
4230fdc8d8SChris Lattner 
43a449698cSZachary Turner CommandObject::CommandObject(CommandInterpreter &interpreter, llvm::StringRef name,
44a449698cSZachary Turner   llvm::StringRef help, llvm::StringRef syntax, uint32_t flags)
45a449698cSZachary Turner     : m_interpreter(interpreter), m_cmd_name(name),
46b9c1b51eSKate Stone       m_cmd_help_short(), m_cmd_help_long(), m_cmd_syntax(), m_flags(flags),
47b9c1b51eSKate Stone       m_arguments(), m_deprecated_command_override_callback(nullptr),
48b9c1b51eSKate Stone       m_command_override_callback(nullptr), m_command_override_baton(nullptr) {
4930fdc8d8SChris Lattner   m_cmd_help_short = help;
5030fdc8d8SChris Lattner   m_cmd_syntax = syntax;
5130fdc8d8SChris Lattner }
5230fdc8d8SChris Lattner 
53b9c1b51eSKate Stone CommandObject::~CommandObject() {}
5430fdc8d8SChris Lattner 
55442f6530SZachary Turner llvm::StringRef CommandObject::GetHelp() { return m_cmd_help_short; }
5630fdc8d8SChris Lattner 
57442f6530SZachary Turner llvm::StringRef CommandObject::GetHelpLong() { return m_cmd_help_long; }
5830fdc8d8SChris Lattner 
59442f6530SZachary Turner llvm::StringRef CommandObject::GetSyntax() {
607cff7d46SEugene Zemtsov   if (!m_cmd_syntax.empty())
61442f6530SZachary Turner     return m_cmd_syntax;
62442f6530SZachary Turner 
63e139cf23SCaroline Tice   StreamString syntax_str;
64442f6530SZachary Turner   syntax_str.PutCString(GetCommandName());
65442f6530SZachary Turner 
66bef55ac8SEnrico Granata   if (!IsDashDashCommand() && GetOptions() != nullptr)
67442f6530SZachary Turner     syntax_str.PutCString(" <cmd-options>");
68442f6530SZachary Turner 
69442f6530SZachary Turner   if (!m_arguments.empty()) {
70442f6530SZachary Turner     syntax_str.PutCString(" ");
71442f6530SZachary Turner 
72b9c1b51eSKate Stone     if (!IsDashDashCommand() && WantsRawCommandString() && GetOptions() &&
73b9c1b51eSKate Stone         GetOptions()->NumCommandOptions())
74442f6530SZachary Turner       syntax_str.PutCString("-- ");
75e139cf23SCaroline Tice     GetFormattedCommandArguments(syntax_str);
76e139cf23SCaroline Tice   }
77c156427dSZachary Turner   m_cmd_syntax = syntax_str.GetString();
78e139cf23SCaroline Tice 
79442f6530SZachary Turner   return m_cmd_syntax;
8030fdc8d8SChris Lattner }
8130fdc8d8SChris Lattner 
82a449698cSZachary Turner llvm::StringRef CommandObject::GetCommandName() const { return m_cmd_name; }
8330fdc8d8SChris Lattner 
84442f6530SZachary Turner void CommandObject::SetCommandName(llvm::StringRef name) { m_cmd_name = name; }
8530fdc8d8SChris Lattner 
86442f6530SZachary Turner void CommandObject::SetHelp(llvm::StringRef str) { m_cmd_help_short = str; }
876f79bb2dSEnrico Granata 
88442f6530SZachary Turner void CommandObject::SetHelpLong(llvm::StringRef str) { m_cmd_help_long = str; }
8999f0b8f9SEnrico Granata 
90442f6530SZachary Turner void CommandObject::SetSyntax(llvm::StringRef str) { m_cmd_syntax = str; }
9130fdc8d8SChris Lattner 
92b9c1b51eSKate Stone Options *CommandObject::GetOptions() {
9330fdc8d8SChris Lattner   // By default commands don't have options unless this virtual function
9430fdc8d8SChris Lattner   // is overridden by base classes.
95d78c9576SEd Maste   return nullptr;
9630fdc8d8SChris Lattner }
9730fdc8d8SChris Lattner 
98b9c1b51eSKate Stone bool CommandObject::ParseOptions(Args &args, CommandReturnObject &result) {
9930fdc8d8SChris Lattner   // See if the subclass has options?
10030fdc8d8SChris Lattner   Options *options = GetOptions();
101b9c1b51eSKate Stone   if (options != nullptr) {
10297206d57SZachary Turner     Status error;
103e1cfbc79STodd Fiala 
104e1cfbc79STodd Fiala     auto exe_ctx = GetCommandInterpreter().GetExecutionContext();
105e1cfbc79STodd Fiala     options->NotifyOptionParsingStarting(&exe_ctx);
10630fdc8d8SChris Lattner 
107e1cfbc79STodd Fiala     const bool require_validation = true;
108*5f56fca4SPavel Labath     llvm::Expected<Args> args_or = options->Parse(
109*5f56fca4SPavel Labath         args, &exe_ctx, GetCommandInterpreter().GetPlatform(true),
110e1cfbc79STodd Fiala         require_validation);
11130fdc8d8SChris Lattner 
112*5f56fca4SPavel Labath     if (args_or) {
113*5f56fca4SPavel Labath       args = std::move(*args_or);
114e1cfbc79STodd Fiala       error = options->NotifyOptionParsingFinished(&exe_ctx);
115*5f56fca4SPavel Labath     } else
116*5f56fca4SPavel Labath       error = args_or.takeError();
117f6b8b581SGreg Clayton 
118b9c1b51eSKate Stone     if (error.Success()) {
119f6b8b581SGreg Clayton       if (options->VerifyOptions(result))
120f6b8b581SGreg Clayton         return true;
121b9c1b51eSKate Stone     } else {
12230fdc8d8SChris Lattner       const char *error_cstr = error.AsCString();
123b9c1b51eSKate Stone       if (error_cstr) {
12430fdc8d8SChris Lattner         // We got an error string, lets use that
12586edbf41SGreg Clayton         result.AppendError(error_cstr);
126b9c1b51eSKate Stone       } else {
12730fdc8d8SChris Lattner         // No error string, output the usage information into result
128b9c1b51eSKate Stone         options->GenerateOptionUsage(
129b9c1b51eSKate Stone             result.GetErrorStream(), this,
130b9c1b51eSKate Stone             GetCommandInterpreter().GetDebugger().GetTerminalWidth());
13130fdc8d8SChris Lattner       }
132f6b8b581SGreg Clayton     }
13330fdc8d8SChris Lattner     result.SetStatus(eReturnStatusFailed);
13430fdc8d8SChris Lattner     return false;
13530fdc8d8SChris Lattner   }
13630fdc8d8SChris Lattner   return true;
13730fdc8d8SChris Lattner }
13830fdc8d8SChris Lattner 
139b9c1b51eSKate Stone bool CommandObject::CheckRequirements(CommandReturnObject &result) {
140f9fc609fSGreg Clayton #ifdef LLDB_CONFIGURATION_DEBUG
141f9fc609fSGreg Clayton   // Nothing should be stored in m_exe_ctx between running commands as m_exe_ctx
142f9fc609fSGreg Clayton   // has shared pointers to the target, process, thread and frame and we don't
143f9fc609fSGreg Clayton   // want any CommandObject instances to keep any of these objects around
144f9fc609fSGreg Clayton   // longer than for a single command. Every command should call
145f9fc609fSGreg Clayton   // CommandObject::Cleanup() after it has completed
146f9fc609fSGreg Clayton   assert(m_exe_ctx.GetTargetPtr() == NULL);
147f9fc609fSGreg Clayton   assert(m_exe_ctx.GetProcessPtr() == NULL);
148f9fc609fSGreg Clayton   assert(m_exe_ctx.GetThreadPtr() == NULL);
149f9fc609fSGreg Clayton   assert(m_exe_ctx.GetFramePtr() == NULL);
150f9fc609fSGreg Clayton #endif
151f9fc609fSGreg Clayton 
152f9fc609fSGreg Clayton   // Lock down the interpreter's execution context prior to running the
153f9fc609fSGreg Clayton   // command so we guarantee the selected target, process, thread and frame
154f9fc609fSGreg Clayton   // can't go away during the execution
155f9fc609fSGreg Clayton   m_exe_ctx = m_interpreter.GetExecutionContext();
156f9fc609fSGreg Clayton 
157f9fc609fSGreg Clayton   const uint32_t flags = GetFlags().Get();
158b9c1b51eSKate Stone   if (flags & (eCommandRequiresTarget | eCommandRequiresProcess |
159b9c1b51eSKate Stone                eCommandRequiresThread | eCommandRequiresFrame |
160b9c1b51eSKate Stone                eCommandTryTargetAPILock)) {
161f9fc609fSGreg Clayton 
162b9c1b51eSKate Stone     if ((flags & eCommandRequiresTarget) && !m_exe_ctx.HasTargetScope()) {
163f9fc609fSGreg Clayton       result.AppendError(GetInvalidTargetDescription());
164f9fc609fSGreg Clayton       return false;
165f9fc609fSGreg Clayton     }
166f9fc609fSGreg Clayton 
167b9c1b51eSKate Stone     if ((flags & eCommandRequiresProcess) && !m_exe_ctx.HasProcessScope()) {
168e59b0d2cSJason Molenda       if (!m_exe_ctx.HasTargetScope())
169e59b0d2cSJason Molenda         result.AppendError(GetInvalidTargetDescription());
170e59b0d2cSJason Molenda       else
171f9fc609fSGreg Clayton         result.AppendError(GetInvalidProcessDescription());
172f9fc609fSGreg Clayton       return false;
173f9fc609fSGreg Clayton     }
174f9fc609fSGreg Clayton 
175b9c1b51eSKate Stone     if ((flags & eCommandRequiresThread) && !m_exe_ctx.HasThreadScope()) {
176e59b0d2cSJason Molenda       if (!m_exe_ctx.HasTargetScope())
177e59b0d2cSJason Molenda         result.AppendError(GetInvalidTargetDescription());
178e59b0d2cSJason Molenda       else if (!m_exe_ctx.HasProcessScope())
179e59b0d2cSJason Molenda         result.AppendError(GetInvalidProcessDescription());
180e59b0d2cSJason Molenda       else
181f9fc609fSGreg Clayton         result.AppendError(GetInvalidThreadDescription());
182f9fc609fSGreg Clayton       return false;
183f9fc609fSGreg Clayton     }
184f9fc609fSGreg Clayton 
185b9c1b51eSKate Stone     if ((flags & eCommandRequiresFrame) && !m_exe_ctx.HasFrameScope()) {
186e59b0d2cSJason Molenda       if (!m_exe_ctx.HasTargetScope())
187e59b0d2cSJason Molenda         result.AppendError(GetInvalidTargetDescription());
188e59b0d2cSJason Molenda       else if (!m_exe_ctx.HasProcessScope())
189e59b0d2cSJason Molenda         result.AppendError(GetInvalidProcessDescription());
190e59b0d2cSJason Molenda       else if (!m_exe_ctx.HasThreadScope())
191e59b0d2cSJason Molenda         result.AppendError(GetInvalidThreadDescription());
192e59b0d2cSJason Molenda       else
193f9fc609fSGreg Clayton         result.AppendError(GetInvalidFrameDescription());
194f9fc609fSGreg Clayton       return false;
195f9fc609fSGreg Clayton     }
196f9fc609fSGreg Clayton 
197b9c1b51eSKate Stone     if ((flags & eCommandRequiresRegContext) &&
198b9c1b51eSKate Stone         (m_exe_ctx.GetRegisterContext() == nullptr)) {
199f9fc609fSGreg Clayton       result.AppendError(GetInvalidRegContextDescription());
200f9fc609fSGreg Clayton       return false;
201f9fc609fSGreg Clayton     }
202f9fc609fSGreg Clayton 
203b9c1b51eSKate Stone     if (flags & eCommandTryTargetAPILock) {
204f9fc609fSGreg Clayton       Target *target = m_exe_ctx.GetTargetPtr();
205f9fc609fSGreg Clayton       if (target)
206b9c1b51eSKate Stone         m_api_locker =
207b9c1b51eSKate Stone             std::unique_lock<std::recursive_mutex>(target->GetAPIMutex());
208f9fc609fSGreg Clayton     }
209f9fc609fSGreg Clayton   }
210f9fc609fSGreg Clayton 
211b9c1b51eSKate Stone   if (GetFlags().AnySet(eCommandProcessMustBeLaunched |
212b9c1b51eSKate Stone                         eCommandProcessMustBePaused)) {
213c14ee32dSGreg Clayton     Process *process = m_interpreter.GetExecutionContext().GetProcessPtr();
214b9c1b51eSKate Stone     if (process == nullptr) {
215b8e8a5f3SJim Ingham       // A process that is not running is considered paused.
216b9c1b51eSKate Stone       if (GetFlags().Test(eCommandProcessMustBeLaunched)) {
21730fdc8d8SChris Lattner         result.AppendError("Process must exist.");
21830fdc8d8SChris Lattner         result.SetStatus(eReturnStatusFailed);
21930fdc8d8SChris Lattner         return false;
22030fdc8d8SChris Lattner       }
221b9c1b51eSKate Stone     } else {
22230fdc8d8SChris Lattner       StateType state = process->GetState();
223b9c1b51eSKate Stone       switch (state) {
2247a5388bfSGreg Clayton       case eStateInvalid:
22530fdc8d8SChris Lattner       case eStateSuspended:
22630fdc8d8SChris Lattner       case eStateCrashed:
22730fdc8d8SChris Lattner       case eStateStopped:
22830fdc8d8SChris Lattner         break;
22930fdc8d8SChris Lattner 
230b766a73dSGreg Clayton       case eStateConnected:
231b766a73dSGreg Clayton       case eStateAttaching:
232b766a73dSGreg Clayton       case eStateLaunching:
23330fdc8d8SChris Lattner       case eStateDetached:
23430fdc8d8SChris Lattner       case eStateExited:
23530fdc8d8SChris Lattner       case eStateUnloaded:
236b9c1b51eSKate Stone         if (GetFlags().Test(eCommandProcessMustBeLaunched)) {
23730fdc8d8SChris Lattner           result.AppendError("Process must be launched.");
23830fdc8d8SChris Lattner           result.SetStatus(eReturnStatusFailed);
23930fdc8d8SChris Lattner           return false;
24030fdc8d8SChris Lattner         }
24130fdc8d8SChris Lattner         break;
24230fdc8d8SChris Lattner 
24330fdc8d8SChris Lattner       case eStateRunning:
24430fdc8d8SChris Lattner       case eStateStepping:
245b9c1b51eSKate Stone         if (GetFlags().Test(eCommandProcessMustBePaused)) {
246b9c1b51eSKate Stone           result.AppendError("Process is running.  Use 'process interrupt' to "
247b9c1b51eSKate Stone                              "pause execution.");
24830fdc8d8SChris Lattner           result.SetStatus(eReturnStatusFailed);
24930fdc8d8SChris Lattner           return false;
25030fdc8d8SChris Lattner         }
25130fdc8d8SChris Lattner       }
25230fdc8d8SChris Lattner     }
253b766a73dSGreg Clayton   }
2545a988416SJim Ingham   return true;
25530fdc8d8SChris Lattner }
25630fdc8d8SChris Lattner 
257b9c1b51eSKate Stone void CommandObject::Cleanup() {
258f9fc609fSGreg Clayton   m_exe_ctx.Clear();
259bb19a13cSSaleem Abdulrasool   if (m_api_locker.owns_lock())
260bb19a13cSSaleem Abdulrasool     m_api_locker.unlock();
261f9fc609fSGreg Clayton }
262f9fc609fSGreg Clayton 
263b9c1b51eSKate Stone int CommandObject::HandleCompletion(Args &input, int &cursor_index,
26430fdc8d8SChris Lattner                                     int &cursor_char_position,
26530fdc8d8SChris Lattner                                     int match_start_point,
26630fdc8d8SChris Lattner                                     int max_return_elements,
267b9c1b51eSKate Stone                                     bool &word_complete, StringList &matches) {
268e171da5cSBruce Mitchener   // Default implementation of WantsCompletion() is !WantsRawCommandString().
2696561d15dSJohnny Chen   // Subclasses who want raw command string but desire, for example,
2706561d15dSJohnny Chen   // argument completion should override WantsCompletion() to return true,
2716561d15dSJohnny Chen   // instead.
272b9c1b51eSKate Stone   if (WantsRawCommandString() && !WantsCompletion()) {
273b9c1b51eSKate Stone     // FIXME: Abstract telling the completion to insert the completion
274b9c1b51eSKate Stone     // character.
27530fdc8d8SChris Lattner     matches.Clear();
27630fdc8d8SChris Lattner     return -1;
277b9c1b51eSKate Stone   } else {
27830fdc8d8SChris Lattner     // Can we do anything generic with the options?
27930fdc8d8SChris Lattner     Options *cur_options = GetOptions();
28030fdc8d8SChris Lattner     CommandReturnObject result;
28130fdc8d8SChris Lattner     OptionElementVector opt_element_vector;
28230fdc8d8SChris Lattner 
283b9c1b51eSKate Stone     if (cur_options != nullptr) {
284*5f56fca4SPavel Labath       opt_element_vector = cur_options->ParseForCompletion(input, cursor_index);
28530fdc8d8SChris Lattner 
28630fdc8d8SChris Lattner       bool handled_by_options;
287b9c1b51eSKate Stone       handled_by_options = cur_options->HandleOptionCompletion(
288b9c1b51eSKate Stone           input, opt_element_vector, cursor_index, cursor_char_position,
289b9c1b51eSKate Stone           match_start_point, max_return_elements, GetCommandInterpreter(),
290b9c1b51eSKate Stone           word_complete, matches);
29130fdc8d8SChris Lattner       if (handled_by_options)
29230fdc8d8SChris Lattner         return matches.GetSize();
29330fdc8d8SChris Lattner     }
29430fdc8d8SChris Lattner 
29530fdc8d8SChris Lattner     // If we got here, the last word is not an option or an option argument.
296b9c1b51eSKate Stone     return HandleArgumentCompletion(
297b9c1b51eSKate Stone         input, cursor_index, cursor_char_position, opt_element_vector,
298b9c1b51eSKate Stone         match_start_point, max_return_elements, word_complete, matches);
29930fdc8d8SChris Lattner   }
30030fdc8d8SChris Lattner }
30130fdc8d8SChris Lattner 
30298896839SZachary Turner bool CommandObject::HelpTextContainsWord(llvm::StringRef search_word,
303d033e1ceSEnrico Granata                                          bool search_short_help,
304d033e1ceSEnrico Granata                                          bool search_long_help,
305d033e1ceSEnrico Granata                                          bool search_syntax,
306b9c1b51eSKate Stone                                          bool search_options) {
30730fdc8d8SChris Lattner   std::string options_usage_help;
30830fdc8d8SChris Lattner 
30930fdc8d8SChris Lattner   bool found_word = false;
31030fdc8d8SChris Lattner 
311442f6530SZachary Turner   llvm::StringRef short_help = GetHelp();
312442f6530SZachary Turner   llvm::StringRef long_help = GetHelpLong();
313442f6530SZachary Turner   llvm::StringRef syntax_help = GetSyntax();
31430fdc8d8SChris Lattner 
315442f6530SZachary Turner   if (search_short_help && short_help.contains_lower(search_word))
31630fdc8d8SChris Lattner     found_word = true;
317442f6530SZachary Turner   else if (search_long_help && long_help.contains_lower(search_word))
31830fdc8d8SChris Lattner     found_word = true;
319442f6530SZachary Turner   else if (search_syntax && syntax_help.contains_lower(search_word))
32030fdc8d8SChris Lattner     found_word = true;
32130fdc8d8SChris Lattner 
322b9c1b51eSKate Stone   if (!found_word && search_options && GetOptions() != nullptr) {
32330fdc8d8SChris Lattner     StreamString usage_help;
324b9c1b51eSKate Stone     GetOptions()->GenerateOptionUsage(
325b9c1b51eSKate Stone         usage_help, this,
326b9c1b51eSKate Stone         GetCommandInterpreter().GetDebugger().GetTerminalWidth());
32798896839SZachary Turner     if (!usage_help.Empty()) {
32898896839SZachary Turner       llvm::StringRef usage_text = usage_help.GetString();
32998896839SZachary Turner       if (usage_text.contains_lower(search_word))
33030fdc8d8SChris Lattner         found_word = true;
33130fdc8d8SChris Lattner     }
33230fdc8d8SChris Lattner   }
33330fdc8d8SChris Lattner 
33430fdc8d8SChris Lattner   return found_word;
33530fdc8d8SChris Lattner }
336e139cf23SCaroline Tice 
337b9c1b51eSKate Stone int CommandObject::GetNumArgumentEntries() { return m_arguments.size(); }
338e139cf23SCaroline Tice 
339e139cf23SCaroline Tice CommandObject::CommandArgumentEntry *
340b9c1b51eSKate Stone CommandObject::GetArgumentEntryAtIndex(int idx) {
3413985c8c6SSaleem Abdulrasool   if (static_cast<size_t>(idx) < m_arguments.size())
342e139cf23SCaroline Tice     return &(m_arguments[idx]);
343e139cf23SCaroline Tice 
344d78c9576SEd Maste   return nullptr;
345e139cf23SCaroline Tice }
346e139cf23SCaroline Tice 
347d7e6a4f2SVince Harron const CommandObject::ArgumentTableEntry *
348b9c1b51eSKate Stone CommandObject::FindArgumentDataByType(CommandArgumentType arg_type) {
349e139cf23SCaroline Tice   const ArgumentTableEntry *table = CommandObject::GetArgumentTable();
350e139cf23SCaroline Tice 
351e139cf23SCaroline Tice   for (int i = 0; i < eArgTypeLastArg; ++i)
352e139cf23SCaroline Tice     if (table[i].arg_type == arg_type)
353d7e6a4f2SVince Harron       return &(table[i]);
354e139cf23SCaroline Tice 
355d78c9576SEd Maste   return nullptr;
356e139cf23SCaroline Tice }
357e139cf23SCaroline Tice 
358b9c1b51eSKate Stone void CommandObject::GetArgumentHelp(Stream &str, CommandArgumentType arg_type,
359b9c1b51eSKate Stone                                     CommandInterpreter &interpreter) {
360e139cf23SCaroline Tice   const ArgumentTableEntry *table = CommandObject::GetArgumentTable();
361d7e6a4f2SVince Harron   const ArgumentTableEntry *entry = &(table[arg_type]);
362e139cf23SCaroline Tice 
363b9c1b51eSKate Stone   // The table is *supposed* to be kept in arg_type order, but someone *could*
364b9c1b51eSKate Stone   // have messed it up...
365e139cf23SCaroline Tice 
366e139cf23SCaroline Tice   if (entry->arg_type != arg_type)
367e139cf23SCaroline Tice     entry = CommandObject::FindArgumentDataByType(arg_type);
368e139cf23SCaroline Tice 
369e139cf23SCaroline Tice   if (!entry)
370e139cf23SCaroline Tice     return;
371e139cf23SCaroline Tice 
372e139cf23SCaroline Tice   StreamString name_str;
373e139cf23SCaroline Tice   name_str.Printf("<%s>", entry->arg_name);
374e139cf23SCaroline Tice 
375b9c1b51eSKate Stone   if (entry->help_function) {
376e0038717SZachary Turner     llvm::StringRef help_text = entry->help_function();
377b9c1b51eSKate Stone     if (!entry->help_function.self_formatting) {
378c156427dSZachary Turner       interpreter.OutputFormattedHelpText(str, name_str.GetString(), "--",
379b9c1b51eSKate Stone                                           help_text, name_str.GetSize());
380b9c1b51eSKate Stone     } else {
381c156427dSZachary Turner       interpreter.OutputHelpText(str, name_str.GetString(), "--", help_text,
38282a7d983SEnrico Granata                                  name_str.GetSize());
38382a7d983SEnrico Granata     }
384b9c1b51eSKate Stone   } else
385c156427dSZachary Turner     interpreter.OutputFormattedHelpText(str, name_str.GetString(), "--",
386b9c1b51eSKate Stone                                         entry->help_text, name_str.GetSize());
387e139cf23SCaroline Tice }
388e139cf23SCaroline Tice 
389b9c1b51eSKate Stone const char *CommandObject::GetArgumentName(CommandArgumentType arg_type) {
390b9c1b51eSKate Stone   const ArgumentTableEntry *entry =
391b9c1b51eSKate Stone       &(CommandObject::GetArgumentTable()[arg_type]);
392deaab222SCaroline Tice 
393b9c1b51eSKate Stone   // The table is *supposed* to be kept in arg_type order, but someone *could*
394b9c1b51eSKate Stone   // have messed it up...
395deaab222SCaroline Tice 
396deaab222SCaroline Tice   if (entry->arg_type != arg_type)
397deaab222SCaroline Tice     entry = CommandObject::FindArgumentDataByType(arg_type);
398deaab222SCaroline Tice 
399e6acf355SJohnny Chen   if (entry)
400deaab222SCaroline Tice     return entry->arg_name;
401e6acf355SJohnny Chen 
402c156427dSZachary Turner   return nullptr;
403e139cf23SCaroline Tice }
404e139cf23SCaroline Tice 
405b9c1b51eSKate Stone bool CommandObject::IsPairType(ArgumentRepetitionType arg_repeat_type) {
406b9c1b51eSKate Stone   if ((arg_repeat_type == eArgRepeatPairPlain) ||
407b9c1b51eSKate Stone       (arg_repeat_type == eArgRepeatPairOptional) ||
408b9c1b51eSKate Stone       (arg_repeat_type == eArgRepeatPairPlus) ||
409b9c1b51eSKate Stone       (arg_repeat_type == eArgRepeatPairStar) ||
410b9c1b51eSKate Stone       (arg_repeat_type == eArgRepeatPairRange) ||
411b9c1b51eSKate Stone       (arg_repeat_type == eArgRepeatPairRangeOptional))
412405fe67fSCaroline Tice     return true;
413405fe67fSCaroline Tice 
414405fe67fSCaroline Tice   return false;
415405fe67fSCaroline Tice }
416405fe67fSCaroline Tice 
41734ddc8dbSJohnny Chen static CommandObject::CommandArgumentEntry
418b9c1b51eSKate Stone OptSetFiltered(uint32_t opt_set_mask,
419b9c1b51eSKate Stone                CommandObject::CommandArgumentEntry &cmd_arg_entry) {
42034ddc8dbSJohnny Chen   CommandObject::CommandArgumentEntry ret_val;
42134ddc8dbSJohnny Chen   for (unsigned i = 0; i < cmd_arg_entry.size(); ++i)
42234ddc8dbSJohnny Chen     if (opt_set_mask & cmd_arg_entry[i].arg_opt_set_association)
42334ddc8dbSJohnny Chen       ret_val.push_back(cmd_arg_entry[i]);
42434ddc8dbSJohnny Chen   return ret_val;
42534ddc8dbSJohnny Chen }
42634ddc8dbSJohnny Chen 
42734ddc8dbSJohnny Chen // Default parameter value of opt_set_mask is LLDB_OPT_SET_ALL, which means take
42834ddc8dbSJohnny Chen // all the argument data into account.  On rare cases where some argument sticks
42934ddc8dbSJohnny Chen // with certain option sets, this function returns the option set filtered args.
430b9c1b51eSKate Stone void CommandObject::GetFormattedCommandArguments(Stream &str,
431b9c1b51eSKate Stone                                                  uint32_t opt_set_mask) {
432e139cf23SCaroline Tice   int num_args = m_arguments.size();
433b9c1b51eSKate Stone   for (int i = 0; i < num_args; ++i) {
434e139cf23SCaroline Tice     if (i > 0)
435e139cf23SCaroline Tice       str.Printf(" ");
43634ddc8dbSJohnny Chen     CommandArgumentEntry arg_entry =
437b9c1b51eSKate Stone         opt_set_mask == LLDB_OPT_SET_ALL
438b9c1b51eSKate Stone             ? m_arguments[i]
43934ddc8dbSJohnny Chen             : OptSetFiltered(opt_set_mask, m_arguments[i]);
440e139cf23SCaroline Tice     int num_alternatives = arg_entry.size();
441405fe67fSCaroline Tice 
442b9c1b51eSKate Stone     if ((num_alternatives == 2) && IsPairType(arg_entry[0].arg_repetition)) {
443405fe67fSCaroline Tice       const char *first_name = GetArgumentName(arg_entry[0].arg_type);
444405fe67fSCaroline Tice       const char *second_name = GetArgumentName(arg_entry[1].arg_type);
445b9c1b51eSKate Stone       switch (arg_entry[0].arg_repetition) {
446405fe67fSCaroline Tice       case eArgRepeatPairPlain:
447405fe67fSCaroline Tice         str.Printf("<%s> <%s>", first_name, second_name);
448405fe67fSCaroline Tice         break;
449405fe67fSCaroline Tice       case eArgRepeatPairOptional:
450405fe67fSCaroline Tice         str.Printf("[<%s> <%s>]", first_name, second_name);
451405fe67fSCaroline Tice         break;
452405fe67fSCaroline Tice       case eArgRepeatPairPlus:
453b9c1b51eSKate Stone         str.Printf("<%s> <%s> [<%s> <%s> [...]]", first_name, second_name,
454b9c1b51eSKate Stone                    first_name, second_name);
455405fe67fSCaroline Tice         break;
456405fe67fSCaroline Tice       case eArgRepeatPairStar:
457b9c1b51eSKate Stone         str.Printf("[<%s> <%s> [<%s> <%s> [...]]]", first_name, second_name,
458b9c1b51eSKate Stone                    first_name, second_name);
459405fe67fSCaroline Tice         break;
460405fe67fSCaroline Tice       case eArgRepeatPairRange:
461b9c1b51eSKate Stone         str.Printf("<%s_1> <%s_1> ... <%s_n> <%s_n>", first_name, second_name,
462b9c1b51eSKate Stone                    first_name, second_name);
463405fe67fSCaroline Tice         break;
464405fe67fSCaroline Tice       case eArgRepeatPairRangeOptional:
465b9c1b51eSKate Stone         str.Printf("[<%s_1> <%s_1> ... <%s_n> <%s_n>]", first_name, second_name,
466b9c1b51eSKate Stone                    first_name, second_name);
467405fe67fSCaroline Tice         break;
468b9c1b51eSKate Stone       // Explicitly test for all the rest of the cases, so if new types get
469b9c1b51eSKate Stone       // added we will notice the
470ca1176aaSCaroline Tice       // missing case statement(s).
471ca1176aaSCaroline Tice       case eArgRepeatPlain:
472ca1176aaSCaroline Tice       case eArgRepeatOptional:
473ca1176aaSCaroline Tice       case eArgRepeatPlus:
474ca1176aaSCaroline Tice       case eArgRepeatStar:
475ca1176aaSCaroline Tice       case eArgRepeatRange:
476b9c1b51eSKate Stone         // These should not be reached, as they should fail the IsPairType test
477b9c1b51eSKate Stone         // above.
478ca1176aaSCaroline Tice         break;
479405fe67fSCaroline Tice       }
480b9c1b51eSKate Stone     } else {
481e139cf23SCaroline Tice       StreamString names;
482b9c1b51eSKate Stone       for (int j = 0; j < num_alternatives; ++j) {
483e139cf23SCaroline Tice         if (j > 0)
484e139cf23SCaroline Tice           names.Printf(" | ");
485e139cf23SCaroline Tice         names.Printf("%s", GetArgumentName(arg_entry[j].arg_type));
486e139cf23SCaroline Tice       }
487c156427dSZachary Turner 
488c156427dSZachary Turner       std::string name_str = names.GetString();
489b9c1b51eSKate Stone       switch (arg_entry[0].arg_repetition) {
490e139cf23SCaroline Tice       case eArgRepeatPlain:
491c156427dSZachary Turner         str.Printf("<%s>", name_str.c_str());
492e139cf23SCaroline Tice         break;
493e139cf23SCaroline Tice       case eArgRepeatPlus:
494c156427dSZachary Turner         str.Printf("<%s> [<%s> [...]]", name_str.c_str(), name_str.c_str());
495e139cf23SCaroline Tice         break;
496e139cf23SCaroline Tice       case eArgRepeatStar:
497c156427dSZachary Turner         str.Printf("[<%s> [<%s> [...]]]", name_str.c_str(), name_str.c_str());
498e139cf23SCaroline Tice         break;
499e139cf23SCaroline Tice       case eArgRepeatOptional:
500c156427dSZachary Turner         str.Printf("[<%s>]", name_str.c_str());
501e139cf23SCaroline Tice         break;
502405fe67fSCaroline Tice       case eArgRepeatRange:
503c156427dSZachary Turner         str.Printf("<%s_1> .. <%s_n>", name_str.c_str(), name_str.c_str());
504ca1176aaSCaroline Tice         break;
505b9c1b51eSKate Stone       // Explicitly test for all the rest of the cases, so if new types get
506b9c1b51eSKate Stone       // added we will notice the
507ca1176aaSCaroline Tice       // missing case statement(s).
508ca1176aaSCaroline Tice       case eArgRepeatPairPlain:
509ca1176aaSCaroline Tice       case eArgRepeatPairOptional:
510ca1176aaSCaroline Tice       case eArgRepeatPairPlus:
511ca1176aaSCaroline Tice       case eArgRepeatPairStar:
512ca1176aaSCaroline Tice       case eArgRepeatPairRange:
513ca1176aaSCaroline Tice       case eArgRepeatPairRangeOptional:
514b9c1b51eSKate Stone         // These should not be hit, as they should pass the IsPairType test
515b9c1b51eSKate Stone         // above, and control should
516ca1176aaSCaroline Tice         // have gone into the other branch of the if statement.
517ca1176aaSCaroline Tice         break;
518405fe67fSCaroline Tice       }
519e139cf23SCaroline Tice     }
520e139cf23SCaroline Tice   }
521e139cf23SCaroline Tice }
522e139cf23SCaroline Tice 
52314f6b2c0SZachary Turner CommandArgumentType
52414f6b2c0SZachary Turner CommandObject::LookupArgumentName(llvm::StringRef arg_name) {
525e139cf23SCaroline Tice   CommandArgumentType return_type = eArgTypeLastArg;
526e139cf23SCaroline Tice 
52714f6b2c0SZachary Turner   arg_name = arg_name.ltrim('<').rtrim('>');
528e139cf23SCaroline Tice 
529331eff39SJohnny Chen   const ArgumentTableEntry *table = GetArgumentTable();
530e139cf23SCaroline Tice   for (int i = 0; i < eArgTypeLastArg; ++i)
53114f6b2c0SZachary Turner     if (arg_name == table[i].arg_name)
532e139cf23SCaroline Tice       return_type = g_arguments_data[i].arg_type;
533e139cf23SCaroline Tice 
534e139cf23SCaroline Tice   return return_type;
535e139cf23SCaroline Tice }
536e139cf23SCaroline Tice 
537e0038717SZachary Turner static llvm::StringRef RegisterNameHelpTextCallback() {
538b9c1b51eSKate Stone   return "Register names can be specified using the architecture specific "
539b9c1b51eSKate Stone          "names.  "
540b9c1b51eSKate Stone          "They can also be specified using generic names.  Not all generic "
541b9c1b51eSKate Stone          "entities have "
542b9c1b51eSKate Stone          "registers backing them on all architectures.  When they don't the "
543b9c1b51eSKate Stone          "generic name "
54484c7bd74SJim Ingham          "will return an error.\n"
545931e674aSJim Ingham          "The generic names defined in lldb are:\n"
546931e674aSJim Ingham          "\n"
547931e674aSJim Ingham          "pc       - program counter register\n"
548931e674aSJim Ingham          "ra       - return address register\n"
549931e674aSJim Ingham          "fp       - frame pointer register\n"
550931e674aSJim Ingham          "sp       - stack pointer register\n"
55184c7bd74SJim Ingham          "flags    - the flags register\n"
552931e674aSJim Ingham          "arg{1-6} - integer argument passing registers.\n";
553931e674aSJim Ingham }
554931e674aSJim Ingham 
555e0038717SZachary Turner static llvm::StringRef BreakpointIDHelpTextCallback() {
5567428a18cSKate Stone   return "Breakpoints are identified using major and minor numbers; the major "
557b9c1b51eSKate Stone          "number corresponds to the single entity that was created with a "
558b9c1b51eSKate Stone          "'breakpoint "
559b9c1b51eSKate Stone          "set' command; the minor numbers correspond to all the locations that "
560b9c1b51eSKate Stone          "were "
561b9c1b51eSKate Stone          "actually found/set based on the major breakpoint.  A full breakpoint "
562b9c1b51eSKate Stone          "ID might "
563b9c1b51eSKate Stone          "look like 3.14, meaning the 14th location set for the 3rd "
564b9c1b51eSKate Stone          "breakpoint.  You "
565b9c1b51eSKate Stone          "can specify all the locations of a breakpoint by just indicating the "
566b9c1b51eSKate Stone          "major "
567b9c1b51eSKate Stone          "breakpoint number. A valid breakpoint ID consists either of just the "
568b9c1b51eSKate Stone          "major "
569b9c1b51eSKate Stone          "number, or the major number followed by a dot and the location "
570b9c1b51eSKate Stone          "number (e.g. "
5717428a18cSKate Stone          "3 or 3.2 could both be valid breakpoint IDs.)";
572e139cf23SCaroline Tice }
573e139cf23SCaroline Tice 
574e0038717SZachary Turner static llvm::StringRef BreakpointIDRangeHelpTextCallback() {
575b9c1b51eSKate Stone   return "A 'breakpoint ID list' is a manner of specifying multiple "
576b9c1b51eSKate Stone          "breakpoints. "
577b9c1b51eSKate Stone          "This can be done through several mechanisms.  The easiest way is to "
578b9c1b51eSKate Stone          "just "
5797428a18cSKate Stone          "enter a space-separated list of breakpoint IDs.  To specify all the "
58086edbf41SGreg Clayton          "breakpoint locations under a major breakpoint, you can use the major "
581b9c1b51eSKate Stone          "breakpoint number followed by '.*', eg. '5.*' means all the "
582b9c1b51eSKate Stone          "locations under "
58386edbf41SGreg Clayton          "breakpoint 5.  You can also indicate a range of breakpoints by using "
584b9c1b51eSKate Stone          "<start-bp-id> - <end-bp-id>.  The start-bp-id and end-bp-id for a "
585b9c1b51eSKate Stone          "range can "
586b9c1b51eSKate Stone          "be any valid breakpoint IDs.  It is not legal, however, to specify a "
587b9c1b51eSKate Stone          "range "
588b9c1b51eSKate Stone          "using specific locations that cross major breakpoint numbers.  I.e. "
589b9c1b51eSKate Stone          "3.2 - 3.7"
59086edbf41SGreg Clayton          " is legal; 2 - 5 is legal; but 3.2 - 4.4 is not legal.";
59186edbf41SGreg Clayton }
59286edbf41SGreg Clayton 
593e0038717SZachary Turner static llvm::StringRef BreakpointNameHelpTextCallback() {
594b9c1b51eSKate Stone   return "A name that can be added to a breakpoint when it is created, or "
595b9c1b51eSKate Stone          "later "
5965e09c8c3SJim Ingham          "on with the \"breakpoint name add\" command.  "
597b9c1b51eSKate Stone          "Breakpoint names can be used to specify breakpoints in all the "
598b9c1b51eSKate Stone          "places breakpoint IDs "
599b9c1b51eSKate Stone          "and breakpoint ID ranges can be used.  As such they provide a "
600b9c1b51eSKate Stone          "convenient way to group breakpoints, "
601b9c1b51eSKate Stone          "and to operate on breakpoints you create without having to track the "
602b9c1b51eSKate Stone          "breakpoint number.  "
603b9c1b51eSKate Stone          "Note, the attributes you set when using a breakpoint name in a "
604b9c1b51eSKate Stone          "breakpoint command don't "
605b9c1b51eSKate Stone          "adhere to the name, but instead are set individually on all the "
606b9c1b51eSKate Stone          "breakpoints currently tagged with that "
6077428a18cSKate Stone          "name.  Future breakpoints "
608b9c1b51eSKate Stone          "tagged with that name will not pick up the attributes previously "
609b9c1b51eSKate Stone          "given using that name.  "
610b9c1b51eSKate Stone          "In order to distinguish breakpoint names from breakpoint IDs and "
611b9c1b51eSKate Stone          "ranges, "
612b9c1b51eSKate Stone          "names must start with a letter from a-z or A-Z and cannot contain "
613b9c1b51eSKate Stone          "spaces, \".\" or \"-\".  "
614b9c1b51eSKate Stone          "Also, breakpoint names can only be applied to breakpoints, not to "
615b9c1b51eSKate Stone          "breakpoint locations.";
6165e09c8c3SJim Ingham }
6175e09c8c3SJim Ingham 
618e0038717SZachary Turner static llvm::StringRef GDBFormatHelpTextCallback() {
619b9c1b51eSKate Stone   return "A GDB format consists of a repeat count, a format letter and a size "
620b9c1b51eSKate Stone          "letter. "
621b9c1b51eSKate Stone          "The repeat count is optional and defaults to 1. The format letter is "
622b9c1b51eSKate Stone          "optional "
623b9c1b51eSKate Stone          "and defaults to the previous format that was used. The size letter "
624b9c1b51eSKate Stone          "is optional "
625f91381e8SGreg Clayton          "and defaults to the previous size that was used.\n"
626f91381e8SGreg Clayton          "\n"
627f91381e8SGreg Clayton          "Format letters include:\n"
628f91381e8SGreg Clayton          "o - octal\n"
629f91381e8SGreg Clayton          "x - hexadecimal\n"
630f91381e8SGreg Clayton          "d - decimal\n"
631f91381e8SGreg Clayton          "u - unsigned decimal\n"
632f91381e8SGreg Clayton          "t - binary\n"
633f91381e8SGreg Clayton          "f - float\n"
634f91381e8SGreg Clayton          "a - address\n"
635f91381e8SGreg Clayton          "i - instruction\n"
636f91381e8SGreg Clayton          "c - char\n"
637f91381e8SGreg Clayton          "s - string\n"
638f91381e8SGreg Clayton          "T - OSType\n"
639f91381e8SGreg Clayton          "A - float as hex\n"
640f91381e8SGreg Clayton          "\n"
641f91381e8SGreg Clayton          "Size letters include:\n"
642f91381e8SGreg Clayton          "b - 1 byte  (byte)\n"
643f91381e8SGreg Clayton          "h - 2 bytes (halfword)\n"
644f91381e8SGreg Clayton          "w - 4 bytes (word)\n"
645f91381e8SGreg Clayton          "g - 8 bytes (giant)\n"
646f91381e8SGreg Clayton          "\n"
647f91381e8SGreg Clayton          "Example formats:\n"
648f91381e8SGreg Clayton          "32xb - show 32 1 byte hexadecimal integer values\n"
649f91381e8SGreg Clayton          "16xh - show 16 2 byte hexadecimal integer values\n"
650b9c1b51eSKate Stone          "64   - show 64 2 byte hexadecimal integer values (format and size "
651b9c1b51eSKate Stone          "from the last format)\n"
652b9c1b51eSKate Stone          "dw   - show 1 4 byte decimal integer value\n";
653e139cf23SCaroline Tice }
654e139cf23SCaroline Tice 
655e0038717SZachary Turner static llvm::StringRef FormatHelpTextCallback() {
656e0038717SZachary Turner   static std::string help_text;
65782a7d983SEnrico Granata 
658e0038717SZachary Turner   if (!help_text.empty())
659e0038717SZachary Turner     return help_text;
66082a7d983SEnrico Granata 
6610a3958e0SEnrico Granata   StreamString sstr;
662b9c1b51eSKate Stone   sstr << "One of the format names (or one-character names) that can be used "
663b9c1b51eSKate Stone           "to show a variable's value:\n";
664b9c1b51eSKate Stone   for (Format f = eFormatDefault; f < kNumFormats; f = Format(f + 1)) {
66582a7d983SEnrico Granata     if (f != eFormatDefault)
66682a7d983SEnrico Granata       sstr.PutChar('\n');
66782a7d983SEnrico Granata 
6680a3958e0SEnrico Granata     char format_char = FormatManager::GetFormatAsFormatChar(f);
6690a3958e0SEnrico Granata     if (format_char)
6700a3958e0SEnrico Granata       sstr.Printf("'%c' or ", format_char);
6710a3958e0SEnrico Granata 
67282a7d983SEnrico Granata     sstr.Printf("\"%s\"", FormatManager::GetFormatAsCString(f));
6730a3958e0SEnrico Granata   }
6740a3958e0SEnrico Granata 
6750a3958e0SEnrico Granata   sstr.Flush();
6760a3958e0SEnrico Granata 
677e0038717SZachary Turner   help_text = sstr.GetString();
6780a3958e0SEnrico Granata 
679e0038717SZachary Turner   return help_text;
6800a3958e0SEnrico Granata }
6810a3958e0SEnrico Granata 
682e0038717SZachary Turner static llvm::StringRef LanguageTypeHelpTextCallback() {
683e0038717SZachary Turner   static std::string help_text;
684d9477397SSean Callanan 
685e0038717SZachary Turner   if (!help_text.empty())
686e0038717SZachary Turner     return help_text;
687d9477397SSean Callanan 
688d9477397SSean Callanan   StreamString sstr;
689d9477397SSean Callanan   sstr << "One of the following languages:\n";
690d9477397SSean Callanan 
6910e0984eeSJim Ingham   Language::PrintAllLanguages(sstr, "  ", "\n");
692d9477397SSean Callanan 
693d9477397SSean Callanan   sstr.Flush();
694d9477397SSean Callanan 
695e0038717SZachary Turner   help_text = sstr.GetString();
696d9477397SSean Callanan 
697e0038717SZachary Turner   return help_text;
698d9477397SSean Callanan }
699d9477397SSean Callanan 
700e0038717SZachary Turner static llvm::StringRef SummaryStringHelpTextCallback() {
701b9c1b51eSKate Stone   return "A summary string is a way to extract information from variables in "
702b9c1b51eSKate Stone          "order to present them using a summary.\n"
703b9c1b51eSKate Stone          "Summary strings contain static text, variables, scopes and control "
704b9c1b51eSKate Stone          "sequences:\n"
705b9c1b51eSKate Stone          "  - Static text can be any sequence of non-special characters, i.e. "
706b9c1b51eSKate Stone          "anything but '{', '}', '$', or '\\'.\n"
707b9c1b51eSKate Stone          "  - Variables are sequences of characters beginning with ${, ending "
708b9c1b51eSKate Stone          "with } and that contain symbols in the format described below.\n"
709b9c1b51eSKate Stone          "  - Scopes are any sequence of text between { and }. Anything "
710b9c1b51eSKate Stone          "included in a scope will only appear in the output summary if there "
711b9c1b51eSKate Stone          "were no errors.\n"
712b9c1b51eSKate Stone          "  - Control sequences are the usual C/C++ '\\a', '\\n', ..., plus "
713b9c1b51eSKate Stone          "'\\$', '\\{' and '\\}'.\n"
714b9c1b51eSKate Stone          "A summary string works by copying static text verbatim, turning "
715b9c1b51eSKate Stone          "control sequences into their character counterpart, expanding "
716b9c1b51eSKate Stone          "variables and trying to expand scopes.\n"
717b9c1b51eSKate Stone          "A variable is expanded by giving it a value other than its textual "
718b9c1b51eSKate Stone          "representation, and the way this is done depends on what comes after "
719b9c1b51eSKate Stone          "the ${ marker.\n"
720b9c1b51eSKate Stone          "The most common sequence if ${var followed by an expression path, "
721b9c1b51eSKate Stone          "which is the text one would type to access a member of an aggregate "
722b9c1b51eSKate Stone          "types, given a variable of that type"
723b9c1b51eSKate Stone          " (e.g. if type T has a member named x, which has a member named y, "
724b9c1b51eSKate Stone          "and if t is of type T, the expression path would be .x.y and the way "
725b9c1b51eSKate Stone          "to fit that into a summary string would be"
726b9c1b51eSKate Stone          " ${var.x.y}). You can also use ${*var followed by an expression path "
727b9c1b51eSKate Stone          "and in that case the object referred by the path will be "
728b9c1b51eSKate Stone          "dereferenced before being displayed."
729b9c1b51eSKate Stone          " If the object is not a pointer, doing so will cause an error. For "
730b9c1b51eSKate Stone          "additional details on expression paths, you can type 'help "
731b9c1b51eSKate Stone          "expr-path'. \n"
732b9c1b51eSKate Stone          "By default, summary strings attempt to display the summary for any "
733b9c1b51eSKate Stone          "variable they reference, and if that fails the value. If neither can "
734b9c1b51eSKate Stone          "be shown, nothing is displayed."
735b9c1b51eSKate Stone          "In a summary string, you can also use an array index [n], or a "
736b9c1b51eSKate Stone          "slice-like range [n-m]. This can have two different meanings "
737b9c1b51eSKate Stone          "depending on what kind of object the expression"
73882a7d983SEnrico Granata          " path refers to:\n"
739b9c1b51eSKate Stone          "  - if it is a scalar type (any basic type like int, float, ...) the "
740b9c1b51eSKate Stone          "expression is a bitfield, i.e. the bits indicated by the indexing "
741b9c1b51eSKate Stone          "operator are extracted out of the number"
74282a7d983SEnrico Granata          " and displayed as an individual variable\n"
743b9c1b51eSKate Stone          "  - if it is an array or pointer the array items indicated by the "
744b9c1b51eSKate Stone          "indexing operator are shown as the result of the variable. if the "
745b9c1b51eSKate Stone          "expression is an array, real array items are"
746b9c1b51eSKate Stone          " printed; if it is a pointer, the pointer-as-array syntax is used to "
747b9c1b51eSKate Stone          "obtain the values (this means, the latter case can have no range "
748b9c1b51eSKate Stone          "checking)\n"
749b9c1b51eSKate Stone          "If you are trying to display an array for which the size is known, "
750b9c1b51eSKate Stone          "you can also use [] instead of giving an exact range. This has the "
751b9c1b51eSKate Stone          "effect of showing items 0 thru size - 1.\n"
752b9c1b51eSKate Stone          "Additionally, a variable can contain an (optional) format code, as "
753b9c1b51eSKate Stone          "in ${var.x.y%code}, where code can be any of the valid formats "
754b9c1b51eSKate Stone          "described in 'help format', or one of the"
7559128ee2fSEnrico Granata          " special symbols only allowed as part of a variable:\n"
7569128ee2fSEnrico Granata          "    %V: show the value of the object by default\n"
7579128ee2fSEnrico Granata          "    %S: show the summary of the object by default\n"
758b9c1b51eSKate Stone          "    %@: show the runtime-provided object description (for "
759b9c1b51eSKate Stone          "Objective-C, it calls NSPrintForDebugger; for C/C++ it does "
760b9c1b51eSKate Stone          "nothing)\n"
761b9c1b51eSKate Stone          "    %L: show the location of the object (memory address or a "
762b9c1b51eSKate Stone          "register name)\n"
7639128ee2fSEnrico Granata          "    %#: show the number of children of the object\n"
7649128ee2fSEnrico Granata          "    %T: show the type of the object\n"
765b9c1b51eSKate Stone          "Another variable that you can use in summary strings is ${svar . "
766b9c1b51eSKate Stone          "This sequence works exactly like ${var, including the fact that "
767b9c1b51eSKate Stone          "${*svar is an allowed sequence, but uses"
768b9c1b51eSKate Stone          " the object's synthetic children provider instead of the actual "
769b9c1b51eSKate Stone          "objects. For instance, if you are using STL synthetic children "
770b9c1b51eSKate Stone          "providers, the following summary string would"
7719128ee2fSEnrico Granata          " count the number of actual elements stored in an std::list:\n"
7729128ee2fSEnrico Granata          "type summary add -s \"${svar%#}\" -x \"std::list<\"";
7739128ee2fSEnrico Granata }
7749128ee2fSEnrico Granata 
775e0038717SZachary Turner static llvm::StringRef ExprPathHelpTextCallback() {
776b9c1b51eSKate Stone   return "An expression path is the sequence of symbols that is used in C/C++ "
777b9c1b51eSKate Stone          "to access a member variable of an aggregate object (class).\n"
7789128ee2fSEnrico Granata          "For instance, given a class:\n"
7799128ee2fSEnrico Granata          "  class foo {\n"
7809128ee2fSEnrico Granata          "      int a;\n"
7819128ee2fSEnrico Granata          "      int b; .\n"
7829128ee2fSEnrico Granata          "      foo* next;\n"
7839128ee2fSEnrico Granata          "  };\n"
784b9c1b51eSKate Stone          "the expression to read item b in the item pointed to by next for foo "
785b9c1b51eSKate Stone          "aFoo would be aFoo.next->b.\n"
786b9c1b51eSKate Stone          "Given that aFoo could just be any object of type foo, the string "
787b9c1b51eSKate Stone          "'.next->b' is the expression path, because it can be attached to any "
788b9c1b51eSKate Stone          "foo instance to achieve the effect.\n"
789b9c1b51eSKate Stone          "Expression paths in LLDB include dot (.) and arrow (->) operators, "
790b9c1b51eSKate Stone          "and most commands using expression paths have ways to also accept "
791b9c1b51eSKate Stone          "the star (*) operator.\n"
792b9c1b51eSKate Stone          "The meaning of these operators is the same as the usual one given to "
793b9c1b51eSKate Stone          "them by the C/C++ standards.\n"
794b9c1b51eSKate Stone          "LLDB also has support for indexing ([ ]) in expression paths, and "
795b9c1b51eSKate Stone          "extends the traditional meaning of the square brackets operator to "
796b9c1b51eSKate Stone          "allow bitfield extraction:\n"
797b9c1b51eSKate Stone          "for objects of native types (int, float, char, ...) saying '[n-m]' "
798b9c1b51eSKate Stone          "as an expression path (where n and m are any positive integers, e.g. "
799b9c1b51eSKate Stone          "[3-5]) causes LLDB to extract"
800b9c1b51eSKate Stone          " bits n thru m from the value of the variable. If n == m, [n] is "
801b9c1b51eSKate Stone          "also allowed as a shortcut syntax. For arrays and pointers, "
802b9c1b51eSKate Stone          "expression paths can only contain one index"
803b9c1b51eSKate Stone          " and the meaning of the operation is the same as the one defined by "
804b9c1b51eSKate Stone          "C/C++ (item extraction). Some commands extend bitfield-like syntax "
805b9c1b51eSKate Stone          "for arrays and pointers with the"
806b9c1b51eSKate Stone          " meaning of array slicing (taking elements n thru m inside the array "
807b9c1b51eSKate Stone          "or pointed-to memory).";
8080a3958e0SEnrico Granata }
8090a3958e0SEnrico Granata 
810b9c1b51eSKate Stone void CommandObject::FormatLongHelpText(Stream &output_strm,
811442f6530SZachary Turner                                        llvm::StringRef long_help) {
812ea671fbdSKate Stone   CommandInterpreter &interpreter = GetCommandInterpreter();
813ea671fbdSKate Stone   std::stringstream lineStream(long_help);
814ea671fbdSKate Stone   std::string line;
815ea671fbdSKate Stone   while (std::getline(lineStream, line)) {
816ea671fbdSKate Stone     if (line.empty()) {
817ea671fbdSKate Stone       output_strm << "\n";
818ea671fbdSKate Stone       continue;
819ea671fbdSKate Stone     }
820ea671fbdSKate Stone     size_t result = line.find_first_not_of(" \t");
821ea671fbdSKate Stone     if (result == std::string::npos) {
822ea671fbdSKate Stone       result = 0;
823ea671fbdSKate Stone     }
824ea671fbdSKate Stone     std::string whitespace_prefix = line.substr(0, result);
825ea671fbdSKate Stone     std::string remainder = line.substr(result);
826b9c1b51eSKate Stone     interpreter.OutputFormattedHelpText(output_strm, whitespace_prefix.c_str(),
827b9c1b51eSKate Stone                                         remainder.c_str());
828ea671fbdSKate Stone   }
829ea671fbdSKate Stone }
830ea671fbdSKate Stone 
831b9c1b51eSKate Stone void CommandObject::GenerateHelpText(CommandReturnObject &result) {
8329b62d1d5SEnrico Granata   GenerateHelpText(result.GetOutputStream());
8339b62d1d5SEnrico Granata 
8349b62d1d5SEnrico Granata   result.SetStatus(eReturnStatusSuccessFinishNoResult);
8359b62d1d5SEnrico Granata }
8369b62d1d5SEnrico Granata 
837b9c1b51eSKate Stone void CommandObject::GenerateHelpText(Stream &output_strm) {
8389b62d1d5SEnrico Granata   CommandInterpreter &interpreter = GetCommandInterpreter();
839b9c1b51eSKate Stone   if (WantsRawCommandString()) {
8409b62d1d5SEnrico Granata     std::string help_text(GetHelp());
8417428a18cSKate Stone     help_text.append("  Expects 'raw' input (see 'help raw-input'.)");
842b9c1b51eSKate Stone     interpreter.OutputFormattedHelpText(output_strm, "", "", help_text.c_str(),
843b9c1b51eSKate Stone                                         1);
844b9c1b51eSKate Stone   } else
8459b62d1d5SEnrico Granata     interpreter.OutputFormattedHelpText(output_strm, "", "", GetHelp(), 1);
84603c9f364SZachary Turner   output_strm << "\nSyntax: " << GetSyntax() << "\n";
8477428a18cSKate Stone   Options *options = GetOptions();
848b9c1b51eSKate Stone   if (options != nullptr) {
849b9c1b51eSKate Stone     options->GenerateOptionUsage(
850b9c1b51eSKate Stone         output_strm, this,
851b9c1b51eSKate Stone         GetCommandInterpreter().GetDebugger().GetTerminalWidth());
8527428a18cSKate Stone   }
853442f6530SZachary Turner   llvm::StringRef long_help = GetHelpLong();
854442f6530SZachary Turner   if (!long_help.empty()) {
855ea671fbdSKate Stone     FormatLongHelpText(output_strm, long_help);
8567428a18cSKate Stone   }
857b9c1b51eSKate Stone   if (!IsDashDashCommand() && options && options->NumCommandOptions() > 0) {
858b9c1b51eSKate Stone     if (WantsRawCommandString() && !WantsCompletion()) {
859b9c1b51eSKate Stone       // Emit the message about using ' -- ' between the end of the command
860b9c1b51eSKate Stone       // options and the raw input
861b9c1b51eSKate Stone       // conditionally, i.e., only if the command object does not want
862b9c1b51eSKate Stone       // completion.
8637428a18cSKate Stone       interpreter.OutputFormattedHelpText(
8647428a18cSKate Stone           output_strm, "", "",
865b9c1b51eSKate Stone           "\nImportant Note: Because this command takes 'raw' input, if you "
866b9c1b51eSKate Stone           "use any command options"
867b9c1b51eSKate Stone           " you must use ' -- ' between the end of the command options and the "
868b9c1b51eSKate Stone           "beginning of the raw input.",
8697428a18cSKate Stone           1);
870b9c1b51eSKate Stone     } else if (GetNumArgumentEntries() > 0) {
871b9c1b51eSKate Stone       // Also emit a warning about using "--" in case you are using a command
872b9c1b51eSKate Stone       // that takes options and arguments.
8737428a18cSKate Stone       interpreter.OutputFormattedHelpText(
874b9c1b51eSKate Stone           output_strm, "", "",
875b9c1b51eSKate Stone           "\nThis command takes options and free-form arguments.  If your "
876b9c1b51eSKate Stone           "arguments resemble"
877b9c1b51eSKate Stone           " option specifiers (i.e., they start with a - or --), you must use "
878b9c1b51eSKate Stone           "' -- ' between"
8797428a18cSKate Stone           " the end of the command options and the beginning of the arguments.",
8807428a18cSKate Stone           1);
8819b62d1d5SEnrico Granata     }
8829b62d1d5SEnrico Granata   }
883bfb75e9bSEnrico Granata }
8849b62d1d5SEnrico Granata 
885b9c1b51eSKate Stone void CommandObject::AddIDsArgumentData(CommandArgumentEntry &arg,
886b9c1b51eSKate Stone                                        CommandArgumentType ID,
887b9c1b51eSKate Stone                                        CommandArgumentType IDRange) {
888184d7a72SJohnny Chen   CommandArgumentData id_arg;
889184d7a72SJohnny Chen   CommandArgumentData id_range_arg;
890184d7a72SJohnny Chen 
891b9c1b51eSKate Stone   // Create the first variant for the first (and only) argument for this
892b9c1b51eSKate Stone   // command.
893de753464SJohnny Chen   id_arg.arg_type = ID;
894184d7a72SJohnny Chen   id_arg.arg_repetition = eArgRepeatOptional;
895184d7a72SJohnny Chen 
896b9c1b51eSKate Stone   // Create the second variant for the first (and only) argument for this
897b9c1b51eSKate Stone   // command.
898de753464SJohnny Chen   id_range_arg.arg_type = IDRange;
899184d7a72SJohnny Chen   id_range_arg.arg_repetition = eArgRepeatOptional;
900184d7a72SJohnny Chen 
901b9c1b51eSKate Stone   // The first (and only) argument for this command could be either an id or an
902b9c1b51eSKate Stone   // id_range.
903184d7a72SJohnny Chen   // Push both variants into the entry for the first argument for this command.
904184d7a72SJohnny Chen   arg.push_back(id_arg);
905184d7a72SJohnny Chen   arg.push_back(id_range_arg);
906184d7a72SJohnny Chen }
907184d7a72SJohnny Chen 
908b9c1b51eSKate Stone const char *CommandObject::GetArgumentTypeAsCString(
909b9c1b51eSKate Stone     const lldb::CommandArgumentType arg_type) {
910b9c1b51eSKate Stone   assert(arg_type < eArgTypeLastArg &&
911b9c1b51eSKate Stone          "Invalid argument type passed to GetArgumentTypeAsCString");
9129d0402b1SGreg Clayton   return g_arguments_data[arg_type].arg_name;
9139d0402b1SGreg Clayton }
9149d0402b1SGreg Clayton 
915b9c1b51eSKate Stone const char *CommandObject::GetArgumentDescriptionAsCString(
916b9c1b51eSKate Stone     const lldb::CommandArgumentType arg_type) {
917b9c1b51eSKate Stone   assert(arg_type < eArgTypeLastArg &&
918b9c1b51eSKate Stone          "Invalid argument type passed to GetArgumentDescriptionAsCString");
9199d0402b1SGreg Clayton   return g_arguments_data[arg_type].help_text;
9209d0402b1SGreg Clayton }
9219d0402b1SGreg Clayton 
922b9c1b51eSKate Stone Target *CommandObject::GetDummyTarget() {
923893c932aSJim Ingham   return m_interpreter.GetDebugger().GetDummyTarget();
924893c932aSJim Ingham }
925893c932aSJim Ingham 
926b9c1b51eSKate Stone Target *CommandObject::GetSelectedOrDummyTarget(bool prefer_dummy) {
92733df7cd3SJim Ingham   return m_interpreter.GetDebugger().GetSelectedOrDummyTarget(prefer_dummy);
928893c932aSJim Ingham }
929893c932aSJim Ingham 
930b9c1b51eSKate Stone Thread *CommandObject::GetDefaultThread() {
9318d94ba0fSJim Ingham   Thread *thread_to_use = m_exe_ctx.GetThreadPtr();
9328d94ba0fSJim Ingham   if (thread_to_use)
9338d94ba0fSJim Ingham     return thread_to_use;
9348d94ba0fSJim Ingham 
9358d94ba0fSJim Ingham   Process *process = m_exe_ctx.GetProcessPtr();
936b9c1b51eSKate Stone   if (!process) {
9378d94ba0fSJim Ingham     Target *target = m_exe_ctx.GetTargetPtr();
938b9c1b51eSKate Stone     if (!target) {
9398d94ba0fSJim Ingham       target = m_interpreter.GetDebugger().GetSelectedTarget().get();
9408d94ba0fSJim Ingham     }
9418d94ba0fSJim Ingham     if (target)
9428d94ba0fSJim Ingham       process = target->GetProcessSP().get();
9438d94ba0fSJim Ingham   }
9448d94ba0fSJim Ingham 
9458d94ba0fSJim Ingham   if (process)
9468d94ba0fSJim Ingham     return process->GetThreadList().GetSelectedThread().get();
9478d94ba0fSJim Ingham   else
9488d94ba0fSJim Ingham     return nullptr;
9498d94ba0fSJim Ingham }
9508d94ba0fSJim Ingham 
951b9c1b51eSKate Stone bool CommandObjectParsed::Execute(const char *args_string,
952b9c1b51eSKate Stone                                   CommandReturnObject &result) {
9535a988416SJim Ingham   bool handled = false;
9545a988416SJim Ingham   Args cmd_args(args_string);
955b9c1b51eSKate Stone   if (HasOverrideCallback()) {
9565a988416SJim Ingham     Args full_args(GetCommandName());
9575a988416SJim Ingham     full_args.AppendArguments(cmd_args);
958b9c1b51eSKate Stone     handled =
959b9c1b51eSKate Stone         InvokeOverrideCallback(full_args.GetConstArgumentVector(), result);
9605a988416SJim Ingham   }
961b9c1b51eSKate Stone   if (!handled) {
96297d2c401SZachary Turner     for (auto entry : llvm::enumerate(cmd_args.entries())) {
9634eb8449dSZachary Turner       if (!entry.value().ref.empty() && entry.value().ref.front() == '`') {
964b9c1b51eSKate Stone         cmd_args.ReplaceArgumentAtIndex(
9654eb8449dSZachary Turner             entry.index(),
9664eb8449dSZachary Turner             m_interpreter.ProcessEmbeddedScriptCommands(entry.value().c_str()));
96797d2c401SZachary Turner       }
9685a988416SJim Ingham     }
9695a988416SJim Ingham 
970b9c1b51eSKate Stone     if (CheckRequirements(result)) {
971b9c1b51eSKate Stone       if (ParseOptions(cmd_args, result)) {
972b9c1b51eSKate Stone         // Call the command-specific version of 'Execute', passing it the
973b9c1b51eSKate Stone         // already processed arguments.
9745a988416SJim Ingham         handled = DoExecute(cmd_args, result);
9755a988416SJim Ingham       }
976f9fc609fSGreg Clayton     }
977f9fc609fSGreg Clayton 
978f9fc609fSGreg Clayton     Cleanup();
979f9fc609fSGreg Clayton   }
9805a988416SJim Ingham   return handled;
9815a988416SJim Ingham }
9825a988416SJim Ingham 
983b9c1b51eSKate Stone bool CommandObjectRaw::Execute(const char *args_string,
984b9c1b51eSKate Stone                                CommandReturnObject &result) {
9855a988416SJim Ingham   bool handled = false;
986b9c1b51eSKate Stone   if (HasOverrideCallback()) {
9875a988416SJim Ingham     std::string full_command(GetCommandName());
9885a988416SJim Ingham     full_command += ' ';
9895a988416SJim Ingham     full_command += args_string;
990d78c9576SEd Maste     const char *argv[2] = {nullptr, nullptr};
9915a988416SJim Ingham     argv[0] = full_command.c_str();
9923b652621SJim Ingham     handled = InvokeOverrideCallback(argv, result);
9935a988416SJim Ingham   }
994b9c1b51eSKate Stone   if (!handled) {
995f9fc609fSGreg Clayton     if (CheckRequirements(result))
9965a988416SJim Ingham       handled = DoExecute(args_string, result);
997f9fc609fSGreg Clayton 
998f9fc609fSGreg Clayton     Cleanup();
9995a988416SJim Ingham   }
10005a988416SJim Ingham   return handled;
10015a988416SJim Ingham }
10025a988416SJim Ingham 
1003e0038717SZachary Turner static llvm::StringRef arch_helper() {
1004d70b14eaSGreg Clayton   static StreamString g_archs_help;
1005b9c1b51eSKate Stone   if (g_archs_help.Empty()) {
1006ca7835c6SJohnny Chen     StringList archs;
10074aa8753cSZachary Turner     ArchSpec::AutoComplete(llvm::StringRef(), archs);
1008d70b14eaSGreg Clayton     g_archs_help.Printf("These are the supported architecture names:\n");
1009797a1b37SJohnny Chen     archs.Join("\n", g_archs_help);
1010d70b14eaSGreg Clayton   }
1011e0038717SZachary Turner   return g_archs_help.GetString();
1012ca7835c6SJohnny Chen }
1013ca7835c6SJohnny Chen 
10147428a18cSKate Stone CommandObject::ArgumentTableEntry CommandObject::g_arguments_data[] = {
10157428a18cSKate Stone     // clang-format off
1016d78c9576SEd Maste     { eArgTypeAddress, "address", CommandCompletions::eNoCompletion, { nullptr, false }, "A valid address in the target program's execution space." },
1017d78c9576SEd Maste     { eArgTypeAddressOrExpression, "address-expression", CommandCompletions::eNoCompletion, { nullptr, false }, "An expression that resolves to an address." },
1018d78c9576SEd Maste     { eArgTypeAliasName, "alias-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of an abbreviation (alias) for a debugger command." },
1019d78c9576SEd 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.)" },
1020ca7835c6SJohnny Chen     { eArgTypeArchitecture, "arch", CommandCompletions::eArchitectureCompletion, { arch_helper, true }, "The architecture name, e.g. i386 or x86_64." },
1021d78c9576SEd Maste     { eArgTypeBoolean, "boolean", CommandCompletions::eNoCompletion, { nullptr, false }, "A Boolean value: 'true' or 'false'" },
1022d78c9576SEd Maste     { eArgTypeBreakpointID, "breakpt-id", CommandCompletions::eNoCompletion, { BreakpointIDHelpTextCallback, false }, nullptr },
1023d78c9576SEd Maste     { eArgTypeBreakpointIDRange, "breakpt-id-list", CommandCompletions::eNoCompletion, { BreakpointIDRangeHelpTextCallback, false }, nullptr },
10245e09c8c3SJim Ingham     { eArgTypeBreakpointName, "breakpoint-name", CommandCompletions::eNoCompletion, { BreakpointNameHelpTextCallback, false }, nullptr },
1025d78c9576SEd Maste     { eArgTypeByteSize, "byte-size", CommandCompletions::eNoCompletion, { nullptr, false }, "Number of bytes to use." },
1026d78c9576SEd Maste     { eArgTypeClassName, "class-name", CommandCompletions::eNoCompletion, { nullptr, false }, "Then name of a class from the debug information in the program." },
1027d78c9576SEd Maste     { eArgTypeCommandName, "cmd-name", CommandCompletions::eNoCompletion, { nullptr, false }, "A debugger command (may be multiple words), without any options or arguments." },
1028d78c9576SEd Maste     { eArgTypeCount, "count", CommandCompletions::eNoCompletion, { nullptr, false }, "An unsigned integer." },
1029d78c9576SEd Maste     { eArgTypeDirectoryName, "directory", CommandCompletions::eDiskDirectoryCompletion, { nullptr, false }, "A directory name." },
1030d78c9576SEd 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" },
1031d78c9576SEd Maste     { eArgTypeDescriptionVerbosity, "description-verbosity", CommandCompletions::eNoCompletion, { nullptr, false }, "How verbose the output of 'po' should be." },
1032d78c9576SEd Maste     { eArgTypeEndAddress, "end-address", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
1033d78c9576SEd Maste     { eArgTypeExpression, "expr", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
1034d78c9576SEd Maste     { eArgTypeExpressionPath, "expr-path", CommandCompletions::eNoCompletion, { ExprPathHelpTextCallback, true }, nullptr },
1035d78c9576SEd 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] ]" },
1036d78c9576SEd Maste     { eArgTypeFilename, "filename", CommandCompletions::eDiskFileCompletion, { nullptr, false }, "The name of a file (can include path)." },
1037d78c9576SEd Maste     { eArgTypeFormat, "format", CommandCompletions::eNoCompletion, { FormatHelpTextCallback, true }, nullptr },
1038d78c9576SEd Maste     { eArgTypeFrameIndex, "frame-index", CommandCompletions::eNoCompletion, { nullptr, false }, "Index into a thread's list of frames." },
1039d78c9576SEd Maste     { eArgTypeFullName, "fullname", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
1040d78c9576SEd Maste     { eArgTypeFunctionName, "function-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a function." },
1041d78c9576SEd Maste     { eArgTypeFunctionOrSymbol, "function-or-symbol", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a function or symbol." },
1042d78c9576SEd Maste     { eArgTypeGDBFormat, "gdb-format", CommandCompletions::eNoCompletion, { GDBFormatHelpTextCallback, true }, nullptr },
1043735152e3SEnrico Granata     { eArgTypeHelpText, "help-text", CommandCompletions::eNoCompletion, { nullptr, false }, "Text to be used as help for some other entity in LLDB" },
1044d78c9576SEd Maste     { eArgTypeIndex, "index", CommandCompletions::eNoCompletion, { nullptr, false }, "An index into a list." },
10457a67ee26SEnrico Granata     { eArgTypeLanguage, "source-language", CommandCompletions::eNoCompletion, { LanguageTypeHelpTextCallback, true }, nullptr },
1046d78c9576SEd Maste     { eArgTypeLineNum, "linenum", CommandCompletions::eNoCompletion, { nullptr, false }, "Line number in a source file." },
1047d78c9576SEd 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." },
1048d78c9576SEd 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)." },
1049d78c9576SEd Maste     { eArgTypeMethod, "method", CommandCompletions::eNoCompletion, { nullptr, false }, "A C++ method name." },
1050d78c9576SEd Maste     { eArgTypeName, "name", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
1051d78c9576SEd Maste     { eArgTypeNewPathPrefix, "new-path-prefix", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
1052d78c9576SEd Maste     { eArgTypeNumLines, "num-lines", CommandCompletions::eNoCompletion, { nullptr, false }, "The number of lines to use." },
1053d78c9576SEd Maste     { eArgTypeNumberPerLine, "number-per-line", CommandCompletions::eNoCompletion, { nullptr, false }, "The number of items per line to display." },
1054d78c9576SEd Maste     { eArgTypeOffset, "offset", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
1055d78c9576SEd Maste     { eArgTypeOldPathPrefix, "old-path-prefix", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
1056d78c9576SEd Maste     { eArgTypeOneLiner, "one-line-command", CommandCompletions::eNoCompletion, { nullptr, false }, "A command that is entered as a single line of text." },
1057d78c9576SEd Maste     { eArgTypePath, "path", CommandCompletions::eDiskFileCompletion, { nullptr, false }, "Path." },
1058d78c9576SEd Maste     { eArgTypePermissionsNumber, "perms-numeric", CommandCompletions::eNoCompletion, { nullptr, false }, "Permissions given as an octal number (e.g. 755)." },
1059d78c9576SEd Maste     { eArgTypePermissionsString, "perms=string", CommandCompletions::eNoCompletion, { nullptr, false }, "Permissions given as a string value (e.g. rw-r-xr--)." },
1060d78c9576SEd Maste     { eArgTypePid, "pid", CommandCompletions::eNoCompletion, { nullptr, false }, "The process ID number." },
1061d78c9576SEd Maste     { eArgTypePlugin, "plugin", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
1062d78c9576SEd Maste     { eArgTypeProcessName, "process-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of the process." },
1063d78c9576SEd Maste     { eArgTypePythonClass, "python-class", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a Python class." },
1064d78c9576SEd Maste     { eArgTypePythonFunction, "python-function", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a Python function." },
1065d78c9576SEd Maste     { eArgTypePythonScript, "python-script", CommandCompletions::eNoCompletion, { nullptr, false }, "Source code written in Python." },
1066d78c9576SEd Maste     { eArgTypeQueueName, "queue-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of the thread queue." },
1067d78c9576SEd Maste     { eArgTypeRegisterName, "register-name", CommandCompletions::eNoCompletion, { RegisterNameHelpTextCallback, true }, nullptr },
1068d78c9576SEd Maste     { eArgTypeRegularExpression, "regular-expression", CommandCompletions::eNoCompletion, { nullptr, false }, "A regular expression." },
1069d78c9576SEd Maste     { eArgTypeRunArgs, "run-args", CommandCompletions::eNoCompletion, { nullptr, false }, "Arguments to be passed to the target program when it starts executing." },
1070d78c9576SEd Maste     { eArgTypeRunMode, "run-mode", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
1071d78c9576SEd Maste     { eArgTypeScriptedCommandSynchronicity, "script-cmd-synchronicity", CommandCompletions::eNoCompletion, { nullptr, false }, "The synchronicity to use to run scripted commands with regard to LLDB event system." },
1072d78c9576SEd Maste     { eArgTypeScriptLang, "script-language", CommandCompletions::eNoCompletion, { nullptr, false }, "The scripting language to be used for script-based commands.  Currently only Python is valid." },
10737428a18cSKate Stone     { eArgTypeSearchWord, "search-word", CommandCompletions::eNoCompletion, { nullptr, false }, "Any word of interest for search purposes." },
1074d78c9576SEd Maste     { eArgTypeSelector, "selector", CommandCompletions::eNoCompletion, { nullptr, false }, "An Objective-C selector name." },
1075d78c9576SEd 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)." },
1076d78c9576SEd 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)." },
1077d78c9576SEd Maste     { eArgTypeSettingPrefix, "setting-prefix", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a settable internal debugger variable up to a dot ('.'), e.g. 'target.process.'" },
1078d78c9576SEd 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." },
1079d78c9576SEd Maste     { eArgTypeShlibName, "shlib-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a shared library." },
1080d78c9576SEd Maste     { eArgTypeSourceFile, "source-file", CommandCompletions::eSourceFileCompletion, { nullptr, false }, "The name of a source file.." },
1081d78c9576SEd Maste     { eArgTypeSortOrder, "sort-order", CommandCompletions::eNoCompletion, { nullptr, false }, "Specify a sort order when dumping lists." },
1082d78c9576SEd Maste     { eArgTypeStartAddress, "start-address", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
1083d78c9576SEd Maste     { eArgTypeSummaryString, "summary-string", CommandCompletions::eNoCompletion, { SummaryStringHelpTextCallback, true }, nullptr },
1084d78c9576SEd Maste     { eArgTypeSymbol, "symbol", CommandCompletions::eSymbolCompletion, { nullptr, false }, "Any symbol name (function name, variable, argument, etc.)" },
1085d78c9576SEd Maste     { eArgTypeThreadID, "thread-id", CommandCompletions::eNoCompletion, { nullptr, false }, "Thread ID number." },
1086d78c9576SEd Maste     { eArgTypeThreadIndex, "thread-index", CommandCompletions::eNoCompletion, { nullptr, false }, "Index into the process' list of threads." },
1087d78c9576SEd Maste     { eArgTypeThreadName, "thread-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The thread's name." },
1088a72b31c7SJim Ingham     { eArgTypeTypeName, "type-name", CommandCompletions::eNoCompletion, { nullptr, false }, "A type name." },
1089d78c9576SEd Maste     { eArgTypeUnsignedInteger, "unsigned-integer", CommandCompletions::eNoCompletion, { nullptr, false }, "An unsigned integer." },
1090d78c9576SEd Maste     { eArgTypeUnixSignal, "unix-signal", CommandCompletions::eNoCompletion, { nullptr, false }, "A valid Unix signal name or number (e.g. SIGKILL, KILL or 9)." },
1091d78c9576SEd Maste     { eArgTypeVarName, "variable-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a variable in your program." },
1092d78c9576SEd Maste     { eArgTypeValue, "value", CommandCompletions::eNoCompletion, { nullptr, false }, "A value could be anything, depending on where and how it is used." },
1093d78c9576SEd Maste     { eArgTypeWidth, "width", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
1094d78c9576SEd Maste     { eArgTypeNone, "none", CommandCompletions::eNoCompletion, { nullptr, false }, "No help available for this." },
1095d78c9576SEd 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." },
1096d78c9576SEd Maste     { eArgTypeWatchpointID, "watchpt-id", CommandCompletions::eNoCompletion, { nullptr, false }, "Watchpoint IDs are positive integers." },
1097d78c9576SEd Maste     { eArgTypeWatchpointIDRange, "watchpt-id-list", CommandCompletions::eNoCompletion, { nullptr, false }, "For example, '1-3' or '1 to 3'." },
10987428a18cSKate Stone     { eArgTypeWatchType, "watch-type", CommandCompletions::eNoCompletion, { nullptr, false }, "Specify the type for a watchpoint." },
1099b842f2ecSJim Ingham     { eArgRawInput, "raw-input", CommandCompletions::eNoCompletion, { nullptr, false }, "Free-form text passed to a command without prior interpretation, allowing spaces without requiring quotes.  To pass arguments and free form text put two dashes ' -- ' between the last argument and any raw input." },
1100b842f2ecSJim Ingham     { eArgTypeCommand, "command", CommandCompletions::eNoCompletion, { nullptr, false }, "An LLDB Command line command." }
11017428a18cSKate Stone     // clang-format on
1102e139cf23SCaroline Tice };
1103e139cf23SCaroline Tice 
1104b9c1b51eSKate Stone const CommandObject::ArgumentTableEntry *CommandObject::GetArgumentTable() {
1105b9c1b51eSKate Stone   // If this assertion fires, then the table above is out of date with the
1106b9c1b51eSKate Stone   // CommandArgumentType enumeration
1107b9c1b51eSKate Stone   assert((sizeof(CommandObject::g_arguments_data) /
1108b9c1b51eSKate Stone           sizeof(CommandObject::ArgumentTableEntry)) == eArgTypeLastArg);
1109e139cf23SCaroline Tice   return CommandObject::g_arguments_data;
1110e139cf23SCaroline Tice }
1111