blob: a1a63cfd898aea748a7db4a48a999b485d58e993 [file] [log] [blame]
Jim Inghamebc09c32010-07-07 03:36:20 +00001//===-- 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
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Jim Inghamebc09c32010-07-07 03:36:20 +000012#include "CommandObjectCommands.h"
13
14// C Includes
15// C++ Includes
16// Other libraries and framework includes
Greg Clayton0e5e5a72011-04-20 22:55:21 +000017#include "llvm/ADT/StringRef.h"
18
Jim Inghamebc09c32010-07-07 03:36:20 +000019// Project includes
Jim Inghamebc09c32010-07-07 03:36:20 +000020#include "lldb/Core/Debugger.h"
Greg Clayton44d93782014-01-27 23:43:24 +000021#include "lldb/Core/IOHandler.h"
Enrico Granatabe93a352011-08-16 16:49:25 +000022#include "lldb/Core/StringList.h"
Greg Claytonde164aa2011-04-20 16:37:46 +000023#include "lldb/Interpreter/Args.h"
Enrico Granata7594f142013-06-17 22:51:50 +000024#include "lldb/Interpreter/CommandHistory.h"
Jim Inghamebc09c32010-07-07 03:36:20 +000025#include "lldb/Interpreter/CommandInterpreter.h"
Greg Claytonde164aa2011-04-20 16:37:46 +000026#include "lldb/Interpreter/CommandObjectRegexCommand.h"
Jim Inghamebc09c32010-07-07 03:36:20 +000027#include "lldb/Interpreter/CommandReturnObject.h"
Enrico Granata012d4fc2013-06-11 01:26:35 +000028#include "lldb/Interpreter/OptionValueBoolean.h"
Enrico Granata7594f142013-06-17 22:51:50 +000029#include "lldb/Interpreter/OptionValueUInt64.h"
Jim Inghamebc09c32010-07-07 03:36:20 +000030#include "lldb/Interpreter/Options.h"
Enrico Granata99f0b8f2011-08-17 01:30:04 +000031#include "lldb/Interpreter/ScriptInterpreter.h"
32#include "lldb/Interpreter/ScriptInterpreterPython.h"
Jim Inghamebc09c32010-07-07 03:36:20 +000033
34using namespace lldb;
35using namespace lldb_private;
36
Jim Inghamebc09c32010-07-07 03:36:20 +000037//-------------------------------------------------------------------------
38// CommandObjectCommandsSource
39//-------------------------------------------------------------------------
40
Jim Ingham5a988412012-06-08 21:56:10 +000041class CommandObjectCommandsHistory : public CommandObjectParsed
Jim Inghama5a97eb2011-07-12 03:12:18 +000042{
Jim Ingham5a988412012-06-08 21:56:10 +000043public:
44 CommandObjectCommandsHistory(CommandInterpreter &interpreter) :
45 CommandObjectParsed (interpreter,
46 "command history",
47 "Dump the history of commands in this session.",
48 NULL),
49 m_options (interpreter)
50 {
51 }
52
53 ~CommandObjectCommandsHistory () {}
54
55 virtual Options *
56 GetOptions ()
57 {
58 return &m_options;
59 }
60
61protected:
Jim Inghama5a97eb2011-07-12 03:12:18 +000062
63 class CommandOptions : public Options
64 {
65 public:
66
67 CommandOptions (CommandInterpreter &interpreter) :
Enrico Granata7594f142013-06-17 22:51:50 +000068 Options (interpreter),
69 m_start_idx(0),
70 m_stop_idx(0),
71 m_count(0),
Enrico Granata63123b62013-06-17 23:28:27 +000072 m_clear(false)
Jim Inghama5a97eb2011-07-12 03:12:18 +000073 {
74 }
75
76 virtual
77 ~CommandOptions (){}
78
79 virtual Error
80 SetOptionValue (uint32_t option_idx, const char *option_arg)
81 {
82 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +000083 const int short_option = m_getopt_table[option_idx].val;
Jim Inghama5a97eb2011-07-12 03:12:18 +000084
85 switch (short_option)
86 {
87 case 'c':
Enrico Granata7594f142013-06-17 22:51:50 +000088 error = m_count.SetValueFromCString(option_arg,eVarSetOperationAssign);
Jim Inghama5a97eb2011-07-12 03:12:18 +000089 break;
90 case 's':
Enrico Granata7594f142013-06-17 22:51:50 +000091 if (option_arg && strcmp("end", option_arg) == 0)
92 {
93 m_start_idx.SetCurrentValue(UINT64_MAX);
94 m_start_idx.SetOptionWasSet();
95 }
96 else
97 error = m_start_idx.SetValueFromCString(option_arg,eVarSetOperationAssign);
98 break;
99 case 'e':
100 error = m_stop_idx.SetValueFromCString(option_arg,eVarSetOperationAssign);
101 break;
Enrico Granata63123b62013-06-17 23:28:27 +0000102 case 'C':
103 m_clear.SetCurrentValue(true);
104 m_clear.SetOptionWasSet();
Jim Inghama5a97eb2011-07-12 03:12:18 +0000105 break;
106 default:
Greg Clayton86edbf42011-10-26 00:56:27 +0000107 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
Jim Inghama5a97eb2011-07-12 03:12:18 +0000108 break;
109 }
110
111 return error;
112 }
113
114 void
115 OptionParsingStarting ()
116 {
Enrico Granata7594f142013-06-17 22:51:50 +0000117 m_start_idx.Clear();
118 m_stop_idx.Clear();
119 m_count.Clear();
Enrico Granata63123b62013-06-17 23:28:27 +0000120 m_clear.Clear();
Jim Inghama5a97eb2011-07-12 03:12:18 +0000121 }
122
123 const OptionDefinition*
124 GetDefinitions ()
125 {
126 return g_option_table;
127 }
128
129 // Options table: Required for subclasses of Options.
130
131 static OptionDefinition g_option_table[];
132
133 // Instance variables to hold the values for command options.
134
Enrico Granata7594f142013-06-17 22:51:50 +0000135 OptionValueUInt64 m_start_idx;
136 OptionValueUInt64 m_stop_idx;
137 OptionValueUInt64 m_count;
Enrico Granata63123b62013-06-17 23:28:27 +0000138 OptionValueBoolean m_clear;
Jim Inghama5a97eb2011-07-12 03:12:18 +0000139 };
140
Jim Inghama5a97eb2011-07-12 03:12:18 +0000141 bool
Jim Ingham5a988412012-06-08 21:56:10 +0000142 DoExecute (Args& command, CommandReturnObject &result)
Jim Inghama5a97eb2011-07-12 03:12:18 +0000143 {
Enrico Granata63123b62013-06-17 23:28:27 +0000144 if (m_options.m_clear.GetCurrentValue() && m_options.m_clear.OptionWasSet())
Enrico Granata7594f142013-06-17 22:51:50 +0000145 {
146 m_interpreter.GetCommandHistory().Clear();
147 result.SetStatus(lldb::eReturnStatusSuccessFinishNoResult);
148 }
149 else
150 {
151 if (m_options.m_start_idx.OptionWasSet() && m_options.m_stop_idx.OptionWasSet() && m_options.m_count.OptionWasSet())
152 {
153 result.AppendError("--count, --start-index and --end-index cannot be all specified in the same invocation");
154 result.SetStatus(lldb::eReturnStatusFailed);
155 }
156 else
157 {
Virgile Bello84400ec2013-08-27 16:22:29 +0000158 std::pair<bool,uint64_t> start_idx(m_options.m_start_idx.OptionWasSet(),m_options.m_start_idx.GetCurrentValue());
159 std::pair<bool,uint64_t> stop_idx(m_options.m_stop_idx.OptionWasSet(),m_options.m_stop_idx.GetCurrentValue());
160 std::pair<bool,uint64_t> count(m_options.m_count.OptionWasSet(),m_options.m_count.GetCurrentValue());
Enrico Granata7594f142013-06-17 22:51:50 +0000161
162 const CommandHistory& history(m_interpreter.GetCommandHistory());
163
164 if (start_idx.first && start_idx.second == UINT64_MAX)
165 {
166 if (count.first)
167 {
168 start_idx.second = history.GetSize() - count.second;
169 stop_idx.second = history.GetSize() - 1;
170 }
171 else if (stop_idx.first)
172 {
173 start_idx.second = stop_idx.second;
174 stop_idx.second = history.GetSize() - 1;
175 }
176 else
177 {
178 start_idx.second = 0;
179 stop_idx.second = history.GetSize() - 1;
180 }
181 }
182 else
183 {
184 if (!start_idx.first && !stop_idx.first && !count.first)
185 {
186 start_idx.second = 0;
187 stop_idx.second = history.GetSize() - 1;
188 }
189 else if (start_idx.first)
190 {
191 if (count.first)
192 {
193 stop_idx.second = start_idx.second + count.second - 1;
194 }
195 else if (!stop_idx.first)
196 {
197 stop_idx.second = history.GetSize() - 1;
198 }
199 }
200 else if (stop_idx.first)
201 {
202 if (count.first)
203 {
204 if (stop_idx.second >= count.second)
205 start_idx.second = stop_idx.second - count.second + 1;
206 else
207 start_idx.second = 0;
208 }
209 }
210 else /* if (count.first) */
211 {
212 start_idx.second = 0;
213 stop_idx.second = count.second - 1;
214 }
215 }
216 history.Dump(result.GetOutputStream(), start_idx.second, stop_idx.second);
217 }
218 }
Jim Inghama5a97eb2011-07-12 03:12:18 +0000219 return result.Succeeded();
220
221 }
Jim Ingham5a988412012-06-08 21:56:10 +0000222
223 CommandOptions m_options;
Jim Inghama5a97eb2011-07-12 03:12:18 +0000224};
225
226OptionDefinition
227CommandObjectCommandsHistory::CommandOptions::g_option_table[] =
228{
Zachary Turnerd37221d2014-07-09 16:31:49 +0000229{ LLDB_OPT_SET_1, false, "count", 'c', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeUnsignedInteger, "How many history commands to print."},
230{ LLDB_OPT_SET_1, false, "start-index", 's', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeUnsignedInteger, "Index at which to start printing history commands (or end to mean tail mode)."},
231{ LLDB_OPT_SET_1, false, "end-index", 'e', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeUnsignedInteger, "Index at which to stop printing history commands."},
232{ LLDB_OPT_SET_2, false, "clear", 'C', OptionParser::eNoArgument, NULL, NULL, 0, eArgTypeBoolean, "Clears the current command history."},
233{ 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
Jim Inghama5a97eb2011-07-12 03:12:18 +0000234};
235
236
237//-------------------------------------------------------------------------
238// CommandObjectCommandsSource
239//-------------------------------------------------------------------------
240
Jim Ingham5a988412012-06-08 21:56:10 +0000241class CommandObjectCommandsSource : public CommandObjectParsed
Jim Inghamebc09c32010-07-07 03:36:20 +0000242{
Jim Ingham5a988412012-06-08 21:56:10 +0000243public:
244 CommandObjectCommandsSource(CommandInterpreter &interpreter) :
245 CommandObjectParsed (interpreter,
246 "command source",
247 "Read in debugger commands from the file <filename> and execute them.",
248 NULL),
249 m_options (interpreter)
250 {
251 CommandArgumentEntry arg;
252 CommandArgumentData file_arg;
253
254 // Define the first (and only) variant of this arg.
255 file_arg.arg_type = eArgTypeFilename;
256 file_arg.arg_repetition = eArgRepeatPlain;
257
258 // There is only one variant this argument could be; put it into the argument entry.
259 arg.push_back (file_arg);
260
261 // Push the data for the first argument into the m_arguments vector.
262 m_arguments.push_back (arg);
263 }
264
265 ~CommandObjectCommandsSource () {}
266
267 virtual const char*
268 GetRepeatCommand (Args &current_command_args, uint32_t index)
269 {
270 return "";
271 }
272
Greg Claytonc7bece562013-01-25 18:06:21 +0000273 virtual int
Jim Ingham5a988412012-06-08 21:56:10 +0000274 HandleArgumentCompletion (Args &input,
275 int &cursor_index,
276 int &cursor_char_position,
277 OptionElementVector &opt_element_vector,
278 int match_start_point,
279 int max_return_elements,
280 bool &word_complete,
281 StringList &matches)
282 {
283 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
284 completion_str.erase (cursor_char_position);
285
286 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
287 CommandCompletions::eDiskFileCompletion,
288 completion_str.c_str(),
289 match_start_point,
290 max_return_elements,
291 NULL,
292 word_complete,
293 matches);
294 return matches.GetSize();
295 }
296
297 virtual Options *
298 GetOptions ()
299 {
300 return &m_options;
301 }
302
303protected:
Jim Inghame16c50a2011-02-18 00:54:25 +0000304
305 class CommandOptions : public Options
306 {
307 public:
308
Greg Claytoneb0103f2011-04-07 22:46:35 +0000309 CommandOptions (CommandInterpreter &interpreter) :
Enrico Granata012d4fc2013-06-11 01:26:35 +0000310 Options (interpreter),
Greg Clayton340b0302014-02-05 17:57:57 +0000311 m_stop_on_error (true),
312 m_silent_run (false),
313 m_stop_on_continue (true)
Greg Claytoneb0103f2011-04-07 22:46:35 +0000314 {
315 }
Jim Inghame16c50a2011-02-18 00:54:25 +0000316
317 virtual
318 ~CommandOptions (){}
319
320 virtual Error
Greg Claytonf6b8b582011-04-13 00:18:08 +0000321 SetOptionValue (uint32_t option_idx, const char *option_arg)
Jim Inghame16c50a2011-02-18 00:54:25 +0000322 {
323 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +0000324 const int short_option = m_getopt_table[option_idx].val;
Jim Inghame16c50a2011-02-18 00:54:25 +0000325
326 switch (short_option)
327 {
328 case 'e':
Enrico Granata15571f12013-06-26 00:36:27 +0000329 error = m_stop_on_error.SetValueFromCString(option_arg);
Jim Inghame16c50a2011-02-18 00:54:25 +0000330 break;
Greg Clayton340b0302014-02-05 17:57:57 +0000331
Jim Inghame16c50a2011-02-18 00:54:25 +0000332 case 'c':
Greg Clayton340b0302014-02-05 17:57:57 +0000333 error = m_stop_on_continue.SetValueFromCString(option_arg);
Jim Inghame16c50a2011-02-18 00:54:25 +0000334 break;
Greg Clayton340b0302014-02-05 17:57:57 +0000335
Michael Sartain60986172013-07-09 23:22:53 +0000336 case 's':
Greg Clayton340b0302014-02-05 17:57:57 +0000337 error = m_silent_run.SetValueFromCString(option_arg);
Michael Sartain60986172013-07-09 23:22:53 +0000338 break;
Greg Clayton340b0302014-02-05 17:57:57 +0000339
Jim Inghame16c50a2011-02-18 00:54:25 +0000340 default:
Greg Clayton86edbf42011-10-26 00:56:27 +0000341 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
Jim Inghame16c50a2011-02-18 00:54:25 +0000342 break;
343 }
344
345 return error;
346 }
347
348 void
Greg Claytonf6b8b582011-04-13 00:18:08 +0000349 OptionParsingStarting ()
Jim Inghame16c50a2011-02-18 00:54:25 +0000350 {
Enrico Granata012d4fc2013-06-11 01:26:35 +0000351 m_stop_on_error.Clear();
Greg Clayton340b0302014-02-05 17:57:57 +0000352 m_silent_run.Clear();
353 m_stop_on_continue.Clear();
Jim Inghame16c50a2011-02-18 00:54:25 +0000354 }
355
Greg Claytone0d378b2011-03-24 21:19:54 +0000356 const OptionDefinition*
Jim Inghame16c50a2011-02-18 00:54:25 +0000357 GetDefinitions ()
358 {
359 return g_option_table;
360 }
361
362 // Options table: Required for subclasses of Options.
363
Greg Claytone0d378b2011-03-24 21:19:54 +0000364 static OptionDefinition g_option_table[];
Jim Inghame16c50a2011-02-18 00:54:25 +0000365
366 // Instance variables to hold the values for command options.
367
Enrico Granata012d4fc2013-06-11 01:26:35 +0000368 OptionValueBoolean m_stop_on_error;
Greg Clayton340b0302014-02-05 17:57:57 +0000369 OptionValueBoolean m_silent_run;
370 OptionValueBoolean m_stop_on_continue;
Jim Inghame16c50a2011-02-18 00:54:25 +0000371 };
372
Jim Inghamebc09c32010-07-07 03:36:20 +0000373 bool
Jim Ingham5a988412012-06-08 21:56:10 +0000374 DoExecute(Args& command, CommandReturnObject &result)
Jim Inghamebc09c32010-07-07 03:36:20 +0000375 {
Greg Claytonc7bece562013-01-25 18:06:21 +0000376 const size_t argc = command.GetArgumentCount();
Jim Inghamebc09c32010-07-07 03:36:20 +0000377 if (argc == 1)
378 {
Jim Ingham5a988412012-06-08 21:56:10 +0000379 const char *filename = command.GetArgumentAtIndex(0);
Jim Inghamebc09c32010-07-07 03:36:20 +0000380
Johnny Chen1ee38532010-10-20 21:40:50 +0000381 FileSpec cmd_file (filename, true);
Jim Inghame16c50a2011-02-18 00:54:25 +0000382 ExecutionContext *exe_ctx = NULL; // Just use the default context.
Greg Clayton340b0302014-02-05 17:57:57 +0000383
384 // If any options were set, then use them
385 if (m_options.m_stop_on_error.OptionWasSet() ||
386 m_options.m_silent_run.OptionWasSet() ||
387 m_options.m_stop_on_continue.OptionWasSet())
388 {
389 // Use user set settings
Jim Ingham26c7bf92014-10-11 00:38:27 +0000390 CommandInterpreterRunOptions options;
391 options.SetStopOnContinue(m_options.m_stop_on_continue.GetCurrentValue());
392 options.SetStopOnError (m_options.m_stop_on_error.GetCurrentValue());
393 options.SetEchoCommands (m_options.m_silent_run.GetCurrentValue());
394 options.SetPrintResults (m_options.m_silent_run.GetCurrentValue());
395
Greg Clayton340b0302014-02-05 17:57:57 +0000396 m_interpreter.HandleCommandsFromFile (cmd_file,
397 exe_ctx,
Jim Ingham26c7bf92014-10-11 00:38:27 +0000398 options,
Greg Clayton340b0302014-02-05 17:57:57 +0000399 result);
400
401 }
402 else
403 {
404 // No options were set, inherit any settings from nested "command source" commands,
405 // or set to sane default settings...
Jim Ingham26c7bf92014-10-11 00:38:27 +0000406 CommandInterpreterRunOptions options;
Greg Clayton340b0302014-02-05 17:57:57 +0000407 m_interpreter.HandleCommandsFromFile (cmd_file,
408 exe_ctx,
Jim Ingham26c7bf92014-10-11 00:38:27 +0000409 options,
Greg Clayton340b0302014-02-05 17:57:57 +0000410 result);
411
412 }
Jim Inghamebc09c32010-07-07 03:36:20 +0000413 }
414 else
415 {
416 result.AppendErrorWithFormat("'%s' takes exactly one executable filename argument.\n", GetCommandName());
417 result.SetStatus (eReturnStatusFailed);
418 }
419 return result.Succeeded();
420
421 }
Jim Ingham5a988412012-06-08 21:56:10 +0000422 CommandOptions m_options;
Jim Inghamebc09c32010-07-07 03:36:20 +0000423};
424
Greg Claytone0d378b2011-03-24 21:19:54 +0000425OptionDefinition
Jim Inghame16c50a2011-02-18 00:54:25 +0000426CommandObjectCommandsSource::CommandOptions::g_option_table[] =
427{
Zachary Turnerd37221d2014-07-09 16:31:49 +0000428{ LLDB_OPT_SET_ALL, false, "stop-on-error", 'e', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "If true, stop executing commands on error."},
429{ LLDB_OPT_SET_ALL, false, "stop-on-continue", 'c', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "If true, stop executing commands on continue."},
430{ LLDB_OPT_SET_ALL, false, "silent-run", 's', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeBoolean, "If true don't echo commands while executing."},
431{ 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
Jim Inghame16c50a2011-02-18 00:54:25 +0000432};
433
Jim Inghamebc09c32010-07-07 03:36:20 +0000434#pragma mark CommandObjectCommandsAlias
435//-------------------------------------------------------------------------
436// CommandObjectCommandsAlias
437//-------------------------------------------------------------------------
438
Enrico Granatabe93a352011-08-16 16:49:25 +0000439static const char *g_python_command_instructions = "Enter your Python command(s). Type 'DONE' to end.\n"
440 "You must define a Python function with this signature:\n"
Greg Clayton44d93782014-01-27 23:43:24 +0000441 "def my_command_impl(debugger, args, result, internal_dict):\n";
Enrico Granatabe93a352011-08-16 16:49:25 +0000442
443
Jim Ingham5a988412012-06-08 21:56:10 +0000444class CommandObjectCommandsAlias : public CommandObjectRaw
Jim Inghamebc09c32010-07-07 03:36:20 +0000445{
Enrico Granatabe93a352011-08-16 16:49:25 +0000446
Enrico Granatabe93a352011-08-16 16:49:25 +0000447
Jim Inghamebc09c32010-07-07 03:36:20 +0000448public:
Greg Claytona7015092010-09-18 01:14:36 +0000449 CommandObjectCommandsAlias (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000450 CommandObjectRaw (interpreter,
Greg Clayton0e5e5a72011-04-20 22:55:21 +0000451 "command alias",
Caroline Ticee3d26312010-09-08 21:06:11 +0000452 "Allow users to define their own debugger command abbreviations.",
Caroline Tice405fe672010-10-04 22:28:36 +0000453 NULL)
Jim Inghamebc09c32010-07-07 03:36:20 +0000454 {
455 SetHelpLong(
456 "'alias' allows the user to create a short-cut or abbreviation for long \n\
457 commands, multi-word commands, and commands that take particular options. \n\
458 Below are some simple examples of how one might use the 'alias' command: \n\
Jason Molenda69c12cc2011-11-10 22:43:35 +0000459 \n 'command alias sc script' // Creates the abbreviation 'sc' for the 'script' \n\
Caroline Tice09799af2010-09-08 22:08:58 +0000460 // command. \n\
Jason Molenda69c12cc2011-11-10 22:43:35 +0000461 'command alias bp breakpoint' // Creates the abbreviation 'bp' for the 'breakpoint' \n\
Caroline Tice09799af2010-09-08 22:08:58 +0000462 // command. Since breakpoint commands are two-word \n\
463 // commands, the user will still need to enter the \n\
464 // second word after 'bp', e.g. 'bp enable' or \n\
465 // 'bp delete'. \n\
Jason Molenda69c12cc2011-11-10 22:43:35 +0000466 'command alias bpl breakpoint list' // Creates the abbreviation 'bpl' for the \n\
Caroline Tice09799af2010-09-08 22:08:58 +0000467 // two-word command 'breakpoint list'. \n\
Jim Inghamebc09c32010-07-07 03:36:20 +0000468 \nAn alias can include some options for the command, with the values either \n\
469 filled in at the time the alias is created, or specified as positional \n\
470 arguments, to be filled in when the alias is invoked. The following example \n\
471 shows how to create aliases with options: \n\
472 \n\
Jason Molenda69c12cc2011-11-10 22:43:35 +0000473 'command alias bfl breakpoint set -f %1 -l %2' \n\
Jim Inghamebc09c32010-07-07 03:36:20 +0000474 \nThis creates the abbreviation 'bfl' (for break-file-line), with the -f and -l \n\
475 options already part of the alias. So if the user wants to set a breakpoint \n\
476 by file and line without explicitly having to use the -f and -l options, the \n\
477 user can now use 'bfl' instead. The '%1' and '%2' are positional placeholders \n\
478 for the actual arguments that will be passed when the alias command is used. \n\
479 The number in the placeholder refers to the position/order the actual value \n\
Jim Ingham81ded932011-08-18 02:29:05 +0000480 occupies when the alias is used. All the occurrences of '%1' in the alias \n\
Jim Inghamebc09c32010-07-07 03:36:20 +0000481 will be replaced with the first argument, all the occurrences of '%2' in the \n\
482 alias will be replaced with the second argument, and so on. This also allows \n\
483 actual arguments to be used multiple times within an alias (see 'process \n\
Jim Ingham81ded932011-08-18 02:29:05 +0000484 launch' example below). \n\
485 Note: the positional arguments must substitute as whole words in the resultant\n\
486 command, so you can't at present do something like:\n\
487 \n\
Jason Molenda69c12cc2011-11-10 22:43:35 +0000488 command alias bcppfl breakpoint set -f %1.cpp -l %2\n\
Jim Ingham81ded932011-08-18 02:29:05 +0000489 \n\
490 to get the file extension \".cpp\" automatically appended. For more complex\n\
491 aliasing, use the \"command regex\" command instead.\n\
492 \nSo in the 'bfl' case, the actual file value will be \n\
Jim Inghamebc09c32010-07-07 03:36:20 +0000493 filled in with the first argument following 'bfl' and the actual line number \n\
494 value will be filled in with the second argument. The user would use this \n\
495 alias as follows: \n\
Jason Molenda69c12cc2011-11-10 22:43:35 +0000496 \n (lldb) command alias bfl breakpoint set -f %1 -l %2 \n\
Sean Callanan0708e2c2010-08-09 18:50:15 +0000497 <... some time later ...> \n\
Caroline Tice09799af2010-09-08 22:08:58 +0000498 (lldb) bfl my-file.c 137 \n\
Jim Inghamebc09c32010-07-07 03:36:20 +0000499 \nThis would be the same as if the user had entered \n\
500 'breakpoint set -f my-file.c -l 137'. \n\
501 \nAnother example: \n\
Jason Molenda69c12cc2011-11-10 22:43:35 +0000502 \n (lldb) command alias pltty process launch -s -o %1 -e %1 \n\
Caroline Tice09799af2010-09-08 22:08:58 +0000503 (lldb) pltty /dev/tty0 \n\
Sean Callanan0708e2c2010-08-09 18:50:15 +0000504 // becomes 'process launch -s -o /dev/tty0 -e /dev/tty0' \n\
Jim Inghamebc09c32010-07-07 03:36:20 +0000505 \nIf the user always wanted to pass the same value to a particular option, the \n\
506 alias could be defined with that value directly in the alias as a constant, \n\
507 rather than using a positional placeholder: \n\
Jason Molenda69c12cc2011-11-10 22:43:35 +0000508 \n command alias bl3 breakpoint set -f %1 -l 3 // Always sets a breakpoint on line \n\
Sean Callanan0708e2c2010-08-09 18:50:15 +0000509 // 3 of whatever file is indicated. \n");
Jim Inghamebc09c32010-07-07 03:36:20 +0000510
Caroline Tice405fe672010-10-04 22:28:36 +0000511 CommandArgumentEntry arg1;
512 CommandArgumentEntry arg2;
513 CommandArgumentEntry arg3;
514 CommandArgumentData alias_arg;
515 CommandArgumentData cmd_arg;
516 CommandArgumentData options_arg;
517
518 // Define the first (and only) variant of this arg.
519 alias_arg.arg_type = eArgTypeAliasName;
520 alias_arg.arg_repetition = eArgRepeatPlain;
521
522 // There is only one variant this argument could be; put it into the argument entry.
523 arg1.push_back (alias_arg);
524
525 // Define the first (and only) variant of this arg.
526 cmd_arg.arg_type = eArgTypeCommandName;
527 cmd_arg.arg_repetition = eArgRepeatPlain;
528
529 // There is only one variant this argument could be; put it into the argument entry.
530 arg2.push_back (cmd_arg);
531
532 // Define the first (and only) variant of this arg.
533 options_arg.arg_type = eArgTypeAliasOptions;
534 options_arg.arg_repetition = eArgRepeatOptional;
535
536 // There is only one variant this argument could be; put it into the argument entry.
537 arg3.push_back (options_arg);
538
539 // Push the data for the first argument into the m_arguments vector.
540 m_arguments.push_back (arg1);
541 m_arguments.push_back (arg2);
542 m_arguments.push_back (arg3);
Jim Inghamebc09c32010-07-07 03:36:20 +0000543 }
544
545 ~CommandObjectCommandsAlias ()
546 {
547 }
548
Jim Ingham5a988412012-06-08 21:56:10 +0000549protected:
550 virtual bool
551 DoExecute (const char *raw_command_line, CommandReturnObject &result)
Caroline Tice844d2302010-12-09 22:52:49 +0000552 {
553 Args args (raw_command_line);
554 std::string raw_command_string (raw_command_line);
555
556 size_t argc = args.GetArgumentCount();
557
558 if (argc < 2)
559 {
560 result.AppendError ("'alias' requires at least two arguments");
561 result.SetStatus (eReturnStatusFailed);
562 return false;
563 }
564
565 // Get the alias command.
566
567 const std::string alias_command = args.GetArgumentAtIndex (0);
Enrico Granatabe93a352011-08-16 16:49:25 +0000568
Caroline Tice844d2302010-12-09 22:52:49 +0000569 // Strip the new alias name off 'raw_command_string' (leave it on args, which gets passed to 'Execute', which
570 // does the stripping itself.
571 size_t pos = raw_command_string.find (alias_command);
572 if (pos == 0)
573 {
574 raw_command_string = raw_command_string.substr (alias_command.size());
575 pos = raw_command_string.find_first_not_of (' ');
576 if ((pos != std::string::npos) && (pos > 0))
577 raw_command_string = raw_command_string.substr (pos);
578 }
579 else
580 {
581 result.AppendError ("Error parsing command string. No alias created.");
582 result.SetStatus (eReturnStatusFailed);
583 return false;
584 }
585
586
587 // Verify that the command is alias-able.
588 if (m_interpreter.CommandExists (alias_command.c_str()))
589 {
590 result.AppendErrorWithFormat ("'%s' is a permanent debugger command and cannot be redefined.\n",
591 alias_command.c_str());
592 result.SetStatus (eReturnStatusFailed);
593 return false;
594 }
595
596 // Get CommandObject that is being aliased. The command name is read from the front of raw_command_string.
597 // raw_command_string is returned with the name of the command object stripped off the front.
598 CommandObject *cmd_obj = m_interpreter.GetCommandObjectForCommand (raw_command_string);
599
600 if (!cmd_obj)
601 {
Greg Clayton86edbf42011-10-26 00:56:27 +0000602 result.AppendErrorWithFormat ("invalid command given to 'alias'. '%s' does not begin with a valid command."
Caroline Tice844d2302010-12-09 22:52:49 +0000603 " No alias created.", raw_command_string.c_str());
604 result.SetStatus (eReturnStatusFailed);
605 return false;
606 }
607 else if (!cmd_obj->WantsRawCommandString ())
608 {
609 // Note that args was initialized with the original command, and has not been updated to this point.
610 // Therefore can we pass it to the version of Execute that does not need/expect raw input in the alias.
Jim Ingham5a988412012-06-08 21:56:10 +0000611 return HandleAliasingNormalCommand (args, result);
Caroline Tice844d2302010-12-09 22:52:49 +0000612 }
613 else
614 {
Jim Ingham5a988412012-06-08 21:56:10 +0000615 return HandleAliasingRawCommand (alias_command, raw_command_string, *cmd_obj, result);
616 }
617 return result.Succeeded();
618 }
619
620 bool
621 HandleAliasingRawCommand (const std::string &alias_command, std::string &raw_command_string, CommandObject &cmd_obj, CommandReturnObject &result)
622 {
Caroline Tice844d2302010-12-09 22:52:49 +0000623 // Verify & handle any options/arguments passed to the alias command
624
625 OptionArgVectorSP option_arg_vector_sp = OptionArgVectorSP (new OptionArgVector);
626 OptionArgVector *option_arg_vector = option_arg_vector_sp.get();
627
Jim Ingham5a988412012-06-08 21:56:10 +0000628 CommandObjectSP cmd_obj_sp = m_interpreter.GetCommandSPExact (cmd_obj.GetCommandName(), false);
Caroline Ticeca90c472011-05-06 21:37:15 +0000629
630 if (!m_interpreter.ProcessAliasOptionsArgs (cmd_obj_sp, raw_command_string.c_str(), option_arg_vector_sp))
Caroline Tice844d2302010-12-09 22:52:49 +0000631 {
Caroline Ticeca90c472011-05-06 21:37:15 +0000632 result.AppendError ("Unable to create requested alias.\n");
633 result.SetStatus (eReturnStatusFailed);
634 return false;
Caroline Tice844d2302010-12-09 22:52:49 +0000635 }
636
637 // Create the alias
638 if (m_interpreter.AliasExists (alias_command.c_str())
639 || m_interpreter.UserCommandExists (alias_command.c_str()))
640 {
641 OptionArgVectorSP temp_option_arg_sp (m_interpreter.GetAliasOptions (alias_command.c_str()));
642 if (temp_option_arg_sp.get())
643 {
644 if (option_arg_vector->size() == 0)
645 m_interpreter.RemoveAliasOptions (alias_command.c_str());
646 }
647 result.AppendWarningWithFormat ("Overwriting existing definition for '%s'.\n",
648 alias_command.c_str());
649 }
650
Caroline Tice472362e2010-12-14 18:51:39 +0000651 if (cmd_obj_sp)
652 {
653 m_interpreter.AddAlias (alias_command.c_str(), cmd_obj_sp);
654 if (option_arg_vector->size() > 0)
655 m_interpreter.AddOrReplaceAliasOptions (alias_command.c_str(), option_arg_vector_sp);
656 result.SetStatus (eReturnStatusSuccessFinishNoResult);
657 }
658 else
659 {
660 result.AppendError ("Unable to create requested alias.\n");
661 result.SetStatus (eReturnStatusFailed);
662 }
Jim Ingham5a988412012-06-08 21:56:10 +0000663 return result.Succeeded ();
Caroline Tice844d2302010-12-09 22:52:49 +0000664 }
Jim Ingham5a988412012-06-08 21:56:10 +0000665
Jim Inghamebc09c32010-07-07 03:36:20 +0000666 bool
Jim Ingham5a988412012-06-08 21:56:10 +0000667 HandleAliasingNormalCommand (Args& args, CommandReturnObject &result)
Jim Inghamebc09c32010-07-07 03:36:20 +0000668 {
Caroline Tice867b185d2010-09-21 23:25:40 +0000669 size_t argc = args.GetArgumentCount();
Jim Inghamebc09c32010-07-07 03:36:20 +0000670
671 if (argc < 2)
Greg Claytonc982c762010-07-09 20:39:50 +0000672 {
Jim Inghamebc09c32010-07-07 03:36:20 +0000673 result.AppendError ("'alias' requires at least two arguments");
674 result.SetStatus (eReturnStatusFailed);
675 return false;
Greg Claytonc982c762010-07-09 20:39:50 +0000676 }
Jim Inghamebc09c32010-07-07 03:36:20 +0000677
678 const std::string alias_command = args.GetArgumentAtIndex(0);
679 const std::string actual_command = args.GetArgumentAtIndex(1);
680
681 args.Shift(); // Shift the alias command word off the argument vector.
682 args.Shift(); // Shift the old command word off the argument vector.
683
684 // Verify that the command is alias'able, and get the appropriate command object.
685
Greg Claytona7015092010-09-18 01:14:36 +0000686 if (m_interpreter.CommandExists (alias_command.c_str()))
Jim Inghamebc09c32010-07-07 03:36:20 +0000687 {
688 result.AppendErrorWithFormat ("'%s' is a permanent debugger command and cannot be redefined.\n",
689 alias_command.c_str());
690 result.SetStatus (eReturnStatusFailed);
691 }
692 else
693 {
Greg Claytona7015092010-09-18 01:14:36 +0000694 CommandObjectSP command_obj_sp(m_interpreter.GetCommandSPExact (actual_command.c_str(), true));
Jim Inghamebc09c32010-07-07 03:36:20 +0000695 CommandObjectSP subcommand_obj_sp;
696 bool use_subcommand = false;
697 if (command_obj_sp.get())
698 {
699 CommandObject *cmd_obj = command_obj_sp.get();
Greg Claytonc982c762010-07-09 20:39:50 +0000700 CommandObject *sub_cmd_obj = NULL;
Jim Inghamebc09c32010-07-07 03:36:20 +0000701 OptionArgVectorSP option_arg_vector_sp = OptionArgVectorSP (new OptionArgVector);
702 OptionArgVector *option_arg_vector = option_arg_vector_sp.get();
703
Caroline Tice844d2302010-12-09 22:52:49 +0000704 while (cmd_obj->IsMultiwordObject() && args.GetArgumentCount() > 0)
Jim Inghamebc09c32010-07-07 03:36:20 +0000705 {
706 if (argc >= 3)
707 {
708 const std::string sub_command = args.GetArgumentAtIndex(0);
709 assert (sub_command.length() != 0);
Greg Clayton998255b2012-10-13 02:07:45 +0000710 subcommand_obj_sp = cmd_obj->GetSubcommandSP (sub_command.c_str());
Jim Inghamebc09c32010-07-07 03:36:20 +0000711 if (subcommand_obj_sp.get())
712 {
713 sub_cmd_obj = subcommand_obj_sp.get();
714 use_subcommand = true;
715 args.Shift(); // Shift the sub_command word off the argument vector.
Caroline Tice844d2302010-12-09 22:52:49 +0000716 cmd_obj = sub_cmd_obj;
Jim Inghamebc09c32010-07-07 03:36:20 +0000717 }
718 else
719 {
Caroline Ticef415eeb2010-11-02 19:00:04 +0000720 result.AppendErrorWithFormat("'%s' is not a valid sub-command of '%s'. "
721 "Unable to create alias.\n",
722 sub_command.c_str(), actual_command.c_str());
Jim Inghamebc09c32010-07-07 03:36:20 +0000723 result.SetStatus (eReturnStatusFailed);
724 return false;
725 }
726 }
727 }
728
729 // Verify & handle any options/arguments passed to the alias command
730
731 if (args.GetArgumentCount () > 0)
732 {
Caroline Ticeca90c472011-05-06 21:37:15 +0000733 CommandObjectSP tmp_sp = m_interpreter.GetCommandSPExact (cmd_obj->GetCommandName(), false);
734 if (use_subcommand)
735 tmp_sp = m_interpreter.GetCommandSPExact (sub_cmd_obj->GetCommandName(), false);
736
737 std::string args_string;
738 args.GetCommandString (args_string);
739
740 if (!m_interpreter.ProcessAliasOptionsArgs (tmp_sp, args_string.c_str(), option_arg_vector_sp))
741 {
742 result.AppendError ("Unable to create requested alias.\n");
743 result.SetStatus (eReturnStatusFailed);
744 return false;
745 }
Jim Inghamebc09c32010-07-07 03:36:20 +0000746 }
747
748 // Create the alias.
749
Greg Claytona7015092010-09-18 01:14:36 +0000750 if (m_interpreter.AliasExists (alias_command.c_str())
751 || m_interpreter.UserCommandExists (alias_command.c_str()))
Jim Inghamebc09c32010-07-07 03:36:20 +0000752 {
Greg Claytona7015092010-09-18 01:14:36 +0000753 OptionArgVectorSP tmp_option_arg_sp (m_interpreter.GetAliasOptions (alias_command.c_str()));
Jim Inghamebc09c32010-07-07 03:36:20 +0000754 if (tmp_option_arg_sp.get())
755 {
756 if (option_arg_vector->size() == 0)
Greg Claytona7015092010-09-18 01:14:36 +0000757 m_interpreter.RemoveAliasOptions (alias_command.c_str());
Jim Inghamebc09c32010-07-07 03:36:20 +0000758 }
759 result.AppendWarningWithFormat ("Overwriting existing definition for '%s'.\n",
760 alias_command.c_str());
761 }
762
763 if (use_subcommand)
Greg Claytona7015092010-09-18 01:14:36 +0000764 m_interpreter.AddAlias (alias_command.c_str(), subcommand_obj_sp);
Jim Inghamebc09c32010-07-07 03:36:20 +0000765 else
Greg Claytona7015092010-09-18 01:14:36 +0000766 m_interpreter.AddAlias (alias_command.c_str(), command_obj_sp);
Jim Inghamebc09c32010-07-07 03:36:20 +0000767 if (option_arg_vector->size() > 0)
Greg Claytona7015092010-09-18 01:14:36 +0000768 m_interpreter.AddOrReplaceAliasOptions (alias_command.c_str(), option_arg_vector_sp);
Jim Inghamebc09c32010-07-07 03:36:20 +0000769 result.SetStatus (eReturnStatusSuccessFinishNoResult);
770 }
771 else
772 {
773 result.AppendErrorWithFormat ("'%s' is not an existing command.\n", actual_command.c_str());
774 result.SetStatus (eReturnStatusFailed);
Caroline Ticee7941792010-10-28 23:17:48 +0000775 return false;
Jim Inghamebc09c32010-07-07 03:36:20 +0000776 }
777 }
778
779 return result.Succeeded();
780 }
Jim Ingham5a988412012-06-08 21:56:10 +0000781
Jim Inghamebc09c32010-07-07 03:36:20 +0000782};
783
784#pragma mark CommandObjectCommandsUnalias
785//-------------------------------------------------------------------------
786// CommandObjectCommandsUnalias
787//-------------------------------------------------------------------------
788
Jim Ingham5a988412012-06-08 21:56:10 +0000789class CommandObjectCommandsUnalias : public CommandObjectParsed
Jim Inghamebc09c32010-07-07 03:36:20 +0000790{
791public:
Greg Claytona7015092010-09-18 01:14:36 +0000792 CommandObjectCommandsUnalias (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000793 CommandObjectParsed (interpreter,
Greg Clayton0e5e5a72011-04-20 22:55:21 +0000794 "command unalias",
Caroline Tice86ddae52010-09-12 04:56:10 +0000795 "Allow the user to remove/delete a user-defined command abbreviation.",
Caroline Tice405fe672010-10-04 22:28:36 +0000796 NULL)
Jim Inghamebc09c32010-07-07 03:36:20 +0000797 {
Caroline Tice405fe672010-10-04 22:28:36 +0000798 CommandArgumentEntry arg;
799 CommandArgumentData alias_arg;
800
801 // Define the first (and only) variant of this arg.
802 alias_arg.arg_type = eArgTypeAliasName;
803 alias_arg.arg_repetition = eArgRepeatPlain;
804
805 // There is only one variant this argument could be; put it into the argument entry.
806 arg.push_back (alias_arg);
807
808 // Push the data for the first argument into the m_arguments vector.
809 m_arguments.push_back (arg);
Jim Inghamebc09c32010-07-07 03:36:20 +0000810 }
811
812 ~CommandObjectCommandsUnalias()
813 {
814 }
815
Jim Ingham5a988412012-06-08 21:56:10 +0000816protected:
Jim Inghamebc09c32010-07-07 03:36:20 +0000817 bool
Jim Ingham5a988412012-06-08 21:56:10 +0000818 DoExecute (Args& args, CommandReturnObject &result)
Jim Inghamebc09c32010-07-07 03:36:20 +0000819 {
820 CommandObject::CommandMap::iterator pos;
821 CommandObject *cmd_obj;
822
823 if (args.GetArgumentCount() != 0)
824 {
825 const char *command_name = args.GetArgumentAtIndex(0);
Greg Claytona7015092010-09-18 01:14:36 +0000826 cmd_obj = m_interpreter.GetCommandObject(command_name);
Jim Inghamebc09c32010-07-07 03:36:20 +0000827 if (cmd_obj)
828 {
Greg Claytona7015092010-09-18 01:14:36 +0000829 if (m_interpreter.CommandExists (command_name))
Jim Inghamebc09c32010-07-07 03:36:20 +0000830 {
831 result.AppendErrorWithFormat ("'%s' is a permanent debugger command and cannot be removed.\n",
832 command_name);
833 result.SetStatus (eReturnStatusFailed);
834 }
835 else
836 {
837
Greg Claytona7015092010-09-18 01:14:36 +0000838 if (m_interpreter.RemoveAlias (command_name) == false)
Jim Inghamebc09c32010-07-07 03:36:20 +0000839 {
Greg Claytona7015092010-09-18 01:14:36 +0000840 if (m_interpreter.AliasExists (command_name))
Jim Inghamebc09c32010-07-07 03:36:20 +0000841 result.AppendErrorWithFormat ("Error occurred while attempting to unalias '%s'.\n",
842 command_name);
843 else
844 result.AppendErrorWithFormat ("'%s' is not an existing alias.\n", command_name);
845 result.SetStatus (eReturnStatusFailed);
846 }
847 else
848 result.SetStatus (eReturnStatusSuccessFinishNoResult);
849 }
850 }
851 else
852 {
853 result.AppendErrorWithFormat ("'%s' is not a known command.\nTry 'help' to see a "
854 "current list of commands.\n",
855 command_name);
856 result.SetStatus (eReturnStatusFailed);
857 }
858 }
859 else
860 {
861 result.AppendError ("must call 'unalias' with a valid alias");
862 result.SetStatus (eReturnStatusFailed);
863 }
864
865 return result.Succeeded();
866 }
867};
868
Greg Claytonde164aa2011-04-20 16:37:46 +0000869//-------------------------------------------------------------------------
870// CommandObjectCommandsAddRegex
871//-------------------------------------------------------------------------
Jim Ingham5a988412012-06-08 21:56:10 +0000872#pragma mark CommandObjectCommandsAddRegex
Greg Claytonde164aa2011-04-20 16:37:46 +0000873
Greg Clayton44d93782014-01-27 23:43:24 +0000874class CommandObjectCommandsAddRegex :
875 public CommandObjectParsed,
Greg Claytonea508632014-11-18 00:43:17 +0000876 public IOHandlerDelegateMultiline
Greg Claytonde164aa2011-04-20 16:37:46 +0000877{
878public:
879 CommandObjectCommandsAddRegex (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +0000880 CommandObjectParsed (interpreter,
Greg Clayton0e5e5a72011-04-20 22:55:21 +0000881 "command regex",
Greg Claytonde164aa2011-04-20 16:37:46 +0000882 "Allow the user to create a regular expression command.",
Greg Clayton0e5e5a72011-04-20 22:55:21 +0000883 "command regex <cmd-name> [s/<regex>/<subst>/ ...]"),
Greg Claytonea508632014-11-18 00:43:17 +0000884 IOHandlerDelegateMultiline ("", IOHandlerDelegate::Completion::LLDBCommand),
Greg Claytonde164aa2011-04-20 16:37:46 +0000885 m_options (interpreter)
886 {
Greg Clayton0e5e5a72011-04-20 22:55:21 +0000887 SetHelpLong(
888"This command allows the user to create powerful regular expression commands\n"
889"with substitutions. The regular expressions and substitutions are specified\n"
Bruce Mitchenerd93c4a32014-07-01 21:22:11 +0000890"using the regular expression substitution format of:\n"
Greg Clayton0e5e5a72011-04-20 22:55:21 +0000891"\n"
892" s/<regex>/<subst>/\n"
893"\n"
894"<regex> is a regular expression that can use parenthesis to capture regular\n"
895"expression input and substitute the captured matches in the output using %1\n"
896"for the first match, %2 for the second, and so on.\n"
897"\n"
898"The regular expressions can all be specified on the command line if more than\n"
899"one argument is provided. If just the command name is provided on the command\n"
900"line, then the regular expressions and substitutions can be entered on separate\n"
901" lines, followed by an empty line to terminate the command definition.\n"
902"\n"
903"EXAMPLES\n"
904"\n"
Sean Callananadc43c92012-08-16 21:46:58 +0000905"The following example will define a regular expression command named 'f' that\n"
Greg Clayton0e5e5a72011-04-20 22:55:21 +0000906"will call 'finish' if there are no arguments, or 'frame select <frame-idx>' if\n"
907"a number follows 'f':\n"
Sean Callananadc43c92012-08-16 21:46:58 +0000908"\n"
909" (lldb) command regex f s/^$/finish/ 's/([0-9]+)/frame select %1/'\n"
910"\n"
Greg Clayton0e5e5a72011-04-20 22:55:21 +0000911 );
Greg Claytonde164aa2011-04-20 16:37:46 +0000912 }
913
914 ~CommandObjectCommandsAddRegex()
915 {
916 }
917
918
Jim Ingham5a988412012-06-08 21:56:10 +0000919protected:
Greg Clayton44d93782014-01-27 23:43:24 +0000920
Greg Claytonea508632014-11-18 00:43:17 +0000921 void
922 IOHandlerActivated (IOHandler &io_handler) override
Greg Clayton44d93782014-01-27 23:43:24 +0000923 {
924 StreamFileSP output_sp(io_handler.GetOutputStreamFile());
925 if (output_sp)
926 {
927 output_sp->PutCString("Enter one of more sed substitution commands in the form: 's/<regex>/<subst>/'.\nTerminate the substitution list with an empty line.\n");
928 output_sp->Flush();
929 }
930 }
931
Greg Claytonea508632014-11-18 00:43:17 +0000932 void
933 IOHandlerInputComplete (IOHandler &io_handler, std::string &data) override
Greg Clayton44d93782014-01-27 23:43:24 +0000934 {
935 io_handler.SetIsDone(true);
936 if (m_regex_cmd_ap.get())
937 {
938 StringList lines;
939 if (lines.SplitIntoLines (data))
940 {
941 const size_t num_lines = lines.GetSize();
942 bool check_only = false;
943 for (size_t i=0; i<num_lines; ++i)
944 {
Greg Clayton44d93782014-01-27 23:43:24 +0000945 llvm::StringRef bytes_strref (lines[i]);
946 Error error = AppendRegexSubstitution (bytes_strref, check_only);
947 if (error.Fail())
948 {
949 if (!m_interpreter.GetDebugger().GetCommandInterpreter().GetBatchCommandMode())
950 {
951 StreamSP out_stream = m_interpreter.GetDebugger().GetAsyncOutputStream();
952 out_stream->Printf("error: %s\n", error.AsCString());
953 }
954 }
955 }
956 }
957 if (m_regex_cmd_ap->HasRegexEntries())
958 {
959 CommandObjectSP cmd_sp (m_regex_cmd_ap.release());
960 m_interpreter.AddCommand(cmd_sp->GetCommandName(), cmd_sp, true);
961 }
962 }
963 }
Greg Clayton44d93782014-01-27 23:43:24 +0000964
Greg Claytonde164aa2011-04-20 16:37:46 +0000965 bool
Jim Ingham5a988412012-06-08 21:56:10 +0000966 DoExecute (Args& command, CommandReturnObject &result)
Greg Claytonde164aa2011-04-20 16:37:46 +0000967 {
Jim Ingham5a988412012-06-08 21:56:10 +0000968 const size_t argc = command.GetArgumentCount();
Greg Clayton0e5e5a72011-04-20 22:55:21 +0000969 if (argc == 0)
Greg Claytonde164aa2011-04-20 16:37:46 +0000970 {
Jason Molenda69c12cc2011-11-10 22:43:35 +0000971 result.AppendError ("usage: 'command regex <command-name> [s/<regex1>/<subst1>/ s/<regex2>/<subst2>/ ...]'\n");
Greg Clayton0e5e5a72011-04-20 22:55:21 +0000972 result.SetStatus (eReturnStatusFailed);
973 }
974 else
975 {
976 Error error;
Jim Ingham5a988412012-06-08 21:56:10 +0000977 const char *name = command.GetArgumentAtIndex(0);
Greg Claytonde164aa2011-04-20 16:37:46 +0000978 m_regex_cmd_ap.reset (new CommandObjectRegexCommand (m_interpreter,
979 name,
980 m_options.GetHelp (),
981 m_options.GetSyntax (),
982 10));
Greg Clayton0e5e5a72011-04-20 22:55:21 +0000983
984 if (argc == 1)
Greg Claytonde164aa2011-04-20 16:37:46 +0000985 {
Greg Clayton44d93782014-01-27 23:43:24 +0000986 Debugger &debugger = m_interpreter.GetDebugger();
Kate Stonee30f11d2014-11-17 19:06:59 +0000987 bool color_prompt = debugger.GetUseColor();
Greg Clayton44d93782014-01-27 23:43:24 +0000988 const bool multiple_lines = true; // Get multiple lines
989 IOHandlerSP io_handler_sp (new IOHandlerEditline (debugger,
Kate Stonee30f11d2014-11-17 19:06:59 +0000990 IOHandler::Type::Other,
Greg Clayton73d80fa2014-07-09 20:18:54 +0000991 "lldb-regex", // Name of input reader for history
Greg Claytonea508632014-11-18 00:43:17 +0000992 "> ", // Prompt
Kate Stonee30f11d2014-11-17 19:06:59 +0000993 NULL, // Continuation prompt
Greg Clayton44d93782014-01-27 23:43:24 +0000994 multiple_lines,
Kate Stonee30f11d2014-11-17 19:06:59 +0000995 color_prompt,
Greg Claytonf6913cd2014-03-07 00:53:24 +0000996 0, // Don't show line numbers
Greg Clayton44d93782014-01-27 23:43:24 +0000997 *this));
998
999 if (io_handler_sp)
Greg Clayton0e5e5a72011-04-20 22:55:21 +00001000 {
Greg Clayton44d93782014-01-27 23:43:24 +00001001 debugger.PushIOHandler(io_handler_sp);
1002 result.SetStatus (eReturnStatusSuccessFinishNoResult);
Greg Claytonde164aa2011-04-20 16:37:46 +00001003 }
1004 }
Greg Clayton0e5e5a72011-04-20 22:55:21 +00001005 else
1006 {
1007 for (size_t arg_idx = 1; arg_idx < argc; ++arg_idx)
1008 {
Jim Ingham5a988412012-06-08 21:56:10 +00001009 llvm::StringRef arg_strref (command.GetArgumentAtIndex(arg_idx));
Greg Clayton44d93782014-01-27 23:43:24 +00001010 bool check_only = false;
1011 error = AppendRegexSubstitution (arg_strref, check_only);
Greg Clayton0e5e5a72011-04-20 22:55:21 +00001012 if (error.Fail())
1013 break;
1014 }
1015
1016 if (error.Success())
1017 {
1018 AddRegexCommandToInterpreter();
1019 }
1020 }
1021 if (error.Fail())
1022 {
1023 result.AppendError (error.AsCString());
1024 result.SetStatus (eReturnStatusFailed);
1025 }
Greg Claytonde164aa2011-04-20 16:37:46 +00001026 }
Greg Clayton0e5e5a72011-04-20 22:55:21 +00001027
Greg Claytonde164aa2011-04-20 16:37:46 +00001028 return result.Succeeded();
1029 }
1030
Greg Clayton0e5e5a72011-04-20 22:55:21 +00001031 Error
Greg Clayton44d93782014-01-27 23:43:24 +00001032 AppendRegexSubstitution (const llvm::StringRef &regex_sed, bool check_only)
Greg Claytonde164aa2011-04-20 16:37:46 +00001033 {
Greg Clayton0e5e5a72011-04-20 22:55:21 +00001034 Error error;
1035
1036 if (m_regex_cmd_ap.get() == NULL)
Greg Claytonde164aa2011-04-20 16:37:46 +00001037 {
Greg Clayton0e5e5a72011-04-20 22:55:21 +00001038 error.SetErrorStringWithFormat("invalid regular expression command object for: '%.*s'",
1039 (int)regex_sed.size(),
1040 regex_sed.data());
1041 return error;
Greg Claytonde164aa2011-04-20 16:37:46 +00001042 }
Greg Clayton0e5e5a72011-04-20 22:55:21 +00001043
1044 size_t regex_sed_size = regex_sed.size();
1045
1046 if (regex_sed_size <= 1)
1047 {
1048 error.SetErrorStringWithFormat("regular expression substitution string is too short: '%.*s'",
1049 (int)regex_sed.size(),
1050 regex_sed.data());
1051 return error;
1052 }
1053
1054 if (regex_sed[0] != 's')
1055 {
1056 error.SetErrorStringWithFormat("regular expression substitution string doesn't start with 's': '%.*s'",
1057 (int)regex_sed.size(),
1058 regex_sed.data());
1059 return error;
1060 }
1061 const size_t first_separator_char_pos = 1;
1062 // use the char that follows 's' as the regex separator character
1063 // so we can have "s/<regex>/<subst>/" or "s|<regex>|<subst>|"
1064 const char separator_char = regex_sed[first_separator_char_pos];
1065 const size_t second_separator_char_pos = regex_sed.find (separator_char, first_separator_char_pos + 1);
1066
1067 if (second_separator_char_pos == std::string::npos)
1068 {
Greg Claytonea508632014-11-18 00:43:17 +00001069 error.SetErrorStringWithFormat("missing second '%c' separator char after '%.*s' in '%.*s'",
Greg Clayton0e5e5a72011-04-20 22:55:21 +00001070 separator_char,
1071 (int)(regex_sed.size() - first_separator_char_pos - 1),
Greg Claytonea508632014-11-18 00:43:17 +00001072 regex_sed.data() + (first_separator_char_pos + 1),
1073 (int)regex_sed.size(),
1074 regex_sed.data());
1075 return error;
Greg Clayton0e5e5a72011-04-20 22:55:21 +00001076 }
1077
1078 const size_t third_separator_char_pos = regex_sed.find (separator_char, second_separator_char_pos + 1);
1079
1080 if (third_separator_char_pos == std::string::npos)
1081 {
Greg Claytonea508632014-11-18 00:43:17 +00001082 error.SetErrorStringWithFormat("missing third '%c' separator char after '%.*s' in '%.*s'",
Greg Clayton0e5e5a72011-04-20 22:55:21 +00001083 separator_char,
1084 (int)(regex_sed.size() - second_separator_char_pos - 1),
Greg Claytonea508632014-11-18 00:43:17 +00001085 regex_sed.data() + (second_separator_char_pos + 1),
1086 (int)regex_sed.size(),
1087 regex_sed.data());
Greg Clayton0e5e5a72011-04-20 22:55:21 +00001088 return error;
1089 }
1090
1091 if (third_separator_char_pos != regex_sed_size - 1)
1092 {
1093 // Make sure that everything that follows the last regex
1094 // separator char
1095 if (regex_sed.find_first_not_of("\t\n\v\f\r ", third_separator_char_pos + 1) != std::string::npos)
1096 {
1097 error.SetErrorStringWithFormat("extra data found after the '%.*s' regular expression substitution string: '%.*s'",
1098 (int)third_separator_char_pos + 1,
1099 regex_sed.data(),
1100 (int)(regex_sed.size() - third_separator_char_pos - 1),
1101 regex_sed.data() + (third_separator_char_pos + 1));
1102 return error;
1103 }
1104
1105 }
1106 else if (first_separator_char_pos + 1 == second_separator_char_pos)
1107 {
1108 error.SetErrorStringWithFormat("<regex> can't be empty in 's%c<regex>%c<subst>%c' string: '%.*s'",
1109 separator_char,
1110 separator_char,
1111 separator_char,
1112 (int)regex_sed.size(),
1113 regex_sed.data());
1114 return error;
1115 }
1116 else if (second_separator_char_pos + 1 == third_separator_char_pos)
1117 {
1118 error.SetErrorStringWithFormat("<subst> can't be empty in 's%c<regex>%c<subst>%c' string: '%.*s'",
1119 separator_char,
1120 separator_char,
1121 separator_char,
1122 (int)regex_sed.size(),
1123 regex_sed.data());
1124 return error;
1125 }
Greg Clayton44d93782014-01-27 23:43:24 +00001126
1127 if (check_only == false)
1128 {
1129 std::string regex(regex_sed.substr(first_separator_char_pos + 1, second_separator_char_pos - first_separator_char_pos - 1));
1130 std::string subst(regex_sed.substr(second_separator_char_pos + 1, third_separator_char_pos - second_separator_char_pos - 1));
1131 m_regex_cmd_ap->AddRegexCommand (regex.c_str(),
1132 subst.c_str());
1133 }
Greg Clayton0e5e5a72011-04-20 22:55:21 +00001134 return error;
Greg Claytonde164aa2011-04-20 16:37:46 +00001135 }
1136
1137 void
Greg Clayton0e5e5a72011-04-20 22:55:21 +00001138 AddRegexCommandToInterpreter()
Greg Claytonde164aa2011-04-20 16:37:46 +00001139 {
1140 if (m_regex_cmd_ap.get())
1141 {
1142 if (m_regex_cmd_ap->HasRegexEntries())
1143 {
1144 CommandObjectSP cmd_sp (m_regex_cmd_ap.release());
1145 m_interpreter.AddCommand(cmd_sp->GetCommandName(), cmd_sp, true);
1146 }
1147 }
1148 }
1149
Greg Claytonde164aa2011-04-20 16:37:46 +00001150private:
Greg Clayton7b0992d2013-04-18 22:45:39 +00001151 std::unique_ptr<CommandObjectRegexCommand> m_regex_cmd_ap;
Greg Claytonde164aa2011-04-20 16:37:46 +00001152
1153 class CommandOptions : public Options
1154 {
1155 public:
1156
1157 CommandOptions (CommandInterpreter &interpreter) :
1158 Options (interpreter)
1159 {
1160 }
1161
1162 virtual
1163 ~CommandOptions (){}
1164
1165 virtual Error
1166 SetOptionValue (uint32_t option_idx, const char *option_arg)
1167 {
1168 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +00001169 const int short_option = m_getopt_table[option_idx].val;
Greg Claytonde164aa2011-04-20 16:37:46 +00001170
1171 switch (short_option)
1172 {
1173 case 'h':
1174 m_help.assign (option_arg);
1175 break;
1176 case 's':
1177 m_syntax.assign (option_arg);
1178 break;
1179
1180 default:
Greg Clayton86edbf42011-10-26 00:56:27 +00001181 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
Greg Claytonde164aa2011-04-20 16:37:46 +00001182 break;
1183 }
1184
1185 return error;
1186 }
1187
1188 void
1189 OptionParsingStarting ()
1190 {
1191 m_help.clear();
1192 m_syntax.clear();
1193 }
1194
1195 const OptionDefinition*
1196 GetDefinitions ()
1197 {
1198 return g_option_table;
1199 }
1200
1201 // Options table: Required for subclasses of Options.
1202
1203 static OptionDefinition g_option_table[];
1204
1205 const char *
1206 GetHelp ()
1207 {
1208 if (m_help.empty())
1209 return NULL;
1210 return m_help.c_str();
1211 }
1212 const char *
1213 GetSyntax ()
1214 {
1215 if (m_syntax.empty())
1216 return NULL;
1217 return m_syntax.c_str();
1218 }
1219 // Instance variables to hold the values for command options.
1220 protected:
1221 std::string m_help;
1222 std::string m_syntax;
1223 };
Jim Ingham5a988412012-06-08 21:56:10 +00001224
Greg Claytonde164aa2011-04-20 16:37:46 +00001225 virtual Options *
1226 GetOptions ()
1227 {
1228 return &m_options;
1229 }
Jim Ingham5a988412012-06-08 21:56:10 +00001230
1231 CommandOptions m_options;
Greg Claytonde164aa2011-04-20 16:37:46 +00001232};
1233
Greg Claytonde164aa2011-04-20 16:37:46 +00001234OptionDefinition
1235CommandObjectCommandsAddRegex::CommandOptions::g_option_table[] =
1236{
Zachary Turnerd37221d2014-07-09 16:31:49 +00001237{ LLDB_OPT_SET_1, false, "help" , 'h', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeNone, "The help text to display for this command."},
1238{ LLDB_OPT_SET_1, false, "syntax", 's', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeNone, "A syntax string showing the typical usage syntax."},
1239{ 0 , false, NULL , 0 , 0 , NULL, NULL, 0, eArgTypeNone, NULL }
Greg Claytonde164aa2011-04-20 16:37:46 +00001240};
1241
1242
Jim Ingham5a988412012-06-08 21:56:10 +00001243class CommandObjectPythonFunction : public CommandObjectRaw
Enrico Granata223383e2011-08-16 23:24:13 +00001244{
1245private:
1246 std::string m_function_name;
Enrico Granata0a305db2011-11-07 22:57:04 +00001247 ScriptedCommandSynchronicity m_synchro;
Enrico Granatafac939e2012-09-18 21:53:02 +00001248 bool m_fetched_help_long;
Enrico Granata223383e2011-08-16 23:24:13 +00001249
1250public:
1251
1252 CommandObjectPythonFunction (CommandInterpreter &interpreter,
1253 std::string name,
Enrico Granata0a305db2011-11-07 22:57:04 +00001254 std::string funct,
Enrico Granata735152e2014-09-15 17:52:44 +00001255 std::string help,
Enrico Granata0a305db2011-11-07 22:57:04 +00001256 ScriptedCommandSynchronicity synch) :
Jim Ingham5a988412012-06-08 21:56:10 +00001257 CommandObjectRaw (interpreter,
1258 name.c_str(),
Enrico Granata735152e2014-09-15 17:52:44 +00001259 NULL,
Jim Ingham5a988412012-06-08 21:56:10 +00001260 NULL),
1261 m_function_name(funct),
Enrico Granatafac939e2012-09-18 21:53:02 +00001262 m_synchro(synch),
1263 m_fetched_help_long(false)
Enrico Granata223383e2011-08-16 23:24:13 +00001264 {
Enrico Granata735152e2014-09-15 17:52:44 +00001265 if (!help.empty())
1266 SetHelp(help.c_str());
1267 else
1268 {
1269 StreamString stream;
1270 stream.Printf("For more information run 'help %s'",name.c_str());
1271 SetHelp(stream.GetData());
1272 }
Enrico Granata223383e2011-08-16 23:24:13 +00001273 }
1274
1275 virtual
1276 ~CommandObjectPythonFunction ()
1277 {
1278 }
1279
1280 virtual bool
Greg Clayton3a18e312012-10-08 22:41:53 +00001281 IsRemovable () const
Jim Ingham5a988412012-06-08 21:56:10 +00001282 {
1283 return true;
1284 }
1285
1286 const std::string&
1287 GetFunctionName ()
1288 {
1289 return m_function_name;
1290 }
1291
1292 ScriptedCommandSynchronicity
1293 GetSynchronicity ()
1294 {
1295 return m_synchro;
1296 }
1297
Enrico Granatafac939e2012-09-18 21:53:02 +00001298 virtual const char *
1299 GetHelpLong ()
1300 {
1301 if (!m_fetched_help_long)
1302 {
1303 ScriptInterpreter* scripter = m_interpreter.GetScriptInterpreter();
1304 if (scripter)
1305 {
1306 std::string docstring;
1307 m_fetched_help_long = scripter->GetDocumentationForItem(m_function_name.c_str(),docstring);
1308 if (!docstring.empty())
1309 SetHelpLong(docstring);
1310 }
1311 }
1312 return CommandObjectRaw::GetHelpLong();
1313 }
1314
Jim Ingham5a988412012-06-08 21:56:10 +00001315protected:
1316 virtual bool
1317 DoExecute (const char *raw_command_line, CommandReturnObject &result)
Enrico Granata223383e2011-08-16 23:24:13 +00001318 {
1319 ScriptInterpreter* scripter = m_interpreter.GetScriptInterpreter();
1320
1321 Error error;
1322
Jim Ingham70f11f82012-06-27 17:25:36 +00001323 result.SetStatus(eReturnStatusInvalid);
1324
Enrico Granata223383e2011-08-16 23:24:13 +00001325 if (!scripter || scripter->RunScriptBasedCommand(m_function_name.c_str(),
1326 raw_command_line,
Enrico Granata0a305db2011-11-07 22:57:04 +00001327 m_synchro,
Enrico Granata223383e2011-08-16 23:24:13 +00001328 result,
Enrico Granata06be0592014-10-01 21:47:29 +00001329 error,
1330 m_exe_ctx) == false)
Enrico Granata223383e2011-08-16 23:24:13 +00001331 {
1332 result.AppendError(error.AsCString());
1333 result.SetStatus(eReturnStatusFailed);
1334 }
1335 else
Jim Ingham70f11f82012-06-27 17:25:36 +00001336 {
1337 // Don't change the status if the command already set it...
1338 if (result.GetStatus() == eReturnStatusInvalid)
1339 {
Daniel Malea9a71a7d2013-07-03 17:58:31 +00001340 if (result.GetOutputData() == NULL || result.GetOutputData()[0] == '\0')
Jim Ingham70f11f82012-06-27 17:25:36 +00001341 result.SetStatus(eReturnStatusSuccessFinishNoResult);
1342 else
1343 result.SetStatus(eReturnStatusSuccessFinishResult);
1344 }
1345 }
Enrico Granata223383e2011-08-16 23:24:13 +00001346
1347 return result.Succeeded();
1348 }
1349
Enrico Granata223383e2011-08-16 23:24:13 +00001350};
1351
Enrico Granataa9dbf432011-10-17 21:45:27 +00001352//-------------------------------------------------------------------------
1353// CommandObjectCommandsScriptImport
1354//-------------------------------------------------------------------------
1355
Jim Ingham5a988412012-06-08 21:56:10 +00001356class CommandObjectCommandsScriptImport : public CommandObjectParsed
Enrico Granataa9dbf432011-10-17 21:45:27 +00001357{
Jim Ingham5a988412012-06-08 21:56:10 +00001358public:
1359 CommandObjectCommandsScriptImport (CommandInterpreter &interpreter) :
1360 CommandObjectParsed (interpreter,
1361 "command script import",
1362 "Import a scripting module in LLDB.",
1363 NULL),
1364 m_options(interpreter)
1365 {
1366 CommandArgumentEntry arg1;
1367 CommandArgumentData cmd_arg;
1368
1369 // Define the first (and only) variant of this arg.
1370 cmd_arg.arg_type = eArgTypeFilename;
1371 cmd_arg.arg_repetition = eArgRepeatPlain;
1372
1373 // There is only one variant this argument could be; put it into the argument entry.
1374 arg1.push_back (cmd_arg);
1375
1376 // Push the data for the first argument into the m_arguments vector.
1377 m_arguments.push_back (arg1);
1378 }
1379
1380 ~CommandObjectCommandsScriptImport ()
1381 {
1382 }
1383
Greg Claytonc7bece562013-01-25 18:06:21 +00001384 virtual int
Jim Ingham5a988412012-06-08 21:56:10 +00001385 HandleArgumentCompletion (Args &input,
1386 int &cursor_index,
1387 int &cursor_char_position,
1388 OptionElementVector &opt_element_vector,
1389 int match_start_point,
1390 int max_return_elements,
1391 bool &word_complete,
1392 StringList &matches)
1393 {
1394 std::string completion_str (input.GetArgumentAtIndex(cursor_index));
1395 completion_str.erase (cursor_char_position);
1396
1397 CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
1398 CommandCompletions::eDiskFileCompletion,
1399 completion_str.c_str(),
1400 match_start_point,
1401 max_return_elements,
1402 NULL,
1403 word_complete,
1404 matches);
1405 return matches.GetSize();
1406 }
1407
1408 virtual Options *
1409 GetOptions ()
1410 {
1411 return &m_options;
1412 }
1413
1414protected:
Enrico Granata0a305db2011-11-07 22:57:04 +00001415
1416 class CommandOptions : public Options
1417 {
1418 public:
1419
1420 CommandOptions (CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00001421 Options (interpreter)
Enrico Granata0a305db2011-11-07 22:57:04 +00001422 {
1423 }
1424
1425 virtual
1426 ~CommandOptions (){}
1427
1428 virtual Error
1429 SetOptionValue (uint32_t option_idx, const char *option_arg)
1430 {
1431 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +00001432 const int short_option = m_getopt_table[option_idx].val;
Enrico Granata0a305db2011-11-07 22:57:04 +00001433
1434 switch (short_option)
1435 {
1436 case 'r':
1437 m_allow_reload = true;
1438 break;
1439 default:
1440 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
1441 break;
1442 }
1443
1444 return error;
1445 }
1446
1447 void
1448 OptionParsingStarting ()
1449 {
Enrico Granatae0c70f12013-05-31 01:03:09 +00001450 m_allow_reload = true;
Enrico Granata0a305db2011-11-07 22:57:04 +00001451 }
1452
1453 const OptionDefinition*
1454 GetDefinitions ()
1455 {
1456 return g_option_table;
1457 }
1458
1459 // Options table: Required for subclasses of Options.
1460
1461 static OptionDefinition g_option_table[];
1462
1463 // Instance variables to hold the values for command options.
1464
1465 bool m_allow_reload;
1466 };
Enrico Granata0a305db2011-11-07 22:57:04 +00001467
Enrico Granataa9dbf432011-10-17 21:45:27 +00001468 bool
Jim Ingham5a988412012-06-08 21:56:10 +00001469 DoExecute (Args& command, CommandReturnObject &result)
Enrico Granataa9dbf432011-10-17 21:45:27 +00001470 {
1471
1472 if (m_interpreter.GetDebugger().GetScriptLanguage() != lldb::eScriptLanguagePython)
1473 {
1474 result.AppendError ("only scripting language supported for module importing is currently Python");
1475 result.SetStatus (eReturnStatusFailed);
1476 return false;
1477 }
1478
Jim Ingham5a988412012-06-08 21:56:10 +00001479 size_t argc = command.GetArgumentCount();
Enrico Granataa9dbf432011-10-17 21:45:27 +00001480
1481 if (argc != 1)
1482 {
1483 result.AppendError ("'command script import' requires one argument");
1484 result.SetStatus (eReturnStatusFailed);
1485 return false;
1486 }
1487
Jim Ingham5a988412012-06-08 21:56:10 +00001488 std::string path = command.GetArgumentAtIndex(0);
Enrico Granataa9dbf432011-10-17 21:45:27 +00001489 Error error;
1490
Greg Claytonc9d645d2012-10-18 22:40:37 +00001491 const bool init_session = true;
Enrico Granata078551c2013-05-09 19:33:49 +00001492 // FIXME: this is necessary because CommandObject::CheckRequirements() assumes that
1493 // commands won't ever be recursively invoked, but it's actually possible to craft
1494 // a Python script that does other "command script imports" in __lldb_init_module
1495 // the real fix is to have recursive commands possible with a CommandInvocation object
1496 // separate from the CommandObject itself, so that recursive command invocations
1497 // won't stomp on each other (wrt to execution contents, options, and more)
1498 m_exe_ctx.Clear();
Enrico Granataa9dbf432011-10-17 21:45:27 +00001499 if (m_interpreter.GetScriptInterpreter()->LoadScriptingModule(path.c_str(),
Enrico Granata0a305db2011-11-07 22:57:04 +00001500 m_options.m_allow_reload,
Greg Claytonc9d645d2012-10-18 22:40:37 +00001501 init_session,
Enrico Granataa9dbf432011-10-17 21:45:27 +00001502 error))
1503 {
1504 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1505 }
1506 else
1507 {
1508 result.AppendErrorWithFormat("module importing failed: %s", error.AsCString());
1509 result.SetStatus (eReturnStatusFailed);
1510 }
1511
1512 return result.Succeeded();
1513 }
Enrico Granata0a305db2011-11-07 22:57:04 +00001514
Jim Ingham5a988412012-06-08 21:56:10 +00001515 CommandOptions m_options;
Enrico Granataa9dbf432011-10-17 21:45:27 +00001516};
Enrico Granata223383e2011-08-16 23:24:13 +00001517
Enrico Granata0a305db2011-11-07 22:57:04 +00001518OptionDefinition
1519CommandObjectCommandsScriptImport::CommandOptions::g_option_table[] =
1520{
Zachary Turnerd37221d2014-07-09 16:31:49 +00001521 { LLDB_OPT_SET_1, false, "allow-reload", 'r', OptionParser::eNoArgument, NULL, NULL, 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."},
1522 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
Enrico Granata0a305db2011-11-07 22:57:04 +00001523};
1524
1525
Enrico Granata223383e2011-08-16 23:24:13 +00001526//-------------------------------------------------------------------------
1527// CommandObjectCommandsScriptAdd
1528//-------------------------------------------------------------------------
1529
Greg Clayton44d93782014-01-27 23:43:24 +00001530class CommandObjectCommandsScriptAdd :
1531 public CommandObjectParsed,
1532 public IOHandlerDelegateMultiline
Enrico Granata223383e2011-08-16 23:24:13 +00001533{
Jim Ingham5a988412012-06-08 21:56:10 +00001534public:
1535 CommandObjectCommandsScriptAdd(CommandInterpreter &interpreter) :
1536 CommandObjectParsed (interpreter,
1537 "command script add",
1538 "Add a scripted function as an LLDB command.",
1539 NULL),
Greg Claytonc3d874a2014-05-08 16:59:00 +00001540 IOHandlerDelegateMultiline ("DONE"),
Jim Ingham5a988412012-06-08 21:56:10 +00001541 m_options (interpreter)
1542 {
1543 CommandArgumentEntry arg1;
1544 CommandArgumentData cmd_arg;
1545
1546 // Define the first (and only) variant of this arg.
1547 cmd_arg.arg_type = eArgTypeCommandName;
1548 cmd_arg.arg_repetition = eArgRepeatPlain;
1549
1550 // There is only one variant this argument could be; put it into the argument entry.
1551 arg1.push_back (cmd_arg);
1552
1553 // Push the data for the first argument into the m_arguments vector.
1554 m_arguments.push_back (arg1);
1555 }
1556
1557 ~CommandObjectCommandsScriptAdd ()
1558 {
1559 }
1560
1561 virtual Options *
1562 GetOptions ()
1563 {
1564 return &m_options;
1565 }
1566
1567protected:
Enrico Granata223383e2011-08-16 23:24:13 +00001568
1569 class CommandOptions : public Options
1570 {
1571 public:
1572
1573 CommandOptions (CommandInterpreter &interpreter) :
Greg Clayton44d93782014-01-27 23:43:24 +00001574 Options (interpreter)
Enrico Granata223383e2011-08-16 23:24:13 +00001575 {
1576 }
1577
1578 virtual
1579 ~CommandOptions (){}
1580
1581 virtual Error
1582 SetOptionValue (uint32_t option_idx, const char *option_arg)
1583 {
1584 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +00001585 const int short_option = m_getopt_table[option_idx].val;
Enrico Granata223383e2011-08-16 23:24:13 +00001586
1587 switch (short_option)
1588 {
1589 case 'f':
Enrico Granata735152e2014-09-15 17:52:44 +00001590 if (option_arg)
1591 m_funct_name.assign(option_arg);
1592 break;
1593 case 'h':
1594 if (option_arg)
1595 m_short_help.assign(option_arg);
Enrico Granata223383e2011-08-16 23:24:13 +00001596 break;
Enrico Granata0a305db2011-11-07 22:57:04 +00001597 case 's':
Greg Clayton44d93782014-01-27 23:43:24 +00001598 m_synchronicity = (ScriptedCommandSynchronicity) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error);
Enrico Granata0a305db2011-11-07 22:57:04 +00001599 if (!error.Success())
1600 error.SetErrorStringWithFormat ("unrecognized value for synchronicity '%s'", option_arg);
1601 break;
Enrico Granata223383e2011-08-16 23:24:13 +00001602 default:
Greg Clayton86edbf42011-10-26 00:56:27 +00001603 error.SetErrorStringWithFormat ("unrecognized option '%c'", short_option);
Enrico Granata223383e2011-08-16 23:24:13 +00001604 break;
1605 }
1606
1607 return error;
1608 }
1609
1610 void
1611 OptionParsingStarting ()
1612 {
Enrico Granata735152e2014-09-15 17:52:44 +00001613 m_funct_name.clear();
1614 m_short_help.clear();
Greg Clayton44d93782014-01-27 23:43:24 +00001615 m_synchronicity = eScriptedCommandSynchronicitySynchronous;
Enrico Granata223383e2011-08-16 23:24:13 +00001616 }
1617
1618 const OptionDefinition*
1619 GetDefinitions ()
1620 {
1621 return g_option_table;
1622 }
1623
1624 // Options table: Required for subclasses of Options.
1625
1626 static OptionDefinition g_option_table[];
1627
1628 // Instance variables to hold the values for command options.
1629
1630 std::string m_funct_name;
Enrico Granata735152e2014-09-15 17:52:44 +00001631 std::string m_short_help;
Greg Clayton44d93782014-01-27 23:43:24 +00001632 ScriptedCommandSynchronicity m_synchronicity;
Enrico Granata223383e2011-08-16 23:24:13 +00001633 };
Jim Ingham5a988412012-06-08 21:56:10 +00001634
Greg Clayton44d93782014-01-27 23:43:24 +00001635 virtual void
1636 IOHandlerActivated (IOHandler &io_handler)
Enrico Granata223383e2011-08-16 23:24:13 +00001637 {
Greg Clayton44d93782014-01-27 23:43:24 +00001638 StreamFileSP output_sp(io_handler.GetOutputStreamFile());
1639 if (output_sp)
Enrico Granata223383e2011-08-16 23:24:13 +00001640 {
Greg Clayton44d93782014-01-27 23:43:24 +00001641 output_sp->PutCString(g_python_command_instructions);
1642 output_sp->Flush();
Enrico Granata223383e2011-08-16 23:24:13 +00001643 }
Greg Clayton44d93782014-01-27 23:43:24 +00001644 }
Enrico Granata223383e2011-08-16 23:24:13 +00001645
Greg Clayton44d93782014-01-27 23:43:24 +00001646
1647 virtual void
1648 IOHandlerInputComplete (IOHandler &io_handler, std::string &data)
1649 {
1650 StreamFileSP error_sp = io_handler.GetErrorStreamFile();
1651
1652 ScriptInterpreter *interpreter = m_interpreter.GetScriptInterpreter();
1653 if (interpreter)
1654 {
1655
1656 StringList lines;
1657 lines.SplitIntoLines(data);
1658 if (lines.GetSize() > 0)
1659 {
1660 std::string funct_name_str;
1661 if (interpreter->GenerateScriptAliasFunction (lines, funct_name_str))
1662 {
1663 if (funct_name_str.empty())
1664 {
1665 error_sp->Printf ("error: unable to obtain a function name, didn't add python command.\n");
1666 error_sp->Flush();
1667 }
1668 else
1669 {
1670 // everything should be fine now, let's add this alias
1671
1672 CommandObjectSP command_obj_sp(new CommandObjectPythonFunction (m_interpreter,
1673 m_cmd_name,
1674 funct_name_str.c_str(),
Enrico Granata735152e2014-09-15 17:52:44 +00001675 m_short_help,
Greg Clayton44d93782014-01-27 23:43:24 +00001676 m_synchronicity));
1677
1678 if (!m_interpreter.AddUserCommand(m_cmd_name, command_obj_sp, true))
1679 {
1680 error_sp->Printf ("error: unable to add selected command, didn't add python command.\n");
1681 error_sp->Flush();
1682 }
1683 }
1684 }
1685 else
1686 {
1687 error_sp->Printf ("error: unable to create function, didn't add python command.\n");
1688 error_sp->Flush();
1689 }
1690 }
1691 else
1692 {
1693 error_sp->Printf ("error: empty function, didn't add python command.\n");
1694 error_sp->Flush();
1695 }
1696 }
1697 else
1698 {
1699 error_sp->Printf ("error: script interpreter missing, didn't add python command.\n");
1700 error_sp->Flush();
1701 }
1702
1703 io_handler.SetIsDone(true);
1704
1705
1706 }
1707
Jim Ingham5a988412012-06-08 21:56:10 +00001708protected:
Enrico Granata223383e2011-08-16 23:24:13 +00001709 bool
Jim Ingham5a988412012-06-08 21:56:10 +00001710 DoExecute (Args& command, CommandReturnObject &result)
Enrico Granata223383e2011-08-16 23:24:13 +00001711 {
Enrico Granata99f0b8f2011-08-17 01:30:04 +00001712
1713 if (m_interpreter.GetDebugger().GetScriptLanguage() != lldb::eScriptLanguagePython)
1714 {
1715 result.AppendError ("only scripting language supported for scripted commands is currently Python");
1716 result.SetStatus (eReturnStatusFailed);
1717 return false;
1718 }
1719
Jim Ingham5a988412012-06-08 21:56:10 +00001720 size_t argc = command.GetArgumentCount();
Enrico Granata223383e2011-08-16 23:24:13 +00001721
1722 if (argc != 1)
1723 {
1724 result.AppendError ("'command script add' requires one argument");
1725 result.SetStatus (eReturnStatusFailed);
1726 return false;
1727 }
1728
Enrico Granata735152e2014-09-15 17:52:44 +00001729 // Store the options in case we get multi-line input
Greg Clayton44d93782014-01-27 23:43:24 +00001730 m_cmd_name = command.GetArgumentAtIndex(0);
Enrico Granata735152e2014-09-15 17:52:44 +00001731 m_short_help.assign(m_options.m_short_help);
Greg Clayton44d93782014-01-27 23:43:24 +00001732 m_synchronicity = m_options.m_synchronicity;
Enrico Granata223383e2011-08-16 23:24:13 +00001733
1734 if (m_options.m_funct_name.empty())
1735 {
Greg Clayton44d93782014-01-27 23:43:24 +00001736 m_interpreter.GetPythonCommandsFromIOHandler (" ", // Prompt
1737 *this, // IOHandlerDelegate
1738 true, // Run IOHandler in async mode
1739 NULL); // Baton for the "io_handler" that will be passed back into our IOHandlerDelegate functions
Enrico Granata223383e2011-08-16 23:24:13 +00001740 }
1741 else
1742 {
Enrico Granata0a305db2011-11-07 22:57:04 +00001743 CommandObjectSP new_cmd(new CommandObjectPythonFunction(m_interpreter,
Greg Clayton44d93782014-01-27 23:43:24 +00001744 m_cmd_name,
Enrico Granata0a305db2011-11-07 22:57:04 +00001745 m_options.m_funct_name,
Enrico Granata735152e2014-09-15 17:52:44 +00001746 m_options.m_short_help,
Greg Clayton44d93782014-01-27 23:43:24 +00001747 m_synchronicity));
1748 if (m_interpreter.AddUserCommand(m_cmd_name, new_cmd, true))
Enrico Granata223383e2011-08-16 23:24:13 +00001749 {
1750 result.SetStatus (eReturnStatusSuccessFinishNoResult);
1751 }
1752 else
1753 {
1754 result.AppendError("cannot add command");
1755 result.SetStatus (eReturnStatusFailed);
1756 }
1757 }
1758
1759 return result.Succeeded();
1760
1761 }
Jim Ingham5a988412012-06-08 21:56:10 +00001762
1763 CommandOptions m_options;
Greg Clayton44d93782014-01-27 23:43:24 +00001764 std::string m_cmd_name;
Enrico Granata735152e2014-09-15 17:52:44 +00001765 std::string m_short_help;
Greg Clayton44d93782014-01-27 23:43:24 +00001766 ScriptedCommandSynchronicity m_synchronicity;
Enrico Granata223383e2011-08-16 23:24:13 +00001767};
1768
Enrico Granata0a305db2011-11-07 22:57:04 +00001769static OptionEnumValueElement g_script_synchro_type[] =
1770{
1771 { eScriptedCommandSynchronicitySynchronous, "synchronous", "Run synchronous"},
1772 { eScriptedCommandSynchronicityAsynchronous, "asynchronous", "Run asynchronous"},
1773 { eScriptedCommandSynchronicityCurrentValue, "current", "Do not alter current setting"},
1774 { 0, NULL, NULL }
1775};
1776
Enrico Granata223383e2011-08-16 23:24:13 +00001777OptionDefinition
1778CommandObjectCommandsScriptAdd::CommandOptions::g_option_table[] =
1779{
Zachary Turnerd37221d2014-07-09 16:31:49 +00001780 { LLDB_OPT_SET_1, false, "function", 'f', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypePythonFunction, "Name of the Python function to bind to this command name."},
Enrico Granata735152e2014-09-15 17:52:44 +00001781 { LLDB_OPT_SET_1, false, "help" , 'h', OptionParser::eRequiredArgument, NULL, NULL, 0, eArgTypeHelpText, "The help text to display for this command."},
Zachary Turnerd37221d2014-07-09 16:31:49 +00001782 { LLDB_OPT_SET_1, false, "synchronicity", 's', OptionParser::eRequiredArgument, NULL, g_script_synchro_type, 0, eArgTypeScriptedCommandSynchronicity, "Set the synchronicity of this command's executions with regard to LLDB event system."},
1783 { 0, false, NULL, 0, 0, NULL, NULL, 0, eArgTypeNone, NULL }
Enrico Granata223383e2011-08-16 23:24:13 +00001784};
1785
1786//-------------------------------------------------------------------------
1787// CommandObjectCommandsScriptList
1788//-------------------------------------------------------------------------
1789
Jim Ingham5a988412012-06-08 21:56:10 +00001790class CommandObjectCommandsScriptList : public CommandObjectParsed
Enrico Granata223383e2011-08-16 23:24:13 +00001791{
1792private:
Enrico Granata0a305db2011-11-07 22:57:04 +00001793
Enrico Granata223383e2011-08-16 23:24:13 +00001794public:
1795 CommandObjectCommandsScriptList(CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00001796 CommandObjectParsed (interpreter,
Enrico Granata223383e2011-08-16 23:24:13 +00001797 "command script list",
1798 "List defined scripted commands.",
1799 NULL)
1800 {
1801 }
1802
1803 ~CommandObjectCommandsScriptList ()
1804 {
1805 }
1806
1807 bool
Jim Ingham5a988412012-06-08 21:56:10 +00001808 DoExecute (Args& command, CommandReturnObject &result)
Enrico Granata223383e2011-08-16 23:24:13 +00001809 {
1810
1811 m_interpreter.GetHelp(result,
1812 CommandInterpreter::eCommandTypesUserDef);
1813
1814 result.SetStatus (eReturnStatusSuccessFinishResult);
1815
1816 return true;
1817
1818
1819 }
1820};
1821
1822//-------------------------------------------------------------------------
1823// CommandObjectCommandsScriptClear
1824//-------------------------------------------------------------------------
1825
Jim Ingham5a988412012-06-08 21:56:10 +00001826class CommandObjectCommandsScriptClear : public CommandObjectParsed
Enrico Granata223383e2011-08-16 23:24:13 +00001827{
1828private:
1829
1830public:
1831 CommandObjectCommandsScriptClear(CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00001832 CommandObjectParsed (interpreter,
1833 "command script clear",
1834 "Delete all scripted commands.",
1835 NULL)
Enrico Granata223383e2011-08-16 23:24:13 +00001836 {
1837 }
1838
1839 ~CommandObjectCommandsScriptClear ()
1840 {
1841 }
1842
Jim Ingham5a988412012-06-08 21:56:10 +00001843protected:
Enrico Granata223383e2011-08-16 23:24:13 +00001844 bool
Jim Ingham5a988412012-06-08 21:56:10 +00001845 DoExecute (Args& command, CommandReturnObject &result)
Enrico Granata223383e2011-08-16 23:24:13 +00001846 {
1847
1848 m_interpreter.RemoveAllUser();
1849
1850 result.SetStatus (eReturnStatusSuccessFinishResult);
1851
1852 return true;
Enrico Granata223383e2011-08-16 23:24:13 +00001853 }
1854};
1855
1856//-------------------------------------------------------------------------
1857// CommandObjectCommandsScriptDelete
1858//-------------------------------------------------------------------------
1859
Jim Ingham5a988412012-06-08 21:56:10 +00001860class CommandObjectCommandsScriptDelete : public CommandObjectParsed
Enrico Granata223383e2011-08-16 23:24:13 +00001861{
Enrico Granata223383e2011-08-16 23:24:13 +00001862public:
1863 CommandObjectCommandsScriptDelete(CommandInterpreter &interpreter) :
Jim Ingham5a988412012-06-08 21:56:10 +00001864 CommandObjectParsed (interpreter,
1865 "command script delete",
1866 "Delete a scripted command.",
1867 NULL)
Enrico Granata223383e2011-08-16 23:24:13 +00001868 {
1869 CommandArgumentEntry arg1;
1870 CommandArgumentData cmd_arg;
1871
1872 // Define the first (and only) variant of this arg.
1873 cmd_arg.arg_type = eArgTypeCommandName;
1874 cmd_arg.arg_repetition = eArgRepeatPlain;
1875
1876 // There is only one variant this argument could be; put it into the argument entry.
1877 arg1.push_back (cmd_arg);
1878
1879 // Push the data for the first argument into the m_arguments vector.
1880 m_arguments.push_back (arg1);
1881 }
1882
1883 ~CommandObjectCommandsScriptDelete ()
1884 {
1885 }
1886
Jim Ingham5a988412012-06-08 21:56:10 +00001887protected:
Enrico Granata223383e2011-08-16 23:24:13 +00001888 bool
Jim Ingham5a988412012-06-08 21:56:10 +00001889 DoExecute (Args& command, CommandReturnObject &result)
Enrico Granata223383e2011-08-16 23:24:13 +00001890 {
1891
Jim Ingham5a988412012-06-08 21:56:10 +00001892 size_t argc = command.GetArgumentCount();
Enrico Granata223383e2011-08-16 23:24:13 +00001893
1894 if (argc != 1)
1895 {
1896 result.AppendError ("'command script delete' requires one argument");
1897 result.SetStatus (eReturnStatusFailed);
1898 return false;
1899 }
1900
Jim Ingham5a988412012-06-08 21:56:10 +00001901 const char* cmd_name = command.GetArgumentAtIndex(0);
Enrico Granata223383e2011-08-16 23:24:13 +00001902
1903 if (cmd_name && *cmd_name && m_interpreter.HasUserCommands() && m_interpreter.UserCommandExists(cmd_name))
1904 {
1905 m_interpreter.RemoveUser(cmd_name);
1906 result.SetStatus (eReturnStatusSuccessFinishResult);
1907 }
1908 else
1909 {
1910 result.AppendErrorWithFormat ("command %s not found", cmd_name);
1911 result.SetStatus (eReturnStatusFailed);
1912 }
1913
1914 return result.Succeeded();
1915
1916 }
1917};
1918
1919#pragma mark CommandObjectMultiwordCommandsScript
1920
1921//-------------------------------------------------------------------------
1922// CommandObjectMultiwordCommandsScript
1923//-------------------------------------------------------------------------
1924
1925class CommandObjectMultiwordCommandsScript : public CommandObjectMultiword
1926{
1927public:
1928 CommandObjectMultiwordCommandsScript (CommandInterpreter &interpreter) :
1929 CommandObjectMultiword (interpreter,
1930 "command script",
1931 "A set of commands for managing or customizing script commands.",
1932 "command script <subcommand> [<subcommand-options>]")
1933 {
1934 LoadSubCommand ("add", CommandObjectSP (new CommandObjectCommandsScriptAdd (interpreter)));
1935 LoadSubCommand ("delete", CommandObjectSP (new CommandObjectCommandsScriptDelete (interpreter)));
1936 LoadSubCommand ("clear", CommandObjectSP (new CommandObjectCommandsScriptClear (interpreter)));
1937 LoadSubCommand ("list", CommandObjectSP (new CommandObjectCommandsScriptList (interpreter)));
Enrico Granataa9dbf432011-10-17 21:45:27 +00001938 LoadSubCommand ("import", CommandObjectSP (new CommandObjectCommandsScriptImport (interpreter)));
Enrico Granata223383e2011-08-16 23:24:13 +00001939 }
1940
1941 ~CommandObjectMultiwordCommandsScript ()
1942 {
1943 }
1944
1945};
1946
1947
Jim Inghamebc09c32010-07-07 03:36:20 +00001948#pragma mark CommandObjectMultiwordCommands
1949
1950//-------------------------------------------------------------------------
1951// CommandObjectMultiwordCommands
1952//-------------------------------------------------------------------------
1953
1954CommandObjectMultiwordCommands::CommandObjectMultiwordCommands (CommandInterpreter &interpreter) :
Greg Claytona7015092010-09-18 01:14:36 +00001955 CommandObjectMultiword (interpreter,
Greg Clayton0e5e5a72011-04-20 22:55:21 +00001956 "command",
Caroline Tice3f4c09c2010-09-07 22:38:08 +00001957 "A set of commands for managing or customizing the debugger commands.",
Greg Clayton0e5e5a72011-04-20 22:55:21 +00001958 "command <subcommand> [<subcommand-options>]")
Jim Inghamebc09c32010-07-07 03:36:20 +00001959{
Greg Claytona7015092010-09-18 01:14:36 +00001960 LoadSubCommand ("source", CommandObjectSP (new CommandObjectCommandsSource (interpreter)));
1961 LoadSubCommand ("alias", CommandObjectSP (new CommandObjectCommandsAlias (interpreter)));
1962 LoadSubCommand ("unalias", CommandObjectSP (new CommandObjectCommandsUnalias (interpreter)));
Greg Claytonde164aa2011-04-20 16:37:46 +00001963 LoadSubCommand ("regex", CommandObjectSP (new CommandObjectCommandsAddRegex (interpreter)));
Jim Inghama5a97eb2011-07-12 03:12:18 +00001964 LoadSubCommand ("history", CommandObjectSP (new CommandObjectCommandsHistory (interpreter)));
Enrico Granata223383e2011-08-16 23:24:13 +00001965 LoadSubCommand ("script", CommandObjectSP (new CommandObjectMultiwordCommandsScript (interpreter)));
Jim Inghamebc09c32010-07-07 03:36:20 +00001966}
1967
1968CommandObjectMultiwordCommands::~CommandObjectMultiwordCommands ()
1969{
1970}
1971