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