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