1 //===-- CommandObject.cpp -------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "lldb/Interpreter/CommandObject.h"
10 
11 #include <map>
12 #include <sstream>
13 #include <string>
14 
15 #include <ctype.h>
16 #include <stdlib.h>
17 
18 #include "lldb/Core/Address.h"
19 #include "lldb/Interpreter/Options.h"
20 #include "lldb/Utility/ArchSpec.h"
21 
22 // These are for the Sourcename completers.
23 // FIXME: Make a separate file for the completers.
24 #include "lldb/Core/FileSpecList.h"
25 #include "lldb/DataFormatters/FormatManager.h"
26 #include "lldb/Target/Process.h"
27 #include "lldb/Target/Target.h"
28 #include "lldb/Utility/FileSpec.h"
29 
30 #include "lldb/Target/Language.h"
31 
32 #include "lldb/Interpreter/CommandInterpreter.h"
33 #include "lldb/Interpreter/CommandReturnObject.h"
34 
35 using namespace lldb;
36 using namespace lldb_private;
37 
38 // CommandObject
39 
40 CommandObject::CommandObject(CommandInterpreter &interpreter,
41                              llvm::StringRef name, llvm::StringRef help,
42                              llvm::StringRef syntax, uint32_t flags)
43     : m_interpreter(interpreter), m_cmd_name(std::string(name)),
44       m_cmd_help_short(), m_cmd_help_long(), m_cmd_syntax(), m_flags(flags),
45       m_arguments(), m_deprecated_command_override_callback(nullptr),
46       m_command_override_callback(nullptr), m_command_override_baton(nullptr) {
47   m_cmd_help_short = std::string(help);
48   m_cmd_syntax = std::string(syntax);
49 }
50 
51 CommandObject::~CommandObject() {}
52 
53 Debugger &CommandObject::GetDebugger() { return m_interpreter.GetDebugger(); }
54 
55 llvm::StringRef CommandObject::GetHelp() { return m_cmd_help_short; }
56 
57 llvm::StringRef CommandObject::GetHelpLong() { return m_cmd_help_long; }
58 
59 llvm::StringRef CommandObject::GetSyntax() {
60   if (!m_cmd_syntax.empty())
61     return m_cmd_syntax;
62 
63   StreamString syntax_str;
64   syntax_str.PutCString(GetCommandName());
65 
66   if (!IsDashDashCommand() && GetOptions() != nullptr)
67     syntax_str.PutCString(" <cmd-options>");
68 
69   if (!m_arguments.empty()) {
70     syntax_str.PutCString(" ");
71 
72     if (!IsDashDashCommand() && WantsRawCommandString() && GetOptions() &&
73         GetOptions()->NumCommandOptions())
74       syntax_str.PutCString("-- ");
75     GetFormattedCommandArguments(syntax_str);
76   }
77   m_cmd_syntax = std::string(syntax_str.GetString());
78 
79   return m_cmd_syntax;
80 }
81 
82 llvm::StringRef CommandObject::GetCommandName() const { return m_cmd_name; }
83 
84 void CommandObject::SetCommandName(llvm::StringRef name) {
85   m_cmd_name = std::string(name);
86 }
87 
88 void CommandObject::SetHelp(llvm::StringRef str) {
89   m_cmd_help_short = std::string(str);
90 }
91 
92 void CommandObject::SetHelpLong(llvm::StringRef str) {
93   m_cmd_help_long = std::string(str);
94 }
95 
96 void CommandObject::SetSyntax(llvm::StringRef str) {
97   m_cmd_syntax = std::string(str);
98 }
99 
100 Options *CommandObject::GetOptions() {
101   // By default commands don't have options unless this virtual function is
102   // overridden by base classes.
103   return nullptr;
104 }
105 
106 bool CommandObject::ParseOptions(Args &args, CommandReturnObject &result) {
107   // See if the subclass has options?
108   Options *options = GetOptions();
109   if (options != nullptr) {
110     Status error;
111 
112     auto exe_ctx = GetCommandInterpreter().GetExecutionContext();
113     options->NotifyOptionParsingStarting(&exe_ctx);
114 
115     const bool require_validation = true;
116     llvm::Expected<Args> args_or = options->Parse(
117         args, &exe_ctx, GetCommandInterpreter().GetPlatform(true),
118         require_validation);
119 
120     if (args_or) {
121       args = std::move(*args_or);
122       error = options->NotifyOptionParsingFinished(&exe_ctx);
123     } else
124       error = args_or.takeError();
125 
126     if (error.Success()) {
127       if (options->VerifyOptions(result))
128         return true;
129     } else {
130       const char *error_cstr = error.AsCString();
131       if (error_cstr) {
132         // We got an error string, lets use that
133         result.AppendError(error_cstr);
134       } else {
135         // No error string, output the usage information into result
136         options->GenerateOptionUsage(
137             result.GetErrorStream(), this,
138             GetCommandInterpreter().GetDebugger().GetTerminalWidth());
139       }
140     }
141     result.SetStatus(eReturnStatusFailed);
142     return false;
143   }
144   return true;
145 }
146 
147 bool CommandObject::CheckRequirements(CommandReturnObject &result) {
148   // Nothing should be stored in m_exe_ctx between running commands as
149   // m_exe_ctx has shared pointers to the target, process, thread and frame and
150   // we don't want any CommandObject instances to keep any of these objects
151   // around longer than for a single command. Every command should call
152   // CommandObject::Cleanup() after it has completed.
153   assert(!m_exe_ctx.GetTargetPtr());
154   assert(!m_exe_ctx.GetProcessPtr());
155   assert(!m_exe_ctx.GetThreadPtr());
156   assert(!m_exe_ctx.GetFramePtr());
157 
158   // Lock down the interpreter's execution context prior to running the command
159   // so we guarantee the selected target, process, thread and frame can't go
160   // away during the execution
161   m_exe_ctx = m_interpreter.GetExecutionContext();
162 
163   const uint32_t flags = GetFlags().Get();
164   if (flags & (eCommandRequiresTarget | eCommandRequiresProcess |
165                eCommandRequiresThread | eCommandRequiresFrame |
166                eCommandTryTargetAPILock)) {
167 
168     if ((flags & eCommandRequiresTarget) && !m_exe_ctx.HasTargetScope()) {
169       result.AppendError(GetInvalidTargetDescription());
170       return false;
171     }
172 
173     if ((flags & eCommandRequiresProcess) && !m_exe_ctx.HasProcessScope()) {
174       if (!m_exe_ctx.HasTargetScope())
175         result.AppendError(GetInvalidTargetDescription());
176       else
177         result.AppendError(GetInvalidProcessDescription());
178       return false;
179     }
180 
181     if ((flags & eCommandRequiresThread) && !m_exe_ctx.HasThreadScope()) {
182       if (!m_exe_ctx.HasTargetScope())
183         result.AppendError(GetInvalidTargetDescription());
184       else if (!m_exe_ctx.HasProcessScope())
185         result.AppendError(GetInvalidProcessDescription());
186       else
187         result.AppendError(GetInvalidThreadDescription());
188       return false;
189     }
190 
191     if ((flags & eCommandRequiresFrame) && !m_exe_ctx.HasFrameScope()) {
192       if (!m_exe_ctx.HasTargetScope())
193         result.AppendError(GetInvalidTargetDescription());
194       else if (!m_exe_ctx.HasProcessScope())
195         result.AppendError(GetInvalidProcessDescription());
196       else if (!m_exe_ctx.HasThreadScope())
197         result.AppendError(GetInvalidThreadDescription());
198       else
199         result.AppendError(GetInvalidFrameDescription());
200       return false;
201     }
202 
203     if ((flags & eCommandRequiresRegContext) &&
204         (m_exe_ctx.GetRegisterContext() == nullptr)) {
205       result.AppendError(GetInvalidRegContextDescription());
206       return false;
207     }
208 
209     if (flags & eCommandTryTargetAPILock) {
210       Target *target = m_exe_ctx.GetTargetPtr();
211       if (target)
212         m_api_locker =
213             std::unique_lock<std::recursive_mutex>(target->GetAPIMutex());
214     }
215   }
216 
217   if (GetFlags().AnySet(eCommandProcessMustBeLaunched |
218                         eCommandProcessMustBePaused)) {
219     Process *process = m_interpreter.GetExecutionContext().GetProcessPtr();
220     if (process == nullptr) {
221       // A process that is not running is considered paused.
222       if (GetFlags().Test(eCommandProcessMustBeLaunched)) {
223         result.AppendError("Process must exist.");
224         result.SetStatus(eReturnStatusFailed);
225         return false;
226       }
227     } else {
228       StateType state = process->GetState();
229       switch (state) {
230       case eStateInvalid:
231       case eStateSuspended:
232       case eStateCrashed:
233       case eStateStopped:
234         break;
235 
236       case eStateConnected:
237       case eStateAttaching:
238       case eStateLaunching:
239       case eStateDetached:
240       case eStateExited:
241       case eStateUnloaded:
242         if (GetFlags().Test(eCommandProcessMustBeLaunched)) {
243           result.AppendError("Process must be launched.");
244           result.SetStatus(eReturnStatusFailed);
245           return false;
246         }
247         break;
248 
249       case eStateRunning:
250       case eStateStepping:
251         if (GetFlags().Test(eCommandProcessMustBePaused)) {
252           result.AppendError("Process is running.  Use 'process interrupt' to "
253                              "pause execution.");
254           result.SetStatus(eReturnStatusFailed);
255           return false;
256         }
257       }
258     }
259   }
260   return true;
261 }
262 
263 void CommandObject::Cleanup() {
264   m_exe_ctx.Clear();
265   if (m_api_locker.owns_lock())
266     m_api_locker.unlock();
267 }
268 
269 void CommandObject::HandleCompletion(CompletionRequest &request) {
270   // Default implementation of WantsCompletion() is !WantsRawCommandString().
271   // Subclasses who want raw command string but desire, for example, argument
272   // completion should override WantsCompletion() to return true, instead.
273   if (WantsRawCommandString() && !WantsCompletion()) {
274     // FIXME: Abstract telling the completion to insert the completion
275     // character.
276     return;
277   } else {
278     // Can we do anything generic with the options?
279     Options *cur_options = GetOptions();
280     CommandReturnObject result;
281     OptionElementVector opt_element_vector;
282 
283     if (cur_options != nullptr) {
284       opt_element_vector = cur_options->ParseForCompletion(
285           request.GetParsedLine(), request.GetCursorIndex());
286 
287       bool handled_by_options = cur_options->HandleOptionCompletion(
288           request, opt_element_vector, GetCommandInterpreter());
289       if (handled_by_options)
290         return;
291     }
292 
293     // If we got here, the last word is not an option or an option argument.
294     HandleArgumentCompletion(request, opt_element_vector);
295   }
296 }
297 
298 bool CommandObject::HelpTextContainsWord(llvm::StringRef search_word,
299                                          bool search_short_help,
300                                          bool search_long_help,
301                                          bool search_syntax,
302                                          bool search_options) {
303   std::string options_usage_help;
304 
305   bool found_word = false;
306 
307   llvm::StringRef short_help = GetHelp();
308   llvm::StringRef long_help = GetHelpLong();
309   llvm::StringRef syntax_help = GetSyntax();
310 
311   if (search_short_help && short_help.contains_lower(search_word))
312     found_word = true;
313   else if (search_long_help && long_help.contains_lower(search_word))
314     found_word = true;
315   else if (search_syntax && syntax_help.contains_lower(search_word))
316     found_word = true;
317 
318   if (!found_word && search_options && GetOptions() != nullptr) {
319     StreamString usage_help;
320     GetOptions()->GenerateOptionUsage(
321         usage_help, this,
322         GetCommandInterpreter().GetDebugger().GetTerminalWidth());
323     if (!usage_help.Empty()) {
324       llvm::StringRef usage_text = usage_help.GetString();
325       if (usage_text.contains_lower(search_word))
326         found_word = true;
327     }
328   }
329 
330   return found_word;
331 }
332 
333 bool CommandObject::ParseOptionsAndNotify(Args &args,
334                                           CommandReturnObject &result,
335                                           OptionGroupOptions &group_options,
336                                           ExecutionContext &exe_ctx) {
337   if (!ParseOptions(args, result))
338     return false;
339 
340   Status error(group_options.NotifyOptionParsingFinished(&exe_ctx));
341   if (error.Fail()) {
342     result.AppendError(error.AsCString());
343     result.SetStatus(eReturnStatusFailed);
344     return false;
345   }
346   return true;
347 }
348 
349 int CommandObject::GetNumArgumentEntries() { return m_arguments.size(); }
350 
351 CommandObject::CommandArgumentEntry *
352 CommandObject::GetArgumentEntryAtIndex(int idx) {
353   if (static_cast<size_t>(idx) < m_arguments.size())
354     return &(m_arguments[idx]);
355 
356   return nullptr;
357 }
358 
359 const CommandObject::ArgumentTableEntry *
360 CommandObject::FindArgumentDataByType(CommandArgumentType arg_type) {
361   const ArgumentTableEntry *table = CommandObject::GetArgumentTable();
362 
363   for (int i = 0; i < eArgTypeLastArg; ++i)
364     if (table[i].arg_type == arg_type)
365       return &(table[i]);
366 
367   return nullptr;
368 }
369 
370 void CommandObject::GetArgumentHelp(Stream &str, CommandArgumentType arg_type,
371                                     CommandInterpreter &interpreter) {
372   const ArgumentTableEntry *table = CommandObject::GetArgumentTable();
373   const ArgumentTableEntry *entry = &(table[arg_type]);
374 
375   // The table is *supposed* to be kept in arg_type order, but someone *could*
376   // have messed it up...
377 
378   if (entry->arg_type != arg_type)
379     entry = CommandObject::FindArgumentDataByType(arg_type);
380 
381   if (!entry)
382     return;
383 
384   StreamString name_str;
385   name_str.Printf("<%s>", entry->arg_name);
386 
387   if (entry->help_function) {
388     llvm::StringRef help_text = entry->help_function();
389     if (!entry->help_function.self_formatting) {
390       interpreter.OutputFormattedHelpText(str, name_str.GetString(), "--",
391                                           help_text, name_str.GetSize());
392     } else {
393       interpreter.OutputHelpText(str, name_str.GetString(), "--", help_text,
394                                  name_str.GetSize());
395     }
396   } else
397     interpreter.OutputFormattedHelpText(str, name_str.GetString(), "--",
398                                         entry->help_text, name_str.GetSize());
399 }
400 
401 const char *CommandObject::GetArgumentName(CommandArgumentType arg_type) {
402   const ArgumentTableEntry *entry =
403       &(CommandObject::GetArgumentTable()[arg_type]);
404 
405   // The table is *supposed* to be kept in arg_type order, but someone *could*
406   // have messed it up...
407 
408   if (entry->arg_type != arg_type)
409     entry = CommandObject::FindArgumentDataByType(arg_type);
410 
411   if (entry)
412     return entry->arg_name;
413 
414   return nullptr;
415 }
416 
417 bool CommandObject::IsPairType(ArgumentRepetitionType arg_repeat_type) {
418   return (arg_repeat_type == eArgRepeatPairPlain) ||
419          (arg_repeat_type == eArgRepeatPairOptional) ||
420          (arg_repeat_type == eArgRepeatPairPlus) ||
421          (arg_repeat_type == eArgRepeatPairStar) ||
422          (arg_repeat_type == eArgRepeatPairRange) ||
423          (arg_repeat_type == eArgRepeatPairRangeOptional);
424 }
425 
426 static CommandObject::CommandArgumentEntry
427 OptSetFiltered(uint32_t opt_set_mask,
428                CommandObject::CommandArgumentEntry &cmd_arg_entry) {
429   CommandObject::CommandArgumentEntry ret_val;
430   for (unsigned i = 0; i < cmd_arg_entry.size(); ++i)
431     if (opt_set_mask & cmd_arg_entry[i].arg_opt_set_association)
432       ret_val.push_back(cmd_arg_entry[i]);
433   return ret_val;
434 }
435 
436 // Default parameter value of opt_set_mask is LLDB_OPT_SET_ALL, which means
437 // take all the argument data into account.  On rare cases where some argument
438 // sticks with certain option sets, this function returns the option set
439 // filtered args.
440 void CommandObject::GetFormattedCommandArguments(Stream &str,
441                                                  uint32_t opt_set_mask) {
442   int num_args = m_arguments.size();
443   for (int i = 0; i < num_args; ++i) {
444     if (i > 0)
445       str.Printf(" ");
446     CommandArgumentEntry arg_entry =
447         opt_set_mask == LLDB_OPT_SET_ALL
448             ? m_arguments[i]
449             : OptSetFiltered(opt_set_mask, m_arguments[i]);
450     int num_alternatives = arg_entry.size();
451 
452     if ((num_alternatives == 2) && IsPairType(arg_entry[0].arg_repetition)) {
453       const char *first_name = GetArgumentName(arg_entry[0].arg_type);
454       const char *second_name = GetArgumentName(arg_entry[1].arg_type);
455       switch (arg_entry[0].arg_repetition) {
456       case eArgRepeatPairPlain:
457         str.Printf("<%s> <%s>", first_name, second_name);
458         break;
459       case eArgRepeatPairOptional:
460         str.Printf("[<%s> <%s>]", first_name, second_name);
461         break;
462       case eArgRepeatPairPlus:
463         str.Printf("<%s> <%s> [<%s> <%s> [...]]", first_name, second_name,
464                    first_name, second_name);
465         break;
466       case eArgRepeatPairStar:
467         str.Printf("[<%s> <%s> [<%s> <%s> [...]]]", first_name, second_name,
468                    first_name, second_name);
469         break;
470       case eArgRepeatPairRange:
471         str.Printf("<%s_1> <%s_1> ... <%s_n> <%s_n>", first_name, second_name,
472                    first_name, second_name);
473         break;
474       case eArgRepeatPairRangeOptional:
475         str.Printf("[<%s_1> <%s_1> ... <%s_n> <%s_n>]", first_name, second_name,
476                    first_name, second_name);
477         break;
478       // Explicitly test for all the rest of the cases, so if new types get
479       // added we will notice the missing case statement(s).
480       case eArgRepeatPlain:
481       case eArgRepeatOptional:
482       case eArgRepeatPlus:
483       case eArgRepeatStar:
484       case eArgRepeatRange:
485         // These should not be reached, as they should fail the IsPairType test
486         // above.
487         break;
488       }
489     } else {
490       StreamString names;
491       for (int j = 0; j < num_alternatives; ++j) {
492         if (j > 0)
493           names.Printf(" | ");
494         names.Printf("%s", GetArgumentName(arg_entry[j].arg_type));
495       }
496 
497       std::string name_str = std::string(names.GetString());
498       switch (arg_entry[0].arg_repetition) {
499       case eArgRepeatPlain:
500         str.Printf("<%s>", name_str.c_str());
501         break;
502       case eArgRepeatPlus:
503         str.Printf("<%s> [<%s> [...]]", name_str.c_str(), name_str.c_str());
504         break;
505       case eArgRepeatStar:
506         str.Printf("[<%s> [<%s> [...]]]", name_str.c_str(), name_str.c_str());
507         break;
508       case eArgRepeatOptional:
509         str.Printf("[<%s>]", name_str.c_str());
510         break;
511       case eArgRepeatRange:
512         str.Printf("<%s_1> .. <%s_n>", name_str.c_str(), name_str.c_str());
513         break;
514       // Explicitly test for all the rest of the cases, so if new types get
515       // added we will notice the missing case statement(s).
516       case eArgRepeatPairPlain:
517       case eArgRepeatPairOptional:
518       case eArgRepeatPairPlus:
519       case eArgRepeatPairStar:
520       case eArgRepeatPairRange:
521       case eArgRepeatPairRangeOptional:
522         // These should not be hit, as they should pass the IsPairType test
523         // above, and control should have gone into the other branch of the if
524         // statement.
525         break;
526       }
527     }
528   }
529 }
530 
531 CommandArgumentType
532 CommandObject::LookupArgumentName(llvm::StringRef arg_name) {
533   CommandArgumentType return_type = eArgTypeLastArg;
534 
535   arg_name = arg_name.ltrim('<').rtrim('>');
536 
537   const ArgumentTableEntry *table = GetArgumentTable();
538   for (int i = 0; i < eArgTypeLastArg; ++i)
539     if (arg_name == table[i].arg_name)
540       return_type = g_arguments_data[i].arg_type;
541 
542   return return_type;
543 }
544 
545 static llvm::StringRef RegisterNameHelpTextCallback() {
546   return "Register names can be specified using the architecture specific "
547          "names.  "
548          "They can also be specified using generic names.  Not all generic "
549          "entities have "
550          "registers backing them on all architectures.  When they don't the "
551          "generic name "
552          "will return an error.\n"
553          "The generic names defined in lldb are:\n"
554          "\n"
555          "pc       - program counter register\n"
556          "ra       - return address register\n"
557          "fp       - frame pointer register\n"
558          "sp       - stack pointer register\n"
559          "flags    - the flags register\n"
560          "arg{1-6} - integer argument passing registers.\n";
561 }
562 
563 static llvm::StringRef BreakpointIDHelpTextCallback() {
564   return "Breakpoints are identified using major and minor numbers; the major "
565          "number corresponds to the single entity that was created with a "
566          "'breakpoint "
567          "set' command; the minor numbers correspond to all the locations that "
568          "were "
569          "actually found/set based on the major breakpoint.  A full breakpoint "
570          "ID might "
571          "look like 3.14, meaning the 14th location set for the 3rd "
572          "breakpoint.  You "
573          "can specify all the locations of a breakpoint by just indicating the "
574          "major "
575          "breakpoint number. A valid breakpoint ID consists either of just the "
576          "major "
577          "number, or the major number followed by a dot and the location "
578          "number (e.g. "
579          "3 or 3.2 could both be valid breakpoint IDs.)";
580 }
581 
582 static llvm::StringRef BreakpointIDRangeHelpTextCallback() {
583   return "A 'breakpoint ID list' is a manner of specifying multiple "
584          "breakpoints. "
585          "This can be done through several mechanisms.  The easiest way is to "
586          "just "
587          "enter a space-separated list of breakpoint IDs.  To specify all the "
588          "breakpoint locations under a major breakpoint, you can use the major "
589          "breakpoint number followed by '.*', eg. '5.*' means all the "
590          "locations under "
591          "breakpoint 5.  You can also indicate a range of breakpoints by using "
592          "<start-bp-id> - <end-bp-id>.  The start-bp-id and end-bp-id for a "
593          "range can "
594          "be any valid breakpoint IDs.  It is not legal, however, to specify a "
595          "range "
596          "using specific locations that cross major breakpoint numbers.  I.e. "
597          "3.2 - 3.7"
598          " is legal; 2 - 5 is legal; but 3.2 - 4.4 is not legal.";
599 }
600 
601 static llvm::StringRef BreakpointNameHelpTextCallback() {
602   return "A name that can be added to a breakpoint when it is created, or "
603          "later "
604          "on with the \"breakpoint name add\" command.  "
605          "Breakpoint names can be used to specify breakpoints in all the "
606          "places breakpoint IDs "
607          "and breakpoint ID ranges can be used.  As such they provide a "
608          "convenient way to group breakpoints, "
609          "and to operate on breakpoints you create without having to track the "
610          "breakpoint number.  "
611          "Note, the attributes you set when using a breakpoint name in a "
612          "breakpoint command don't "
613          "adhere to the name, but instead are set individually on all the "
614          "breakpoints currently tagged with that "
615          "name.  Future breakpoints "
616          "tagged with that name will not pick up the attributes previously "
617          "given using that name.  "
618          "In order to distinguish breakpoint names from breakpoint IDs and "
619          "ranges, "
620          "names must start with a letter from a-z or A-Z and cannot contain "
621          "spaces, \".\" or \"-\".  "
622          "Also, breakpoint names can only be applied to breakpoints, not to "
623          "breakpoint locations.";
624 }
625 
626 static llvm::StringRef GDBFormatHelpTextCallback() {
627   return "A GDB format consists of a repeat count, a format letter and a size "
628          "letter. "
629          "The repeat count is optional and defaults to 1. The format letter is "
630          "optional "
631          "and defaults to the previous format that was used. The size letter "
632          "is optional "
633          "and defaults to the previous size that was used.\n"
634          "\n"
635          "Format letters include:\n"
636          "o - octal\n"
637          "x - hexadecimal\n"
638          "d - decimal\n"
639          "u - unsigned decimal\n"
640          "t - binary\n"
641          "f - float\n"
642          "a - address\n"
643          "i - instruction\n"
644          "c - char\n"
645          "s - string\n"
646          "T - OSType\n"
647          "A - float as hex\n"
648          "\n"
649          "Size letters include:\n"
650          "b - 1 byte  (byte)\n"
651          "h - 2 bytes (halfword)\n"
652          "w - 4 bytes (word)\n"
653          "g - 8 bytes (giant)\n"
654          "\n"
655          "Example formats:\n"
656          "32xb - show 32 1 byte hexadecimal integer values\n"
657          "16xh - show 16 2 byte hexadecimal integer values\n"
658          "64   - show 64 2 byte hexadecimal integer values (format and size "
659          "from the last format)\n"
660          "dw   - show 1 4 byte decimal integer value\n";
661 }
662 
663 static llvm::StringRef FormatHelpTextCallback() {
664   static std::string help_text;
665 
666   if (!help_text.empty())
667     return help_text;
668 
669   StreamString sstr;
670   sstr << "One of the format names (or one-character names) that can be used "
671           "to show a variable's value:\n";
672   for (Format f = eFormatDefault; f < kNumFormats; f = Format(f + 1)) {
673     if (f != eFormatDefault)
674       sstr.PutChar('\n');
675 
676     char format_char = FormatManager::GetFormatAsFormatChar(f);
677     if (format_char)
678       sstr.Printf("'%c' or ", format_char);
679 
680     sstr.Printf("\"%s\"", FormatManager::GetFormatAsCString(f));
681   }
682 
683   sstr.Flush();
684 
685   help_text = std::string(sstr.GetString());
686 
687   return help_text;
688 }
689 
690 static llvm::StringRef LanguageTypeHelpTextCallback() {
691   static std::string help_text;
692 
693   if (!help_text.empty())
694     return help_text;
695 
696   StreamString sstr;
697   sstr << "One of the following languages:\n";
698 
699   Language::PrintAllLanguages(sstr, "  ", "\n");
700 
701   sstr.Flush();
702 
703   help_text = std::string(sstr.GetString());
704 
705   return help_text;
706 }
707 
708 static llvm::StringRef SummaryStringHelpTextCallback() {
709   return "A summary string is a way to extract information from variables in "
710          "order to present them using a summary.\n"
711          "Summary strings contain static text, variables, scopes and control "
712          "sequences:\n"
713          "  - Static text can be any sequence of non-special characters, i.e. "
714          "anything but '{', '}', '$', or '\\'.\n"
715          "  - Variables are sequences of characters beginning with ${, ending "
716          "with } and that contain symbols in the format described below.\n"
717          "  - Scopes are any sequence of text between { and }. Anything "
718          "included in a scope will only appear in the output summary if there "
719          "were no errors.\n"
720          "  - Control sequences are the usual C/C++ '\\a', '\\n', ..., plus "
721          "'\\$', '\\{' and '\\}'.\n"
722          "A summary string works by copying static text verbatim, turning "
723          "control sequences into their character counterpart, expanding "
724          "variables and trying to expand scopes.\n"
725          "A variable is expanded by giving it a value other than its textual "
726          "representation, and the way this is done depends on what comes after "
727          "the ${ marker.\n"
728          "The most common sequence if ${var followed by an expression path, "
729          "which is the text one would type to access a member of an aggregate "
730          "types, given a variable of that type"
731          " (e.g. if type T has a member named x, which has a member named y, "
732          "and if t is of type T, the expression path would be .x.y and the way "
733          "to fit that into a summary string would be"
734          " ${var.x.y}). You can also use ${*var followed by an expression path "
735          "and in that case the object referred by the path will be "
736          "dereferenced before being displayed."
737          " If the object is not a pointer, doing so will cause an error. For "
738          "additional details on expression paths, you can type 'help "
739          "expr-path'. \n"
740          "By default, summary strings attempt to display the summary for any "
741          "variable they reference, and if that fails the value. If neither can "
742          "be shown, nothing is displayed."
743          "In a summary string, you can also use an array index [n], or a "
744          "slice-like range [n-m]. This can have two different meanings "
745          "depending on what kind of object the expression"
746          " path refers to:\n"
747          "  - if it is a scalar type (any basic type like int, float, ...) the "
748          "expression is a bitfield, i.e. the bits indicated by the indexing "
749          "operator are extracted out of the number"
750          " and displayed as an individual variable\n"
751          "  - if it is an array or pointer the array items indicated by the "
752          "indexing operator are shown as the result of the variable. if the "
753          "expression is an array, real array items are"
754          " printed; if it is a pointer, the pointer-as-array syntax is used to "
755          "obtain the values (this means, the latter case can have no range "
756          "checking)\n"
757          "If you are trying to display an array for which the size is known, "
758          "you can also use [] instead of giving an exact range. This has the "
759          "effect of showing items 0 thru size - 1.\n"
760          "Additionally, a variable can contain an (optional) format code, as "
761          "in ${var.x.y%code}, where code can be any of the valid formats "
762          "described in 'help format', or one of the"
763          " special symbols only allowed as part of a variable:\n"
764          "    %V: show the value of the object by default\n"
765          "    %S: show the summary of the object by default\n"
766          "    %@: show the runtime-provided object description (for "
767          "Objective-C, it calls NSPrintForDebugger; for C/C++ it does "
768          "nothing)\n"
769          "    %L: show the location of the object (memory address or a "
770          "register name)\n"
771          "    %#: show the number of children of the object\n"
772          "    %T: show the type of the object\n"
773          "Another variable that you can use in summary strings is ${svar . "
774          "This sequence works exactly like ${var, including the fact that "
775          "${*svar is an allowed sequence, but uses"
776          " the object's synthetic children provider instead of the actual "
777          "objects. For instance, if you are using STL synthetic children "
778          "providers, the following summary string would"
779          " count the number of actual elements stored in an std::list:\n"
780          "type summary add -s \"${svar%#}\" -x \"std::list<\"";
781 }
782 
783 static llvm::StringRef ExprPathHelpTextCallback() {
784   return "An expression path is the sequence of symbols that is used in C/C++ "
785          "to access a member variable of an aggregate object (class).\n"
786          "For instance, given a class:\n"
787          "  class foo {\n"
788          "      int a;\n"
789          "      int b; .\n"
790          "      foo* next;\n"
791          "  };\n"
792          "the expression to read item b in the item pointed to by next for foo "
793          "aFoo would be aFoo.next->b.\n"
794          "Given that aFoo could just be any object of type foo, the string "
795          "'.next->b' is the expression path, because it can be attached to any "
796          "foo instance to achieve the effect.\n"
797          "Expression paths in LLDB include dot (.) and arrow (->) operators, "
798          "and most commands using expression paths have ways to also accept "
799          "the star (*) operator.\n"
800          "The meaning of these operators is the same as the usual one given to "
801          "them by the C/C++ standards.\n"
802          "LLDB also has support for indexing ([ ]) in expression paths, and "
803          "extends the traditional meaning of the square brackets operator to "
804          "allow bitfield extraction:\n"
805          "for objects of native types (int, float, char, ...) saying '[n-m]' "
806          "as an expression path (where n and m are any positive integers, e.g. "
807          "[3-5]) causes LLDB to extract"
808          " bits n thru m from the value of the variable. If n == m, [n] is "
809          "also allowed as a shortcut syntax. For arrays and pointers, "
810          "expression paths can only contain one index"
811          " and the meaning of the operation is the same as the one defined by "
812          "C/C++ (item extraction). Some commands extend bitfield-like syntax "
813          "for arrays and pointers with the"
814          " meaning of array slicing (taking elements n thru m inside the array "
815          "or pointed-to memory).";
816 }
817 
818 void CommandObject::FormatLongHelpText(Stream &output_strm,
819                                        llvm::StringRef long_help) {
820   CommandInterpreter &interpreter = GetCommandInterpreter();
821   std::stringstream lineStream{std::string(long_help)};
822   std::string line;
823   while (std::getline(lineStream, line)) {
824     if (line.empty()) {
825       output_strm << "\n";
826       continue;
827     }
828     size_t result = line.find_first_not_of(" \t");
829     if (result == std::string::npos) {
830       result = 0;
831     }
832     std::string whitespace_prefix = line.substr(0, result);
833     std::string remainder = line.substr(result);
834     interpreter.OutputFormattedHelpText(output_strm, whitespace_prefix.c_str(),
835                                         remainder.c_str());
836   }
837 }
838 
839 void CommandObject::GenerateHelpText(CommandReturnObject &result) {
840   GenerateHelpText(result.GetOutputStream());
841 
842   result.SetStatus(eReturnStatusSuccessFinishNoResult);
843 }
844 
845 void CommandObject::GenerateHelpText(Stream &output_strm) {
846   CommandInterpreter &interpreter = GetCommandInterpreter();
847   if (WantsRawCommandString()) {
848     std::string help_text(GetHelp());
849     help_text.append("  Expects 'raw' input (see 'help raw-input'.)");
850     interpreter.OutputFormattedHelpText(output_strm, "", "", help_text.c_str(),
851                                         1);
852   } else
853     interpreter.OutputFormattedHelpText(output_strm, "", "", GetHelp(), 1);
854   output_strm << "\nSyntax: " << GetSyntax() << "\n";
855   Options *options = GetOptions();
856   if (options != nullptr) {
857     options->GenerateOptionUsage(
858         output_strm, this,
859         GetCommandInterpreter().GetDebugger().GetTerminalWidth());
860   }
861   llvm::StringRef long_help = GetHelpLong();
862   if (!long_help.empty()) {
863     FormatLongHelpText(output_strm, long_help);
864   }
865   if (!IsDashDashCommand() && options && options->NumCommandOptions() > 0) {
866     if (WantsRawCommandString() && !WantsCompletion()) {
867       // Emit the message about using ' -- ' between the end of the command
868       // options and the raw input conditionally, i.e., only if the command
869       // object does not want completion.
870       interpreter.OutputFormattedHelpText(
871           output_strm, "", "",
872           "\nImportant Note: Because this command takes 'raw' input, if you "
873           "use any command options"
874           " you must use ' -- ' between the end of the command options and the "
875           "beginning of the raw input.",
876           1);
877     } else if (GetNumArgumentEntries() > 0) {
878       // Also emit a warning about using "--" in case you are using a command
879       // that takes options and arguments.
880       interpreter.OutputFormattedHelpText(
881           output_strm, "", "",
882           "\nThis command takes options and free-form arguments.  If your "
883           "arguments resemble"
884           " option specifiers (i.e., they start with a - or --), you must use "
885           "' -- ' between"
886           " the end of the command options and the beginning of the arguments.",
887           1);
888     }
889   }
890 }
891 
892 void CommandObject::AddIDsArgumentData(CommandArgumentEntry &arg,
893                                        CommandArgumentType ID,
894                                        CommandArgumentType IDRange) {
895   CommandArgumentData id_arg;
896   CommandArgumentData id_range_arg;
897 
898   // Create the first variant for the first (and only) argument for this
899   // command.
900   id_arg.arg_type = ID;
901   id_arg.arg_repetition = eArgRepeatOptional;
902 
903   // Create the second variant for the first (and only) argument for this
904   // command.
905   id_range_arg.arg_type = IDRange;
906   id_range_arg.arg_repetition = eArgRepeatOptional;
907 
908   // The first (and only) argument for this command could be either an id or an
909   // id_range. Push both variants into the entry for the first argument for
910   // this command.
911   arg.push_back(id_arg);
912   arg.push_back(id_range_arg);
913 }
914 
915 const char *CommandObject::GetArgumentTypeAsCString(
916     const lldb::CommandArgumentType arg_type) {
917   assert(arg_type < eArgTypeLastArg &&
918          "Invalid argument type passed to GetArgumentTypeAsCString");
919   return g_arguments_data[arg_type].arg_name;
920 }
921 
922 const char *CommandObject::GetArgumentDescriptionAsCString(
923     const lldb::CommandArgumentType arg_type) {
924   assert(arg_type < eArgTypeLastArg &&
925          "Invalid argument type passed to GetArgumentDescriptionAsCString");
926   return g_arguments_data[arg_type].help_text;
927 }
928 
929 Target &CommandObject::GetDummyTarget() {
930   return *m_interpreter.GetDebugger().GetDummyTarget();
931 }
932 
933 Target &CommandObject::GetSelectedOrDummyTarget(bool prefer_dummy) {
934   return *m_interpreter.GetDebugger().GetSelectedOrDummyTarget(prefer_dummy);
935 }
936 
937 Target &CommandObject::GetSelectedTarget() {
938   assert(m_flags.AnySet(eCommandRequiresTarget | eCommandProcessMustBePaused |
939                         eCommandProcessMustBeLaunched | eCommandRequiresFrame |
940                         eCommandRequiresThread | eCommandRequiresProcess |
941                         eCommandRequiresRegContext) &&
942          "GetSelectedTarget called from object that may have no target");
943   return *m_interpreter.GetDebugger().GetSelectedTarget();
944 }
945 
946 Thread *CommandObject::GetDefaultThread() {
947   Thread *thread_to_use = m_exe_ctx.GetThreadPtr();
948   if (thread_to_use)
949     return thread_to_use;
950 
951   Process *process = m_exe_ctx.GetProcessPtr();
952   if (!process) {
953     Target *target = m_exe_ctx.GetTargetPtr();
954     if (!target) {
955       target = m_interpreter.GetDebugger().GetSelectedTarget().get();
956     }
957     if (target)
958       process = target->GetProcessSP().get();
959   }
960 
961   if (process)
962     return process->GetThreadList().GetSelectedThread().get();
963   else
964     return nullptr;
965 }
966 
967 bool CommandObjectParsed::Execute(const char *args_string,
968                                   CommandReturnObject &result) {
969   bool handled = false;
970   Args cmd_args(args_string);
971   if (HasOverrideCallback()) {
972     Args full_args(GetCommandName());
973     full_args.AppendArguments(cmd_args);
974     handled =
975         InvokeOverrideCallback(full_args.GetConstArgumentVector(), result);
976   }
977   if (!handled) {
978     for (auto entry : llvm::enumerate(cmd_args.entries())) {
979       if (!entry.value().ref().empty() && entry.value().ref().front() == '`') {
980         cmd_args.ReplaceArgumentAtIndex(
981             entry.index(),
982             m_interpreter.ProcessEmbeddedScriptCommands(entry.value().c_str()));
983       }
984     }
985 
986     if (CheckRequirements(result)) {
987       if (ParseOptions(cmd_args, result)) {
988         // Call the command-specific version of 'Execute', passing it the
989         // already processed arguments.
990         handled = DoExecute(cmd_args, result);
991       }
992     }
993 
994     Cleanup();
995   }
996   return handled;
997 }
998 
999 bool CommandObjectRaw::Execute(const char *args_string,
1000                                CommandReturnObject &result) {
1001   bool handled = false;
1002   if (HasOverrideCallback()) {
1003     std::string full_command(GetCommandName());
1004     full_command += ' ';
1005     full_command += args_string;
1006     const char *argv[2] = {nullptr, nullptr};
1007     argv[0] = full_command.c_str();
1008     handled = InvokeOverrideCallback(argv, result);
1009   }
1010   if (!handled) {
1011     if (CheckRequirements(result))
1012       handled = DoExecute(args_string, result);
1013 
1014     Cleanup();
1015   }
1016   return handled;
1017 }
1018 
1019 static llvm::StringRef arch_helper() {
1020   static StreamString g_archs_help;
1021   if (g_archs_help.Empty()) {
1022     StringList archs;
1023 
1024     ArchSpec::ListSupportedArchNames(archs);
1025     g_archs_help.Printf("These are the supported architecture names:\n");
1026     archs.Join("\n", g_archs_help);
1027   }
1028   return g_archs_help.GetString();
1029 }
1030 
1031 CommandObject::ArgumentTableEntry CommandObject::g_arguments_data[] = {
1032     // clang-format off
1033     { eArgTypeAddress, "address", CommandCompletions::eNoCompletion, { nullptr, false }, "A valid address in the target program's execution space." },
1034     { eArgTypeAddressOrExpression, "address-expression", CommandCompletions::eNoCompletion, { nullptr, false }, "An expression that resolves to an address." },
1035     { eArgTypeAliasName, "alias-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of an abbreviation (alias) for a debugger command." },
1036     { 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.)" },
1037     { eArgTypeArchitecture, "arch", CommandCompletions::eArchitectureCompletion, { arch_helper, true }, "The architecture name, e.g. i386 or x86_64." },
1038     { eArgTypeBoolean, "boolean", CommandCompletions::eNoCompletion, { nullptr, false }, "A Boolean value: 'true' or 'false'" },
1039     { eArgTypeBreakpointID, "breakpt-id", CommandCompletions::eNoCompletion, { BreakpointIDHelpTextCallback, false }, nullptr },
1040     { eArgTypeBreakpointIDRange, "breakpt-id-list", CommandCompletions::eNoCompletion, { BreakpointIDRangeHelpTextCallback, false }, nullptr },
1041     { eArgTypeBreakpointName, "breakpoint-name", CommandCompletions::eNoCompletion, { BreakpointNameHelpTextCallback, false }, nullptr },
1042     { eArgTypeByteSize, "byte-size", CommandCompletions::eNoCompletion, { nullptr, false }, "Number of bytes to use." },
1043     { eArgTypeClassName, "class-name", CommandCompletions::eNoCompletion, { nullptr, false }, "Then name of a class from the debug information in the program." },
1044     { eArgTypeCommandName, "cmd-name", CommandCompletions::eNoCompletion, { nullptr, false }, "A debugger command (may be multiple words), without any options or arguments." },
1045     { eArgTypeCount, "count", CommandCompletions::eNoCompletion, { nullptr, false }, "An unsigned integer." },
1046     { eArgTypeDirectoryName, "directory", CommandCompletions::eDiskDirectoryCompletion, { nullptr, false }, "A directory name." },
1047     { 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" },
1048     { eArgTypeDescriptionVerbosity, "description-verbosity", CommandCompletions::eNoCompletion, { nullptr, false }, "How verbose the output of 'po' should be." },
1049     { eArgTypeEndAddress, "end-address", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
1050     { eArgTypeExpression, "expr", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
1051     { eArgTypeExpressionPath, "expr-path", CommandCompletions::eNoCompletion, { ExprPathHelpTextCallback, true }, nullptr },
1052     { eArgTypeExprFormat, "expression-format", CommandCompletions::eNoCompletion, { nullptr, false }, "[ [bool|b] | [bin] | [char|c] | [oct|o] | [dec|i|d|u] | [hex|x] | [float|f] | [cstr|s] ]" },
1053     { eArgTypeFilename, "filename", CommandCompletions::eDiskFileCompletion, { nullptr, false }, "The name of a file (can include path)." },
1054     { eArgTypeFormat, "format", CommandCompletions::eNoCompletion, { FormatHelpTextCallback, true }, nullptr },
1055     { eArgTypeFrameIndex, "frame-index", CommandCompletions::eNoCompletion, { nullptr, false }, "Index into a thread's list of frames." },
1056     { eArgTypeFullName, "fullname", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
1057     { eArgTypeFunctionName, "function-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a function." },
1058     { eArgTypeFunctionOrSymbol, "function-or-symbol", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a function or symbol." },
1059     { eArgTypeGDBFormat, "gdb-format", CommandCompletions::eNoCompletion, { GDBFormatHelpTextCallback, true }, nullptr },
1060     { eArgTypeHelpText, "help-text", CommandCompletions::eNoCompletion, { nullptr, false }, "Text to be used as help for some other entity in LLDB" },
1061     { eArgTypeIndex, "index", CommandCompletions::eNoCompletion, { nullptr, false }, "An index into a list." },
1062     { eArgTypeLanguage, "source-language", CommandCompletions::eNoCompletion, { LanguageTypeHelpTextCallback, true }, nullptr },
1063     { eArgTypeLineNum, "linenum", CommandCompletions::eNoCompletion, { nullptr, false }, "Line number in a source file." },
1064     { 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." },
1065     { 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)." },
1066     { eArgTypeMethod, "method", CommandCompletions::eNoCompletion, { nullptr, false }, "A C++ method name." },
1067     { eArgTypeName, "name", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
1068     { eArgTypeNewPathPrefix, "new-path-prefix", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
1069     { eArgTypeNumLines, "num-lines", CommandCompletions::eNoCompletion, { nullptr, false }, "The number of lines to use." },
1070     { eArgTypeNumberPerLine, "number-per-line", CommandCompletions::eNoCompletion, { nullptr, false }, "The number of items per line to display." },
1071     { eArgTypeOffset, "offset", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
1072     { eArgTypeOldPathPrefix, "old-path-prefix", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
1073     { eArgTypeOneLiner, "one-line-command", CommandCompletions::eNoCompletion, { nullptr, false }, "A command that is entered as a single line of text." },
1074     { eArgTypePath, "path", CommandCompletions::eDiskFileCompletion, { nullptr, false }, "Path." },
1075     { eArgTypePermissionsNumber, "perms-numeric", CommandCompletions::eNoCompletion, { nullptr, false }, "Permissions given as an octal number (e.g. 755)." },
1076     { eArgTypePermissionsString, "perms=string", CommandCompletions::eNoCompletion, { nullptr, false }, "Permissions given as a string value (e.g. rw-r-xr--)." },
1077     { eArgTypePid, "pid", CommandCompletions::eNoCompletion, { nullptr, false }, "The process ID number." },
1078     { eArgTypePlugin, "plugin", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
1079     { eArgTypeProcessName, "process-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of the process." },
1080     { eArgTypePythonClass, "python-class", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a Python class." },
1081     { eArgTypePythonFunction, "python-function", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a Python function." },
1082     { eArgTypePythonScript, "python-script", CommandCompletions::eNoCompletion, { nullptr, false }, "Source code written in Python." },
1083     { eArgTypeQueueName, "queue-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of the thread queue." },
1084     { eArgTypeRegisterName, "register-name", CommandCompletions::eNoCompletion, { RegisterNameHelpTextCallback, true }, nullptr },
1085     { eArgTypeRegularExpression, "regular-expression", CommandCompletions::eNoCompletion, { nullptr, false }, "A POSIX-compliant extended regular expression." },
1086     { eArgTypeRunArgs, "run-args", CommandCompletions::eNoCompletion, { nullptr, false }, "Arguments to be passed to the target program when it starts executing." },
1087     { eArgTypeRunMode, "run-mode", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
1088     { eArgTypeScriptedCommandSynchronicity, "script-cmd-synchronicity", CommandCompletions::eNoCompletion, { nullptr, false }, "The synchronicity to use to run scripted commands with regard to LLDB event system." },
1089     { eArgTypeScriptLang, "script-language", CommandCompletions::eNoCompletion, { nullptr, false }, "The scripting language to be used for script-based commands.  Currently only Python is valid." },
1090     { eArgTypeSearchWord, "search-word", CommandCompletions::eNoCompletion, { nullptr, false }, "Any word of interest for search purposes." },
1091     { eArgTypeSelector, "selector", CommandCompletions::eNoCompletion, { nullptr, false }, "An Objective-C selector name." },
1092     { 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)." },
1093     { 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)." },
1094     { eArgTypeSettingPrefix, "setting-prefix", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a settable internal debugger variable up to a dot ('.'), e.g. 'target.process.'" },
1095     { 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." },
1096     { eArgTypeShlibName, "shlib-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a shared library." },
1097     { eArgTypeSourceFile, "source-file", CommandCompletions::eSourceFileCompletion, { nullptr, false }, "The name of a source file.." },
1098     { eArgTypeSortOrder, "sort-order", CommandCompletions::eNoCompletion, { nullptr, false }, "Specify a sort order when dumping lists." },
1099     { eArgTypeStartAddress, "start-address", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
1100     { eArgTypeSummaryString, "summary-string", CommandCompletions::eNoCompletion, { SummaryStringHelpTextCallback, true }, nullptr },
1101     { eArgTypeSymbol, "symbol", CommandCompletions::eSymbolCompletion, { nullptr, false }, "Any symbol name (function name, variable, argument, etc.)" },
1102     { eArgTypeThreadID, "thread-id", CommandCompletions::eNoCompletion, { nullptr, false }, "Thread ID number." },
1103     { eArgTypeThreadIndex, "thread-index", CommandCompletions::eNoCompletion, { nullptr, false }, "Index into the process' list of threads." },
1104     { eArgTypeThreadName, "thread-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The thread's name." },
1105     { eArgTypeTypeName, "type-name", CommandCompletions::eNoCompletion, { nullptr, false }, "A type name." },
1106     { eArgTypeUnsignedInteger, "unsigned-integer", CommandCompletions::eNoCompletion, { nullptr, false }, "An unsigned integer." },
1107     { eArgTypeUnixSignal, "unix-signal", CommandCompletions::eNoCompletion, { nullptr, false }, "A valid Unix signal name or number (e.g. SIGKILL, KILL or 9)." },
1108     { eArgTypeVarName, "variable-name", CommandCompletions::eNoCompletion, { nullptr, false }, "The name of a variable in your program." },
1109     { eArgTypeValue, "value", CommandCompletions::eNoCompletion, { nullptr, false }, "A value could be anything, depending on where and how it is used." },
1110     { eArgTypeWidth, "width", CommandCompletions::eNoCompletion, { nullptr, false }, "Help text goes here." },
1111     { eArgTypeNone, "none", CommandCompletions::eNoCompletion, { nullptr, false }, "No help available for this." },
1112     { 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." },
1113     { eArgTypeWatchpointID, "watchpt-id", CommandCompletions::eNoCompletion, { nullptr, false }, "Watchpoint IDs are positive integers." },
1114     { eArgTypeWatchpointIDRange, "watchpt-id-list", CommandCompletions::eNoCompletion, { nullptr, false }, "For example, '1-3' or '1 to 3'." },
1115     { eArgTypeWatchType, "watch-type", CommandCompletions::eNoCompletion, { nullptr, false }, "Specify the type for a watchpoint." },
1116     { eArgRawInput, "raw-input", CommandCompletions::eNoCompletion, { nullptr, false }, "Free-form text passed to a command without prior interpretation, allowing spaces without requiring quotes.  To pass arguments and free form text put two dashes ' -- ' between the last argument and any raw input." },
1117     { eArgTypeCommand, "command", CommandCompletions::eNoCompletion, { nullptr, false }, "An LLDB Command line command." },
1118     { eArgTypeColumnNum, "column", CommandCompletions::eNoCompletion, { nullptr, false }, "Column number in a source file." }
1119     // clang-format on
1120 };
1121 
1122 const CommandObject::ArgumentTableEntry *CommandObject::GetArgumentTable() {
1123   // If this assertion fires, then the table above is out of date with the
1124   // CommandArgumentType enumeration
1125   static_assert((sizeof(CommandObject::g_arguments_data) /
1126                  sizeof(CommandObject::ArgumentTableEntry)) == eArgTypeLastArg,
1127                 "");
1128   return CommandObject::g_arguments_data;
1129 }
1130