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