55 #include "lldb/Host/Config.h"
56 #if LLDB_ENABLE_LIBEDIT
79 #include "llvm/ADT/STLExtras.h"
80 #include "llvm/ADT/ScopeExit.h"
81 #include "llvm/ADT/SmallString.h"
82 #include "llvm/Support/FormatAdapters.h"
83 #include "llvm/Support/Path.h"
84 #include "llvm/Support/PrettyStackTrace.h"
85 #include "llvm/Support/ScopedPrinter.h"
87 #if defined(__APPLE__)
88 #include <TargetConditionals.h>
97 "There is a .lldbinit file in the current directory which is not being "
99 "To silence this warning without sourcing in the local .lldbinit,\n"
100 "add the following to the lldbinit file in your home directory:\n"
101 " settings set target.load-cwd-lldbinit false\n"
102 "To allow lldb to source .lldbinit files in the current working "
104 "set the value of this variable to true. Only do so if you understand "
106 "accept the security risk.";
108 #define LLDB_PROPERTIES_interpreter
109 #include "InterpreterProperties.inc"
112 #define LLDB_PROPERTIES_interpreter
113 #include "InterpreterPropertiesEnum.inc"
117 static ConstString class_name(
"lldb.commandInterpreter");
121 CommandInterpreter::CommandInterpreter(
Debugger &debugger,
122 bool synchronous_execution)
128 m_debugger(debugger), m_synchronous_execution(true),
129 m_skip_lldbinit_files(false), m_skip_app_init_files(false),
130 m_comment_char(
'#'), m_batch_command_mode(false),
131 m_truncation_warning(eNoOmission), m_max_depth_warning(eNoOmission),
132 m_command_source_depth(0) {
142 const uint32_t idx = ePropertyExpandRegexAliases;
144 nullptr, idx, g_interpreter_properties[idx].default_uint_value != 0);
148 const uint32_t idx = ePropertyPromptOnQuit;
150 nullptr, idx, g_interpreter_properties[idx].default_uint_value != 0);
154 const uint32_t idx = ePropertyPromptOnQuit;
159 const uint32_t idx = ePropertySaveSessionOnQuit;
161 nullptr, idx, g_interpreter_properties[idx].default_uint_value != 0);
165 const uint32_t idx = ePropertySaveSessionOnQuit;
170 const uint32_t idx = ePropertySaveSessionDirectory;
175 const uint32_t idx = ePropertySaveSessionDirectory;
180 const uint32_t idx = ePropertyEchoCommands;
182 nullptr, idx, g_interpreter_properties[idx].default_uint_value != 0);
186 const uint32_t idx = ePropertyEchoCommands;
191 const uint32_t idx = ePropertyEchoCommentCommands;
193 nullptr, idx, g_interpreter_properties[idx].default_uint_value != 0);
197 const uint32_t idx = ePropertyEchoCommentCommands;
231 const uint32_t idx = ePropertyStopCmdSourceOnError;
233 nullptr, idx, g_interpreter_properties[idx].default_uint_value != 0);
237 const uint32_t idx = ePropertySpaceReplPrompts;
239 nullptr, idx, g_interpreter_properties[idx].default_uint_value != 0);
243 const uint32_t idx = ePropertyRepeatPreviousCommand;
245 nullptr, idx, g_interpreter_properties[idx].default_uint_value != 0);
249 const uint32_t idx = ePropertyRequireCommandOverwrite;
251 nullptr, idx, g_interpreter_properties[idx].default_uint_value != 0);
311 "sif", cmd_obj_sp,
"--end-linenumber block --step-in-target %1");
313 sif_alias->
SetHelp(
"Step through the current block, stopping if you step "
314 "directly into a function whose name matches the "
315 "TargetFunctionName.");
316 sif_alias->
SetSyntax(
"sif <TargetFunctionName>");
397 alias_arguments_vector_sp = std::make_shared<OptionArgVector>();
404 if (
auto *po =
AddAlias(
"po", cmd_obj_sp,
"-O --")) {
405 po->SetHelp(
"Evaluate an expression on the current thread. Displays any "
406 "returned value with formatting "
407 "controlled by the type's author.");
411 AddAlias(
"parray", cmd_obj_sp,
"--element-count %1 --");
414 (
"parray <COUNT> <EXPRESSION> -- lldb will evaluate EXPRESSION "
415 "to get a typed-pointer-to-an-array in memory, and will display "
416 "COUNT elements of that type from the array.");
420 "--object-description --element-count %1 --");
422 poarray_alias->
SetHelp(
"poarray <COUNT> <EXPRESSION> -- lldb will "
423 "evaluate EXPRESSION to get the address of an array of COUNT "
424 "objects in memory, and will call po on them.");
433 shell_alias->
SetHelp(
"Run a shell command on the host.");
435 shell_alias->
SetSyntax(
"shell <shell-command>");
446 alias_arguments_vector_sp = std::make_shared<OptionArgVector>();
447 #if defined(__APPLE__)
452 AddAlias(
"r", cmd_obj_sp,
"--shell-expand-args true --");
453 AddAlias(
"run", cmd_obj_sp,
"--shell-expand-args true --");
457 defaultshell.
Printf(
"--shell=%s --",
458 HostInfo::GetDefaultShell().GetPath().c_str());
471 AddAlias(
"rbreak", cmd_obj_sp,
"--func-regex %1");
478 AddAlias(
"vo", cmd_obj_sp,
"--object-description");
509 #define REGISTER_COMMAND_OBJECT(NAME, CLASS) \
510 m_command_dict[NAME] = std::make_shared<CLASS>(*this);
545 const char *break_regexes[][2] = {
546 {
"^(.*[^[:space:]])[[:space:]]*:[[:space:]]*([[:digit:]]+)[[:space:]]*:[[:space:]]*([[:digit:]]+)[[:space:]]*$",
547 "breakpoint set --file '%1' --line %2 --column %3"},
548 {
"^(.*[^[:space:]])[[:space:]]*:[[:space:]]*([[:digit:]]+)[[:space:]]*$",
549 "breakpoint set --file '%1' --line %2"},
550 {
"^/([^/]+)/$",
"breakpoint set --source-pattern-regexp '%1'"},
551 {
"^([[:digit:]]+)[[:space:]]*$",
"breakpoint set --line %1"},
552 {
"^\\*?(0x[[:xdigit:]]+)[[:space:]]*$",
"breakpoint set --address %1"},
553 {
"^[\"']?([-+]?\\[.*\\])[\"']?[[:space:]]*$",
554 "breakpoint set --name '%1'"},
555 {
"^(-.*)$",
"breakpoint set %1"},
556 {
"^(.*[^[:space:]])`(.*[^[:space:]])[[:space:]]*$",
557 "breakpoint set --name '%2' --shlib '%1'"},
558 {
"^\\&(.*[^[:space:]])[[:space:]]*$",
559 "breakpoint set --name '%1' --skip-prologue=0"},
560 {
"^[\"']?(.*[^[:space:]\"'])[\"']?[[:space:]]*$",
561 "breakpoint set --name '%1'"}};
564 size_t num_regexes = llvm::array_lengthof(break_regexes);
566 std::unique_ptr<CommandObjectRegexCommand> break_regex_cmd_up(
568 *
this,
"_regexp-break",
569 "Set a breakpoint using one of several shorthand formats.",
571 "_regexp-break <filename>:<linenum>:<colnum>\n"
572 " main.c:12:21 // Break at line 12 and column "
574 "_regexp-break <filename>:<linenum>\n"
575 " main.c:12 // Break at line 12 of "
577 "_regexp-break <linenum>\n"
578 " 12 // Break at line 12 of current "
580 "_regexp-break 0x<address>\n"
581 " 0x1234000 // Break at address "
583 "_regexp-break <name>\n"
584 " main // Break in 'main' after the "
586 "_regexp-break &<name>\n"
587 " &main // Break at first instruction "
589 "_regexp-break <module>`<name>\n"
590 " libc.so`malloc // Break in 'malloc' from "
592 "_regexp-break /<source-regex>/\n"
593 " /break here/ // Break on source lines in "
595 " // containing text 'break "
602 if (break_regex_cmd_up) {
604 for (
size_t i = 0; i < num_regexes; i++) {
605 success = break_regex_cmd_up->AddRegexCommand(break_regexes[i][0],
606 break_regexes[i][1]);
611 break_regex_cmd_up->AddRegexCommand(
"^$",
"breakpoint list --full");
614 CommandObjectSP break_regex_cmd_sp(break_regex_cmd_up.release());
620 std::unique_ptr<CommandObjectRegexCommand> tbreak_regex_cmd_up(
622 *
this,
"_regexp-tbreak",
623 "Set a one-shot breakpoint using one of several shorthand formats.",
625 "_regexp-break <filename>:<linenum>:<colnum>\n"
626 " main.c:12:21 // Break at line 12 and column "
628 "_regexp-break <filename>:<linenum>\n"
629 " main.c:12 // Break at line 12 of "
631 "_regexp-break <linenum>\n"
632 " 12 // Break at line 12 of current "
634 "_regexp-break 0x<address>\n"
635 " 0x1234000 // Break at address "
637 "_regexp-break <name>\n"
638 " main // Break in 'main' after the "
640 "_regexp-break &<name>\n"
641 " &main // Break at first instruction "
643 "_regexp-break <module>`<name>\n"
644 " libc.so`malloc // Break in 'malloc' from "
646 "_regexp-break /<source-regex>/\n"
647 " /break here/ // Break on source lines in "
649 " // containing text 'break "
656 if (tbreak_regex_cmd_up) {
658 for (
size_t i = 0; i < num_regexes; i++) {
662 tbreak_regex_cmd_up->AddRegexCommand(break_regexes[i][0], command);
667 tbreak_regex_cmd_up->AddRegexCommand(
"^$",
"breakpoint list --full");
670 CommandObjectSP tbreak_regex_cmd_sp(tbreak_regex_cmd_up.release());
676 std::unique_ptr<CommandObjectRegexCommand> attach_regex_cmd_up(
678 *
this,
"_regexp-attach",
"Attach to process by ID or name.",
679 "_regexp-attach <pid> | <process-name>", 2, 0,
false));
680 if (attach_regex_cmd_up) {
681 if (attach_regex_cmd_up->AddRegexCommand(
"^([0-9]+)[[:space:]]*$",
682 "process attach --pid %1") &&
683 attach_regex_cmd_up->AddRegexCommand(
684 "^(-.*|.* -.*)$",
"process attach %1") &&
687 attach_regex_cmd_up->AddRegexCommand(
"^(.+)$",
688 "process attach --name '%1'") &&
689 attach_regex_cmd_up->AddRegexCommand(
"^$",
"process attach")) {
690 CommandObjectSP attach_regex_cmd_sp(attach_regex_cmd_up.release());
696 std::unique_ptr<CommandObjectRegexCommand> down_regex_cmd_up(
698 "Select a newer stack frame. Defaults to "
699 "moving one frame, a numeric argument can "
700 "specify an arbitrary number.",
701 "_regexp-down [<count>]", 2, 0,
false));
702 if (down_regex_cmd_up) {
703 if (down_regex_cmd_up->AddRegexCommand(
"^$",
"frame select -r -1") &&
704 down_regex_cmd_up->AddRegexCommand(
"^([0-9]+)$",
705 "frame select -r -%1")) {
706 CommandObjectSP down_regex_cmd_sp(down_regex_cmd_up.release());
712 std::unique_ptr<CommandObjectRegexCommand> up_regex_cmd_up(
715 "Select an older stack frame. Defaults to moving one "
716 "frame, a numeric argument can specify an arbitrary number.",
717 "_regexp-up [<count>]", 2, 0,
false));
718 if (up_regex_cmd_up) {
719 if (up_regex_cmd_up->AddRegexCommand(
"^$",
"frame select -r 1") &&
720 up_regex_cmd_up->AddRegexCommand(
"^([0-9]+)$",
"frame select -r %1")) {
721 CommandObjectSP up_regex_cmd_sp(up_regex_cmd_up.release());
727 std::unique_ptr<CommandObjectRegexCommand> display_regex_cmd_up(
729 *
this,
"_regexp-display",
730 "Evaluate an expression at every stop (see 'help target stop-hook'.)",
731 "_regexp-display expression", 2, 0,
false));
732 if (display_regex_cmd_up) {
733 if (display_regex_cmd_up->AddRegexCommand(
734 "^(.+)$",
"target stop-hook add -o \"expr -- %1\"")) {
735 CommandObjectSP display_regex_cmd_sp(display_regex_cmd_up.release());
737 display_regex_cmd_sp;
741 std::unique_ptr<CommandObjectRegexCommand> undisplay_regex_cmd_up(
743 "Stop displaying expression at every "
744 "stop (specified by stop-hook index.)",
745 "_regexp-undisplay stop-hook-number", 2, 0,
747 if (undisplay_regex_cmd_up) {
748 if (undisplay_regex_cmd_up->AddRegexCommand(
"^([0-9]+)$",
749 "target stop-hook delete %1")) {
750 CommandObjectSP undisplay_regex_cmd_sp(undisplay_regex_cmd_up.release());
752 undisplay_regex_cmd_sp;
756 std::unique_ptr<CommandObjectRegexCommand> connect_gdb_remote_cmd_up(
759 "Connect to a process via remote GDB server.\n"
760 "If no host is specifed, localhost is assumed.\n"
761 "gdb-remote is an abbreviation for 'process connect --plugin "
762 "gdb-remote connect://<hostname>:<port>'\n",
763 "gdb-remote [<hostname>:]<portnum>", 2, 0,
false));
764 if (connect_gdb_remote_cmd_up) {
765 if (connect_gdb_remote_cmd_up->AddRegexCommand(
766 "^([^:]+|\\[[0-9a-fA-F:]+.*\\]):([0-9]+)$",
767 "process connect --plugin gdb-remote connect://%1:%2") &&
768 connect_gdb_remote_cmd_up->AddRegexCommand(
770 "process connect --plugin gdb-remote connect://localhost:%1")) {
771 CommandObjectSP command_sp(connect_gdb_remote_cmd_up.release());
776 std::unique_ptr<CommandObjectRegexCommand> connect_kdp_remote_cmd_up(
779 "Connect to a process via remote KDP server.\n"
780 "If no UDP port is specified, port 41139 is assumed.\n"
781 "kdp-remote is an abbreviation for 'process connect --plugin "
782 "kdp-remote udp://<hostname>:<port>'\n",
783 "kdp-remote <hostname>[:<portnum>]", 2, 0,
false));
784 if (connect_kdp_remote_cmd_up) {
785 if (connect_kdp_remote_cmd_up->AddRegexCommand(
786 "^([^:]+:[[:digit:]]+)$",
787 "process connect --plugin kdp-remote udp://%1") &&
788 connect_kdp_remote_cmd_up->AddRegexCommand(
789 "^(.+)$",
"process connect --plugin kdp-remote udp://%1:41139")) {
790 CommandObjectSP command_sp(connect_kdp_remote_cmd_up.release());
795 std::unique_ptr<CommandObjectRegexCommand> bt_regex_cmd_up(
798 "Show the current thread's call stack. Any numeric argument "
799 "displays at most that many "
800 "frames. The argument 'all' displays all threads. Use 'settings"
801 " set frame-format' to customize the printing of individual frames "
802 "and 'settings set thread-format' to customize the thread header.",
803 "bt [<digit> | all]", 2, 0,
false));
804 if (bt_regex_cmd_up) {
809 if (bt_regex_cmd_up->AddRegexCommand(
"^([[:digit:]]+)[[:space:]]*$",
810 "thread backtrace -c %1") &&
811 bt_regex_cmd_up->AddRegexCommand(
"^-c ([[:digit:]]+)[[:space:]]*$",
812 "thread backtrace -c %1") &&
813 bt_regex_cmd_up->AddRegexCommand(
"^all[[:space:]]*$",
"thread backtrace all") &&
814 bt_regex_cmd_up->AddRegexCommand(
"^[[:space:]]*$",
"thread backtrace")) {
815 CommandObjectSP command_sp(bt_regex_cmd_up.release());
820 std::unique_ptr<CommandObjectRegexCommand> list_regex_cmd_up(
822 *
this,
"_regexp-list",
823 "List relevant source code using one of several shorthand formats.",
825 "_regexp-list <file>:<line> // List around specific file/line\n"
826 "_regexp-list <line> // List current file around specified "
828 "_regexp-list <function-name> // List specified function\n"
829 "_regexp-list 0x<address> // List around specified address\n"
830 "_regexp-list -[<count>] // List previous <count> lines\n"
831 "_regexp-list // List subsequent lines",
833 if (list_regex_cmd_up) {
834 if (list_regex_cmd_up->AddRegexCommand(
"^([0-9]+)[[:space:]]*$",
835 "source list --line %1") &&
836 list_regex_cmd_up->AddRegexCommand(
837 "^(.*[^[:space:]])[[:space:]]*:[[:space:]]*([[:digit:]]+)[[:space:]"
839 "source list --file '%1' --line %2") &&
840 list_regex_cmd_up->AddRegexCommand(
841 "^\\*?(0x[[:xdigit:]]+)[[:space:]]*$",
842 "source list --address %1") &&
843 list_regex_cmd_up->AddRegexCommand(
"^-[[:space:]]*$",
844 "source list --reverse") &&
845 list_regex_cmd_up->AddRegexCommand(
846 "^-([[:digit:]]+)[[:space:]]*$",
847 "source list --reverse --count %1") &&
848 list_regex_cmd_up->AddRegexCommand(
"^(.+)$",
849 "source list --name \"%1\"") &&
850 list_regex_cmd_up->AddRegexCommand(
"^$",
"source list")) {
851 CommandObjectSP list_regex_cmd_sp(list_regex_cmd_up.release());
857 std::unique_ptr<CommandObjectRegexCommand> env_regex_cmd_up(
859 *
this,
"_regexp-env",
860 "Shorthand for viewing and setting environment variables.",
862 "_regexp-env // Show environment\n"
863 "_regexp-env <name>=<value> // Set an environment variable",
865 if (env_regex_cmd_up) {
866 if (env_regex_cmd_up->AddRegexCommand(
"^$",
867 "settings show target.env-vars") &&
868 env_regex_cmd_up->AddRegexCommand(
"^([A-Za-z_][A-Za-z_0-9]*=.*)$",
869 "settings set target.env-vars %1")) {
870 CommandObjectSP env_regex_cmd_sp(env_regex_cmd_up.release());
876 std::unique_ptr<CommandObjectRegexCommand> jump_regex_cmd_up(
878 *
this,
"_regexp-jump",
"Set the program counter to a new address.",
880 "_regexp-jump <line>\n"
881 "_regexp-jump +<line-offset> | -<line-offset>\n"
882 "_regexp-jump <file>:<line>\n"
883 "_regexp-jump *<addr>\n",
885 if (jump_regex_cmd_up) {
886 if (jump_regex_cmd_up->AddRegexCommand(
"^\\*(.*)$",
887 "thread jump --addr %1") &&
888 jump_regex_cmd_up->AddRegexCommand(
"^([0-9]+)$",
889 "thread jump --line %1") &&
890 jump_regex_cmd_up->AddRegexCommand(
"^([^:]+):([0-9]+)$",
891 "thread jump --file %1 --line %2") &&
892 jump_regex_cmd_up->AddRegexCommand(
"^([+\\-][0-9]+)$",
893 "thread jump --by %1")) {
894 CommandObjectSP jump_regex_cmd_sp(jump_regex_cmd_up.release());
902 const char *cmd_str,
bool include_aliases,
StringList &matches,
907 if (include_aliases) {
916 Args &path,
bool leaf_is_command,
Status &result) {
919 auto get_multi_or_report_error =
920 [&result](CommandObjectSP cmd_sp,
926 if (!cmd_sp->IsUserCommand()) {
948 if (num_args == 1 && leaf_is_command) {
958 get_multi_or_report_error(cur_cmd_sp, cur_name);
959 if (cur_as_multi ==
nullptr)
962 size_t num_path_elements = num_args - (leaf_is_command ? 1 : 0);
963 for (
size_t cursor = 1; cursor < num_path_elements && cur_as_multi !=
nullptr;
967 cur_as_multi = get_multi_or_report_error(cur_cmd_sp, cur_name);
976 CommandObjectSP command_sp;
983 command_sp = pos->second;
989 command_sp = alias_pos->second;
995 command_sp = pos->second;
1001 command_sp = pos->second;
1004 if (!exact && !command_sp) {
1007 CommandObjectSP user_match_sp, user_mw_match_sp, alias_match_sp,
1011 if (matches ==
nullptr)
1012 matches = &local_matches;
1014 unsigned int num_cmd_matches = 0;
1015 unsigned int num_alias_matches = 0;
1016 unsigned int num_user_matches = 0;
1017 unsigned int num_user_mw_matches = 0;
1025 *matches, descriptions);
1028 if (num_cmd_matches == 1) {
1032 real_match_sp = pos->second;
1037 *matches, descriptions);
1040 if (num_alias_matches == 1) {
1044 alias_match_sp = alias_pos->second;
1049 *matches, descriptions);
1052 if (num_user_matches == 1) {
1058 user_match_sp = pos->second;
1066 if (num_user_mw_matches == 1) {
1072 user_mw_match_sp = pos->second;
1078 if (num_user_matches + num_user_mw_matches + num_cmd_matches +
1079 num_alias_matches ==
1081 if (num_cmd_matches)
1082 return real_match_sp;
1083 else if (num_alias_matches)
1084 return alias_match_sp;
1085 else if (num_user_mw_matches)
1086 return user_mw_match_sp;
1088 return user_match_sp;
1090 }
else if (matches && command_sp) {
1100 const lldb::CommandObjectSP &cmd_sp,
1103 lldbassert((
this == &cmd_sp->GetCommandInterpreter()) &&
1104 "tried to add a CommandObject from a different interpreter");
1109 cmd_sp->SetIsUserCommand(
false);
1114 if (!can_replace || !name_iter->second->IsRemovable())
1116 name_iter->second = cmd_sp;
1124 const lldb::CommandObjectSP &cmd_sp,
1128 lldbassert((
this == &cmd_sp->GetCommandInterpreter()) &&
1129 "tried to add a CommandObject from a different interpreter");
1131 result.
SetErrorString(
"can't use the empty string for a command name");
1142 result.
SetErrorString(
"user command exists and force replace not set");
1145 if (cmd_sp->IsMultiwordObject()) {
1148 "can't replace explicitly non-removable multi-word command");
1153 result.
SetErrorString(
"can't replace explicitly non-removable command");
1159 cmd_sp->SetIsUserCommand(
true);
1161 if (cmd_sp->IsMultiwordObject())
1170 bool include_aliases)
const {
1172 Args cmd_words(cmd_str);
1174 if (cmd_str.empty())
1177 if (cmd_words.GetArgumentCount() == 1)
1182 CommandObjectSP cmd_obj_sp =
1183 GetCommandSP(cmd_words.GetArgumentAtIndex(0), include_aliases,
true);
1190 size_t end = cmd_words.GetArgumentCount();
1191 for (
size_t i = 1; i < end; ++i) {
1192 if (!cmd_obj_sp->IsMultiwordObject()) {
1198 cmd_obj_sp = cmd_obj_sp->GetSubcommandSP(cmd_words.GetArgumentAtIndex(i));
1215 GetCommandSP(cmd_str,
false,
true, matches, descriptions).get();
1223 command_obj =
GetCommandSP(cmd_str,
true,
true, matches, descriptions).get();
1230 command_obj =
GetCommandSP(cmd_str,
false,
false,
nullptr).get();
1243 return GetCommandSP(cmd_str,
true,
false, matches, descriptions).get();
1251 if (found_elem == map.end())
1274 StringList *matches_ptr = matches ? matches : &tmp_list;
1277 cmd_str, *matches_ptr);
1295 size_t num_alias_matches;
1298 if (num_alias_matches == 1) {
1301 const bool include_aliases =
false;
1302 const bool exact =
false;
1303 CommandObjectSP cmd_obj_sp(
1304 GetCommandSP(cmd, include_aliases, exact, ®ular_matches));
1305 if (cmd_obj_sp || regular_matches.
GetSize() > 0)
1330 lldb::CommandObjectSP &command_obj_sp,
1331 llvm::StringRef args_string) {
1332 if (command_obj_sp.get())
1333 lldbassert((
this == &command_obj_sp->GetCommandInterpreter()) &&
1334 "tried to add a CommandObject from a different interpreter");
1336 std::unique_ptr<CommandAlias> command_alias_up(
1337 new CommandAlias(*
this, command_obj_sp, args_string, alias_name));
1339 if (command_alias_up && command_alias_up->IsValid()) {
1341 CommandObjectSP(command_alias_up.get());
1342 return command_alias_up.release();
1360 if (pos->second->IsRemovable()) {
1370 CommandObject::CommandMap::iterator pos =
1380 CommandObject::CommandMap::iterator pos =
1391 llvm::StringRef help_prologue(
GetDebugger().GetIOHandlerHelpPrologue());
1392 if (!help_prologue.empty()) {
1397 CommandObject::CommandMap::const_iterator pos;
1406 (pos->first.compare(0, 1,
"_") == 0))
1410 pos->second->GetHelp(), max_len);
1418 "Current command abbreviations "
1419 "(type '%shelp command alias' for more info):\n",
1427 alias_pos->second->GetHelp(), max_len);
1439 pos->second->GetHelp(), max_len);
1446 result.
AppendMessage(
"Current user-defined container commands:");
1451 pos->second->GetHelp(), max_len);
1457 "For more information on any command, type '%shelp <command-name>'.\n",
1462 llvm::StringRef &command_string) {
1468 size_t start = command_string.find_first_not_of(
k_white_space);
1472 if (start != std::string::npos) {
1475 if (end == std::string::npos)
1476 end = command_string.size();
1478 std::string(command_string.substr(start, end - start));
1480 if (cmd_obj ==
nullptr)
1490 cmd_obj = sub_cmd_obj;
1502 end >= command_string.size())
1505 start = command_string.find_first_not_of(
k_white_space, end);
1511 command_string = command_string.substr(end);
1515 static const char *k_valid_command_chars =
1516 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
1520 if (pos == std::string::npos)
1528 static size_t FindArgumentTerminator(
const std::string &s) {
1529 const size_t s_len = s.size();
1531 while (offset < s_len) {
1532 size_t pos = s.find(
"--", offset);
1533 if (pos == std::string::npos)
1536 if (llvm::isSpace(s[pos - 1])) {
1539 if ((pos + 2 >= s_len) || llvm::isSpace(s[pos + 2])) {
1546 return std::string::npos;
1553 StripLeadingSpaces(command_string);
1555 bool result =
false;
1558 if (!command_string.empty()) {
1559 const char first_char = command_string[0];
1560 if (first_char ==
'\'' || first_char ==
'"') {
1561 quote_char = first_char;
1562 const size_t end_quote_pos = command_string.find(quote_char, 1);
1563 if (end_quote_pos == std::string::npos) {
1564 command.swap(command_string);
1565 command_string.erase();
1567 command.assign(command_string, 1, end_quote_pos - 1);
1568 if (end_quote_pos + 1 < command_string.size())
1569 command_string.erase(0, command_string.find_first_not_of(
1572 command_string.erase();
1575 const size_t first_space_pos =
1577 if (first_space_pos == std::string::npos) {
1578 command.swap(command_string);
1579 command_string.erase();
1581 command.assign(command_string, 0, first_space_pos);
1582 command_string.erase(0, command_string.find_first_not_of(
1589 if (!command.empty()) {
1591 if (command[0] !=
'-' && command[0] !=
'_') {
1592 size_t pos = command.find_first_not_of(k_valid_command_chars);
1593 if (pos > 0 && pos != std::string::npos) {
1594 suffix.assign(command.begin() + pos, command.end());
1604 llvm::StringRef alias_name,
std::string &raw_input_string,
1607 Args cmd_args(raw_input_string);
1611 if (!alias_cmd_obj || !alias_cmd_obj->
IsAlias()) {
1612 alias_result.clear();
1613 return alias_cmd_obj;
1615 std::pair<CommandObjectSP, OptionArgVectorSP> desugared =
1618 alias_cmd_obj = desugared.first.get();
1620 if ((cmd_args.GetArgumentCount() == 0) ||
1621 (alias_name_str != cmd_args.GetArgumentAtIndex(0)))
1622 cmd_args.Unshift(alias_name_str);
1626 if (!option_arg_vector_sp.get()) {
1628 return alias_cmd_obj;
1635 for (
const auto &entry : *option_arg_vector) {
1636 std::tie(option, value_type, value) = entry;
1637 if (option ==
"<argument>") {
1638 result_str.
Printf(
" %s", value.c_str());
1642 result_str.
Printf(
" %s", option.c_str());
1650 result_str.
Printf(
"%s", value.c_str());
1651 else if (
static_cast<size_t>(index) >= cmd_args.GetArgumentCount()) {
1654 "need at least %d arguments to use "
1659 size_t strpos = raw_input_string.find(cmd_args.GetArgumentAtIndex(index));
1660 if (strpos != std::string::npos)
1661 raw_input_string = raw_input_string.erase(
1662 strpos, strlen(cmd_args.GetArgumentAtIndex(index)));
1663 result_str.
Printf(
"%s", cmd_args.GetArgumentAtIndex(index));
1668 return alias_cmd_obj;
1679 size_t start_backtick;
1681 while ((start_backtick = command.find(
'`', pos)) != std::string::npos) {
1686 if (start_backtick > 0 && command[start_backtick - 1] ==
'\\') {
1689 command.erase(start_backtick - 1, 1);
1691 pos = start_backtick;
1695 const size_t expr_content_start = start_backtick + 1;
1696 const size_t end_backtick = command.find(
'`', expr_content_start);
1698 if (end_backtick == std::string::npos) {
1703 if (end_backtick == expr_content_start) {
1705 command.erase(start_backtick, 2);
1710 end_backtick - expr_content_start);
1717 Target *exe_target = exe_ctx.GetTargetPtr();
1720 ValueObjectSP expr_result_valobj_sp;
1732 expr_result_valobj_sp, options);
1736 if (expr_result_valobj_sp)
1737 expr_result_valobj_sp =
1738 expr_result_valobj_sp->GetQualifiedRepresentationIfAvailable(
1739 expr_result_valobj_sp->GetDynamicValueType(),
true);
1740 if (expr_result_valobj_sp->ResolveValue(scalar)) {
1741 command.erase(start_backtick, end_backtick - start_backtick + 1);
1743 const bool show_type =
false;
1744 scalar.
GetValue(&value_strm, show_type);
1745 size_t value_string_size = value_strm.
GetSize();
1746 if (value_string_size) {
1748 pos = start_backtick + value_string_size;
1751 error.SetErrorStringWithFormat(
"expression value didn't result "
1752 "in a scalar value for the "
1758 error.SetErrorStringWithFormat(
"expression value didn't result "
1759 "in a scalar value for the "
1768 if (expr_result_valobj_sp)
1769 error = expr_result_valobj_sp->GetError();
1771 if (
error.Success()) {
1772 switch (expr_result) {
1774 error.SetErrorStringWithFormat(
1775 "expression setup error for the expression '%s'", expr_str.c_str());
1778 error.SetErrorStringWithFormat(
1779 "expression parse error for the expression '%s'", expr_str.c_str());
1782 error.SetErrorStringWithFormat(
1783 "expression error fetching result for the expression '%s'",
1789 error.SetErrorStringWithFormat(
1790 "expression discarded for the expression '%s'", expr_str.c_str());
1793 error.SetErrorStringWithFormat(
1794 "expression interrupted for the expression '%s'", expr_str.c_str());
1797 error.SetErrorStringWithFormat(
1798 "expression hit breakpoint for the expression '%s'",
1802 error.SetErrorStringWithFormat(
1803 "expression timed out for the expression '%s'", expr_str.c_str());
1806 error.SetErrorStringWithFormat(
"expression stop at entry point "
1807 "for debugging for the "
1812 error.SetErrorStringWithFormat(
1813 "expression thread vanished for the expression '%s'",
1828 bool status =
HandleCommand(command_line, lazy_add_to_history, result);
1838 std::string original_command_string(command_line);
1841 llvm::PrettyStackTraceFormat stack_trace(
"HandleCommand(command = \"%s\")",
1844 LLDB_LOGF(log,
"Processing command: %s", command_line);
1852 bool add_to_history;
1856 add_to_history = (lazy_add_to_history ==
eLazyBoolYes);
1860 bool empty_command =
false;
1861 bool comment_command =
false;
1862 if (command_string.empty())
1863 empty_command =
true;
1865 const char *k_space_characters =
"\t\n\v\f\r ";
1867 size_t non_space = command_string.find_first_not_of(k_space_characters);
1870 if (non_space == std::string::npos)
1871 empty_command =
true;
1873 comment_command =
true;
1875 llvm::StringRef search_str(command_string);
1876 search_str = search_str.drop_front(non_space);
1878 add_to_history =
false;
1883 command_string.c_str());
1889 if (empty_command) {
1901 command_string = command_line;
1902 original_command_string = command_line;
1908 add_to_history =
false;
1909 }
else if (comment_command) {
1942 llvm::StringRef command_name = cmd_obj ? cmd_obj->
GetCommandName() :
"<not found>";
1943 LLDB_LOGF(log,
"HandleCommand, cmd_obj : '%s'", command_name.str().c_str());
1944 LLDB_LOGF(log,
"HandleCommand, (revised) command_string: '%s'",
1945 command_string.c_str());
1946 const bool wants_raw_input =
1948 LLDB_LOGF(log,
"HandleCommand, wants_raw_input:'%s'",
1949 wants_raw_input ?
"True" :
"False");
1957 if (cmd_obj !=
nullptr) {
1961 if (add_to_history || empty_command) {
1962 Args command_args(command_string);
1963 llvm::Optional<std::string> repeat_command =
1975 const std::size_t actual_cmd_name_len = cmd_obj->
GetCommandName().size();
1976 if (actual_cmd_name_len < command_string.length())
1977 remainder = command_string.substr(actual_cmd_name_len);
1981 if (pos != 0 && pos != std::string::npos)
1982 remainder.erase(0, pos);
1985 log,
"HandleCommand, command line after removing command name(s): '%s'",
1988 cmd_obj->
Execute(remainder.c_str(), result);
1991 LLDB_LOGF(log,
"HandleCommand, command %s",
1992 (result.
Succeeded() ?
"succeeded" :
"did not succeed"));
2001 bool look_for_subcommand =
false;
2007 bool include_aliases =
true;
2018 &new_matches, &new_descriptions);
2025 look_for_subcommand =
true;
2040 if (command_object) {
2053 if (!first_arg.empty()) {
2058 request.
AddCompletion(*hist_str,
"Previous command history event",
2067 llvm::Optional<std::string>
2072 for (
int i = s - 1; i >= 0; --i) {
2074 if (entry.consume_front(line))
2081 EventSP prompt_change_event_sp(
2092 return default_answer;
2096 IOHandlerSP io_handler_sp(confirm);
2125 const char *alias_name,
2137 cmd_args.
Unshift(alias_name_str);
2140 if (new_args.GetArgumentCount() == 2)
2143 if (option_arg_vector_sp.get()) {
2144 if (wants_raw_input) {
2148 size_t pos = raw_input_string.find(
" -- ");
2149 if (pos == std::string::npos) {
2151 raw_input_string.insert(0,
" -- ");
2157 std::vector<bool> used(old_size + 1,
false);
2164 for (
const auto &option_entry : *option_arg_vector) {
2165 std::tie(option, value_type, value) = option_entry;
2166 if (option ==
"<argument>") {
2167 if (!wants_raw_input || (value !=
"--")) {
2169 new_args.AppendArgument(value);
2175 new_args.AppendArgument(option);
2177 if (value ==
"<no-argument>")
2184 new_args.AppendArgument(value);
2186 new_args.AppendArgument(option + value);
2191 "need at least %d arguments to use "
2199 if (strpos != std::string::npos) {
2200 raw_input_string = raw_input_string.erase(
2213 for (
auto entry : llvm::enumerate(cmd_args.
entries())) {
2214 if (!used[entry.index()] && !wants_raw_input)
2215 new_args.AppendArgument(entry.value().ref());
2220 new_args.GetConstArgumentVector());
2227 if (wants_raw_input) {
2230 new_args.GetConstArgumentVector());
2243 const char *cptr = in_string;
2246 if (cptr[0] ==
'%') {
2250 if (isdigit(cptr[0])) {
2251 const char *start = cptr;
2252 while (isdigit(cptr[0]))
2257 if (cptr[0] ==
'\0')
2258 position = atoi(start);
2266 llvm::StringRef suffix = {}) {
2268 if (!suffix.empty()) {
2269 init_file_name.append(
"-");
2270 init_file_name.append(suffix.str());
2274 llvm::sys::path::append(init_file, init_file_name);
2284 language = *main_repl_language;
2290 (llvm::Twine(
".lldbinit-") +
2292 llvm::Twine(
"-repl"))
2295 llvm::sys::path::append(init_file, init_file_name);
2300 llvm::StringRef s =
".lldbinit";
2301 init_file.assign(s.begin(), s.end());
2333 llvm::SmallString<128> init_file;
2334 GetCwdInitFile(init_file);
2343 switch (should_load) {
2351 llvm::SmallString<128> home_init_file;
2352 GetHomeInitFile(home_init_file);
2353 if (llvm::sys::path::parent_path(init_file) ==
2354 llvm::sys::path::parent_path(home_init_file)) {
2374 llvm::SmallString<128> init_file;
2377 GetHomeREPLInitFile(init_file,
GetDebugger().GetREPLLanguage());
2379 if (init_file.empty())
2380 GetHomeInitFile(init_file);
2383 llvm::StringRef program_name =
2384 HostInfo::GetProgramFileSpec().GetFilename().GetStringRef();
2385 llvm::SmallString<128> program_init_file;
2386 GetHomeInitFile(program_init_file, program_name);
2388 init_file = program_init_file;
2395 #ifdef LLDB_GLOBAL_INIT_DIRECTORY
2397 FileSpec init_file(LLDB_GLOBAL_INIT_DIRECTORY);
2399 init_file.MakeAbsolute(HostInfo::GetShlibDir());
2401 init_file.AppendPathComponent(
"lldbinit");
2411 return prefix ==
nullptr ?
"" : prefix;
2415 PlatformSP platform_sp;
2416 if (prefer_target_platform) {
2418 Target *target = exe_ctx.GetTargetPtr();
2430 TargetSP target_sp = exe_ctx.GetTargetSP();
2434 ProcessSP process_sp(target_sp->GetProcessSP());
2441 for (
const auto &thread_sp : process_sp->GetThreadList().Threads()) {
2442 StopInfoSP stop_info = thread_sp->GetStopInfo();
2446 const StopReason reason = stop_info->GetStopReason();
2453 const auto stop_signal =
static_cast<int32_t
>(stop_info->GetValue());
2454 UnixSignalsSP signals_sp = process_sp->GetUnixSignals();
2455 if (!signals_sp || !signals_sp->SignalIsValid(stop_signal))
2459 const auto sigint_num = signals_sp->GetSignalNumberFromName(
"SIGINT");
2460 const auto sigstop_num = signals_sp->GetSignalNumberFromName(
"SIGSTOP");
2461 if ((stop_signal != sigint_num) && (stop_signal != sigstop_num))
2484 size_t num_lines = commands.
GetSize();
2496 for (
size_t idx = 0; idx < num_lines && !
WasInterrupted(); idx++) {
2509 tmp_result.SetSuppressImmediateOutput(
true);
2521 if (tmp_result.Succeeded())
2525 if (!success || !tmp_result.Succeeded()) {
2526 llvm::StringRef error_msg = tmp_result.GetErrorData();
2527 if (error_msg.empty())
2528 error_msg =
"<unknown error>.\n";
2531 "Aborting reading of commands after command #%" PRIu64
2532 ": '%s' failed with %s",
2533 (uint64_t)idx, cmd, error_msg.str().c_str());
2538 "Command #%" PRIu64
" '%s' failed with %s", (uint64_t)idx + 1, cmd,
2539 error_msg.str().c_str());
2560 if (idx != num_lines - 1)
2562 "Aborting reading of commands after command #%" PRIu64
2563 ": '%s' continued the target.\n",
2564 (uint64_t)idx + 1, cmd);
2567 " '%s' continued the target.\n",
2568 (uint64_t)idx + 1, cmd);
2570 result.
SetStatus(tmp_result.GetStatus());
2578 if (tmp_result.GetDidChangeProcessState() && options.
GetStopOnCrash() &&
2580 if (idx != num_lines - 1)
2582 "Aborting reading of commands after command #%" PRIu64
2583 ": '%s' stopped with a signal or exception.\n",
2584 (uint64_t)idx + 1, cmd);
2587 "Command #%" PRIu64
" '%s' stopped with a signal or exception.\n",
2588 (uint64_t)idx + 1, cmd);
2590 result.
SetStatus(tmp_result.GetStatus());
2604 eHandleCommandFlagStopOnContinue = (1u << 0),
2605 eHandleCommandFlagStopOnError = (1u << 1),
2606 eHandleCommandFlagEchoCommand = (1u << 2),
2607 eHandleCommandFlagEchoCommentCommand = (1u << 3),
2608 eHandleCommandFlagPrintResult = (1u << 4),
2609 eHandleCommandFlagPrintErrors = (1u << 5),
2610 eHandleCommandFlagStopOnCrash = (1u << 6)
2625 "Error reading commands from file %s - file not found.\n",
2631 auto input_file_up =
2633 if (!input_file_up) {
2636 "error: an error occurred read file '{0}': {1}\n", cmd_file_path,
2637 llvm::fmt_consume(input_file_up.takeError()));
2640 FileSP input_file_sp = FileSP(std::move(input_file_up.get()));
2649 flags |= eHandleCommandFlagStopOnContinue;
2651 eHandleCommandFlagStopOnContinue) {
2652 flags |= eHandleCommandFlagStopOnContinue;
2655 flags |= eHandleCommandFlagStopOnContinue;
2661 flags |= eHandleCommandFlagStopOnError;
2663 flags |= eHandleCommandFlagStopOnError;
2666 flags |= eHandleCommandFlagStopOnError;
2673 flags |= eHandleCommandFlagStopOnCrash;
2675 flags |= eHandleCommandFlagStopOnCrash;
2682 flags |= eHandleCommandFlagEchoCommand;
2684 flags |= eHandleCommandFlagEchoCommand;
2687 flags |= eHandleCommandFlagEchoCommand;
2694 flags |= eHandleCommandFlagEchoCommentCommand;
2696 eHandleCommandFlagEchoCommentCommand) {
2697 flags |= eHandleCommandFlagEchoCommentCommand;
2700 flags |= eHandleCommandFlagEchoCommentCommand;
2706 flags |= eHandleCommandFlagPrintResult;
2708 flags |= eHandleCommandFlagPrintResult;
2711 flags |= eHandleCommandFlagPrintResult;
2717 flags |= eHandleCommandFlagPrintErrors;
2719 flags |= eHandleCommandFlagPrintErrors;
2722 flags |= eHandleCommandFlagPrintErrors;
2725 if (flags & eHandleCommandFlagPrintResult) {
2727 cmd_file_path.c_str());
2732 lldb::StreamFileSP empty_stream_sp;
2743 debugger.
GetPrompt(), llvm::StringRef(),
2749 if ((flags & eHandleCommandFlagStopOnContinue) == 0)
2776 llvm::StringRef prefix,
2777 llvm::StringRef help_text) {
2780 size_t line_width_max = max_columns - prefix.size();
2781 if (line_width_max < 16)
2782 line_width_max = help_text.size() + prefix.size();
2785 bool prefixed_yet =
false;
2787 if (help_text.empty())
2788 help_text =
"No help text";
2789 while (!help_text.empty()) {
2791 if (!prefixed_yet) {
2793 prefixed_yet =
true;
2798 llvm::StringRef this_line = help_text.substr(0, line_width_max);
2801 std::size_t first_newline = this_line.find_first_of(
"\n");
2804 std::size_t last_space = llvm::StringRef::npos;
2805 if (this_line.size() != help_text.size())
2806 last_space = this_line.find_last_of(
" \t");
2809 this_line = this_line.substr(0, std::min(first_newline, last_space));
2814 help_text = help_text.drop_front(this_line.size()).ltrim();
2820 llvm::StringRef word_text,
2821 llvm::StringRef separator,
2822 llvm::StringRef help_text,
2823 size_t max_word_len) {
2825 prefix_stream.
Printf(
" %-*s %*s ", (
int)max_word_len, word_text.data(),
2826 (
int)separator.size(), separator.data());
2831 llvm::StringRef separator,
2832 llvm::StringRef help_text,
2834 int indent_size = max_word_len + separator.size() + 2;
2839 text_strm.
Printf(
"%-*s ", (
int)max_word_len, word_text.data());
2840 text_strm << separator <<
" " << help_text;
2844 llvm::StringRef text = text_strm.
GetString();
2848 auto nextWordLength = [](llvm::StringRef S) {
2849 size_t pos = S.find(
' ');
2850 return pos == llvm::StringRef::npos ? S.size() : pos;
2853 while (!text.empty()) {
2854 if (text.front() ==
'\n' ||
2855 (text.front() ==
' ' && nextWordLength(text.ltrim(
' ')) > chars_left)) {
2858 chars_left = max_columns - indent_size;
2859 if (text.front() ==
'\n')
2860 text = text.drop_front();
2862 text = text.ltrim(
' ');
2866 text = text.drop_front();
2875 llvm::StringRef search_word,
StringList &commands_found,
2877 for (
const auto &pair : command_map) {
2878 llvm::StringRef command_name = pair.first;
2881 const bool search_short_help =
true;
2882 const bool search_long_help =
false;
2883 const bool search_syntax =
false;
2884 const bool search_options =
false;
2885 if (command_name.contains_insensitive(search_word) ||
2887 search_long_help, search_syntax,
2896 multiword_cmd->GetSubcommandDictionary());
2897 for (
const auto &subcommand_name : subcommands_found) {
2899 (command_name +
" " + subcommand_name).str();
2909 bool search_builtin_commands,
2910 bool search_user_commands,
2911 bool search_alias_commands,
2912 bool search_user_mw_commands) {
2913 CommandObject::CommandMap::const_iterator pos;
2915 if (search_builtin_commands)
2919 if (search_user_commands)
2923 if (search_user_mw_commands)
2927 if (search_alias_commands)
2979 bool was_interrupted =
2982 return was_interrupted;
2986 llvm::StringRef str,
2993 llvm::StringRef line;
2994 std::tie(line, str) = str.split(
'\n');
2996 std::lock_guard<std::recursive_mutex> guard(io_handler.
GetOutputMutex());
2997 stream->Write(line.data(), line.size());
2998 stream->Write(
"\n", 1);
3002 std::lock_guard<std::recursive_mutex> guard(io_handler.
GetOutputMutex());
3004 stream->Printf(
"\n... Interrupted.\n");
3009 llvm::StringRef line,
const Flags &io_handler_flags)
const {
3010 if (!io_handler_flags.
Test(eHandleCommandFlagEchoCommand))
3013 llvm::StringRef command = line.trim();
3014 if (command.empty())
3018 return io_handler_flags.
Test(eHandleCommandFlagEchoCommentCommand);
3030 if (!is_interactive) {
3042 std::lock_guard<std::recursive_mutex> guard(io_handler.
GetOutputMutex());
3044 "%s%s\n", io_handler.
GetPrompt(), line.c_str());
3051 bool pushed_exe_ctx =
false;
3054 pushed_exe_ctx =
true;
3056 auto finalize = llvm::make_scope_exit([
this, pushed_exe_ctx]() {
3066 io_handler.
GetFlags().
Test(eHandleCommandFlagPrintResult)) ||
3067 io_handler.
GetFlags().
Test(eHandleCommandFlagPrintErrors)) {
3094 if (io_handler.
GetFlags().
Test(eHandleCommandFlagStopOnContinue))
3100 if (io_handler.
GetFlags().
Test(eHandleCommandFlagStopOnError)) {
3115 io_handler.
GetFlags().
Test(eHandleCommandFlagStopOnCrash) &&
3139 if (script_interpreter) {
3148 if (output_file == llvm::None || output_file->empty()) {
3149 std::string now = llvm::to_string(std::chrono::system_clock::now());
3150 std::replace(now.begin(), now.end(),
' ',
'_');
3151 const std::string file_name =
"lldb_session_" + now +
".log";
3156 save_location = HostInfo::GetGlobalTempDir();
3160 output_file = save_location.
GetPath();
3163 auto error_out = [&](llvm::StringRef error_message,
std::string description) {
3165 output_file, description);
3167 "Failed to save session's transcripts to {0}!", *output_file);
3178 return error_out(
"Unable to create file",
3181 FileUP file = std::move(opened_file.get());
3188 return error_out(
"Unable to write to destination file",
3189 "Bytes written do not match transcript size.");
3193 output_file->c_str());
3211 IOHandlerSP io_handler_sp(
3214 llvm::StringRef(prompt),
3222 if (io_handler_sp) {
3223 io_handler_sp->SetUserData(baton);
3231 IOHandlerSP io_handler_sp(
3234 llvm::StringRef(prompt),
3242 if (io_handler_sp) {
3243 io_handler_sp->SetUserData(baton);
3266 flags |= eHandleCommandFlagStopOnContinue;
3268 flags |= eHandleCommandFlagStopOnError;
3270 flags |= eHandleCommandFlagStopOnCrash;
3272 flags |= eHandleCommandFlagEchoCommand;
3274 flags |= eHandleCommandFlagEchoCommentCommand;
3276 flags |= eHandleCommandFlagPrintResult;
3278 flags |= eHandleCommandFlagPrintErrors;
3280 flags = eHandleCommandFlagEchoCommand | eHandleCommandFlagPrintResult |
3281 eHandleCommandFlagPrintErrors;
3302 bool force_create =
true;
3328 bool wants_raw_input =
false;
3333 char quote_char =
'\0';
3335 ExtractCommand(scratch_command, next_word, suffix, quote_char);
3336 if (cmd_obj ==
nullptr) {
3340 bool is_real_command =
3341 (!is_alias) || (cmd_obj !=
nullptr && !cmd_obj->
IsAlias());
3342 if (!is_real_command) {
3347 revised_command_line.
Printf(
"%s", alias_result.c_str());
3354 revised_command_line.
Printf(
"%s", cmd_name.str().c_str());
3357 revised_command_line.
Printf(
"%s", next_word.c_str());
3368 revised_command_line.
Clear();
3369 revised_command_line.
Printf(
"%s", sub_cmd_name.str().c_str());
3370 cmd_obj = sub_cmd_obj;
3374 revised_command_line.
Printf(
" %c%s%s%c", quote_char,
3375 next_word.c_str(), suffix.c_str(),
3378 revised_command_line.
Printf(
" %s%s", next_word.c_str(),
3384 revised_command_line.
Printf(
" %c%s%s%c", quote_char,
3385 next_word.c_str(), suffix.c_str(),
3388 revised_command_line.
Printf(
" %s%s", next_word.c_str(),
3394 if (cmd_obj ==
nullptr) {
3395 const size_t num_matches = matches.
GetSize();
3398 error_msg.
Printf(
"Ambiguous command '%s'. Possible matches:\n",
3401 for (
uint32_t i = 0; i < num_matches; ++i) {
3415 if (!suffix.empty()) {
3417 "command '%s' did not recognize '%s%s%s' as valid (subcommand "
3418 "might be invalid).\n",
3420 next_word.empty() ?
"" : next_word.c_str(),
3421 next_word.empty() ?
" -- " :
" ", suffix.c_str());
3427 if (!suffix.empty()) {
3428 switch (suffix[0]) {
3433 if (command_options &&
3436 gdb_format_option += (suffix.c_str() + 1);
3439 size_t arg_terminator_idx = FindArgumentTerminator(cmd);
3440 if (arg_terminator_idx != std::string::npos) {
3443 gdb_format_option.append(1,
' ');
3444 cmd.insert(arg_terminator_idx, gdb_format_option);
3445 revised_command_line.
Clear();
3448 revised_command_line.
Printf(
" %s", gdb_format_option.c_str());
3450 if (wants_raw_input &&
3451 FindArgumentTerminator(cmd) == std::string::npos)
3455 "the '%s' command doesn't support the --gdb-format option\n",
3464 "unknown command shorthand suffix: '%s'\n", suffix.c_str());
3469 if (scratch_command.empty())
3473 if (!scratch_command.empty())
3474 revised_command_line.
Printf(
" %s", scratch_command.c_str());
3476 if (cmd_obj !=
nullptr)