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