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