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