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