Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- CommandInterpreter.cpp ----------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include <string> |
Caroline Tice | bd5c63e | 2010-10-12 21:57:09 +0000 | [diff] [blame] | 11 | #include <vector> |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | |
| 13 | #include <getopt.h> |
| 14 | #include <stdlib.h> |
| 15 | |
Eli Friedman | ccdb9ec | 2010-06-13 02:17:17 +0000 | [diff] [blame] | 16 | #include "../Commands/CommandObjectApropos.h" |
| 17 | #include "../Commands/CommandObjectArgs.h" |
| 18 | #include "../Commands/CommandObjectBreakpoint.h" |
Sean Callanan | 65dafa8 | 2010-08-27 01:01:44 +0000 | [diff] [blame] | 19 | //#include "../Commands/CommandObjectCall.h" |
Eli Friedman | ccdb9ec | 2010-06-13 02:17:17 +0000 | [diff] [blame] | 20 | #include "../Commands/CommandObjectDisassemble.h" |
| 21 | #include "../Commands/CommandObjectExpression.h" |
| 22 | #include "../Commands/CommandObjectFile.h" |
| 23 | #include "../Commands/CommandObjectFrame.h" |
| 24 | #include "../Commands/CommandObjectHelp.h" |
| 25 | #include "../Commands/CommandObjectImage.h" |
Eli Friedman | ccdb9ec | 2010-06-13 02:17:17 +0000 | [diff] [blame] | 26 | #include "../Commands/CommandObjectLog.h" |
| 27 | #include "../Commands/CommandObjectMemory.h" |
| 28 | #include "../Commands/CommandObjectProcess.h" |
| 29 | #include "../Commands/CommandObjectQuit.h" |
Eli Friedman | b34d2a2 | 2010-06-09 22:08:29 +0000 | [diff] [blame] | 30 | #include "lldb/Interpreter/CommandObjectRegexCommand.h" |
Eli Friedman | ccdb9ec | 2010-06-13 02:17:17 +0000 | [diff] [blame] | 31 | #include "../Commands/CommandObjectRegister.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | #include "CommandObjectScript.h" |
Eli Friedman | ccdb9ec | 2010-06-13 02:17:17 +0000 | [diff] [blame] | 33 | #include "../Commands/CommandObjectSettings.h" |
Eli Friedman | ccdb9ec | 2010-06-13 02:17:17 +0000 | [diff] [blame] | 34 | #include "../Commands/CommandObjectSource.h" |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 35 | #include "../Commands/CommandObjectCommands.h" |
Eli Friedman | ccdb9ec | 2010-06-13 02:17:17 +0000 | [diff] [blame] | 36 | #include "../Commands/CommandObjectSyntax.h" |
| 37 | #include "../Commands/CommandObjectTarget.h" |
| 38 | #include "../Commands/CommandObjectThread.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | |
Jim Ingham | 84cdc15 | 2010-06-15 19:49:27 +0000 | [diff] [blame] | 40 | #include "lldb/Interpreter/Args.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | #include "lldb/Core/Debugger.h" |
Jim Ingham | 5e16ef5 | 2010-10-04 19:49:29 +0000 | [diff] [blame] | 42 | #include "lldb/Core/InputReader.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | #include "lldb/Core/Stream.h" |
| 44 | #include "lldb/Core/Timer.h" |
| 45 | #include "lldb/Target/Process.h" |
| 46 | #include "lldb/Target/Thread.h" |
| 47 | #include "lldb/Target/TargetList.h" |
| 48 | |
| 49 | #include "lldb/Interpreter/CommandReturnObject.h" |
| 50 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 51 | |
| 52 | using namespace lldb; |
| 53 | using namespace lldb_private; |
| 54 | |
| 55 | CommandInterpreter::CommandInterpreter |
| 56 | ( |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 57 | Debugger &debugger, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 58 | ScriptLanguage script_language, |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 59 | bool synchronous_execution |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 60 | ) : |
| 61 | Broadcaster ("CommandInterpreter"), |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 62 | m_debugger (debugger), |
Greg Clayton | 887aa28 | 2010-10-11 01:05:37 +0000 | [diff] [blame] | 63 | m_synchronous_execution (synchronous_execution), |
| 64 | m_skip_lldbinit_files (false) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 65 | { |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 66 | const char *dbg_name = debugger.GetInstanceName().AsCString(); |
| 67 | std::string lang_name = ScriptInterpreter::LanguageToString (script_language); |
| 68 | StreamString var_name; |
| 69 | var_name.Printf ("[%s].script-lang", dbg_name); |
Caroline Tice | 1d2aefd | 2010-09-09 06:25:08 +0000 | [diff] [blame] | 70 | debugger.GetSettingsController()->SetVariable (var_name.GetData(), lang_name.c_str(), |
| 71 | lldb::eVarSetOperationAssign, false, |
| 72 | m_debugger.GetInstanceName().AsCString()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | void |
| 76 | CommandInterpreter::Initialize () |
| 77 | { |
| 78 | Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); |
| 79 | |
| 80 | CommandReturnObject result; |
| 81 | |
| 82 | LoadCommandDictionary (); |
| 83 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 84 | // Set up some initial aliases. |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 85 | result.Clear(); HandleCommand ("command alias q quit", false, result); |
| 86 | result.Clear(); HandleCommand ("command alias run process launch", false, result); |
| 87 | result.Clear(); HandleCommand ("command alias r process launch", false, result); |
| 88 | result.Clear(); HandleCommand ("command alias c process continue", false, result); |
| 89 | result.Clear(); HandleCommand ("command alias continue process continue", false, result); |
| 90 | result.Clear(); HandleCommand ("command alias expr expression", false, result); |
| 91 | result.Clear(); HandleCommand ("command alias exit quit", false, result); |
Greg Clayton | 0f3a8eb | 2010-09-16 17:09:23 +0000 | [diff] [blame] | 92 | result.Clear(); HandleCommand ("command alias b regexp-break", false, result); |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 93 | result.Clear(); HandleCommand ("command alias bt thread backtrace", false, result); |
| 94 | result.Clear(); HandleCommand ("command alias si thread step-inst", false, result); |
| 95 | result.Clear(); HandleCommand ("command alias step thread step-in", false, result); |
| 96 | result.Clear(); HandleCommand ("command alias s thread step-in", false, result); |
| 97 | result.Clear(); HandleCommand ("command alias next thread step-over", false, result); |
| 98 | result.Clear(); HandleCommand ("command alias n thread step-over", false, result); |
| 99 | result.Clear(); HandleCommand ("command alias finish thread step-out", false, result); |
| 100 | result.Clear(); HandleCommand ("command alias x memory read", false, result); |
| 101 | result.Clear(); HandleCommand ("command alias l source list", false, result); |
| 102 | result.Clear(); HandleCommand ("command alias list source list", false, result); |
Greg Clayton | 0f3a8eb | 2010-09-16 17:09:23 +0000 | [diff] [blame] | 103 | result.Clear(); HandleCommand ("command alias p frame variable", false, result); |
| 104 | result.Clear(); HandleCommand ("command alias print frame variable", false, result); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 107 | const char * |
| 108 | CommandInterpreter::ProcessEmbeddedScriptCommands (const char *arg) |
| 109 | { |
| 110 | // This function has not yet been implemented. |
| 111 | |
| 112 | // Look for any embedded script command |
| 113 | // If found, |
| 114 | // get interpreter object from the command dictionary, |
| 115 | // call execute_one_command on it, |
| 116 | // get the results as a string, |
| 117 | // substitute that string for current stuff. |
| 118 | |
| 119 | return arg; |
| 120 | } |
| 121 | |
| 122 | |
| 123 | void |
| 124 | CommandInterpreter::LoadCommandDictionary () |
| 125 | { |
| 126 | Timer scoped_timer (__PRETTY_FUNCTION__, __PRETTY_FUNCTION__); |
| 127 | |
| 128 | // **** IMPORTANT **** IMPORTANT *** IMPORTANT *** **** IMPORTANT **** IMPORTANT *** IMPORTANT *** |
| 129 | // |
| 130 | // Command objects that are used as cross reference objects (i.e. they inherit from CommandObjectCrossref) |
| 131 | // *MUST* be created and put into the command dictionary *BEFORE* any multi-word commands (which may use |
| 132 | // the cross-referencing stuff) are created!!! |
| 133 | // |
| 134 | // **** IMPORTANT **** IMPORTANT *** IMPORTANT *** **** IMPORTANT **** IMPORTANT *** IMPORTANT *** |
| 135 | |
| 136 | |
| 137 | // Command objects that inherit from CommandObjectCrossref must be created before other command objects |
| 138 | // are created. This is so that when another command is created that needs to go into a crossref object, |
| 139 | // the crossref object exists and is ready to take the cross reference. Put the cross referencing command |
| 140 | // objects into the CommandDictionary now, so they are ready for use when the other commands get created. |
| 141 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 142 | // Non-CommandObjectCrossref commands can now be created. |
| 143 | |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 144 | lldb::ScriptLanguage script_language = m_debugger.GetScriptLanguage(); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 145 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 146 | m_command_dict["apropos"] = CommandObjectSP (new CommandObjectApropos (*this)); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 147 | m_command_dict["breakpoint"]= CommandObjectSP (new CommandObjectMultiwordBreakpoint (*this)); |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 148 | //m_command_dict["call"] = CommandObjectSP (new CommandObjectCall (*this)); |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 149 | m_command_dict["commands"] = CommandObjectSP (new CommandObjectMultiwordCommands (*this)); |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 150 | m_command_dict["disassemble"] = CommandObjectSP (new CommandObjectDisassemble (*this)); |
| 151 | m_command_dict["expression"]= CommandObjectSP (new CommandObjectExpression (*this)); |
| 152 | m_command_dict["file"] = CommandObjectSP (new CommandObjectFile (*this)); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 153 | m_command_dict["frame"] = CommandObjectSP (new CommandObjectMultiwordFrame (*this)); |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 154 | m_command_dict["help"] = CommandObjectSP (new CommandObjectHelp (*this)); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 155 | m_command_dict["image"] = CommandObjectSP (new CommandObjectImage (*this)); |
| 156 | m_command_dict["log"] = CommandObjectSP (new CommandObjectLog (*this)); |
| 157 | m_command_dict["memory"] = CommandObjectSP (new CommandObjectMemory (*this)); |
| 158 | m_command_dict["process"] = CommandObjectSP (new CommandObjectMultiwordProcess (*this)); |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 159 | m_command_dict["quit"] = CommandObjectSP (new CommandObjectQuit (*this)); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 160 | m_command_dict["register"] = CommandObjectSP (new CommandObjectRegister (*this)); |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 161 | m_command_dict["script"] = CommandObjectSP (new CommandObjectScript (*this, script_language)); |
Caroline Tice | 6e4c5ce | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 162 | m_command_dict["settings"] = CommandObjectSP (new CommandObjectMultiwordSettings (*this)); |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 163 | m_command_dict["source"] = CommandObjectSP (new CommandObjectMultiwordSource (*this)); |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 164 | m_command_dict["target"] = CommandObjectSP (new CommandObjectMultiwordTarget (*this)); |
| 165 | m_command_dict["thread"] = CommandObjectSP (new CommandObjectMultiwordThread (*this)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 166 | |
| 167 | std::auto_ptr<CommandObjectRegexCommand> |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 168 | break_regex_cmd_ap(new CommandObjectRegexCommand (*this, |
| 169 | "regexp-break", |
Caroline Tice | c1ad82e | 2010-09-07 22:38:08 +0000 | [diff] [blame] | 170 | "Set a breakpoint using a regular expression to specify the location.", |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 171 | "regexp-break [<filename>:<linenum>]\nregexp-break [<address>]\nregexp-break <...>", 2)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 172 | if (break_regex_cmd_ap.get()) |
| 173 | { |
| 174 | if (break_regex_cmd_ap->AddRegexCommand("^(.*[^[:space:]])[[:space:]]*:[[:space:]]*([[:digit:]]+)[[:space:]]*$", "breakpoint set --file '%1' --line %2") && |
| 175 | break_regex_cmd_ap->AddRegexCommand("^(0x[[:xdigit:]]+)[[:space:]]*$", "breakpoint set --address %1") && |
| 176 | break_regex_cmd_ap->AddRegexCommand("^[\"']?([-+]\\[.*\\])[\"']?[[:space:]]*$", "breakpoint set --name '%1'") && |
| 177 | break_regex_cmd_ap->AddRegexCommand("^$", "breakpoint list") && |
| 178 | break_regex_cmd_ap->AddRegexCommand("^(-.*)$", "breakpoint set %1") && |
| 179 | break_regex_cmd_ap->AddRegexCommand("^(.*[^[:space:]])[[:space:]]*$", "breakpoint set --name '%1'")) |
| 180 | { |
| 181 | CommandObjectSP break_regex_cmd_sp(break_regex_cmd_ap.release()); |
| 182 | m_command_dict[break_regex_cmd_sp->GetCommandName ()] = break_regex_cmd_sp; |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | int |
| 188 | CommandInterpreter::GetCommandNamesMatchingPartialString (const char *cmd_str, bool include_aliases, |
| 189 | StringList &matches) |
| 190 | { |
| 191 | CommandObject::AddNamesMatchingPartialString (m_command_dict, cmd_str, matches); |
| 192 | |
| 193 | if (include_aliases) |
| 194 | { |
| 195 | CommandObject::AddNamesMatchingPartialString (m_alias_dict, cmd_str, matches); |
| 196 | } |
| 197 | |
| 198 | return matches.GetSize(); |
| 199 | } |
| 200 | |
| 201 | CommandObjectSP |
| 202 | CommandInterpreter::GetCommandSP (const char *cmd_cstr, bool include_aliases, bool exact, StringList *matches) |
| 203 | { |
| 204 | CommandObject::CommandMap::iterator pos; |
| 205 | CommandObjectSP ret_val; |
| 206 | |
| 207 | std::string cmd(cmd_cstr); |
| 208 | |
| 209 | if (HasCommands()) |
| 210 | { |
| 211 | pos = m_command_dict.find(cmd); |
| 212 | if (pos != m_command_dict.end()) |
| 213 | ret_val = pos->second; |
| 214 | } |
| 215 | |
| 216 | if (include_aliases && HasAliases()) |
| 217 | { |
| 218 | pos = m_alias_dict.find(cmd); |
| 219 | if (pos != m_alias_dict.end()) |
| 220 | ret_val = pos->second; |
| 221 | } |
| 222 | |
| 223 | if (HasUserCommands()) |
| 224 | { |
| 225 | pos = m_user_dict.find(cmd); |
| 226 | if (pos != m_user_dict.end()) |
| 227 | ret_val = pos->second; |
| 228 | } |
| 229 | |
| 230 | if (!exact && ret_val == NULL) |
| 231 | { |
Jim Ingham | d40f8a6 | 2010-07-06 22:46:59 +0000 | [diff] [blame] | 232 | // We will only get into here if we didn't find any exact matches. |
| 233 | |
| 234 | CommandObjectSP user_match_sp, alias_match_sp, real_match_sp; |
| 235 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 236 | StringList local_matches; |
| 237 | if (matches == NULL) |
| 238 | matches = &local_matches; |
| 239 | |
Jim Ingham | d40f8a6 | 2010-07-06 22:46:59 +0000 | [diff] [blame] | 240 | unsigned int num_cmd_matches = 0; |
| 241 | unsigned int num_alias_matches = 0; |
| 242 | unsigned int num_user_matches = 0; |
| 243 | |
| 244 | // Look through the command dictionaries one by one, and if we get only one match from any of |
| 245 | // them in toto, then return that, otherwise return an empty CommandObjectSP and the list of matches. |
| 246 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 247 | if (HasCommands()) |
| 248 | { |
| 249 | num_cmd_matches = CommandObject::AddNamesMatchingPartialString (m_command_dict, cmd_cstr, *matches); |
| 250 | } |
| 251 | |
| 252 | if (num_cmd_matches == 1) |
| 253 | { |
| 254 | cmd.assign(matches->GetStringAtIndex(0)); |
| 255 | pos = m_command_dict.find(cmd); |
| 256 | if (pos != m_command_dict.end()) |
Jim Ingham | d40f8a6 | 2010-07-06 22:46:59 +0000 | [diff] [blame] | 257 | real_match_sp = pos->second; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Jim Ingham | 9a57417 | 2010-06-24 20:28:42 +0000 | [diff] [blame] | 260 | if (include_aliases && HasAliases()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 261 | { |
| 262 | num_alias_matches = CommandObject::AddNamesMatchingPartialString (m_alias_dict, cmd_cstr, *matches); |
| 263 | |
| 264 | } |
| 265 | |
Jim Ingham | d40f8a6 | 2010-07-06 22:46:59 +0000 | [diff] [blame] | 266 | if (num_alias_matches == 1) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 267 | { |
| 268 | cmd.assign(matches->GetStringAtIndex (num_cmd_matches)); |
| 269 | pos = m_alias_dict.find(cmd); |
| 270 | if (pos != m_alias_dict.end()) |
Jim Ingham | d40f8a6 | 2010-07-06 22:46:59 +0000 | [diff] [blame] | 271 | alias_match_sp = pos->second; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Jim Ingham | 9a57417 | 2010-06-24 20:28:42 +0000 | [diff] [blame] | 274 | if (HasUserCommands()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 275 | { |
| 276 | num_user_matches = CommandObject::AddNamesMatchingPartialString (m_user_dict, cmd_cstr, *matches); |
| 277 | } |
| 278 | |
Jim Ingham | d40f8a6 | 2010-07-06 22:46:59 +0000 | [diff] [blame] | 279 | if (num_user_matches == 1) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 280 | { |
| 281 | cmd.assign (matches->GetStringAtIndex (num_cmd_matches + num_alias_matches)); |
| 282 | |
| 283 | pos = m_user_dict.find (cmd); |
| 284 | if (pos != m_user_dict.end()) |
Jim Ingham | d40f8a6 | 2010-07-06 22:46:59 +0000 | [diff] [blame] | 285 | user_match_sp = pos->second; |
| 286 | } |
| 287 | |
| 288 | // If we got exactly one match, return that, otherwise return the match list. |
| 289 | |
| 290 | if (num_user_matches + num_cmd_matches + num_alias_matches == 1) |
| 291 | { |
| 292 | if (num_cmd_matches) |
| 293 | return real_match_sp; |
| 294 | else if (num_alias_matches) |
| 295 | return alias_match_sp; |
| 296 | else |
| 297 | return user_match_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 298 | } |
| 299 | } |
Jim Ingham | d40f8a6 | 2010-07-06 22:46:59 +0000 | [diff] [blame] | 300 | else if (matches && ret_val != NULL) |
| 301 | { |
| 302 | matches->AppendString (cmd_cstr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | |
| 306 | return ret_val; |
| 307 | } |
| 308 | |
Jim Ingham | d40f8a6 | 2010-07-06 22:46:59 +0000 | [diff] [blame] | 309 | CommandObjectSP |
| 310 | CommandInterpreter::GetCommandSPExact (const char *cmd_cstr, bool include_aliases) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 311 | { |
Jim Ingham | d40f8a6 | 2010-07-06 22:46:59 +0000 | [diff] [blame] | 312 | return GetCommandSP(cmd_cstr, include_aliases, true, NULL); |
| 313 | } |
| 314 | |
| 315 | CommandObject * |
| 316 | CommandInterpreter::GetCommandObjectExact (const char *cmd_cstr, bool include_aliases) |
| 317 | { |
| 318 | return GetCommandSPExact (cmd_cstr, include_aliases).get(); |
| 319 | } |
| 320 | |
| 321 | CommandObject * |
| 322 | CommandInterpreter::GetCommandObject (const char *cmd_cstr, StringList *matches) |
| 323 | { |
| 324 | CommandObject *command_obj = GetCommandSP (cmd_cstr, false, true, matches).get(); |
| 325 | |
| 326 | // If we didn't find an exact match to the command string in the commands, look in |
| 327 | // the aliases. |
| 328 | |
| 329 | if (command_obj == NULL) |
| 330 | { |
| 331 | command_obj = GetCommandSP (cmd_cstr, true, true, matches).get(); |
| 332 | } |
| 333 | |
| 334 | // Finally, if there wasn't an exact match among the aliases, look for an inexact match |
| 335 | // in both the commands and the aliases. |
| 336 | |
| 337 | if (command_obj == NULL) |
| 338 | command_obj = GetCommandSP(cmd_cstr, true, false, matches).get(); |
| 339 | |
| 340 | return command_obj; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | bool |
| 344 | CommandInterpreter::CommandExists (const char *cmd) |
| 345 | { |
| 346 | return m_command_dict.find(cmd) != m_command_dict.end(); |
| 347 | } |
| 348 | |
| 349 | bool |
| 350 | CommandInterpreter::AliasExists (const char *cmd) |
| 351 | { |
| 352 | return m_alias_dict.find(cmd) != m_alias_dict.end(); |
| 353 | } |
| 354 | |
| 355 | bool |
| 356 | CommandInterpreter::UserCommandExists (const char *cmd) |
| 357 | { |
| 358 | return m_user_dict.find(cmd) != m_user_dict.end(); |
| 359 | } |
| 360 | |
| 361 | void |
| 362 | CommandInterpreter::AddAlias (const char *alias_name, CommandObjectSP& command_obj_sp) |
| 363 | { |
Jim Ingham | d40f8a6 | 2010-07-06 22:46:59 +0000 | [diff] [blame] | 364 | command_obj_sp->SetIsAlias (true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 365 | m_alias_dict[alias_name] = command_obj_sp; |
| 366 | } |
| 367 | |
| 368 | bool |
| 369 | CommandInterpreter::RemoveAlias (const char *alias_name) |
| 370 | { |
| 371 | CommandObject::CommandMap::iterator pos = m_alias_dict.find(alias_name); |
| 372 | if (pos != m_alias_dict.end()) |
| 373 | { |
| 374 | m_alias_dict.erase(pos); |
| 375 | return true; |
| 376 | } |
| 377 | return false; |
| 378 | } |
| 379 | bool |
| 380 | CommandInterpreter::RemoveUser (const char *alias_name) |
| 381 | { |
| 382 | CommandObject::CommandMap::iterator pos = m_user_dict.find(alias_name); |
| 383 | if (pos != m_user_dict.end()) |
| 384 | { |
| 385 | m_user_dict.erase(pos); |
| 386 | return true; |
| 387 | } |
| 388 | return false; |
| 389 | } |
| 390 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 391 | void |
| 392 | CommandInterpreter::GetAliasHelp (const char *alias_name, const char *command_name, StreamString &help_string) |
| 393 | { |
| 394 | help_string.Printf ("'%s", command_name); |
| 395 | OptionArgVectorSP option_arg_vector_sp = GetAliasOptions (alias_name); |
| 396 | |
| 397 | if (option_arg_vector_sp != NULL) |
| 398 | { |
| 399 | OptionArgVector *options = option_arg_vector_sp.get(); |
| 400 | for (int i = 0; i < options->size(); ++i) |
| 401 | { |
| 402 | OptionArgPair cur_option = (*options)[i]; |
| 403 | std::string opt = cur_option.first; |
| 404 | std::string value = cur_option.second; |
| 405 | if (opt.compare("<argument>") == 0) |
| 406 | { |
| 407 | help_string.Printf (" %s", value.c_str()); |
| 408 | } |
| 409 | else |
| 410 | { |
| 411 | help_string.Printf (" %s", opt.c_str()); |
| 412 | if ((value.compare ("<no-argument>") != 0) |
| 413 | && (value.compare ("<need-argument") != 0)) |
| 414 | { |
| 415 | help_string.Printf (" %s", value.c_str()); |
| 416 | } |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | help_string.Printf ("'"); |
| 422 | } |
| 423 | |
Greg Clayton | 65124ea | 2010-08-26 22:05:43 +0000 | [diff] [blame] | 424 | size_t |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 425 | CommandInterpreter::FindLongestCommandWord (CommandObject::CommandMap &dict) |
| 426 | { |
| 427 | CommandObject::CommandMap::const_iterator pos; |
Greg Clayton | 65124ea | 2010-08-26 22:05:43 +0000 | [diff] [blame] | 428 | CommandObject::CommandMap::const_iterator end = dict.end(); |
| 429 | size_t max_len = 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 430 | |
Greg Clayton | 65124ea | 2010-08-26 22:05:43 +0000 | [diff] [blame] | 431 | for (pos = dict.begin(); pos != end; ++pos) |
| 432 | { |
| 433 | size_t len = pos->first.size(); |
| 434 | if (max_len < len) |
| 435 | max_len = len; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 436 | } |
Greg Clayton | 65124ea | 2010-08-26 22:05:43 +0000 | [diff] [blame] | 437 | return max_len; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | void |
| 441 | CommandInterpreter::GetHelp (CommandReturnObject &result) |
| 442 | { |
| 443 | CommandObject::CommandMap::const_iterator pos; |
| 444 | result.AppendMessage("The following is a list of built-in, permanent debugger commands:"); |
| 445 | result.AppendMessage(""); |
Greg Clayton | 65124ea | 2010-08-26 22:05:43 +0000 | [diff] [blame] | 446 | uint32_t max_len = FindLongestCommandWord (m_command_dict); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 447 | |
| 448 | for (pos = m_command_dict.begin(); pos != m_command_dict.end(); ++pos) |
| 449 | { |
| 450 | OutputFormattedHelpText (result.GetOutputStream(), pos->first.c_str(), "--", pos->second->GetHelp(), |
| 451 | max_len); |
| 452 | } |
| 453 | result.AppendMessage(""); |
| 454 | |
| 455 | if (m_alias_dict.size() > 0) |
| 456 | { |
Caroline Tice | 00edd3a | 2010-09-13 05:27:16 +0000 | [diff] [blame] | 457 | result.AppendMessage("The following is a list of your current command abbreviations (see 'help commands alias' for more info):"); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 458 | result.AppendMessage(""); |
Greg Clayton | 65124ea | 2010-08-26 22:05:43 +0000 | [diff] [blame] | 459 | max_len = FindLongestCommandWord (m_alias_dict); |
| 460 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 461 | for (pos = m_alias_dict.begin(); pos != m_alias_dict.end(); ++pos) |
| 462 | { |
| 463 | StreamString sstr; |
| 464 | StreamString translation_and_help; |
| 465 | std::string entry_name = pos->first; |
| 466 | std::string second_entry = pos->second.get()->GetCommandName(); |
| 467 | GetAliasHelp (pos->first.c_str(), pos->second->GetCommandName(), sstr); |
| 468 | |
| 469 | translation_and_help.Printf ("(%s) %s", sstr.GetData(), pos->second->GetHelp()); |
| 470 | OutputFormattedHelpText (result.GetOutputStream(), pos->first.c_str(), "--", |
| 471 | translation_and_help.GetData(), max_len); |
| 472 | } |
| 473 | result.AppendMessage(""); |
| 474 | } |
| 475 | |
| 476 | if (m_user_dict.size() > 0) |
| 477 | { |
| 478 | result.AppendMessage ("The following is a list of your current user-defined commands:"); |
| 479 | result.AppendMessage(""); |
| 480 | for (pos = m_user_dict.begin(); pos != m_user_dict.end(); ++pos) |
| 481 | { |
| 482 | result.AppendMessageWithFormat ("%s -- %s\n", pos->first.c_str(), pos->second->GetHelp()); |
| 483 | } |
| 484 | result.AppendMessage(""); |
| 485 | } |
| 486 | |
| 487 | result.AppendMessage("For more information on any particular command, try 'help <command-name>'."); |
| 488 | } |
| 489 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 490 | bool |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 491 | CommandInterpreter::HandleCommand |
| 492 | ( |
| 493 | const char *command_line, |
| 494 | bool add_to_history, |
| 495 | CommandReturnObject &result, |
| 496 | ExecutionContext *override_context |
| 497 | ) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 498 | { |
| 499 | // FIXME: there should probably be a mutex to make sure only one thread can |
| 500 | // run the interpreter at a time. |
| 501 | |
| 502 | // TODO: this should be a logging channel in lldb. |
| 503 | // if (DebugSelf()) |
| 504 | // { |
| 505 | // result.AppendMessageWithFormat ("Processing command: %s\n", command_line); |
| 506 | // } |
| 507 | |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 508 | m_debugger.UpdateExecutionContext (override_context); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 509 | |
| 510 | if (command_line == NULL || command_line[0] == '\0') |
| 511 | { |
| 512 | if (m_command_history.empty()) |
| 513 | { |
| 514 | result.AppendError ("empty command"); |
| 515 | result.SetStatus(eReturnStatusFailed); |
| 516 | return false; |
| 517 | } |
| 518 | else |
| 519 | { |
Jim Ingham | 5d9cbd4 | 2010-07-06 23:48:33 +0000 | [diff] [blame] | 520 | command_line = m_repeat_command.c_str(); |
| 521 | if (m_repeat_command.empty()) |
| 522 | { |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 523 | result.AppendErrorWithFormat("No auto repeat.\n"); |
Jim Ingham | 5d9cbd4 | 2010-07-06 23:48:33 +0000 | [diff] [blame] | 524 | result.SetStatus (eReturnStatusFailed); |
| 525 | return false; |
| 526 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 527 | } |
| 528 | add_to_history = false; |
| 529 | } |
| 530 | |
| 531 | Args command_args(command_line); |
| 532 | |
| 533 | if (command_args.GetArgumentCount() > 0) |
| 534 | { |
| 535 | const char *command_cstr = command_args.GetArgumentAtIndex(0); |
| 536 | if (command_cstr) |
| 537 | { |
| 538 | |
| 539 | // We're looking up the command object here. So first find an exact match to the |
| 540 | // command in the commands. |
Jim Ingham | d40f8a6 | 2010-07-06 22:46:59 +0000 | [diff] [blame] | 541 | CommandObject *command_obj = GetCommandObject(command_cstr); |
| 542 | |
| 543 | if (command_obj != NULL) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 544 | { |
Jim Ingham | d40f8a6 | 2010-07-06 22:46:59 +0000 | [diff] [blame] | 545 | if (command_obj->IsAlias()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 546 | { |
| 547 | BuildAliasCommandArgs (command_obj, command_cstr, command_args, result); |
| 548 | if (!result.Succeeded()) |
| 549 | return false; |
| 550 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 551 | |
Jim Ingham | 5d9cbd4 | 2010-07-06 23:48:33 +0000 | [diff] [blame] | 552 | if (add_to_history) |
| 553 | { |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 554 | const char *repeat_command = command_obj->GetRepeatCommand(command_args, 0); |
| 555 | if (repeat_command != NULL) |
Jim Ingham | 5d9cbd4 | 2010-07-06 23:48:33 +0000 | [diff] [blame] | 556 | m_repeat_command.assign(repeat_command); |
| 557 | else |
Jim Ingham | 767af88 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 558 | m_repeat_command.assign(command_line); |
Jim Ingham | 5d9cbd4 | 2010-07-06 23:48:33 +0000 | [diff] [blame] | 559 | |
| 560 | m_command_history.push_back (command_line); |
| 561 | } |
| 562 | |
| 563 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 564 | if (command_obj->WantsRawCommandString()) |
| 565 | { |
| 566 | const char *stripped_command = ::strstr (command_line, command_cstr); |
| 567 | if (stripped_command) |
| 568 | { |
| 569 | stripped_command += strlen(command_cstr); |
| 570 | while (isspace(*stripped_command)) |
| 571 | ++stripped_command; |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 572 | command_obj->ExecuteRawCommandString (stripped_command, result); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 573 | } |
| 574 | } |
| 575 | else |
| 576 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 577 | // Remove the command from the args. |
| 578 | command_args.Shift(); |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 579 | command_obj->ExecuteWithOptions (command_args, result); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 580 | } |
| 581 | } |
| 582 | else |
| 583 | { |
Jim Ingham | d40f8a6 | 2010-07-06 22:46:59 +0000 | [diff] [blame] | 584 | // We didn't find the first command object, so complete the first argument. |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 585 | StringList matches; |
| 586 | int num_matches; |
Jim Ingham | d40f8a6 | 2010-07-06 22:46:59 +0000 | [diff] [blame] | 587 | int cursor_index = 0; |
| 588 | int cursor_char_position = strlen (command_args.GetArgumentAtIndex(0)); |
Jim Ingham | 802f8b0 | 2010-06-30 05:02:46 +0000 | [diff] [blame] | 589 | bool word_complete; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 590 | num_matches = HandleCompletionMatches (command_args, |
| 591 | cursor_index, |
| 592 | cursor_char_position, |
| 593 | 0, |
| 594 | -1, |
Jim Ingham | 802f8b0 | 2010-06-30 05:02:46 +0000 | [diff] [blame] | 595 | word_complete, |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 596 | matches); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 597 | |
| 598 | if (num_matches > 0) |
| 599 | { |
| 600 | std::string error_msg; |
| 601 | error_msg.assign ("ambiguous command '"); |
| 602 | error_msg.append(command_cstr); |
| 603 | error_msg.append ("'."); |
| 604 | |
| 605 | error_msg.append (" Possible completions:"); |
| 606 | for (int i = 0; i < num_matches; i++) |
| 607 | { |
| 608 | error_msg.append ("\n\t"); |
| 609 | error_msg.append (matches.GetStringAtIndex (i)); |
| 610 | } |
| 611 | error_msg.append ("\n"); |
| 612 | result.AppendRawError (error_msg.c_str(), error_msg.size()); |
| 613 | } |
| 614 | else |
| 615 | result.AppendErrorWithFormat ("Unrecognized command '%s'.\n", command_cstr); |
| 616 | |
| 617 | result.SetStatus (eReturnStatusFailed); |
| 618 | } |
| 619 | } |
| 620 | } |
| 621 | return result.Succeeded(); |
| 622 | } |
| 623 | |
| 624 | int |
| 625 | CommandInterpreter::HandleCompletionMatches (Args &parsed_line, |
| 626 | int &cursor_index, |
| 627 | int &cursor_char_position, |
| 628 | int match_start_point, |
| 629 | int max_return_elements, |
Jim Ingham | 802f8b0 | 2010-06-30 05:02:46 +0000 | [diff] [blame] | 630 | bool &word_complete, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 631 | StringList &matches) |
| 632 | { |
| 633 | int num_command_matches = 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 634 | bool look_for_subcommand = false; |
Jim Ingham | 802f8b0 | 2010-06-30 05:02:46 +0000 | [diff] [blame] | 635 | |
| 636 | // For any of the command completions a unique match will be a complete word. |
| 637 | word_complete = true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 638 | |
| 639 | if (cursor_index == -1) |
| 640 | { |
| 641 | // We got nothing on the command line, so return the list of commands |
Jim Ingham | d40f8a6 | 2010-07-06 22:46:59 +0000 | [diff] [blame] | 642 | bool include_aliases = true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 643 | num_command_matches = GetCommandNamesMatchingPartialString ("", include_aliases, matches); |
| 644 | } |
| 645 | else if (cursor_index == 0) |
| 646 | { |
| 647 | // The cursor is in the first argument, so just do a lookup in the dictionary. |
Jim Ingham | d40f8a6 | 2010-07-06 22:46:59 +0000 | [diff] [blame] | 648 | CommandObject *cmd_obj = GetCommandObject (parsed_line.GetArgumentAtIndex(0), &matches); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 649 | num_command_matches = matches.GetSize(); |
| 650 | |
| 651 | if (num_command_matches == 1 |
| 652 | && cmd_obj && cmd_obj->IsMultiwordObject() |
| 653 | && matches.GetStringAtIndex(0) != NULL |
| 654 | && strcmp (parsed_line.GetArgumentAtIndex(0), matches.GetStringAtIndex(0)) == 0) |
| 655 | { |
| 656 | look_for_subcommand = true; |
| 657 | num_command_matches = 0; |
| 658 | matches.DeleteStringAtIndex(0); |
| 659 | parsed_line.AppendArgument (""); |
| 660 | cursor_index++; |
| 661 | cursor_char_position = 0; |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | if (cursor_index > 0 || look_for_subcommand) |
| 666 | { |
| 667 | // We are completing further on into a commands arguments, so find the command and tell it |
| 668 | // to complete the command. |
| 669 | // First see if there is a matching initial command: |
Jim Ingham | d40f8a6 | 2010-07-06 22:46:59 +0000 | [diff] [blame] | 670 | CommandObject *command_object = GetCommandObject (parsed_line.GetArgumentAtIndex(0)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 671 | if (command_object == NULL) |
| 672 | { |
| 673 | return 0; |
| 674 | } |
| 675 | else |
| 676 | { |
| 677 | parsed_line.Shift(); |
| 678 | cursor_index--; |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 679 | num_command_matches = command_object->HandleCompletion (parsed_line, |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 680 | cursor_index, |
| 681 | cursor_char_position, |
| 682 | match_start_point, |
Jim Ingham | 802f8b0 | 2010-06-30 05:02:46 +0000 | [diff] [blame] | 683 | max_return_elements, |
| 684 | word_complete, |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 685 | matches); |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | return num_command_matches; |
| 690 | |
| 691 | } |
| 692 | |
| 693 | int |
| 694 | CommandInterpreter::HandleCompletion (const char *current_line, |
| 695 | const char *cursor, |
| 696 | const char *last_char, |
| 697 | int match_start_point, |
| 698 | int max_return_elements, |
| 699 | StringList &matches) |
| 700 | { |
| 701 | // We parse the argument up to the cursor, so the last argument in parsed_line is |
| 702 | // the one containing the cursor, and the cursor is after the last character. |
| 703 | |
| 704 | Args parsed_line(current_line, last_char - current_line); |
| 705 | Args partial_parsed_line(current_line, cursor - current_line); |
| 706 | |
| 707 | int num_args = partial_parsed_line.GetArgumentCount(); |
| 708 | int cursor_index = partial_parsed_line.GetArgumentCount() - 1; |
| 709 | int cursor_char_position; |
| 710 | |
| 711 | if (cursor_index == -1) |
| 712 | cursor_char_position = 0; |
| 713 | else |
| 714 | cursor_char_position = strlen (partial_parsed_line.GetArgumentAtIndex(cursor_index)); |
| 715 | |
| 716 | int num_command_matches; |
| 717 | |
| 718 | matches.Clear(); |
| 719 | |
| 720 | // Only max_return_elements == -1 is supported at present: |
| 721 | assert (max_return_elements == -1); |
Jim Ingham | 802f8b0 | 2010-06-30 05:02:46 +0000 | [diff] [blame] | 722 | bool word_complete; |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 723 | num_command_matches = HandleCompletionMatches (parsed_line, |
| 724 | cursor_index, |
| 725 | cursor_char_position, |
| 726 | match_start_point, |
Jim Ingham | 802f8b0 | 2010-06-30 05:02:46 +0000 | [diff] [blame] | 727 | max_return_elements, |
| 728 | word_complete, |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 729 | matches); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 730 | |
| 731 | if (num_command_matches <= 0) |
| 732 | return num_command_matches; |
| 733 | |
| 734 | if (num_args == 0) |
| 735 | { |
| 736 | // If we got an empty string, insert nothing. |
| 737 | matches.InsertStringAtIndex(0, ""); |
| 738 | } |
| 739 | else |
| 740 | { |
| 741 | // Now figure out if there is a common substring, and if so put that in element 0, otherwise |
| 742 | // put an empty string in element 0. |
| 743 | std::string command_partial_str; |
| 744 | if (cursor_index >= 0) |
| 745 | command_partial_str.assign(parsed_line.GetArgumentAtIndex(cursor_index), parsed_line.GetArgumentAtIndex(cursor_index) + cursor_char_position); |
| 746 | |
| 747 | std::string common_prefix; |
| 748 | matches.LongestCommonPrefix (common_prefix); |
| 749 | int partial_name_len = command_partial_str.size(); |
| 750 | |
| 751 | // If we matched a unique single command, add a space... |
Jim Ingham | 802f8b0 | 2010-06-30 05:02:46 +0000 | [diff] [blame] | 752 | // Only do this if the completer told us this was a complete word, however... |
| 753 | if (num_command_matches == 1 && word_complete) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 754 | { |
| 755 | char quote_char = parsed_line.GetArgumentQuoteCharAtIndex(cursor_index); |
| 756 | if (quote_char != '\0') |
| 757 | common_prefix.push_back(quote_char); |
| 758 | |
| 759 | common_prefix.push_back(' '); |
| 760 | } |
| 761 | common_prefix.erase (0, partial_name_len); |
| 762 | matches.InsertStringAtIndex(0, common_prefix.c_str()); |
| 763 | } |
| 764 | return num_command_matches; |
| 765 | } |
| 766 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 767 | |
| 768 | CommandInterpreter::~CommandInterpreter () |
| 769 | { |
| 770 | } |
| 771 | |
| 772 | const char * |
| 773 | CommandInterpreter::GetPrompt () |
| 774 | { |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 775 | return m_debugger.GetPrompt(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | void |
| 779 | CommandInterpreter::SetPrompt (const char *new_prompt) |
| 780 | { |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 781 | m_debugger.SetPrompt (new_prompt); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 782 | } |
| 783 | |
Jim Ingham | 5e16ef5 | 2010-10-04 19:49:29 +0000 | [diff] [blame] | 784 | size_t |
| 785 | CommandInterpreter::GetConfirmationInputReaderCallback (void *baton, |
| 786 | InputReader &reader, |
| 787 | lldb::InputReaderAction action, |
| 788 | const char *bytes, |
| 789 | size_t bytes_len) |
| 790 | { |
| 791 | FILE *out_fh = reader.GetDebugger().GetOutputFileHandle(); |
| 792 | bool *response_ptr = (bool *) baton; |
| 793 | |
| 794 | switch (action) |
| 795 | { |
| 796 | case eInputReaderActivate: |
| 797 | if (out_fh) |
| 798 | { |
| 799 | if (reader.GetPrompt()) |
| 800 | ::fprintf (out_fh, "%s", reader.GetPrompt()); |
| 801 | } |
| 802 | break; |
| 803 | |
| 804 | case eInputReaderDeactivate: |
| 805 | break; |
| 806 | |
| 807 | case eInputReaderReactivate: |
| 808 | if (out_fh && reader.GetPrompt()) |
| 809 | ::fprintf (out_fh, "%s", reader.GetPrompt()); |
| 810 | break; |
| 811 | |
| 812 | case eInputReaderGotToken: |
| 813 | if (bytes_len == 0) |
| 814 | { |
| 815 | reader.SetIsDone(true); |
| 816 | } |
| 817 | else if (bytes[0] == 'y') |
| 818 | { |
| 819 | *response_ptr = true; |
| 820 | reader.SetIsDone(true); |
| 821 | } |
| 822 | else if (bytes[0] == 'n') |
| 823 | { |
| 824 | *response_ptr = false; |
| 825 | reader.SetIsDone(true); |
| 826 | } |
| 827 | else |
| 828 | { |
| 829 | if (out_fh && !reader.IsDone() && reader.GetPrompt()) |
| 830 | { |
| 831 | ::fprintf (out_fh, "Please answer \"y\" or \"n\"\n"); |
| 832 | ::fprintf (out_fh, "%s", reader.GetPrompt()); |
| 833 | } |
| 834 | } |
| 835 | break; |
| 836 | |
| 837 | case eInputReaderDone: |
| 838 | break; |
| 839 | } |
| 840 | |
| 841 | return bytes_len; |
| 842 | |
| 843 | } |
| 844 | |
| 845 | bool |
| 846 | CommandInterpreter::Confirm (const char *message, bool default_answer) |
| 847 | { |
Jim Ingham | 9305747 | 2010-10-04 22:44:14 +0000 | [diff] [blame] | 848 | // Check AutoConfirm first: |
| 849 | if (m_debugger.GetAutoConfirm()) |
| 850 | return default_answer; |
| 851 | |
Jim Ingham | 5e16ef5 | 2010-10-04 19:49:29 +0000 | [diff] [blame] | 852 | InputReaderSP reader_sp (new InputReader(GetDebugger())); |
| 853 | bool response = default_answer; |
| 854 | if (reader_sp) |
| 855 | { |
| 856 | std::string prompt(message); |
| 857 | prompt.append(": ["); |
| 858 | if (default_answer) |
| 859 | prompt.append ("Y/n] "); |
| 860 | else |
| 861 | prompt.append ("y/N] "); |
| 862 | |
| 863 | Error err (reader_sp->Initialize (CommandInterpreter::GetConfirmationInputReaderCallback, |
| 864 | &response, // baton |
| 865 | eInputReaderGranularityLine, // token size, to pass to callback function |
| 866 | NULL, // end token |
| 867 | prompt.c_str(), // prompt |
| 868 | true)); // echo input |
| 869 | if (err.Success()) |
| 870 | { |
| 871 | GetDebugger().PushInputReader (reader_sp); |
| 872 | } |
| 873 | reader_sp->WaitOnReaderIsDone(); |
| 874 | } |
| 875 | return response; |
| 876 | } |
| 877 | |
| 878 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 879 | void |
| 880 | CommandInterpreter::CrossRegisterCommand (const char * dest_cmd, const char * object_type) |
| 881 | { |
Jim Ingham | d40f8a6 | 2010-07-06 22:46:59 +0000 | [diff] [blame] | 882 | CommandObjectSP cmd_obj_sp = GetCommandSPExact (dest_cmd, true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 883 | |
| 884 | if (cmd_obj_sp != NULL) |
| 885 | { |
| 886 | CommandObject *cmd_obj = cmd_obj_sp.get(); |
| 887 | if (cmd_obj->IsCrossRefObject ()) |
| 888 | cmd_obj->AddObject (object_type); |
| 889 | } |
| 890 | } |
| 891 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 892 | OptionArgVectorSP |
| 893 | CommandInterpreter::GetAliasOptions (const char *alias_name) |
| 894 | { |
| 895 | OptionArgMap::iterator pos; |
| 896 | OptionArgVectorSP ret_val; |
| 897 | |
| 898 | std::string alias (alias_name); |
| 899 | |
| 900 | if (HasAliasOptions()) |
| 901 | { |
| 902 | pos = m_alias_options.find (alias); |
| 903 | if (pos != m_alias_options.end()) |
| 904 | ret_val = pos->second; |
| 905 | } |
| 906 | |
| 907 | return ret_val; |
| 908 | } |
| 909 | |
| 910 | void |
| 911 | CommandInterpreter::RemoveAliasOptions (const char *alias_name) |
| 912 | { |
| 913 | OptionArgMap::iterator pos = m_alias_options.find(alias_name); |
| 914 | if (pos != m_alias_options.end()) |
| 915 | { |
| 916 | m_alias_options.erase (pos); |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | void |
| 921 | CommandInterpreter::AddOrReplaceAliasOptions (const char *alias_name, OptionArgVectorSP &option_arg_vector_sp) |
| 922 | { |
| 923 | m_alias_options[alias_name] = option_arg_vector_sp; |
| 924 | } |
| 925 | |
| 926 | bool |
| 927 | CommandInterpreter::HasCommands () |
| 928 | { |
| 929 | return (!m_command_dict.empty()); |
| 930 | } |
| 931 | |
| 932 | bool |
| 933 | CommandInterpreter::HasAliases () |
| 934 | { |
| 935 | return (!m_alias_dict.empty()); |
| 936 | } |
| 937 | |
| 938 | bool |
| 939 | CommandInterpreter::HasUserCommands () |
| 940 | { |
| 941 | return (!m_user_dict.empty()); |
| 942 | } |
| 943 | |
| 944 | bool |
| 945 | CommandInterpreter::HasAliasOptions () |
| 946 | { |
| 947 | return (!m_alias_options.empty()); |
| 948 | } |
| 949 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 950 | void |
Caroline Tice | bd5c63e | 2010-10-12 21:57:09 +0000 | [diff] [blame] | 951 | CommandInterpreter::BuildAliasCommandArgs (CommandObject *alias_cmd_obj, |
| 952 | const char *alias_name, |
| 953 | Args &cmd_args, |
| 954 | CommandReturnObject &result) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 955 | { |
| 956 | OptionArgVectorSP option_arg_vector_sp = GetAliasOptions (alias_name); |
| 957 | |
| 958 | if (option_arg_vector_sp.get()) |
| 959 | { |
| 960 | // Make sure that the alias name is the 0th element in cmd_args |
| 961 | std::string alias_name_str = alias_name; |
| 962 | if (alias_name_str.compare (cmd_args.GetArgumentAtIndex(0)) != 0) |
| 963 | cmd_args.Unshift (alias_name); |
| 964 | |
| 965 | Args new_args (alias_cmd_obj->GetCommandName()); |
| 966 | if (new_args.GetArgumentCount() == 2) |
| 967 | new_args.Shift(); |
| 968 | |
| 969 | OptionArgVector *option_arg_vector = option_arg_vector_sp.get(); |
| 970 | int old_size = cmd_args.GetArgumentCount(); |
Caroline Tice | bd5c63e | 2010-10-12 21:57:09 +0000 | [diff] [blame] | 971 | std::vector<bool> used (old_size + 1, false); |
| 972 | |
| 973 | used[0] = true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 974 | |
| 975 | for (int i = 0; i < option_arg_vector->size(); ++i) |
| 976 | { |
| 977 | OptionArgPair option_pair = (*option_arg_vector)[i]; |
| 978 | std::string option = option_pair.first; |
| 979 | std::string value = option_pair.second; |
| 980 | if (option.compare ("<argument>") == 0) |
| 981 | new_args.AppendArgument (value.c_str()); |
| 982 | else |
| 983 | { |
| 984 | new_args.AppendArgument (option.c_str()); |
| 985 | if (value.compare ("<no-argument>") != 0) |
| 986 | { |
| 987 | int index = GetOptionArgumentPosition (value.c_str()); |
| 988 | if (index == 0) |
| 989 | // value was NOT a positional argument; must be a real value |
| 990 | new_args.AppendArgument (value.c_str()); |
| 991 | else if (index >= cmd_args.GetArgumentCount()) |
| 992 | { |
| 993 | result.AppendErrorWithFormat |
| 994 | ("Not enough arguments provided; you need at least %d arguments to use this alias.\n", |
| 995 | index); |
| 996 | result.SetStatus (eReturnStatusFailed); |
| 997 | return; |
| 998 | } |
| 999 | else |
| 1000 | { |
| 1001 | new_args.AppendArgument (cmd_args.GetArgumentAtIndex (index)); |
Caroline Tice | bd5c63e | 2010-10-12 21:57:09 +0000 | [diff] [blame] | 1002 | used[index] = true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1003 | } |
| 1004 | } |
| 1005 | } |
| 1006 | } |
| 1007 | |
| 1008 | for (int j = 0; j < cmd_args.GetArgumentCount(); ++j) |
| 1009 | { |
| 1010 | if (!used[j]) |
| 1011 | new_args.AppendArgument (cmd_args.GetArgumentAtIndex (j)); |
| 1012 | } |
| 1013 | |
| 1014 | cmd_args.Clear(); |
| 1015 | cmd_args.SetArguments (new_args.GetArgumentCount(), (const char **) new_args.GetArgumentVector()); |
| 1016 | } |
| 1017 | else |
| 1018 | { |
| 1019 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1020 | // This alias was not created with any options; nothing further needs to be done. |
| 1021 | return; |
| 1022 | } |
| 1023 | |
| 1024 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 1025 | return; |
| 1026 | } |
| 1027 | |
| 1028 | |
| 1029 | int |
| 1030 | CommandInterpreter::GetOptionArgumentPosition (const char *in_string) |
| 1031 | { |
| 1032 | int position = 0; // Any string that isn't an argument position, i.e. '%' followed by an integer, gets a position |
| 1033 | // of zero. |
| 1034 | |
| 1035 | char *cptr = (char *) in_string; |
| 1036 | |
| 1037 | // Does it start with '%' |
| 1038 | if (cptr[0] == '%') |
| 1039 | { |
| 1040 | ++cptr; |
| 1041 | |
| 1042 | // Is the rest of it entirely digits? |
| 1043 | if (isdigit (cptr[0])) |
| 1044 | { |
| 1045 | const char *start = cptr; |
| 1046 | while (isdigit (cptr[0])) |
| 1047 | ++cptr; |
| 1048 | |
| 1049 | // We've gotten to the end of the digits; are we at the end of the string? |
| 1050 | if (cptr[0] == '\0') |
| 1051 | position = atoi (start); |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | return position; |
| 1056 | } |
| 1057 | |
| 1058 | void |
| 1059 | CommandInterpreter::SourceInitFile (bool in_cwd, CommandReturnObject &result) |
| 1060 | { |
Greg Clayton | 887aa28 | 2010-10-11 01:05:37 +0000 | [diff] [blame] | 1061 | // Don't parse any .lldbinit files if we were asked not to |
| 1062 | if (m_skip_lldbinit_files) |
| 1063 | return; |
| 1064 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1065 | const char *init_file_path = in_cwd ? "./.lldbinit" : "~/.lldbinit"; |
| 1066 | FileSpec init_file (init_file_path); |
| 1067 | // If the file exists, tell HandleCommand to 'source' it; this will do the actual broadcasting |
| 1068 | // of the commands back to any appropriate listener (see CommandObjectSource::Execute for more details). |
| 1069 | |
| 1070 | if (init_file.Exists()) |
| 1071 | { |
| 1072 | char path[PATH_MAX]; |
| 1073 | init_file.GetPath(path, sizeof(path)); |
| 1074 | StreamString source_command; |
Johnny Chen | 7c98424 | 2010-07-28 21:16:11 +0000 | [diff] [blame] | 1075 | source_command.Printf ("command source '%s'", path); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1076 | HandleCommand (source_command.GetData(), false, result); |
| 1077 | } |
| 1078 | else |
| 1079 | { |
| 1080 | // nothing to be done if the file doesn't exist |
| 1081 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | ScriptInterpreter * |
| 1086 | CommandInterpreter::GetScriptInterpreter () |
| 1087 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1088 | CommandObject::CommandMap::iterator pos; |
| 1089 | |
| 1090 | pos = m_command_dict.find ("script"); |
| 1091 | if (pos != m_command_dict.end()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1092 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1093 | CommandObject *script_cmd_obj = pos->second.get(); |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1094 | return ((CommandObjectScript *) script_cmd_obj)->GetInterpreter (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1095 | } |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 1096 | return NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | |
| 1100 | |
| 1101 | bool |
| 1102 | CommandInterpreter::GetSynchronous () |
| 1103 | { |
| 1104 | return m_synchronous_execution; |
| 1105 | } |
| 1106 | |
| 1107 | void |
| 1108 | CommandInterpreter::SetSynchronous (bool value) |
| 1109 | { |
Johnny Chen | d7a4eb0 | 2010-10-14 01:22:03 +0000 | [diff] [blame^] | 1110 | m_synchronous_execution = value; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | void |
| 1114 | CommandInterpreter::OutputFormattedHelpText (Stream &strm, |
| 1115 | const char *word_text, |
| 1116 | const char *separator, |
| 1117 | const char *help_text, |
| 1118 | uint32_t max_word_len) |
| 1119 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1120 | const uint32_t max_columns = m_debugger.GetTerminalWidth(); |
| 1121 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1122 | int indent_size = max_word_len + strlen (separator) + 2; |
| 1123 | |
| 1124 | strm.IndentMore (indent_size); |
| 1125 | |
| 1126 | int len = indent_size + strlen (help_text) + 1; |
| 1127 | char *text = (char *) malloc (len); |
| 1128 | sprintf (text, "%-*s %s %s", max_word_len, word_text, separator, help_text); |
| 1129 | if (text[len - 1] == '\n') |
| 1130 | text[--len] = '\0'; |
| 1131 | |
| 1132 | if (len < max_columns) |
| 1133 | { |
| 1134 | // Output it as a single line. |
| 1135 | strm.Printf ("%s", text); |
| 1136 | } |
| 1137 | else |
| 1138 | { |
| 1139 | // We need to break it up into multiple lines. |
| 1140 | bool first_line = true; |
| 1141 | int text_width; |
| 1142 | int start = 0; |
| 1143 | int end = start; |
| 1144 | int final_end = strlen (text); |
| 1145 | int sub_len; |
| 1146 | |
| 1147 | while (end < final_end) |
| 1148 | { |
| 1149 | if (first_line) |
| 1150 | text_width = max_columns - 1; |
| 1151 | else |
| 1152 | text_width = max_columns - indent_size - 1; |
| 1153 | |
| 1154 | // Don't start the 'text' on a space, since we're already outputting the indentation. |
| 1155 | if (!first_line) |
| 1156 | { |
| 1157 | while ((start < final_end) && (text[start] == ' ')) |
| 1158 | start++; |
| 1159 | } |
| 1160 | |
| 1161 | end = start + text_width; |
| 1162 | if (end > final_end) |
| 1163 | end = final_end; |
| 1164 | else |
| 1165 | { |
| 1166 | // If we're not at the end of the text, make sure we break the line on white space. |
| 1167 | while (end > start |
| 1168 | && text[end] != ' ' && text[end] != '\t' && text[end] != '\n') |
| 1169 | end--; |
| 1170 | } |
| 1171 | |
| 1172 | sub_len = end - start; |
| 1173 | if (start != 0) |
| 1174 | strm.EOL(); |
| 1175 | if (!first_line) |
| 1176 | strm.Indent(); |
| 1177 | else |
| 1178 | first_line = false; |
| 1179 | assert (start <= final_end); |
| 1180 | assert (start + sub_len <= final_end); |
| 1181 | if (sub_len > 0) |
| 1182 | strm.Write (text + start, sub_len); |
| 1183 | start = end + 1; |
| 1184 | } |
| 1185 | } |
| 1186 | strm.EOL(); |
| 1187 | strm.IndentLess(indent_size); |
| 1188 | free (text); |
| 1189 | } |
| 1190 | |
| 1191 | void |
| 1192 | CommandInterpreter::AproposAllSubCommands (CommandObject *cmd_obj, const char *prefix, const char *search_word, |
| 1193 | StringList &commands_found, StringList &commands_help) |
| 1194 | { |
| 1195 | CommandObject::CommandMap::const_iterator pos; |
| 1196 | CommandObject::CommandMap sub_cmd_dict = ((CommandObjectMultiword *) cmd_obj)->m_subcommand_dict; |
| 1197 | CommandObject *sub_cmd_obj; |
| 1198 | |
| 1199 | for (pos = sub_cmd_dict.begin(); pos != sub_cmd_dict.end(); ++pos) |
| 1200 | { |
| 1201 | const char * command_name = pos->first.c_str(); |
| 1202 | sub_cmd_obj = pos->second.get(); |
| 1203 | StreamString complete_command_name; |
| 1204 | |
| 1205 | complete_command_name.Printf ("%s %s", prefix, command_name); |
| 1206 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1207 | if (sub_cmd_obj->HelpTextContainsWord (search_word)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1208 | { |
| 1209 | commands_found.AppendString (complete_command_name.GetData()); |
| 1210 | commands_help.AppendString (sub_cmd_obj->GetHelp()); |
| 1211 | } |
| 1212 | |
| 1213 | if (sub_cmd_obj->IsMultiwordObject()) |
| 1214 | AproposAllSubCommands (sub_cmd_obj, complete_command_name.GetData(), search_word, commands_found, |
| 1215 | commands_help); |
| 1216 | } |
| 1217 | |
| 1218 | } |
| 1219 | |
| 1220 | void |
| 1221 | CommandInterpreter::FindCommandsForApropos (const char *search_word, StringList &commands_found, |
| 1222 | StringList &commands_help) |
| 1223 | { |
| 1224 | CommandObject::CommandMap::const_iterator pos; |
| 1225 | |
| 1226 | for (pos = m_command_dict.begin(); pos != m_command_dict.end(); ++pos) |
| 1227 | { |
| 1228 | const char *command_name = pos->first.c_str(); |
| 1229 | CommandObject *cmd_obj = pos->second.get(); |
| 1230 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1231 | if (cmd_obj->HelpTextContainsWord (search_word)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1232 | { |
| 1233 | commands_found.AppendString (command_name); |
| 1234 | commands_help.AppendString (cmd_obj->GetHelp()); |
| 1235 | } |
| 1236 | |
| 1237 | if (cmd_obj->IsMultiwordObject()) |
| 1238 | AproposAllSubCommands (cmd_obj, command_name, search_word, commands_found, commands_help); |
| 1239 | |
| 1240 | } |
| 1241 | } |