Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 1 | //===-- CommandObjectSource.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 | |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 10 | // C Includes |
| 11 | // C++ Includes |
| 12 | // Other libraries and framework includes |
Greg Clayton | 0e5e5a7 | 2011-04-20 22:55:21 +0000 | [diff] [blame] | 13 | #include "llvm/ADT/StringRef.h" |
| 14 | |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 15 | // Project includes |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 16 | #include "CommandObjectCommands.h" |
Enrico Granata | 46d4aa2 | 2016-02-29 23:22:53 +0000 | [diff] [blame] | 17 | #include "CommandObjectHelp.h" |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 18 | #include "lldb/Core/Debugger.h" |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 19 | #include "lldb/Core/IOHandler.h" |
Enrico Granata | be93a35 | 2011-08-16 16:49:25 +0000 | [diff] [blame] | 20 | #include "lldb/Core/StringList.h" |
Greg Clayton | de164aa | 2011-04-20 16:37:46 +0000 | [diff] [blame] | 21 | #include "lldb/Interpreter/Args.h" |
Enrico Granata | 7594f14 | 2013-06-17 22:51:50 +0000 | [diff] [blame] | 22 | #include "lldb/Interpreter/CommandHistory.h" |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 23 | #include "lldb/Interpreter/CommandInterpreter.h" |
Greg Clayton | de164aa | 2011-04-20 16:37:46 +0000 | [diff] [blame] | 24 | #include "lldb/Interpreter/CommandObjectRegexCommand.h" |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 25 | #include "lldb/Interpreter/CommandReturnObject.h" |
Enrico Granata | 012d4fc | 2013-06-11 01:26:35 +0000 | [diff] [blame] | 26 | #include "lldb/Interpreter/OptionValueBoolean.h" |
Enrico Granata | 45d0e23 | 2016-03-31 01:10:54 +0000 | [diff] [blame] | 27 | #include "lldb/Interpreter/OptionValueString.h" |
Enrico Granata | 7594f14 | 2013-06-17 22:51:50 +0000 | [diff] [blame] | 28 | #include "lldb/Interpreter/OptionValueUInt64.h" |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 29 | #include "lldb/Interpreter/Options.h" |
Enrico Granata | 99f0b8f | 2011-08-17 01:30:04 +0000 | [diff] [blame] | 30 | #include "lldb/Interpreter/ScriptInterpreter.h" |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 31 | |
| 32 | using namespace lldb; |
| 33 | using namespace lldb_private; |
| 34 | |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 35 | //------------------------------------------------------------------------- |
| 36 | // CommandObjectCommandsSource |
| 37 | //------------------------------------------------------------------------- |
| 38 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 39 | static OptionDefinition g_history_options[] = { |
| 40 | // clang-format off |
| 41 | { LLDB_OPT_SET_1, false, "count", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "How many history commands to print." }, |
| 42 | { LLDB_OPT_SET_1, false, "start-index", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "Index at which to start printing history commands (or end to mean tail mode)." }, |
| 43 | { LLDB_OPT_SET_1, false, "end-index", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeUnsignedInteger, "Index at which to stop printing history commands." }, |
| 44 | { LLDB_OPT_SET_2, false, "clear", 'C', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeBoolean, "Clears the current command history." }, |
| 45 | // clang-format on |
| 46 | }; |
| 47 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 48 | class CommandObjectCommandsHistory : public CommandObjectParsed { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 49 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 50 | CommandObjectCommandsHistory(CommandInterpreter &interpreter) |
| 51 | : CommandObjectParsed(interpreter, "command history", |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 52 | "Dump the history of commands in this session.", |
| 53 | nullptr), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 54 | m_options() {} |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 55 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 56 | ~CommandObjectCommandsHistory() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 57 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 58 | Options *GetOptions() override { return &m_options; } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 59 | |
| 60 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 61 | class CommandOptions : public Options { |
| 62 | public: |
| 63 | CommandOptions() |
| 64 | : Options(), m_start_idx(0), m_stop_idx(0), m_count(0), m_clear(false) { |
Jim Ingham | a5a97eb | 2011-07-12 03:12:18 +0000 | [diff] [blame] | 65 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 66 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 67 | ~CommandOptions() override = default; |
| 68 | |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame^] | 69 | Error SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 70 | ExecutionContext *execution_context) override { |
| 71 | Error error; |
| 72 | const int short_option = m_getopt_table[option_idx].val; |
| 73 | |
| 74 | switch (short_option) { |
| 75 | case 'c': |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame^] | 76 | error = m_count.SetValueFromString(option_arg, eVarSetOperationAssign); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 77 | break; |
| 78 | case 's': |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame^] | 79 | if (option_arg == "end") { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 80 | m_start_idx.SetCurrentValue(UINT64_MAX); |
| 81 | m_start_idx.SetOptionWasSet(); |
| 82 | } else |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame^] | 83 | error = m_start_idx.SetValueFromString(option_arg, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 84 | eVarSetOperationAssign); |
| 85 | break; |
| 86 | case 'e': |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame^] | 87 | error = |
| 88 | m_stop_idx.SetValueFromString(option_arg, eVarSetOperationAssign); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 89 | break; |
| 90 | case 'C': |
| 91 | m_clear.SetCurrentValue(true); |
| 92 | m_clear.SetOptionWasSet(); |
| 93 | break; |
| 94 | default: |
| 95 | error.SetErrorStringWithFormat("unrecognized option '%c'", |
| 96 | short_option); |
| 97 | break; |
| 98 | } |
| 99 | |
| 100 | return error; |
| 101 | } |
| 102 | |
| 103 | void OptionParsingStarting(ExecutionContext *execution_context) override { |
| 104 | m_start_idx.Clear(); |
| 105 | m_stop_idx.Clear(); |
| 106 | m_count.Clear(); |
| 107 | m_clear.Clear(); |
| 108 | } |
| 109 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 110 | llvm::ArrayRef<OptionDefinition> GetDefinitions() override { |
Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 111 | return llvm::makeArrayRef(g_history_options); |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 112 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 113 | |
| 114 | // Instance variables to hold the values for command options. |
| 115 | |
| 116 | OptionValueUInt64 m_start_idx; |
| 117 | OptionValueUInt64 m_stop_idx; |
| 118 | OptionValueUInt64 m_count; |
| 119 | OptionValueBoolean m_clear; |
| 120 | }; |
| 121 | |
| 122 | bool DoExecute(Args &command, CommandReturnObject &result) override { |
| 123 | if (m_options.m_clear.GetCurrentValue() && |
| 124 | m_options.m_clear.OptionWasSet()) { |
| 125 | m_interpreter.GetCommandHistory().Clear(); |
| 126 | result.SetStatus(lldb::eReturnStatusSuccessFinishNoResult); |
| 127 | } else { |
| 128 | if (m_options.m_start_idx.OptionWasSet() && |
| 129 | m_options.m_stop_idx.OptionWasSet() && |
| 130 | m_options.m_count.OptionWasSet()) { |
| 131 | result.AppendError("--count, --start-index and --end-index cannot be " |
| 132 | "all specified in the same invocation"); |
| 133 | result.SetStatus(lldb::eReturnStatusFailed); |
| 134 | } else { |
| 135 | std::pair<bool, uint64_t> start_idx( |
| 136 | m_options.m_start_idx.OptionWasSet(), |
| 137 | m_options.m_start_idx.GetCurrentValue()); |
| 138 | std::pair<bool, uint64_t> stop_idx( |
| 139 | m_options.m_stop_idx.OptionWasSet(), |
| 140 | m_options.m_stop_idx.GetCurrentValue()); |
| 141 | std::pair<bool, uint64_t> count(m_options.m_count.OptionWasSet(), |
| 142 | m_options.m_count.GetCurrentValue()); |
| 143 | |
| 144 | const CommandHistory &history(m_interpreter.GetCommandHistory()); |
| 145 | |
| 146 | if (start_idx.first && start_idx.second == UINT64_MAX) { |
| 147 | if (count.first) { |
| 148 | start_idx.second = history.GetSize() - count.second; |
| 149 | stop_idx.second = history.GetSize() - 1; |
| 150 | } else if (stop_idx.first) { |
| 151 | start_idx.second = stop_idx.second; |
| 152 | stop_idx.second = history.GetSize() - 1; |
| 153 | } else { |
| 154 | start_idx.second = 0; |
| 155 | stop_idx.second = history.GetSize() - 1; |
| 156 | } |
| 157 | } else { |
| 158 | if (!start_idx.first && !stop_idx.first && !count.first) { |
| 159 | start_idx.second = 0; |
| 160 | stop_idx.second = history.GetSize() - 1; |
| 161 | } else if (start_idx.first) { |
| 162 | if (count.first) { |
| 163 | stop_idx.second = start_idx.second + count.second - 1; |
| 164 | } else if (!stop_idx.first) { |
| 165 | stop_idx.second = history.GetSize() - 1; |
| 166 | } |
| 167 | } else if (stop_idx.first) { |
| 168 | if (count.first) { |
| 169 | if (stop_idx.second >= count.second) |
| 170 | start_idx.second = stop_idx.second - count.second + 1; |
| 171 | else |
| 172 | start_idx.second = 0; |
| 173 | } |
| 174 | } else /* if (count.first) */ |
| 175 | { |
| 176 | start_idx.second = 0; |
| 177 | stop_idx.second = count.second - 1; |
| 178 | } |
| 179 | } |
| 180 | history.Dump(result.GetOutputStream(), start_idx.second, |
| 181 | stop_idx.second); |
| 182 | } |
| 183 | } |
| 184 | return result.Succeeded(); |
| 185 | } |
| 186 | |
| 187 | CommandOptions m_options; |
Jim Ingham | a5a97eb | 2011-07-12 03:12:18 +0000 | [diff] [blame] | 188 | }; |
| 189 | |
Jim Ingham | a5a97eb | 2011-07-12 03:12:18 +0000 | [diff] [blame] | 190 | //------------------------------------------------------------------------- |
| 191 | // CommandObjectCommandsSource |
| 192 | //------------------------------------------------------------------------- |
| 193 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 194 | static OptionDefinition g_source_options[] = { |
| 195 | // clang-format off |
| 196 | { LLDB_OPT_SET_ALL, false, "stop-on-error", 'e', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true, stop executing commands on error." }, |
| 197 | { LLDB_OPT_SET_ALL, false, "stop-on-continue", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true, stop executing commands on continue." }, |
| 198 | { LLDB_OPT_SET_ALL, false, "silent-run", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeBoolean, "If true don't echo commands while executing." }, |
| 199 | // clang-format on |
| 200 | }; |
| 201 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 202 | class CommandObjectCommandsSource : public CommandObjectParsed { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 203 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 204 | CommandObjectCommandsSource(CommandInterpreter &interpreter) |
| 205 | : CommandObjectParsed( |
| 206 | interpreter, "command source", |
| 207 | "Read and execute LLDB commands from the file <filename>.", |
| 208 | nullptr), |
| 209 | m_options() { |
| 210 | CommandArgumentEntry arg; |
| 211 | CommandArgumentData file_arg; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 212 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 213 | // Define the first (and only) variant of this arg. |
| 214 | file_arg.arg_type = eArgTypeFilename; |
| 215 | file_arg.arg_repetition = eArgRepeatPlain; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 216 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 217 | // There is only one variant this argument could be; put it into the |
| 218 | // argument entry. |
| 219 | arg.push_back(file_arg); |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 220 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 221 | // Push the data for the first argument into the m_arguments vector. |
| 222 | m_arguments.push_back(arg); |
| 223 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 224 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 225 | ~CommandObjectCommandsSource() override = default; |
| 226 | |
| 227 | const char *GetRepeatCommand(Args ¤t_command_args, |
| 228 | uint32_t index) override { |
| 229 | return ""; |
| 230 | } |
| 231 | |
| 232 | int HandleArgumentCompletion(Args &input, int &cursor_index, |
| 233 | int &cursor_char_position, |
| 234 | OptionElementVector &opt_element_vector, |
| 235 | int match_start_point, int max_return_elements, |
| 236 | bool &word_complete, |
| 237 | StringList &matches) override { |
| 238 | std::string completion_str(input.GetArgumentAtIndex(cursor_index)); |
| 239 | completion_str.erase(cursor_char_position); |
| 240 | |
| 241 | CommandCompletions::InvokeCommonCompletionCallbacks( |
| 242 | GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion, |
| 243 | completion_str.c_str(), match_start_point, max_return_elements, nullptr, |
| 244 | word_complete, matches); |
| 245 | return matches.GetSize(); |
| 246 | } |
| 247 | |
| 248 | Options *GetOptions() override { return &m_options; } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 249 | |
| 250 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 251 | class CommandOptions : public Options { |
| 252 | public: |
| 253 | CommandOptions() |
| 254 | : Options(), m_stop_on_error(true), m_silent_run(false), |
| 255 | m_stop_on_continue(true) {} |
Jim Ingham | e16c50a | 2011-02-18 00:54:25 +0000 | [diff] [blame] | 256 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 257 | ~CommandOptions() override = default; |
Jim Ingham | e16c50a | 2011-02-18 00:54:25 +0000 | [diff] [blame] | 258 | |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame^] | 259 | Error SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 260 | ExecutionContext *execution_context) override { |
| 261 | Error error; |
| 262 | const int short_option = m_getopt_table[option_idx].val; |
Greg Clayton | 340b030 | 2014-02-05 17:57:57 +0000 | [diff] [blame] | 263 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 264 | switch (short_option) { |
| 265 | case 'e': |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame^] | 266 | error = m_stop_on_error.SetValueFromString(option_arg); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 267 | break; |
Greg Clayton | 340b030 | 2014-02-05 17:57:57 +0000 | [diff] [blame] | 268 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 269 | case 'c': |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame^] | 270 | error = m_stop_on_continue.SetValueFromString(option_arg); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 271 | break; |
Greg Clayton | 340b030 | 2014-02-05 17:57:57 +0000 | [diff] [blame] | 272 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 273 | case 's': |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame^] | 274 | error = m_silent_run.SetValueFromString(option_arg); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 275 | break; |
Jim Ingham | e16c50a | 2011-02-18 00:54:25 +0000 | [diff] [blame] | 276 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 277 | default: |
| 278 | error.SetErrorStringWithFormat("unrecognized option '%c'", |
| 279 | short_option); |
| 280 | break; |
| 281 | } |
Jim Ingham | e16c50a | 2011-02-18 00:54:25 +0000 | [diff] [blame] | 282 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 283 | return error; |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 284 | } |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 285 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 286 | void OptionParsingStarting(ExecutionContext *execution_context) override { |
| 287 | m_stop_on_error.Clear(); |
| 288 | m_silent_run.Clear(); |
| 289 | m_stop_on_continue.Clear(); |
| 290 | } |
| 291 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 292 | llvm::ArrayRef<OptionDefinition> GetDefinitions() override { |
Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 293 | return llvm::makeArrayRef(g_source_options); |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 294 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 295 | |
| 296 | // Instance variables to hold the values for command options. |
| 297 | |
| 298 | OptionValueBoolean m_stop_on_error; |
| 299 | OptionValueBoolean m_silent_run; |
| 300 | OptionValueBoolean m_stop_on_continue; |
| 301 | }; |
| 302 | |
| 303 | bool DoExecute(Args &command, CommandReturnObject &result) override { |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 304 | if (command.GetArgumentCount() == 1) { |
| 305 | llvm::StringRef filename = command.GetArgumentAtIndex(0); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 306 | |
| 307 | FileSpec cmd_file(filename, true); |
| 308 | ExecutionContext *exe_ctx = nullptr; // Just use the default context. |
| 309 | |
| 310 | // If any options were set, then use them |
| 311 | if (m_options.m_stop_on_error.OptionWasSet() || |
| 312 | m_options.m_silent_run.OptionWasSet() || |
| 313 | m_options.m_stop_on_continue.OptionWasSet()) { |
| 314 | // Use user set settings |
| 315 | CommandInterpreterRunOptions options; |
| 316 | options.SetStopOnContinue( |
| 317 | m_options.m_stop_on_continue.GetCurrentValue()); |
| 318 | options.SetStopOnError(m_options.m_stop_on_error.GetCurrentValue()); |
| 319 | options.SetEchoCommands(!m_options.m_silent_run.GetCurrentValue()); |
| 320 | options.SetPrintResults(!m_options.m_silent_run.GetCurrentValue()); |
| 321 | |
| 322 | m_interpreter.HandleCommandsFromFile(cmd_file, exe_ctx, options, |
| 323 | result); |
| 324 | } else { |
| 325 | // No options were set, inherit any settings from nested "command |
| 326 | // source" commands, |
| 327 | // or set to sane default settings... |
| 328 | CommandInterpreterRunOptions options; |
| 329 | m_interpreter.HandleCommandsFromFile(cmd_file, exe_ctx, options, |
| 330 | result); |
| 331 | } |
| 332 | } else { |
| 333 | result.AppendErrorWithFormat( |
| 334 | "'%s' takes exactly one executable filename argument.\n", |
Zachary Turner | a449698 | 2016-10-05 21:14:38 +0000 | [diff] [blame] | 335 | GetCommandName().str().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 336 | result.SetStatus(eReturnStatusFailed); |
| 337 | } |
| 338 | return result.Succeeded(); |
| 339 | } |
| 340 | |
| 341 | CommandOptions m_options; |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 342 | }; |
| 343 | |
| 344 | #pragma mark CommandObjectCommandsAlias |
| 345 | //------------------------------------------------------------------------- |
| 346 | // CommandObjectCommandsAlias |
| 347 | //------------------------------------------------------------------------- |
| 348 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 349 | static OptionDefinition g_alias_options[] = { |
| 350 | // clang-format off |
| 351 | { LLDB_OPT_SET_ALL, false, "help", 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeHelpText, "Help text for this command" }, |
| 352 | { LLDB_OPT_SET_ALL, false, "long-help", 'H', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeHelpText, "Long help text for this command" }, |
| 353 | // clang-format on |
| 354 | }; |
| 355 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 356 | static const char *g_python_command_instructions = |
| 357 | "Enter your Python command(s). Type 'DONE' to end.\n" |
| 358 | "You must define a Python function with this signature:\n" |
| 359 | "def my_command_impl(debugger, args, result, internal_dict):\n"; |
Enrico Granata | be93a35 | 2011-08-16 16:49:25 +0000 | [diff] [blame] | 360 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 361 | class CommandObjectCommandsAlias : public CommandObjectRaw { |
Enrico Granata | 45d0e23 | 2016-03-31 01:10:54 +0000 | [diff] [blame] | 362 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 363 | class CommandOptions : public OptionGroup { |
| 364 | public: |
| 365 | CommandOptions() : OptionGroup(), m_help(), m_long_help() {} |
Enrico Granata | 45d0e23 | 2016-03-31 01:10:54 +0000 | [diff] [blame] | 366 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 367 | ~CommandOptions() override = default; |
| 368 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 369 | llvm::ArrayRef<OptionDefinition> GetDefinitions() override { |
Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 370 | return llvm::makeArrayRef(g_alias_options); |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 371 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 372 | |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 373 | Error SetOptionValue(uint32_t option_idx, llvm::StringRef option_value, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 374 | ExecutionContext *execution_context) override { |
| 375 | Error error; |
| 376 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 377 | const int short_option = GetDefinitions()[option_idx].short_option; |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 378 | std::string option_str(option_value); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 379 | |
| 380 | switch (short_option) { |
| 381 | case 'h': |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 382 | m_help.SetCurrentValue(option_str); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 383 | m_help.SetOptionWasSet(); |
| 384 | break; |
| 385 | |
| 386 | case 'H': |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 387 | m_long_help.SetCurrentValue(option_str); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 388 | m_long_help.SetOptionWasSet(); |
| 389 | break; |
| 390 | |
| 391 | default: |
| 392 | error.SetErrorStringWithFormat("invalid short option character '%c'", |
| 393 | short_option); |
| 394 | break; |
| 395 | } |
| 396 | |
| 397 | return error; |
Enrico Granata | 45d0e23 | 2016-03-31 01:10:54 +0000 | [diff] [blame] | 398 | } |
| 399 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 400 | void OptionParsingStarting(ExecutionContext *execution_context) override { |
| 401 | m_help.Clear(); |
| 402 | m_long_help.Clear(); |
| 403 | } |
Enrico Granata | 45d0e23 | 2016-03-31 01:10:54 +0000 | [diff] [blame] | 404 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 405 | OptionValueString m_help; |
| 406 | OptionValueString m_long_help; |
| 407 | }; |
| 408 | |
| 409 | OptionGroupOptions m_option_group; |
| 410 | CommandOptions m_command_options; |
| 411 | |
| 412 | public: |
| 413 | Options *GetOptions() override { return &m_option_group; } |
| 414 | |
| 415 | CommandObjectCommandsAlias(CommandInterpreter &interpreter) |
| 416 | : CommandObjectRaw( |
| 417 | interpreter, "command alias", |
Zachary Turner | a449698 | 2016-10-05 21:14:38 +0000 | [diff] [blame] | 418 | "Define a custom command in terms of an existing command."), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 419 | m_option_group(), m_command_options() { |
| 420 | m_option_group.Append(&m_command_options); |
| 421 | m_option_group.Finalize(); |
| 422 | |
| 423 | SetHelpLong( |
| 424 | "'alias' allows the user to create a short-cut or abbreviation for long \ |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 425 | commands, multi-word commands, and commands that take particular options. \ |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 426 | Below are some simple examples of how one might use the 'alias' command:" |
| 427 | R"( |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 428 | |
| 429 | (lldb) command alias sc script |
| 430 | |
| 431 | Creates the abbreviation 'sc' for the 'script' command. |
| 432 | |
| 433 | (lldb) command alias bp breakpoint |
| 434 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 435 | )" |
| 436 | " Creates the abbreviation 'bp' for the 'breakpoint' command. Since \ |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 437 | breakpoint commands are two-word commands, the user would still need to \ |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 438 | enter the second word after 'bp', e.g. 'bp enable' or 'bp delete'." |
| 439 | R"( |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 440 | |
| 441 | (lldb) command alias bpl breakpoint list |
| 442 | |
| 443 | Creates the abbreviation 'bpl' for the two-word command 'breakpoint list'. |
| 444 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 445 | )" |
| 446 | "An alias can include some options for the command, with the values either \ |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 447 | filled in at the time the alias is created, or specified as positional \ |
| 448 | arguments, to be filled in when the alias is invoked. The following example \ |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 449 | shows how to create aliases with options:" |
| 450 | R"( |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 451 | |
| 452 | (lldb) command alias bfl breakpoint set -f %1 -l %2 |
| 453 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 454 | )" |
| 455 | " Creates the abbreviation 'bfl' (for break-file-line), with the -f and -l \ |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 456 | options already part of the alias. So if the user wants to set a breakpoint \ |
| 457 | by file and line without explicitly having to use the -f and -l options, the \ |
| 458 | user can now use 'bfl' instead. The '%1' and '%2' are positional placeholders \ |
| 459 | for the actual arguments that will be passed when the alias command is used. \ |
| 460 | The number in the placeholder refers to the position/order the actual value \ |
| 461 | occupies when the alias is used. All the occurrences of '%1' in the alias \ |
| 462 | will be replaced with the first argument, all the occurrences of '%2' in the \ |
| 463 | alias will be replaced with the second argument, and so on. This also allows \ |
| 464 | actual arguments to be used multiple times within an alias (see 'process \ |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 465 | launch' example below)." |
| 466 | R"( |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 467 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 468 | )" |
| 469 | "Note: the positional arguments must substitute as whole words in the resultant \ |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 470 | command, so you can't at present do something like this to append the file extension \ |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 471 | \".cpp\":" |
| 472 | R"( |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 473 | |
| 474 | (lldb) command alias bcppfl breakpoint set -f %1.cpp -l %2 |
| 475 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 476 | )" |
| 477 | "For more complex aliasing, use the \"command regex\" command instead. In the \ |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 478 | 'bfl' case above, the actual file value will be filled in with the first argument \ |
| 479 | following 'bfl' and the actual line number value will be filled in with the second \ |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 480 | argument. The user would use this alias as follows:" |
| 481 | R"( |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 482 | |
| 483 | (lldb) command alias bfl breakpoint set -f %1 -l %2 |
| 484 | (lldb) bfl my-file.c 137 |
| 485 | |
| 486 | This would be the same as if the user had entered 'breakpoint set -f my-file.c -l 137'. |
| 487 | |
| 488 | Another example: |
| 489 | |
| 490 | (lldb) command alias pltty process launch -s -o %1 -e %1 |
| 491 | (lldb) pltty /dev/tty0 |
| 492 | |
| 493 | Interpreted as 'process launch -s -o /dev/tty0 -e /dev/tty0' |
| 494 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 495 | )" |
| 496 | "If the user always wanted to pass the same value to a particular option, the \ |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 497 | alias could be defined with that value directly in the alias as a constant, \ |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 498 | rather than using a positional placeholder:" |
| 499 | R"( |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 500 | |
| 501 | (lldb) command alias bl3 breakpoint set -f %1 -l 3 |
| 502 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 503 | Always sets a breakpoint on line 3 of whatever file is indicated.)"); |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 504 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 505 | CommandArgumentEntry arg1; |
| 506 | CommandArgumentEntry arg2; |
| 507 | CommandArgumentEntry arg3; |
| 508 | CommandArgumentData alias_arg; |
| 509 | CommandArgumentData cmd_arg; |
| 510 | CommandArgumentData options_arg; |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 511 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 512 | // Define the first (and only) variant of this arg. |
| 513 | alias_arg.arg_type = eArgTypeAliasName; |
| 514 | alias_arg.arg_repetition = eArgRepeatPlain; |
| 515 | |
| 516 | // There is only one variant this argument could be; put it into the |
| 517 | // argument entry. |
| 518 | arg1.push_back(alias_arg); |
| 519 | |
| 520 | // Define the first (and only) variant of this arg. |
| 521 | cmd_arg.arg_type = eArgTypeCommandName; |
| 522 | cmd_arg.arg_repetition = eArgRepeatPlain; |
| 523 | |
| 524 | // There is only one variant this argument could be; put it into the |
| 525 | // argument entry. |
| 526 | arg2.push_back(cmd_arg); |
| 527 | |
| 528 | // Define the first (and only) variant of this arg. |
| 529 | options_arg.arg_type = eArgTypeAliasOptions; |
| 530 | options_arg.arg_repetition = eArgRepeatOptional; |
| 531 | |
| 532 | // There is only one variant this argument could be; put it into the |
| 533 | // argument entry. |
| 534 | arg3.push_back(options_arg); |
| 535 | |
| 536 | // Push the data for the first argument into the m_arguments vector. |
| 537 | m_arguments.push_back(arg1); |
| 538 | m_arguments.push_back(arg2); |
| 539 | m_arguments.push_back(arg3); |
| 540 | } |
| 541 | |
| 542 | ~CommandObjectCommandsAlias() override = default; |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 543 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 544 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 545 | bool DoExecute(const char *raw_command_line, |
| 546 | CommandReturnObject &result) override { |
| 547 | if (!raw_command_line || !raw_command_line[0]) { |
| 548 | result.AppendError("'command alias' requires at least two arguments"); |
| 549 | return false; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 550 | } |
| 551 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 552 | ExecutionContext exe_ctx = GetCommandInterpreter().GetExecutionContext(); |
| 553 | m_option_group.NotifyOptionParsingStarting(&exe_ctx); |
Caroline Tice | ca90c47 | 2011-05-06 21:37:15 +0000 | [diff] [blame] | 554 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 555 | const char *remainder = nullptr; |
Enrico Granata | 212130a | 2016-03-08 05:37:15 +0000 | [diff] [blame] | 556 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 557 | if (raw_command_line[0] == '-') { |
| 558 | // We have some options and these options MUST end with --. |
| 559 | const char *end_options = nullptr; |
| 560 | const char *s = raw_command_line; |
| 561 | while (s && s[0]) { |
| 562 | end_options = ::strstr(s, "--"); |
| 563 | if (end_options) { |
| 564 | end_options += 2; // Get past the "--" |
| 565 | if (::isspace(end_options[0])) { |
| 566 | remainder = end_options; |
| 567 | while (::isspace(*remainder)) |
| 568 | ++remainder; |
| 569 | break; |
| 570 | } |
| 571 | } |
| 572 | s = end_options; |
| 573 | } |
| 574 | |
| 575 | if (end_options) { |
| 576 | Args args( |
| 577 | llvm::StringRef(raw_command_line, end_options - raw_command_line)); |
| 578 | if (!ParseOptions(args, result)) |
| 579 | return false; |
| 580 | |
| 581 | Error error(m_option_group.NotifyOptionParsingFinished(&exe_ctx)); |
| 582 | if (error.Fail()) { |
| 583 | result.AppendError(error.AsCString()); |
| 584 | result.SetStatus(eReturnStatusFailed); |
| 585 | return false; |
| 586 | } |
| 587 | } |
Caroline Tice | 844d230 | 2010-12-09 22:52:49 +0000 | [diff] [blame] | 588 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 589 | if (nullptr == remainder) |
| 590 | remainder = raw_command_line; |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 591 | |
Zachary Turner | a01bccd | 2016-10-05 21:14:56 +0000 | [diff] [blame] | 592 | llvm::StringRef raw_command_string(remainder); |
| 593 | Args args(raw_command_string); |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 594 | |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 595 | if (args.GetArgumentCount() < 2) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 596 | result.AppendError("'command alias' requires at least two arguments"); |
| 597 | result.SetStatus(eReturnStatusFailed); |
| 598 | return false; |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 599 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 600 | |
| 601 | // Get the alias command. |
| 602 | |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 603 | // TODO: Convert this function to use StringRef. Requires converting |
| 604 | // GetCommandObjectForCommand. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 605 | const std::string alias_command = args.GetArgumentAtIndex(0); |
| 606 | if (alias_command.size() > 1 && alias_command[0] == '-') { |
| 607 | result.AppendError("aliases starting with a dash are not supported"); |
| 608 | if (alias_command == "--help" || alias_command == "--long-help") { |
| 609 | result.AppendWarning("if trying to pass options to 'command alias' add " |
| 610 | "a -- at the end of the options"); |
| 611 | } |
| 612 | result.SetStatus(eReturnStatusFailed); |
| 613 | return false; |
| 614 | } |
| 615 | |
| 616 | // Strip the new alias name off 'raw_command_string' (leave it on args, |
| 617 | // which gets passed to 'Execute', which |
| 618 | // does the stripping itself. |
| 619 | size_t pos = raw_command_string.find(alias_command); |
| 620 | if (pos == 0) { |
| 621 | raw_command_string = raw_command_string.substr(alias_command.size()); |
| 622 | pos = raw_command_string.find_first_not_of(' '); |
| 623 | if ((pos != std::string::npos) && (pos > 0)) |
| 624 | raw_command_string = raw_command_string.substr(pos); |
| 625 | } else { |
| 626 | result.AppendError("Error parsing command string. No alias created."); |
| 627 | result.SetStatus(eReturnStatusFailed); |
| 628 | return false; |
| 629 | } |
| 630 | |
| 631 | // Verify that the command is alias-able. |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 632 | if (m_interpreter.CommandExists(alias_command)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 633 | result.AppendErrorWithFormat( |
| 634 | "'%s' is a permanent debugger command and cannot be redefined.\n", |
| 635 | alias_command.c_str()); |
| 636 | result.SetStatus(eReturnStatusFailed); |
| 637 | return false; |
| 638 | } |
| 639 | |
| 640 | // Get CommandObject that is being aliased. The command name is read from |
Zachary Turner | a01bccd | 2016-10-05 21:14:56 +0000 | [diff] [blame] | 641 | // the front of raw_command_string. raw_command_string is returned with the |
| 642 | // name of the command object stripped off the front. |
| 643 | llvm::StringRef original_raw_command_string = raw_command_string; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 644 | CommandObject *cmd_obj = |
| 645 | m_interpreter.GetCommandObjectForCommand(raw_command_string); |
| 646 | |
| 647 | if (!cmd_obj) { |
| 648 | result.AppendErrorWithFormat("invalid command given to 'command alias'. " |
| 649 | "'%s' does not begin with a valid command." |
| 650 | " No alias created.", |
Zachary Turner | a01bccd | 2016-10-05 21:14:56 +0000 | [diff] [blame] | 651 | original_raw_command_string.str().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 652 | result.SetStatus(eReturnStatusFailed); |
| 653 | return false; |
| 654 | } else if (!cmd_obj->WantsRawCommandString()) { |
| 655 | // Note that args was initialized with the original command, and has not |
| 656 | // been updated to this point. |
| 657 | // Therefore can we pass it to the version of Execute that does not |
| 658 | // need/expect raw input in the alias. |
| 659 | return HandleAliasingNormalCommand(args, result); |
| 660 | } else { |
| 661 | return HandleAliasingRawCommand(alias_command, raw_command_string, |
| 662 | *cmd_obj, result); |
| 663 | } |
| 664 | return result.Succeeded(); |
| 665 | } |
| 666 | |
Zachary Turner | a01bccd | 2016-10-05 21:14:56 +0000 | [diff] [blame] | 667 | bool HandleAliasingRawCommand(llvm::StringRef alias_command, |
| 668 | llvm::StringRef raw_command_string, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 669 | CommandObject &cmd_obj, |
| 670 | CommandReturnObject &result) { |
| 671 | // Verify & handle any options/arguments passed to the alias command |
| 672 | |
| 673 | OptionArgVectorSP option_arg_vector_sp = |
| 674 | OptionArgVectorSP(new OptionArgVector); |
| 675 | |
| 676 | if (CommandObjectSP cmd_obj_sp = |
| 677 | m_interpreter.GetCommandSPExact(cmd_obj.GetCommandName(), false)) { |
Zachary Turner | a01bccd | 2016-10-05 21:14:56 +0000 | [diff] [blame] | 678 | if (m_interpreter.AliasExists(alias_command) || |
| 679 | m_interpreter.UserCommandExists(alias_command)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 680 | result.AppendWarningWithFormat( |
| 681 | "Overwriting existing definition for '%s'.\n", |
Zachary Turner | a01bccd | 2016-10-05 21:14:56 +0000 | [diff] [blame] | 682 | alias_command.str().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 683 | } |
| 684 | if (CommandAlias *alias = m_interpreter.AddAlias( |
Zachary Turner | a01bccd | 2016-10-05 21:14:56 +0000 | [diff] [blame] | 685 | alias_command, cmd_obj_sp, raw_command_string)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 686 | if (m_command_options.m_help.OptionWasSet()) |
| 687 | alias->SetHelp(m_command_options.m_help.GetCurrentValue()); |
| 688 | if (m_command_options.m_long_help.OptionWasSet()) |
| 689 | alias->SetHelpLong(m_command_options.m_long_help.GetCurrentValue()); |
| 690 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 691 | } else { |
| 692 | result.AppendError("Unable to create requested alias.\n"); |
| 693 | result.SetStatus(eReturnStatusFailed); |
| 694 | } |
| 695 | |
| 696 | } else { |
| 697 | result.AppendError("Unable to create requested alias.\n"); |
| 698 | result.SetStatus(eReturnStatusFailed); |
| 699 | } |
| 700 | |
| 701 | return result.Succeeded(); |
| 702 | } |
| 703 | |
| 704 | bool HandleAliasingNormalCommand(Args &args, CommandReturnObject &result) { |
| 705 | size_t argc = args.GetArgumentCount(); |
| 706 | |
| 707 | if (argc < 2) { |
| 708 | result.AppendError("'command alias' requires at least two arguments"); |
| 709 | result.SetStatus(eReturnStatusFailed); |
| 710 | return false; |
| 711 | } |
| 712 | |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 713 | // TODO: Convert these to StringRefs. Should convert other dependent |
| 714 | // functions (CommandExists, UserCommandExists, AliasExists, AddAlias, |
| 715 | // etc at the same time. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 716 | const std::string alias_command = args.GetArgumentAtIndex(0); |
| 717 | const std::string actual_command = args.GetArgumentAtIndex(1); |
| 718 | |
| 719 | args.Shift(); // Shift the alias command word off the argument vector. |
| 720 | args.Shift(); // Shift the old command word off the argument vector. |
| 721 | |
| 722 | // Verify that the command is alias'able, and get the appropriate command |
| 723 | // object. |
| 724 | |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 725 | if (m_interpreter.CommandExists(alias_command)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 726 | result.AppendErrorWithFormat( |
| 727 | "'%s' is a permanent debugger command and cannot be redefined.\n", |
| 728 | alias_command.c_str()); |
| 729 | result.SetStatus(eReturnStatusFailed); |
| 730 | } else { |
| 731 | CommandObjectSP command_obj_sp( |
Zachary Turner | a449698 | 2016-10-05 21:14:38 +0000 | [diff] [blame] | 732 | m_interpreter.GetCommandSPExact(actual_command, true)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 733 | CommandObjectSP subcommand_obj_sp; |
| 734 | bool use_subcommand = false; |
| 735 | if (command_obj_sp) { |
| 736 | CommandObject *cmd_obj = command_obj_sp.get(); |
| 737 | CommandObject *sub_cmd_obj = nullptr; |
| 738 | OptionArgVectorSP option_arg_vector_sp = |
| 739 | OptionArgVectorSP(new OptionArgVector); |
| 740 | |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 741 | while (cmd_obj->IsMultiwordObject() && !args.empty()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 742 | if (argc >= 3) { |
Zachary Turner | a449698 | 2016-10-05 21:14:38 +0000 | [diff] [blame] | 743 | const std::string sub_command = args.GetArgumentAtIndex(0); |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 744 | assert(!sub_command.empty()); |
| 745 | subcommand_obj_sp = cmd_obj->GetSubcommandSP(sub_command.data()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 746 | if (subcommand_obj_sp) { |
| 747 | sub_cmd_obj = subcommand_obj_sp.get(); |
| 748 | use_subcommand = true; |
| 749 | args.Shift(); // Shift the sub_command word off the argument |
| 750 | // vector. |
| 751 | cmd_obj = sub_cmd_obj; |
| 752 | } else { |
| 753 | result.AppendErrorWithFormat( |
| 754 | "'%s' is not a valid sub-command of '%s'. " |
| 755 | "Unable to create alias.\n", |
Zachary Turner | a449698 | 2016-10-05 21:14:38 +0000 | [diff] [blame] | 756 | sub_command.c_str(), actual_command.c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 757 | result.SetStatus(eReturnStatusFailed); |
| 758 | return false; |
| 759 | } |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | // Verify & handle any options/arguments passed to the alias command |
| 764 | |
| 765 | std::string args_string; |
| 766 | |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 767 | if (!args.empty()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 768 | CommandObjectSP tmp_sp = |
| 769 | m_interpreter.GetCommandSPExact(cmd_obj->GetCommandName(), false); |
| 770 | if (use_subcommand) |
| 771 | tmp_sp = m_interpreter.GetCommandSPExact( |
| 772 | sub_cmd_obj->GetCommandName(), false); |
| 773 | |
| 774 | args.GetCommandString(args_string); |
| 775 | } |
| 776 | |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 777 | if (m_interpreter.AliasExists(alias_command) || |
| 778 | m_interpreter.UserCommandExists(alias_command)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 779 | result.AppendWarningWithFormat( |
| 780 | "Overwriting existing definition for '%s'.\n", |
| 781 | alias_command.c_str()); |
| 782 | } |
| 783 | |
| 784 | if (CommandAlias *alias = m_interpreter.AddAlias( |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 785 | alias_command, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 786 | use_subcommand ? subcommand_obj_sp : command_obj_sp, |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 787 | args_string)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 788 | if (m_command_options.m_help.OptionWasSet()) |
| 789 | alias->SetHelp(m_command_options.m_help.GetCurrentValue()); |
| 790 | if (m_command_options.m_long_help.OptionWasSet()) |
| 791 | alias->SetHelpLong(m_command_options.m_long_help.GetCurrentValue()); |
| 792 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 793 | } else { |
| 794 | result.AppendError("Unable to create requested alias.\n"); |
| 795 | result.SetStatus(eReturnStatusFailed); |
| 796 | return false; |
| 797 | } |
| 798 | } else { |
| 799 | result.AppendErrorWithFormat("'%s' is not an existing command.\n", |
| 800 | actual_command.c_str()); |
| 801 | result.SetStatus(eReturnStatusFailed); |
| 802 | return false; |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | return result.Succeeded(); |
| 807 | } |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 808 | }; |
| 809 | |
| 810 | #pragma mark CommandObjectCommandsUnalias |
| 811 | //------------------------------------------------------------------------- |
| 812 | // CommandObjectCommandsUnalias |
| 813 | //------------------------------------------------------------------------- |
| 814 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 815 | class CommandObjectCommandsUnalias : public CommandObjectParsed { |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 816 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 817 | CommandObjectCommandsUnalias(CommandInterpreter &interpreter) |
| 818 | : CommandObjectParsed( |
| 819 | interpreter, "command unalias", |
| 820 | "Delete one or more custom commands defined by 'command alias'.", |
| 821 | nullptr) { |
| 822 | CommandArgumentEntry arg; |
| 823 | CommandArgumentData alias_arg; |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 824 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 825 | // Define the first (and only) variant of this arg. |
| 826 | alias_arg.arg_type = eArgTypeAliasName; |
| 827 | alias_arg.arg_repetition = eArgRepeatPlain; |
| 828 | |
| 829 | // There is only one variant this argument could be; put it into the |
| 830 | // argument entry. |
| 831 | arg.push_back(alias_arg); |
| 832 | |
| 833 | // Push the data for the first argument into the m_arguments vector. |
| 834 | m_arguments.push_back(arg); |
| 835 | } |
| 836 | |
| 837 | ~CommandObjectCommandsUnalias() override = default; |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 838 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 839 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 840 | bool DoExecute(Args &args, CommandReturnObject &result) override { |
| 841 | CommandObject::CommandMap::iterator pos; |
| 842 | CommandObject *cmd_obj; |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 843 | |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 844 | if (args.empty()) { |
| 845 | result.AppendError("must call 'unalias' with a valid alias"); |
| 846 | result.SetStatus(eReturnStatusFailed); |
| 847 | return false; |
| 848 | } |
| 849 | |
| 850 | // TODO: Convert this function to return a StringRef. Should also convert |
| 851 | // dependent functions GetCommandObject, CommandExists, RemoveAlias, |
| 852 | // AliasExists, etc. |
| 853 | const char *command_name = args.GetArgumentAtIndex(0); |
| 854 | cmd_obj = m_interpreter.GetCommandObject(command_name); |
| 855 | if (cmd_obj) { |
| 856 | if (m_interpreter.CommandExists(command_name)) { |
| 857 | if (cmd_obj->IsRemovable()) { |
| 858 | result.AppendErrorWithFormat( |
| 859 | "'%s' is not an alias, it is a debugger command which can be " |
| 860 | "removed using the 'command delete' command.\n", |
| 861 | command_name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 862 | } else { |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 863 | result.AppendErrorWithFormat( |
| 864 | "'%s' is a permanent debugger command and cannot be removed.\n", |
| 865 | command_name); |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 866 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 867 | result.SetStatus(eReturnStatusFailed); |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 868 | } else { |
| 869 | if (!m_interpreter.RemoveAlias(command_name)) { |
| 870 | if (m_interpreter.AliasExists(command_name)) |
| 871 | result.AppendErrorWithFormat( |
| 872 | "Error occurred while attempting to unalias '%s'.\n", |
| 873 | command_name); |
| 874 | else |
| 875 | result.AppendErrorWithFormat("'%s' is not an existing alias.\n", |
| 876 | command_name); |
| 877 | result.SetStatus(eReturnStatusFailed); |
| 878 | } else |
| 879 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 880 | } |
| 881 | } else { |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 882 | result.AppendErrorWithFormat( |
| 883 | "'%s' is not a known command.\nTry 'help' to see a " |
| 884 | "current list of commands.\n", |
| 885 | command_name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 886 | result.SetStatus(eReturnStatusFailed); |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 887 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 888 | |
| 889 | return result.Succeeded(); |
| 890 | } |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 891 | }; |
| 892 | |
Greg Clayton | b547278 | 2015-01-09 19:08:20 +0000 | [diff] [blame] | 893 | #pragma mark CommandObjectCommandsDelete |
| 894 | //------------------------------------------------------------------------- |
| 895 | // CommandObjectCommandsDelete |
| 896 | //------------------------------------------------------------------------- |
| 897 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 898 | class CommandObjectCommandsDelete : public CommandObjectParsed { |
Greg Clayton | b547278 | 2015-01-09 19:08:20 +0000 | [diff] [blame] | 899 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 900 | CommandObjectCommandsDelete(CommandInterpreter &interpreter) |
| 901 | : CommandObjectParsed( |
| 902 | interpreter, "command delete", |
| 903 | "Delete one or more custom commands defined by 'command regex'.", |
| 904 | nullptr) { |
| 905 | CommandArgumentEntry arg; |
| 906 | CommandArgumentData alias_arg; |
Greg Clayton | b547278 | 2015-01-09 19:08:20 +0000 | [diff] [blame] | 907 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 908 | // Define the first (and only) variant of this arg. |
| 909 | alias_arg.arg_type = eArgTypeCommandName; |
| 910 | alias_arg.arg_repetition = eArgRepeatPlain; |
Greg Clayton | b547278 | 2015-01-09 19:08:20 +0000 | [diff] [blame] | 911 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 912 | // There is only one variant this argument could be; put it into the |
| 913 | // argument entry. |
| 914 | arg.push_back(alias_arg); |
Greg Clayton | b547278 | 2015-01-09 19:08:20 +0000 | [diff] [blame] | 915 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 916 | // Push the data for the first argument into the m_arguments vector. |
| 917 | m_arguments.push_back(arg); |
| 918 | } |
Greg Clayton | b547278 | 2015-01-09 19:08:20 +0000 | [diff] [blame] | 919 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 920 | ~CommandObjectCommandsDelete() override = default; |
Greg Clayton | b547278 | 2015-01-09 19:08:20 +0000 | [diff] [blame] | 921 | |
| 922 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 923 | bool DoExecute(Args &args, CommandReturnObject &result) override { |
| 924 | CommandObject::CommandMap::iterator pos; |
Greg Clayton | b547278 | 2015-01-09 19:08:20 +0000 | [diff] [blame] | 925 | |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 926 | if (args.empty()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 927 | result.AppendErrorWithFormat("must call '%s' with one or more valid user " |
| 928 | "defined regular expression command names", |
Zachary Turner | a449698 | 2016-10-05 21:14:38 +0000 | [diff] [blame] | 929 | GetCommandName().str().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 930 | result.SetStatus(eReturnStatusFailed); |
Greg Clayton | b547278 | 2015-01-09 19:08:20 +0000 | [diff] [blame] | 931 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 932 | |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 933 | // TODO: Convert this to accept a stringRef. |
| 934 | const char *command_name = args.GetArgumentAtIndex(0); |
| 935 | if (m_interpreter.CommandExists(command_name)) { |
| 936 | if (m_interpreter.RemoveCommand(command_name)) { |
| 937 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 938 | } else { |
| 939 | result.AppendErrorWithFormat( |
| 940 | "'%s' is a permanent debugger command and cannot be removed.\n", |
| 941 | command_name); |
| 942 | result.SetStatus(eReturnStatusFailed); |
| 943 | } |
| 944 | } else { |
| 945 | StreamString error_msg_stream; |
| 946 | const bool generate_apropos = true; |
| 947 | const bool generate_type_lookup = false; |
| 948 | CommandObjectHelp::GenerateAdditionalHelpAvenuesMessage( |
| 949 | &error_msg_stream, command_name, nullptr, nullptr, generate_apropos, |
| 950 | generate_type_lookup); |
| 951 | result.AppendErrorWithFormat("%s", error_msg_stream.GetData()); |
| 952 | result.SetStatus(eReturnStatusFailed); |
| 953 | } |
| 954 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 955 | return result.Succeeded(); |
| 956 | } |
Greg Clayton | b547278 | 2015-01-09 19:08:20 +0000 | [diff] [blame] | 957 | }; |
| 958 | |
Greg Clayton | de164aa | 2011-04-20 16:37:46 +0000 | [diff] [blame] | 959 | //------------------------------------------------------------------------- |
| 960 | // CommandObjectCommandsAddRegex |
| 961 | //------------------------------------------------------------------------- |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 962 | |
| 963 | static OptionDefinition g_regex_options[] = { |
| 964 | // clang-format off |
| 965 | { LLDB_OPT_SET_1, false, "help" , 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeNone, "The help text to display for this command." }, |
| 966 | { LLDB_OPT_SET_1, false, "syntax", 's', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeNone, "A syntax string showing the typical usage syntax." }, |
| 967 | // clang-format on |
| 968 | }; |
| 969 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 970 | #pragma mark CommandObjectCommandsAddRegex |
Greg Clayton | de164aa | 2011-04-20 16:37:46 +0000 | [diff] [blame] | 971 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 972 | class CommandObjectCommandsAddRegex : public CommandObjectParsed, |
| 973 | public IOHandlerDelegateMultiline { |
Greg Clayton | de164aa | 2011-04-20 16:37:46 +0000 | [diff] [blame] | 974 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 975 | CommandObjectCommandsAddRegex(CommandInterpreter &interpreter) |
| 976 | : CommandObjectParsed( |
| 977 | interpreter, "command regex", "Define a custom command in terms of " |
| 978 | "existing commands by matching " |
| 979 | "regular expressions.", |
| 980 | "command regex <cmd-name> [s/<regex>/<subst>/ ...]"), |
| 981 | IOHandlerDelegateMultiline("", |
| 982 | IOHandlerDelegate::Completion::LLDBCommand), |
| 983 | m_options() { |
| 984 | SetHelpLong( |
| 985 | R"( |
| 986 | )" |
| 987 | "This command allows the user to create powerful regular expression commands \ |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 988 | with substitutions. The regular expressions and substitutions are specified \ |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 989 | using the regular expression substitution format of:" |
| 990 | R"( |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 991 | |
| 992 | s/<regex>/<subst>/ |
| 993 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 994 | )" |
| 995 | "<regex> is a regular expression that can use parenthesis to capture regular \ |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 996 | expression input and substitute the captured matches in the output using %1 \ |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 997 | for the first match, %2 for the second, and so on." |
| 998 | R"( |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 999 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1000 | )" |
| 1001 | "The regular expressions can all be specified on the command line if more than \ |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 1002 | one argument is provided. If just the command name is provided on the command \ |
| 1003 | line, then the regular expressions and substitutions can be entered on separate \ |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1004 | lines, followed by an empty line to terminate the command definition." |
| 1005 | R"( |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 1006 | |
| 1007 | EXAMPLES |
| 1008 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1009 | )" |
| 1010 | "The following example will define a regular expression command named 'f' that \ |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 1011 | will call 'finish' if there are no arguments, or 'frame select <frame-idx>' if \ |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1012 | a number follows 'f':" |
| 1013 | R"( |
Kate Stone | ea671fb | 2015-07-14 05:48:36 +0000 | [diff] [blame] | 1014 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1015 | (lldb) command regex f s/^$/finish/ 's/([0-9]+)/frame select %1/')"); |
| 1016 | } |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1017 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1018 | ~CommandObjectCommandsAddRegex() override = default; |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1019 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1020 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1021 | void IOHandlerActivated(IOHandler &io_handler) override { |
| 1022 | StreamFileSP output_sp(io_handler.GetOutputStreamFile()); |
| 1023 | if (output_sp) { |
| 1024 | output_sp->PutCString("Enter one of more sed substitution commands in " |
| 1025 | "the form: 's/<regex>/<subst>/'.\nTerminate the " |
| 1026 | "substitution list with an empty line.\n"); |
| 1027 | output_sp->Flush(); |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | void IOHandlerInputComplete(IOHandler &io_handler, |
| 1032 | std::string &data) override { |
| 1033 | io_handler.SetIsDone(true); |
| 1034 | if (m_regex_cmd_ap) { |
| 1035 | StringList lines; |
| 1036 | if (lines.SplitIntoLines(data)) { |
| 1037 | const size_t num_lines = lines.GetSize(); |
| 1038 | bool check_only = false; |
| 1039 | for (size_t i = 0; i < num_lines; ++i) { |
| 1040 | llvm::StringRef bytes_strref(lines[i]); |
| 1041 | Error error = AppendRegexSubstitution(bytes_strref, check_only); |
| 1042 | if (error.Fail()) { |
| 1043 | if (!m_interpreter.GetDebugger() |
| 1044 | .GetCommandInterpreter() |
| 1045 | .GetBatchCommandMode()) { |
| 1046 | StreamSP out_stream = |
| 1047 | m_interpreter.GetDebugger().GetAsyncOutputStream(); |
| 1048 | out_stream->Printf("error: %s\n", error.AsCString()); |
| 1049 | } |
| 1050 | } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1051 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1052 | } |
| 1053 | if (m_regex_cmd_ap->HasRegexEntries()) { |
| 1054 | CommandObjectSP cmd_sp(m_regex_cmd_ap.release()); |
| 1055 | m_interpreter.AddCommand(cmd_sp->GetCommandName(), cmd_sp, true); |
| 1056 | } |
| 1057 | } |
| 1058 | } |
| 1059 | |
| 1060 | bool DoExecute(Args &command, CommandReturnObject &result) override { |
| 1061 | const size_t argc = command.GetArgumentCount(); |
| 1062 | if (argc == 0) { |
| 1063 | result.AppendError("usage: 'command regex <command-name> " |
| 1064 | "[s/<regex1>/<subst1>/ s/<regex2>/<subst2>/ ...]'\n"); |
| 1065 | result.SetStatus(eReturnStatusFailed); |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 1066 | return false; |
| 1067 | } |
| 1068 | |
| 1069 | Error error; |
| 1070 | const char *name = command.GetArgumentAtIndex(0); |
| 1071 | m_regex_cmd_ap.reset( |
| 1072 | new CommandObjectRegexCommand(m_interpreter, name, m_options.GetHelp(), |
| 1073 | m_options.GetSyntax(), 10, 0, true)); |
| 1074 | |
| 1075 | if (argc == 1) { |
| 1076 | Debugger &debugger = m_interpreter.GetDebugger(); |
| 1077 | bool color_prompt = debugger.GetUseColor(); |
| 1078 | const bool multiple_lines = true; // Get multiple lines |
| 1079 | IOHandlerSP io_handler_sp(new IOHandlerEditline( |
| 1080 | debugger, IOHandler::Type::Other, |
| 1081 | "lldb-regex", // Name of input reader for history |
| 1082 | llvm::StringRef("> "), // Prompt |
| 1083 | llvm::StringRef(), // Continuation prompt |
| 1084 | multiple_lines, color_prompt, |
| 1085 | 0, // Don't show line numbers |
| 1086 | *this)); |
| 1087 | |
| 1088 | if (io_handler_sp) { |
| 1089 | debugger.PushIOHandler(io_handler_sp); |
| 1090 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 1091 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1092 | } else { |
Zachary Turner | 97d2c40 | 2016-10-05 23:40:23 +0000 | [diff] [blame] | 1093 | for (auto &entry : command.entries().drop_front()) { |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 1094 | bool check_only = false; |
Zachary Turner | 97d2c40 | 2016-10-05 23:40:23 +0000 | [diff] [blame] | 1095 | error = AppendRegexSubstitution(entry.ref, check_only); |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 1096 | if (error.Fail()) |
| 1097 | break; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1098 | } |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 1099 | |
| 1100 | if (error.Success()) { |
| 1101 | AddRegexCommandToInterpreter(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1102 | } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1103 | } |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 1104 | if (error.Fail()) { |
| 1105 | result.AppendError(error.AsCString()); |
| 1106 | result.SetStatus(eReturnStatusFailed); |
| 1107 | } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1108 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1109 | return result.Succeeded(); |
| 1110 | } |
| 1111 | |
| 1112 | Error AppendRegexSubstitution(const llvm::StringRef ®ex_sed, |
| 1113 | bool check_only) { |
| 1114 | Error error; |
| 1115 | |
| 1116 | if (!m_regex_cmd_ap) { |
| 1117 | error.SetErrorStringWithFormat( |
| 1118 | "invalid regular expression command object for: '%.*s'", |
| 1119 | (int)regex_sed.size(), regex_sed.data()); |
| 1120 | return error; |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1121 | } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1122 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1123 | size_t regex_sed_size = regex_sed.size(); |
Greg Clayton | 0e5e5a7 | 2011-04-20 22:55:21 +0000 | [diff] [blame] | 1124 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1125 | if (regex_sed_size <= 1) { |
| 1126 | error.SetErrorStringWithFormat( |
| 1127 | "regular expression substitution string is too short: '%.*s'", |
| 1128 | (int)regex_sed.size(), regex_sed.data()); |
| 1129 | return error; |
Greg Clayton | de164aa | 2011-04-20 16:37:46 +0000 | [diff] [blame] | 1130 | } |
Greg Clayton | 0e5e5a7 | 2011-04-20 22:55:21 +0000 | [diff] [blame] | 1131 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1132 | if (regex_sed[0] != 's') { |
| 1133 | error.SetErrorStringWithFormat("regular expression substitution string " |
| 1134 | "doesn't start with 's': '%.*s'", |
| 1135 | (int)regex_sed.size(), regex_sed.data()); |
| 1136 | return error; |
| 1137 | } |
| 1138 | const size_t first_separator_char_pos = 1; |
| 1139 | // use the char that follows 's' as the regex separator character |
| 1140 | // so we can have "s/<regex>/<subst>/" or "s|<regex>|<subst>|" |
| 1141 | const char separator_char = regex_sed[first_separator_char_pos]; |
| 1142 | const size_t second_separator_char_pos = |
| 1143 | regex_sed.find(separator_char, first_separator_char_pos + 1); |
Greg Clayton | 0e5e5a7 | 2011-04-20 22:55:21 +0000 | [diff] [blame] | 1144 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1145 | if (second_separator_char_pos == std::string::npos) { |
| 1146 | error.SetErrorStringWithFormat( |
| 1147 | "missing second '%c' separator char after '%.*s' in '%.*s'", |
| 1148 | separator_char, |
| 1149 | (int)(regex_sed.size() - first_separator_char_pos - 1), |
| 1150 | regex_sed.data() + (first_separator_char_pos + 1), |
| 1151 | (int)regex_sed.size(), regex_sed.data()); |
| 1152 | return error; |
| 1153 | } |
Greg Clayton | 0e5e5a7 | 2011-04-20 22:55:21 +0000 | [diff] [blame] | 1154 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1155 | const size_t third_separator_char_pos = |
| 1156 | regex_sed.find(separator_char, second_separator_char_pos + 1); |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1157 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1158 | if (third_separator_char_pos == std::string::npos) { |
| 1159 | error.SetErrorStringWithFormat( |
| 1160 | "missing third '%c' separator char after '%.*s' in '%.*s'", |
| 1161 | separator_char, |
| 1162 | (int)(regex_sed.size() - second_separator_char_pos - 1), |
| 1163 | regex_sed.data() + (second_separator_char_pos + 1), |
| 1164 | (int)regex_sed.size(), regex_sed.data()); |
| 1165 | return error; |
| 1166 | } |
| 1167 | |
| 1168 | if (third_separator_char_pos != regex_sed_size - 1) { |
| 1169 | // Make sure that everything that follows the last regex |
| 1170 | // separator char |
| 1171 | if (regex_sed.find_first_not_of("\t\n\v\f\r ", |
| 1172 | third_separator_char_pos + 1) != |
| 1173 | std::string::npos) { |
| 1174 | error.SetErrorStringWithFormat( |
| 1175 | "extra data found after the '%.*s' regular expression substitution " |
| 1176 | "string: '%.*s'", |
| 1177 | (int)third_separator_char_pos + 1, regex_sed.data(), |
| 1178 | (int)(regex_sed.size() - third_separator_char_pos - 1), |
| 1179 | regex_sed.data() + (third_separator_char_pos + 1)); |
Greg Clayton | 0e5e5a7 | 2011-04-20 22:55:21 +0000 | [diff] [blame] | 1180 | return error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1181 | } |
| 1182 | } else if (first_separator_char_pos + 1 == second_separator_char_pos) { |
| 1183 | error.SetErrorStringWithFormat( |
| 1184 | "<regex> can't be empty in 's%c<regex>%c<subst>%c' string: '%.*s'", |
| 1185 | separator_char, separator_char, separator_char, (int)regex_sed.size(), |
| 1186 | regex_sed.data()); |
| 1187 | return error; |
| 1188 | } else if (second_separator_char_pos + 1 == third_separator_char_pos) { |
| 1189 | error.SetErrorStringWithFormat( |
| 1190 | "<subst> can't be empty in 's%c<regex>%c<subst>%c' string: '%.*s'", |
| 1191 | separator_char, separator_char, separator_char, (int)regex_sed.size(), |
| 1192 | regex_sed.data()); |
| 1193 | return error; |
Greg Clayton | de164aa | 2011-04-20 16:37:46 +0000 | [diff] [blame] | 1194 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1195 | |
| 1196 | if (!check_only) { |
| 1197 | std::string regex(regex_sed.substr(first_separator_char_pos + 1, |
| 1198 | second_separator_char_pos - |
| 1199 | first_separator_char_pos - 1)); |
| 1200 | std::string subst(regex_sed.substr(second_separator_char_pos + 1, |
| 1201 | third_separator_char_pos - |
| 1202 | second_separator_char_pos - 1)); |
| 1203 | m_regex_cmd_ap->AddRegexCommand(regex.c_str(), subst.c_str()); |
Greg Clayton | de164aa | 2011-04-20 16:37:46 +0000 | [diff] [blame] | 1204 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1205 | return error; |
| 1206 | } |
| 1207 | |
| 1208 | void AddRegexCommandToInterpreter() { |
| 1209 | if (m_regex_cmd_ap) { |
| 1210 | if (m_regex_cmd_ap->HasRegexEntries()) { |
| 1211 | CommandObjectSP cmd_sp(m_regex_cmd_ap.release()); |
| 1212 | m_interpreter.AddCommand(cmd_sp->GetCommandName(), cmd_sp, true); |
| 1213 | } |
| 1214 | } |
| 1215 | } |
Greg Clayton | de164aa | 2011-04-20 16:37:46 +0000 | [diff] [blame] | 1216 | |
Greg Clayton | de164aa | 2011-04-20 16:37:46 +0000 | [diff] [blame] | 1217 | private: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1218 | std::unique_ptr<CommandObjectRegexCommand> m_regex_cmd_ap; |
Greg Clayton | de164aa | 2011-04-20 16:37:46 +0000 | [diff] [blame] | 1219 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1220 | class CommandOptions : public Options { |
| 1221 | public: |
| 1222 | CommandOptions() : Options() {} |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1223 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1224 | ~CommandOptions() override = default; |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1225 | |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame^] | 1226 | Error SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1227 | ExecutionContext *execution_context) override { |
| 1228 | Error error; |
| 1229 | const int short_option = m_getopt_table[option_idx].val; |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1230 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1231 | switch (short_option) { |
| 1232 | case 'h': |
| 1233 | m_help.assign(option_arg); |
| 1234 | break; |
| 1235 | case 's': |
| 1236 | m_syntax.assign(option_arg); |
| 1237 | break; |
| 1238 | default: |
| 1239 | error.SetErrorStringWithFormat("unrecognized option '%c'", |
| 1240 | short_option); |
| 1241 | break; |
| 1242 | } |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1243 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1244 | return error; |
| 1245 | } |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1246 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1247 | void OptionParsingStarting(ExecutionContext *execution_context) override { |
| 1248 | m_help.clear(); |
| 1249 | m_syntax.clear(); |
| 1250 | } |
| 1251 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1252 | llvm::ArrayRef<OptionDefinition> GetDefinitions() override { |
Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 1253 | return llvm::makeArrayRef(g_regex_options); |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1254 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1255 | |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 1256 | // TODO: Convert these functions to return StringRefs. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1257 | const char *GetHelp() { |
| 1258 | return (m_help.empty() ? nullptr : m_help.c_str()); |
| 1259 | } |
| 1260 | |
| 1261 | const char *GetSyntax() { |
| 1262 | return (m_syntax.empty() ? nullptr : m_syntax.c_str()); |
| 1263 | } |
| 1264 | |
| 1265 | protected: |
| 1266 | // Instance variables to hold the values for command options. |
| 1267 | |
| 1268 | std::string m_help; |
| 1269 | std::string m_syntax; |
| 1270 | }; |
| 1271 | |
| 1272 | Options *GetOptions() override { return &m_options; } |
| 1273 | |
| 1274 | CommandOptions m_options; |
Greg Clayton | de164aa | 2011-04-20 16:37:46 +0000 | [diff] [blame] | 1275 | }; |
| 1276 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1277 | class CommandObjectPythonFunction : public CommandObjectRaw { |
Enrico Granata | 223383e | 2011-08-16 23:24:13 +0000 | [diff] [blame] | 1278 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1279 | CommandObjectPythonFunction(CommandInterpreter &interpreter, std::string name, |
| 1280 | std::string funct, std::string help, |
| 1281 | ScriptedCommandSynchronicity synch) |
Zachary Turner | a449698 | 2016-10-05 21:14:38 +0000 | [diff] [blame] | 1282 | : CommandObjectRaw(interpreter, name), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1283 | m_function_name(funct), m_synchro(synch), m_fetched_help_long(false) { |
| 1284 | if (!help.empty()) |
| 1285 | SetHelp(help.c_str()); |
| 1286 | else { |
| 1287 | StreamString stream; |
| 1288 | stream.Printf("For more information run 'help %s'", name.c_str()); |
| 1289 | SetHelp(stream.GetData()); |
Enrico Granata | 223383e | 2011-08-16 23:24:13 +0000 | [diff] [blame] | 1290 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1291 | } |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1292 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1293 | ~CommandObjectPythonFunction() override = default; |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1294 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1295 | bool IsRemovable() const override { return true; } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1296 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1297 | const std::string &GetFunctionName() { return m_function_name; } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1298 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1299 | ScriptedCommandSynchronicity GetSynchronicity() { return m_synchro; } |
| 1300 | |
| 1301 | const char *GetHelpLong() override { |
| 1302 | if (!m_fetched_help_long) { |
| 1303 | ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter(); |
| 1304 | if (scripter) { |
| 1305 | std::string docstring; |
| 1306 | m_fetched_help_long = scripter->GetDocumentationForItem( |
| 1307 | m_function_name.c_str(), docstring); |
| 1308 | if (!docstring.empty()) |
| 1309 | SetHelpLong(docstring.c_str()); |
| 1310 | } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1311 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1312 | return CommandObjectRaw::GetHelpLong(); |
| 1313 | } |
| 1314 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1315 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1316 | bool DoExecute(const char *raw_command_line, |
| 1317 | CommandReturnObject &result) override { |
| 1318 | ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter(); |
| 1319 | |
| 1320 | Error error; |
| 1321 | |
| 1322 | result.SetStatus(eReturnStatusInvalid); |
| 1323 | |
| 1324 | if (!scripter || |
| 1325 | !scripter->RunScriptBasedCommand(m_function_name.c_str(), |
| 1326 | raw_command_line, m_synchro, result, |
| 1327 | error, m_exe_ctx)) { |
| 1328 | result.AppendError(error.AsCString()); |
| 1329 | result.SetStatus(eReturnStatusFailed); |
| 1330 | } else { |
| 1331 | // Don't change the status if the command already set it... |
| 1332 | if (result.GetStatus() == eReturnStatusInvalid) { |
| 1333 | if (result.GetOutputData() == nullptr || |
| 1334 | result.GetOutputData()[0] == '\0') |
| 1335 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
Enrico Granata | 223383e | 2011-08-16 23:24:13 +0000 | [diff] [blame] | 1336 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1337 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 1338 | } |
Enrico Granata | 223383e | 2011-08-16 23:24:13 +0000 | [diff] [blame] | 1339 | } |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1340 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1341 | return result.Succeeded(); |
| 1342 | } |
| 1343 | |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1344 | private: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1345 | std::string m_function_name; |
| 1346 | ScriptedCommandSynchronicity m_synchro; |
| 1347 | bool m_fetched_help_long; |
Enrico Granata | 223383e | 2011-08-16 23:24:13 +0000 | [diff] [blame] | 1348 | }; |
| 1349 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1350 | class CommandObjectScriptingObject : public CommandObjectRaw { |
Enrico Granata | 9fe00e5 | 2015-03-13 02:20:41 +0000 | [diff] [blame] | 1351 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1352 | CommandObjectScriptingObject(CommandInterpreter &interpreter, |
| 1353 | std::string name, |
| 1354 | StructuredData::GenericSP cmd_obj_sp, |
| 1355 | ScriptedCommandSynchronicity synch) |
Zachary Turner | a449698 | 2016-10-05 21:14:38 +0000 | [diff] [blame] | 1356 | : CommandObjectRaw(interpreter, name), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1357 | m_cmd_obj_sp(cmd_obj_sp), m_synchro(synch), m_fetched_help_short(false), |
| 1358 | m_fetched_help_long(false) { |
| 1359 | StreamString stream; |
| 1360 | stream.Printf("For more information run 'help %s'", name.c_str()); |
| 1361 | SetHelp(stream.GetData()); |
| 1362 | if (ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter()) |
| 1363 | GetFlags().Set(scripter->GetFlagsForCommandObject(cmd_obj_sp)); |
| 1364 | } |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1365 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1366 | ~CommandObjectScriptingObject() override = default; |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1367 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1368 | bool IsRemovable() const override { return true; } |
Enrico Granata | 6f79bb2 | 2015-03-13 22:22:28 +0000 | [diff] [blame] | 1369 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1370 | StructuredData::GenericSP GetImplementingObject() { return m_cmd_obj_sp; } |
| 1371 | |
| 1372 | ScriptedCommandSynchronicity GetSynchronicity() { return m_synchro; } |
| 1373 | |
| 1374 | const char *GetHelp() override { |
| 1375 | if (!m_fetched_help_short) { |
| 1376 | ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter(); |
| 1377 | if (scripter) { |
| 1378 | std::string docstring; |
| 1379 | m_fetched_help_short = |
| 1380 | scripter->GetShortHelpForCommandObject(m_cmd_obj_sp, docstring); |
| 1381 | if (!docstring.empty()) |
| 1382 | SetHelp(docstring.c_str()); |
| 1383 | } |
Enrico Granata | 6f79bb2 | 2015-03-13 22:22:28 +0000 | [diff] [blame] | 1384 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1385 | return CommandObjectRaw::GetHelp(); |
| 1386 | } |
| 1387 | |
| 1388 | const char *GetHelpLong() override { |
| 1389 | if (!m_fetched_help_long) { |
| 1390 | ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter(); |
| 1391 | if (scripter) { |
| 1392 | std::string docstring; |
| 1393 | m_fetched_help_long = |
| 1394 | scripter->GetLongHelpForCommandObject(m_cmd_obj_sp, docstring); |
| 1395 | if (!docstring.empty()) |
| 1396 | SetHelpLong(docstring.c_str()); |
| 1397 | } |
Enrico Granata | 9fe00e5 | 2015-03-13 02:20:41 +0000 | [diff] [blame] | 1398 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1399 | return CommandObjectRaw::GetHelpLong(); |
| 1400 | } |
| 1401 | |
Enrico Granata | 9fe00e5 | 2015-03-13 02:20:41 +0000 | [diff] [blame] | 1402 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1403 | bool DoExecute(const char *raw_command_line, |
| 1404 | CommandReturnObject &result) override { |
| 1405 | ScriptInterpreter *scripter = m_interpreter.GetScriptInterpreter(); |
| 1406 | |
| 1407 | Error error; |
| 1408 | |
| 1409 | result.SetStatus(eReturnStatusInvalid); |
| 1410 | |
| 1411 | if (!scripter || |
| 1412 | !scripter->RunScriptBasedCommand(m_cmd_obj_sp, raw_command_line, |
| 1413 | m_synchro, result, error, m_exe_ctx)) { |
| 1414 | result.AppendError(error.AsCString()); |
| 1415 | result.SetStatus(eReturnStatusFailed); |
| 1416 | } else { |
| 1417 | // Don't change the status if the command already set it... |
| 1418 | if (result.GetStatus() == eReturnStatusInvalid) { |
| 1419 | if (result.GetOutputData() == nullptr || |
| 1420 | result.GetOutputData()[0] == '\0') |
| 1421 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
Enrico Granata | 9fe00e5 | 2015-03-13 02:20:41 +0000 | [diff] [blame] | 1422 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1423 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 1424 | } |
Enrico Granata | 9fe00e5 | 2015-03-13 02:20:41 +0000 | [diff] [blame] | 1425 | } |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1426 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1427 | return result.Succeeded(); |
| 1428 | } |
| 1429 | |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1430 | private: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1431 | StructuredData::GenericSP m_cmd_obj_sp; |
| 1432 | ScriptedCommandSynchronicity m_synchro; |
| 1433 | bool m_fetched_help_short : 1; |
| 1434 | bool m_fetched_help_long : 1; |
Enrico Granata | 9fe00e5 | 2015-03-13 02:20:41 +0000 | [diff] [blame] | 1435 | }; |
| 1436 | |
Enrico Granata | a9dbf43 | 2011-10-17 21:45:27 +0000 | [diff] [blame] | 1437 | //------------------------------------------------------------------------- |
| 1438 | // CommandObjectCommandsScriptImport |
| 1439 | //------------------------------------------------------------------------- |
| 1440 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1441 | OptionDefinition g_script_import_options[] = { |
| 1442 | // clang-format off |
| 1443 | { LLDB_OPT_SET_1, false, "allow-reload", 'r', OptionParser::eNoArgument, nullptr, nullptr, 0, eArgTypeNone, "Allow the script to be loaded even if it was already loaded before. This argument exists for backwards compatibility, but reloading is always allowed, whether you specify it or not." }, |
| 1444 | // clang-format on |
| 1445 | }; |
| 1446 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1447 | class CommandObjectCommandsScriptImport : public CommandObjectParsed { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1448 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1449 | CommandObjectCommandsScriptImport(CommandInterpreter &interpreter) |
| 1450 | : CommandObjectParsed(interpreter, "command script import", |
| 1451 | "Import a scripting module in LLDB.", nullptr), |
| 1452 | m_options() { |
| 1453 | CommandArgumentEntry arg1; |
| 1454 | CommandArgumentData cmd_arg; |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1455 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1456 | // Define the first (and only) variant of this arg. |
| 1457 | cmd_arg.arg_type = eArgTypeFilename; |
| 1458 | cmd_arg.arg_repetition = eArgRepeatPlus; |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1459 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1460 | // There is only one variant this argument could be; put it into the |
| 1461 | // argument entry. |
| 1462 | arg1.push_back(cmd_arg); |
Todd Fiala | e1cfbc7 | 2016-08-11 23:51:28 +0000 | [diff] [blame] | 1463 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1464 | // Push the data for the first argument into the m_arguments vector. |
| 1465 | m_arguments.push_back(arg1); |
| 1466 | } |
| 1467 | |
| 1468 | ~CommandObjectCommandsScriptImport() override = default; |
| 1469 | |
| 1470 | int HandleArgumentCompletion(Args &input, int &cursor_index, |
| 1471 | int &cursor_char_position, |
| 1472 | OptionElementVector &opt_element_vector, |
| 1473 | int match_start_point, int max_return_elements, |
| 1474 | bool &word_complete, |
| 1475 | StringList &matches) override { |
| 1476 | std::string completion_str(input.GetArgumentAtIndex(cursor_index)); |
| 1477 | completion_str.erase(cursor_char_position); |
| 1478 | |
| 1479 | CommandCompletions::InvokeCommonCompletionCallbacks( |
| 1480 | GetCommandInterpreter(), CommandCompletions::eDiskFileCompletion, |
| 1481 | completion_str.c_str(), match_start_point, max_return_elements, nullptr, |
| 1482 | word_complete, matches); |
| 1483 | return matches.GetSize(); |
| 1484 | } |
| 1485 | |
| 1486 | Options *GetOptions() override { return &m_options; } |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1487 | |
| 1488 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1489 | class CommandOptions : public Options { |
| 1490 | public: |
| 1491 | CommandOptions() : Options() {} |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1492 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1493 | ~CommandOptions() override = default; |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1494 | |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame^] | 1495 | Error SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1496 | ExecutionContext *execution_context) override { |
| 1497 | Error error; |
| 1498 | const int short_option = m_getopt_table[option_idx].val; |
Enrico Granata | 0a305db | 2011-11-07 22:57:04 +0000 | [diff] [blame] | 1499 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1500 | switch (short_option) { |
| 1501 | case 'r': |
| 1502 | m_allow_reload = true; |
| 1503 | break; |
| 1504 | default: |
| 1505 | error.SetErrorStringWithFormat("unrecognized option '%c'", |
| 1506 | short_option); |
| 1507 | break; |
| 1508 | } |
| 1509 | |
| 1510 | return error; |
Enrico Granata | a9dbf43 | 2011-10-17 21:45:27 +0000 | [diff] [blame] | 1511 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1512 | |
| 1513 | void OptionParsingStarting(ExecutionContext *execution_context) override { |
| 1514 | m_allow_reload = true; |
| 1515 | } |
| 1516 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1517 | llvm::ArrayRef<OptionDefinition> GetDefinitions() override { |
Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 1518 | return llvm::makeArrayRef(g_script_import_options); |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1519 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1520 | |
| 1521 | // Instance variables to hold the values for command options. |
| 1522 | |
| 1523 | bool m_allow_reload; |
| 1524 | }; |
| 1525 | |
| 1526 | bool DoExecute(Args &command, CommandReturnObject &result) override { |
| 1527 | if (m_interpreter.GetDebugger().GetScriptLanguage() != |
| 1528 | lldb::eScriptLanguagePython) { |
| 1529 | result.AppendError("only scripting language supported for module " |
| 1530 | "importing is currently Python"); |
| 1531 | result.SetStatus(eReturnStatusFailed); |
| 1532 | return false; |
| 1533 | } |
| 1534 | |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 1535 | if (command.empty()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1536 | result.AppendError("command script import needs one or more arguments"); |
| 1537 | result.SetStatus(eReturnStatusFailed); |
| 1538 | return false; |
| 1539 | } |
| 1540 | |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 1541 | for (auto &entry : command.entries()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1542 | Error error; |
| 1543 | |
| 1544 | const bool init_session = true; |
| 1545 | // FIXME: this is necessary because CommandObject::CheckRequirements() |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 1546 | // assumes that commands won't ever be recursively invoked, but it's |
| 1547 | // actually possible to craft a Python script that does other "command |
| 1548 | // script imports" in __lldb_init_module the real fix is to have recursive |
| 1549 | // commands possible with a CommandInvocation object separate from the |
| 1550 | // CommandObject itself, so that recursive command invocations won't stomp |
| 1551 | // on each other (wrt to execution contents, options, and more) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1552 | m_exe_ctx.Clear(); |
| 1553 | if (m_interpreter.GetScriptInterpreter()->LoadScriptingModule( |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 1554 | entry.c_str(), m_options.m_allow_reload, init_session, error)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1555 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 1556 | } else { |
| 1557 | result.AppendErrorWithFormat("module importing failed: %s", |
| 1558 | error.AsCString()); |
| 1559 | result.SetStatus(eReturnStatusFailed); |
| 1560 | } |
| 1561 | } |
| 1562 | |
| 1563 | return result.Succeeded(); |
| 1564 | } |
| 1565 | |
| 1566 | CommandOptions m_options; |
Enrico Granata | a9dbf43 | 2011-10-17 21:45:27 +0000 | [diff] [blame] | 1567 | }; |
Enrico Granata | 223383e | 2011-08-16 23:24:13 +0000 | [diff] [blame] | 1568 | |
| 1569 | //------------------------------------------------------------------------- |
| 1570 | // CommandObjectCommandsScriptAdd |
| 1571 | //------------------------------------------------------------------------- |
| 1572 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1573 | static OptionEnumValueElement g_script_synchro_type[] = { |
| 1574 | {eScriptedCommandSynchronicitySynchronous, "synchronous", |
| 1575 | "Run synchronous"}, |
| 1576 | {eScriptedCommandSynchronicityAsynchronous, "asynchronous", |
| 1577 | "Run asynchronous"}, |
| 1578 | {eScriptedCommandSynchronicityCurrentValue, "current", |
| 1579 | "Do not alter current setting"}, |
| 1580 | {0, nullptr, nullptr}}; |
| 1581 | |
| 1582 | static OptionDefinition g_script_add_options[] = { |
| 1583 | // clang-format off |
| 1584 | { LLDB_OPT_SET_1, false, "function", 'f', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonFunction, "Name of the Python function to bind to this command name." }, |
| 1585 | { LLDB_OPT_SET_2, false, "class", 'c', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypePythonClass, "Name of the Python class to bind to this command name." }, |
| 1586 | { LLDB_OPT_SET_1, false, "help" , 'h', OptionParser::eRequiredArgument, nullptr, nullptr, 0, eArgTypeHelpText, "The help text to display for this command." }, |
| 1587 | { LLDB_OPT_SET_ALL, false, "synchronicity", 's', OptionParser::eRequiredArgument, nullptr, g_script_synchro_type, 0, eArgTypeScriptedCommandSynchronicity, "Set the synchronicity of this command's executions with regard to LLDB event system." }, |
| 1588 | // clang-format on |
| 1589 | }; |
| 1590 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1591 | class CommandObjectCommandsScriptAdd : public CommandObjectParsed, |
| 1592 | public IOHandlerDelegateMultiline { |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1593 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1594 | CommandObjectCommandsScriptAdd(CommandInterpreter &interpreter) |
| 1595 | : CommandObjectParsed(interpreter, "command script add", |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1596 | "Add a scripted function as an LLDB command.", |
| 1597 | nullptr), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1598 | IOHandlerDelegateMultiline("DONE"), m_options() { |
| 1599 | CommandArgumentEntry arg1; |
| 1600 | CommandArgumentData cmd_arg; |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1601 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1602 | // Define the first (and only) variant of this arg. |
| 1603 | cmd_arg.arg_type = eArgTypeCommandName; |
| 1604 | cmd_arg.arg_repetition = eArgRepeatPlain; |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1605 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1606 | // There is only one variant this argument could be; put it into the |
| 1607 | // argument entry. |
| 1608 | arg1.push_back(cmd_arg); |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1609 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1610 | // Push the data for the first argument into the m_arguments vector. |
| 1611 | m_arguments.push_back(arg1); |
| 1612 | } |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1613 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1614 | ~CommandObjectCommandsScriptAdd() override = default; |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1615 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1616 | Options *GetOptions() override { return &m_options; } |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1617 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1618 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1619 | class CommandOptions : public Options { |
| 1620 | public: |
| 1621 | CommandOptions() |
| 1622 | : Options(), m_class_name(), m_funct_name(), m_short_help(), |
| 1623 | m_synchronicity(eScriptedCommandSynchronicitySynchronous) {} |
Enrico Granata | 223383e | 2011-08-16 23:24:13 +0000 | [diff] [blame] | 1624 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1625 | ~CommandOptions() override = default; |
| 1626 | |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame^] | 1627 | Error SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1628 | ExecutionContext *execution_context) override { |
| 1629 | Error error; |
| 1630 | const int short_option = m_getopt_table[option_idx].val; |
| 1631 | |
| 1632 | switch (short_option) { |
| 1633 | case 'f': |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame^] | 1634 | if (!option_arg.empty()) |
| 1635 | m_funct_name = option_arg; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1636 | break; |
| 1637 | case 'c': |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame^] | 1638 | if (!option_arg.empty()) |
| 1639 | m_class_name = option_arg; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1640 | break; |
| 1641 | case 'h': |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame^] | 1642 | if (!option_arg.empty()) |
| 1643 | m_short_help = option_arg; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1644 | break; |
| 1645 | case 's': |
| 1646 | m_synchronicity = |
| 1647 | (ScriptedCommandSynchronicity)Args::StringToOptionEnum( |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame^] | 1648 | option_arg, GetDefinitions()[option_idx].enum_values, 0, error); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1649 | if (!error.Success()) |
| 1650 | error.SetErrorStringWithFormat( |
Zachary Turner | fe11483 | 2016-11-12 16:56:47 +0000 | [diff] [blame^] | 1651 | "unrecognized value for synchronicity '%s'", |
| 1652 | option_arg.str().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1653 | break; |
| 1654 | default: |
| 1655 | error.SetErrorStringWithFormat("unrecognized option '%c'", |
| 1656 | short_option); |
| 1657 | break; |
| 1658 | } |
| 1659 | |
| 1660 | return error; |
Enrico Granata | 223383e | 2011-08-16 23:24:13 +0000 | [diff] [blame] | 1661 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1662 | |
| 1663 | void OptionParsingStarting(ExecutionContext *execution_context) override { |
| 1664 | m_class_name.clear(); |
| 1665 | m_funct_name.clear(); |
| 1666 | m_short_help.clear(); |
| 1667 | m_synchronicity = eScriptedCommandSynchronicitySynchronous; |
| 1668 | } |
| 1669 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1670 | llvm::ArrayRef<OptionDefinition> GetDefinitions() override { |
Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 1671 | return llvm::makeArrayRef(g_script_add_options); |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 1672 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1673 | |
| 1674 | // Instance variables to hold the values for command options. |
| 1675 | |
| 1676 | std::string m_class_name; |
| 1677 | std::string m_funct_name; |
Enrico Granata | 735152e | 2014-09-15 17:52:44 +0000 | [diff] [blame] | 1678 | std::string m_short_help; |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 1679 | ScriptedCommandSynchronicity m_synchronicity; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1680 | }; |
| 1681 | |
| 1682 | void IOHandlerActivated(IOHandler &io_handler) override { |
| 1683 | StreamFileSP output_sp(io_handler.GetOutputStreamFile()); |
| 1684 | if (output_sp) { |
| 1685 | output_sp->PutCString(g_python_command_instructions); |
| 1686 | output_sp->Flush(); |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | void IOHandlerInputComplete(IOHandler &io_handler, |
| 1691 | std::string &data) override { |
| 1692 | StreamFileSP error_sp = io_handler.GetErrorStreamFile(); |
| 1693 | |
| 1694 | ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter(); |
| 1695 | if (interpreter) { |
| 1696 | |
| 1697 | StringList lines; |
| 1698 | lines.SplitIntoLines(data); |
| 1699 | if (lines.GetSize() > 0) { |
| 1700 | std::string funct_name_str; |
| 1701 | if (interpreter->GenerateScriptAliasFunction(lines, funct_name_str)) { |
| 1702 | if (funct_name_str.empty()) { |
| 1703 | error_sp->Printf("error: unable to obtain a function name, didn't " |
| 1704 | "add python command.\n"); |
| 1705 | error_sp->Flush(); |
| 1706 | } else { |
| 1707 | // everything should be fine now, let's add this alias |
| 1708 | |
| 1709 | CommandObjectSP command_obj_sp(new CommandObjectPythonFunction( |
Malcolm Parsons | 771ef6d | 2016-11-02 20:34:10 +0000 | [diff] [blame] | 1710 | m_interpreter, m_cmd_name, funct_name_str, m_short_help, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1711 | m_synchronicity)); |
| 1712 | |
| 1713 | if (!m_interpreter.AddUserCommand(m_cmd_name, command_obj_sp, |
| 1714 | true)) { |
| 1715 | error_sp->Printf("error: unable to add selected command, didn't " |
| 1716 | "add python command.\n"); |
| 1717 | error_sp->Flush(); |
| 1718 | } |
| 1719 | } |
| 1720 | } else { |
| 1721 | error_sp->Printf( |
| 1722 | "error: unable to create function, didn't add python command.\n"); |
| 1723 | error_sp->Flush(); |
| 1724 | } |
| 1725 | } else { |
| 1726 | error_sp->Printf("error: empty function, didn't add python command.\n"); |
| 1727 | error_sp->Flush(); |
| 1728 | } |
| 1729 | } else { |
| 1730 | error_sp->Printf( |
| 1731 | "error: script interpreter missing, didn't add python command.\n"); |
| 1732 | error_sp->Flush(); |
| 1733 | } |
| 1734 | |
| 1735 | io_handler.SetIsDone(true); |
| 1736 | } |
| 1737 | |
| 1738 | protected: |
| 1739 | bool DoExecute(Args &command, CommandReturnObject &result) override { |
| 1740 | if (m_interpreter.GetDebugger().GetScriptLanguage() != |
| 1741 | lldb::eScriptLanguagePython) { |
| 1742 | result.AppendError("only scripting language supported for scripted " |
| 1743 | "commands is currently Python"); |
| 1744 | result.SetStatus(eReturnStatusFailed); |
| 1745 | return false; |
| 1746 | } |
| 1747 | |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 1748 | if (command.GetArgumentCount() != 1) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1749 | result.AppendError("'command script add' requires one argument"); |
| 1750 | result.SetStatus(eReturnStatusFailed); |
| 1751 | return false; |
| 1752 | } |
| 1753 | |
| 1754 | // Store the options in case we get multi-line input |
| 1755 | m_cmd_name = command.GetArgumentAtIndex(0); |
| 1756 | m_short_help.assign(m_options.m_short_help); |
| 1757 | m_synchronicity = m_options.m_synchronicity; |
| 1758 | |
| 1759 | if (m_options.m_class_name.empty()) { |
| 1760 | if (m_options.m_funct_name.empty()) { |
| 1761 | m_interpreter.GetPythonCommandsFromIOHandler( |
| 1762 | " ", // Prompt |
| 1763 | *this, // IOHandlerDelegate |
| 1764 | true, // Run IOHandler in async mode |
| 1765 | nullptr); // Baton for the "io_handler" that will be passed back |
| 1766 | // into our IOHandlerDelegate functions |
| 1767 | } else { |
| 1768 | CommandObjectSP new_cmd(new CommandObjectPythonFunction( |
| 1769 | m_interpreter, m_cmd_name, m_options.m_funct_name, |
| 1770 | m_options.m_short_help, m_synchronicity)); |
| 1771 | if (m_interpreter.AddUserCommand(m_cmd_name, new_cmd, true)) { |
| 1772 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 1773 | } else { |
| 1774 | result.AppendError("cannot add command"); |
| 1775 | result.SetStatus(eReturnStatusFailed); |
| 1776 | } |
| 1777 | } |
| 1778 | } else { |
| 1779 | ScriptInterpreter *interpreter = |
| 1780 | GetCommandInterpreter().GetScriptInterpreter(); |
| 1781 | if (!interpreter) { |
| 1782 | result.AppendError("cannot find ScriptInterpreter"); |
| 1783 | result.SetStatus(eReturnStatusFailed); |
| 1784 | return false; |
| 1785 | } |
| 1786 | |
| 1787 | auto cmd_obj_sp = interpreter->CreateScriptCommandObject( |
| 1788 | m_options.m_class_name.c_str()); |
| 1789 | if (!cmd_obj_sp) { |
| 1790 | result.AppendError("cannot create helper object"); |
| 1791 | result.SetStatus(eReturnStatusFailed); |
| 1792 | return false; |
| 1793 | } |
| 1794 | |
| 1795 | CommandObjectSP new_cmd(new CommandObjectScriptingObject( |
| 1796 | m_interpreter, m_cmd_name, cmd_obj_sp, m_synchronicity)); |
| 1797 | if (m_interpreter.AddUserCommand(m_cmd_name, new_cmd, true)) { |
| 1798 | result.SetStatus(eReturnStatusSuccessFinishNoResult); |
| 1799 | } else { |
| 1800 | result.AppendError("cannot add command"); |
| 1801 | result.SetStatus(eReturnStatusFailed); |
| 1802 | } |
| 1803 | } |
| 1804 | |
| 1805 | return result.Succeeded(); |
| 1806 | } |
| 1807 | |
| 1808 | CommandOptions m_options; |
| 1809 | std::string m_cmd_name; |
| 1810 | std::string m_short_help; |
| 1811 | ScriptedCommandSynchronicity m_synchronicity; |
Enrico Granata | 223383e | 2011-08-16 23:24:13 +0000 | [diff] [blame] | 1812 | }; |
| 1813 | |
Enrico Granata | 223383e | 2011-08-16 23:24:13 +0000 | [diff] [blame] | 1814 | //------------------------------------------------------------------------- |
| 1815 | // CommandObjectCommandsScriptList |
| 1816 | //------------------------------------------------------------------------- |
| 1817 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1818 | class CommandObjectCommandsScriptList : public CommandObjectParsed { |
Enrico Granata | 223383e | 2011-08-16 23:24:13 +0000 | [diff] [blame] | 1819 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1820 | CommandObjectCommandsScriptList(CommandInterpreter &interpreter) |
| 1821 | : CommandObjectParsed(interpreter, "command script list", |
| 1822 | "List defined scripted commands.", nullptr) {} |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1823 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1824 | ~CommandObjectCommandsScriptList() override = default; |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1825 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1826 | bool DoExecute(Args &command, CommandReturnObject &result) override { |
| 1827 | m_interpreter.GetHelp(result, CommandInterpreter::eCommandTypesUserDef); |
| 1828 | |
| 1829 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 1830 | |
| 1831 | return true; |
| 1832 | } |
Enrico Granata | 223383e | 2011-08-16 23:24:13 +0000 | [diff] [blame] | 1833 | }; |
| 1834 | |
| 1835 | //------------------------------------------------------------------------- |
| 1836 | // CommandObjectCommandsScriptClear |
| 1837 | //------------------------------------------------------------------------- |
| 1838 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1839 | class CommandObjectCommandsScriptClear : public CommandObjectParsed { |
Enrico Granata | 223383e | 2011-08-16 23:24:13 +0000 | [diff] [blame] | 1840 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1841 | CommandObjectCommandsScriptClear(CommandInterpreter &interpreter) |
| 1842 | : CommandObjectParsed(interpreter, "command script clear", |
| 1843 | "Delete all scripted commands.", nullptr) {} |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1844 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1845 | ~CommandObjectCommandsScriptClear() override = default; |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1846 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1847 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1848 | bool DoExecute(Args &command, CommandReturnObject &result) override { |
| 1849 | m_interpreter.RemoveAllUser(); |
| 1850 | |
| 1851 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 1852 | |
| 1853 | return true; |
| 1854 | } |
Enrico Granata | 223383e | 2011-08-16 23:24:13 +0000 | [diff] [blame] | 1855 | }; |
| 1856 | |
| 1857 | //------------------------------------------------------------------------- |
| 1858 | // CommandObjectCommandsScriptDelete |
| 1859 | //------------------------------------------------------------------------- |
| 1860 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1861 | class CommandObjectCommandsScriptDelete : public CommandObjectParsed { |
Enrico Granata | 223383e | 2011-08-16 23:24:13 +0000 | [diff] [blame] | 1862 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1863 | CommandObjectCommandsScriptDelete(CommandInterpreter &interpreter) |
| 1864 | : CommandObjectParsed(interpreter, "command script delete", |
| 1865 | "Delete a scripted command.", nullptr) { |
| 1866 | CommandArgumentEntry arg1; |
| 1867 | CommandArgumentData cmd_arg; |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1868 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1869 | // Define the first (and only) variant of this arg. |
| 1870 | cmd_arg.arg_type = eArgTypeCommandName; |
| 1871 | cmd_arg.arg_repetition = eArgRepeatPlain; |
| 1872 | |
| 1873 | // There is only one variant this argument could be; put it into the |
| 1874 | // argument entry. |
| 1875 | arg1.push_back(cmd_arg); |
| 1876 | |
| 1877 | // Push the data for the first argument into the m_arguments vector. |
| 1878 | m_arguments.push_back(arg1); |
| 1879 | } |
| 1880 | |
| 1881 | ~CommandObjectCommandsScriptDelete() override = default; |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1882 | |
Jim Ingham | 5a98841 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 1883 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1884 | bool DoExecute(Args &command, CommandReturnObject &result) override { |
| 1885 | |
Zachary Turner | 11eb9c6 | 2016-10-05 20:03:37 +0000 | [diff] [blame] | 1886 | if (command.GetArgumentCount() != 1) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1887 | result.AppendError("'command script delete' requires one argument"); |
| 1888 | result.SetStatus(eReturnStatusFailed); |
| 1889 | return false; |
Enrico Granata | 223383e | 2011-08-16 23:24:13 +0000 | [diff] [blame] | 1890 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1891 | |
| 1892 | const char *cmd_name = command.GetArgumentAtIndex(0); |
| 1893 | |
| 1894 | if (cmd_name && *cmd_name && m_interpreter.HasUserCommands() && |
| 1895 | m_interpreter.UserCommandExists(cmd_name)) { |
| 1896 | m_interpreter.RemoveUser(cmd_name); |
| 1897 | result.SetStatus(eReturnStatusSuccessFinishResult); |
| 1898 | } else { |
| 1899 | result.AppendErrorWithFormat("command %s not found", cmd_name); |
| 1900 | result.SetStatus(eReturnStatusFailed); |
| 1901 | } |
| 1902 | |
| 1903 | return result.Succeeded(); |
| 1904 | } |
Enrico Granata | 223383e | 2011-08-16 23:24:13 +0000 | [diff] [blame] | 1905 | }; |
| 1906 | |
| 1907 | #pragma mark CommandObjectMultiwordCommandsScript |
| 1908 | |
| 1909 | //------------------------------------------------------------------------- |
| 1910 | // CommandObjectMultiwordCommandsScript |
| 1911 | //------------------------------------------------------------------------- |
| 1912 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1913 | class CommandObjectMultiwordCommandsScript : public CommandObjectMultiword { |
Enrico Granata | 223383e | 2011-08-16 23:24:13 +0000 | [diff] [blame] | 1914 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1915 | CommandObjectMultiwordCommandsScript(CommandInterpreter &interpreter) |
| 1916 | : CommandObjectMultiword( |
| 1917 | interpreter, "command script", "Commands for managing custom " |
| 1918 | "commands implemented by " |
| 1919 | "interpreter scripts.", |
| 1920 | "command script <subcommand> [<subcommand-options>]") { |
| 1921 | LoadSubCommand("add", CommandObjectSP( |
| 1922 | new CommandObjectCommandsScriptAdd(interpreter))); |
| 1923 | LoadSubCommand( |
| 1924 | "delete", |
| 1925 | CommandObjectSP(new CommandObjectCommandsScriptDelete(interpreter))); |
| 1926 | LoadSubCommand( |
| 1927 | "clear", |
| 1928 | CommandObjectSP(new CommandObjectCommandsScriptClear(interpreter))); |
| 1929 | LoadSubCommand("list", CommandObjectSP(new CommandObjectCommandsScriptList( |
| 1930 | interpreter))); |
| 1931 | LoadSubCommand( |
| 1932 | "import", |
| 1933 | CommandObjectSP(new CommandObjectCommandsScriptImport(interpreter))); |
| 1934 | } |
Enrico Granata | 223383e | 2011-08-16 23:24:13 +0000 | [diff] [blame] | 1935 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1936 | ~CommandObjectMultiwordCommandsScript() override = default; |
Enrico Granata | 223383e | 2011-08-16 23:24:13 +0000 | [diff] [blame] | 1937 | }; |
| 1938 | |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 1939 | #pragma mark CommandObjectMultiwordCommands |
| 1940 | |
| 1941 | //------------------------------------------------------------------------- |
| 1942 | // CommandObjectMultiwordCommands |
| 1943 | //------------------------------------------------------------------------- |
| 1944 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1945 | CommandObjectMultiwordCommands::CommandObjectMultiwordCommands( |
| 1946 | CommandInterpreter &interpreter) |
| 1947 | : CommandObjectMultiword(interpreter, "command", |
| 1948 | "Commands for managing custom LLDB commands.", |
| 1949 | "command <subcommand> [<subcommand-options>]") { |
| 1950 | LoadSubCommand("source", |
| 1951 | CommandObjectSP(new CommandObjectCommandsSource(interpreter))); |
| 1952 | LoadSubCommand("alias", |
| 1953 | CommandObjectSP(new CommandObjectCommandsAlias(interpreter))); |
| 1954 | LoadSubCommand("unalias", CommandObjectSP( |
| 1955 | new CommandObjectCommandsUnalias(interpreter))); |
| 1956 | LoadSubCommand("delete", |
| 1957 | CommandObjectSP(new CommandObjectCommandsDelete(interpreter))); |
| 1958 | LoadSubCommand( |
| 1959 | "regex", CommandObjectSP(new CommandObjectCommandsAddRegex(interpreter))); |
| 1960 | LoadSubCommand("history", CommandObjectSP( |
| 1961 | new CommandObjectCommandsHistory(interpreter))); |
| 1962 | LoadSubCommand( |
| 1963 | "script", |
| 1964 | CommandObjectSP(new CommandObjectMultiwordCommandsScript(interpreter))); |
Jim Ingham | ebc09c3 | 2010-07-07 03:36:20 +0000 | [diff] [blame] | 1965 | } |
| 1966 | |
Eugene Zelenko | 6e3d8e7 | 2016-02-22 23:46:47 +0000 | [diff] [blame] | 1967 | CommandObjectMultiwordCommands::~CommandObjectMultiwordCommands() = default; |