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