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