blob: 68756050c6f7ce6f125e648c18ed69833123ce93 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- CommandObject.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 Malead891f9b2012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner24943d22010-06-08 16:52:24 +000012#include "lldb/Interpreter/CommandObject.h"
13
14#include <string>
15#include <map>
16
17#include <getopt.h>
18#include <stdlib.h>
19#include <ctype.h>
20
21#include "lldb/Core/Address.h"
Johnny Chen746323a2012-05-26 00:32:39 +000022#include "lldb/Core/ArchSpec.h"
Jim Ingham84cdc152010-06-15 19:49:27 +000023#include "lldb/Interpreter/Options.h"
Chris Lattner24943d22010-06-08 16:52:24 +000024
25// These are for the Sourcename completers.
26// FIXME: Make a separate file for the completers.
Greg Clayton5f54ac32011-02-08 05:05:52 +000027#include "lldb/Host/FileSpec.h"
Chris Lattner24943d22010-06-08 16:52:24 +000028#include "lldb/Core/FileSpecList.h"
29#include "lldb/Target/Process.h"
30#include "lldb/Target/Target.h"
31
32#include "lldb/Interpreter/CommandInterpreter.h"
33#include "lldb/Interpreter/CommandReturnObject.h"
34#include "lldb/Interpreter/ScriptInterpreter.h"
35#include "lldb/Interpreter/ScriptInterpreterPython.h"
36
37using namespace lldb;
38using namespace lldb_private;
39
40//-------------------------------------------------------------------------
41// CommandObject
42//-------------------------------------------------------------------------
43
Greg Clayton238c0a12010-09-18 01:14:36 +000044CommandObject::CommandObject
45(
46 CommandInterpreter &interpreter,
47 const char *name,
48 const char *help,
49 const char *syntax,
50 uint32_t flags
51) :
52 m_interpreter (interpreter),
Chris Lattner24943d22010-06-08 16:52:24 +000053 m_cmd_name (name),
54 m_cmd_help_short (),
55 m_cmd_help_long (),
56 m_cmd_syntax (),
Jim Inghamd40f8a62010-07-06 22:46:59 +000057 m_is_alias (false),
Caroline Ticefb355112010-10-01 17:46:38 +000058 m_flags (flags),
Greg Claytonf1252502012-02-29 04:21:24 +000059 m_arguments(),
60 m_command_override_callback (NULL),
61 m_command_override_baton (NULL)
Chris Lattner24943d22010-06-08 16:52:24 +000062{
63 if (help && help[0])
64 m_cmd_help_short = help;
65 if (syntax && syntax[0])
66 m_cmd_syntax = syntax;
67}
68
69CommandObject::~CommandObject ()
70{
71}
72
73const char *
74CommandObject::GetHelp ()
75{
76 return m_cmd_help_short.c_str();
77}
78
79const char *
80CommandObject::GetHelpLong ()
81{
82 return m_cmd_help_long.c_str();
83}
84
85const char *
86CommandObject::GetSyntax ()
87{
Caroline Ticefb355112010-10-01 17:46:38 +000088 if (m_cmd_syntax.length() == 0)
89 {
90 StreamString syntax_str;
91 syntax_str.Printf ("%s", GetCommandName());
92 if (GetOptions() != NULL)
Caroline Tice43b014a2010-10-04 22:28:36 +000093 syntax_str.Printf (" <cmd-options>");
Caroline Ticefb355112010-10-01 17:46:38 +000094 if (m_arguments.size() > 0)
95 {
96 syntax_str.Printf (" ");
Sean Callanan9798d7b2012-01-04 19:11:25 +000097 if (WantsRawCommandString())
98 syntax_str.Printf("-- ");
Caroline Ticefb355112010-10-01 17:46:38 +000099 GetFormattedCommandArguments (syntax_str);
100 }
101 m_cmd_syntax = syntax_str.GetData ();
102 }
103
Chris Lattner24943d22010-06-08 16:52:24 +0000104 return m_cmd_syntax.c_str();
105}
106
107const char *
108CommandObject::Translate ()
109{
110 //return m_cmd_func_name.c_str();
111 return "This function is currently not implemented.";
112}
113
114const char *
115CommandObject::GetCommandName ()
116{
117 return m_cmd_name.c_str();
118}
119
120void
121CommandObject::SetCommandName (const char *name)
122{
123 m_cmd_name = name;
124}
125
126void
127CommandObject::SetHelp (const char *cstr)
128{
129 m_cmd_help_short = cstr;
130}
131
132void
133CommandObject::SetHelpLong (const char *cstr)
134{
135 m_cmd_help_long = cstr;
136}
137
138void
Enrico Granatae5e34cb2011-08-17 01:30:04 +0000139CommandObject::SetHelpLong (std::string str)
140{
141 m_cmd_help_long = str;
142}
143
144void
Chris Lattner24943d22010-06-08 16:52:24 +0000145CommandObject::SetSyntax (const char *cstr)
146{
147 m_cmd_syntax = cstr;
148}
149
150Options *
151CommandObject::GetOptions ()
152{
153 // By default commands don't have options unless this virtual function
154 // is overridden by base classes.
155 return NULL;
156}
157
Chris Lattner24943d22010-06-08 16:52:24 +0000158bool
Chris Lattner24943d22010-06-08 16:52:24 +0000159CommandObject::ParseOptions
160(
161 Args& args,
Chris Lattner24943d22010-06-08 16:52:24 +0000162 CommandReturnObject &result
163)
164{
165 // See if the subclass has options?
166 Options *options = GetOptions();
167 if (options != NULL)
168 {
169 Error error;
Greg Clayton143fcc32011-04-13 00:18:08 +0000170 options->NotifyOptionParsingStarting();
Chris Lattner24943d22010-06-08 16:52:24 +0000171
Greg Clayton3f2f7412013-04-04 20:35:24 +0000172 // ParseOptions calls getopt_long_only, which always skips the zero'th item in the array and starts at position 1,
Chris Lattner24943d22010-06-08 16:52:24 +0000173 // so we need to push a dummy value into position zero.
174 args.Unshift("dummy_string");
175 error = args.ParseOptions (*options);
176
177 // The "dummy_string" will have already been removed by ParseOptions,
178 // so no need to remove it.
179
Greg Clayton143fcc32011-04-13 00:18:08 +0000180 if (error.Success())
181 error = options->NotifyOptionParsingFinished();
182
183 if (error.Success())
184 {
185 if (options->VerifyOptions (result))
186 return true;
187 }
188 else
Chris Lattner24943d22010-06-08 16:52:24 +0000189 {
190 const char *error_cstr = error.AsCString();
191 if (error_cstr)
192 {
193 // We got an error string, lets use that
Greg Clayton9c236732011-10-26 00:56:27 +0000194 result.AppendError(error_cstr);
Chris Lattner24943d22010-06-08 16:52:24 +0000195 }
196 else
197 {
198 // No error string, output the usage information into result
Greg Claytonf15996e2011-04-07 22:46:35 +0000199 options->GenerateOptionUsage (result.GetErrorStream(), this);
Chris Lattner24943d22010-06-08 16:52:24 +0000200 }
Chris Lattner24943d22010-06-08 16:52:24 +0000201 }
Greg Clayton143fcc32011-04-13 00:18:08 +0000202 result.SetStatus (eReturnStatusFailed);
203 return false;
Chris Lattner24943d22010-06-08 16:52:24 +0000204 }
205 return true;
206}
Chris Lattner24943d22010-06-08 16:52:24 +0000207
Jim Inghamda26bd22012-06-08 21:56:10 +0000208
209
210bool
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000211CommandObject::CheckRequirements (CommandReturnObject &result)
Jim Inghamda26bd22012-06-08 21:56:10 +0000212{
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000213#ifdef LLDB_CONFIGURATION_DEBUG
214 // Nothing should be stored in m_exe_ctx between running commands as m_exe_ctx
215 // has shared pointers to the target, process, thread and frame and we don't
216 // want any CommandObject instances to keep any of these objects around
217 // longer than for a single command. Every command should call
218 // CommandObject::Cleanup() after it has completed
219 assert (m_exe_ctx.GetTargetPtr() == NULL);
220 assert (m_exe_ctx.GetProcessPtr() == NULL);
221 assert (m_exe_ctx.GetThreadPtr() == NULL);
222 assert (m_exe_ctx.GetFramePtr() == NULL);
223#endif
224
225 // Lock down the interpreter's execution context prior to running the
226 // command so we guarantee the selected target, process, thread and frame
227 // can't go away during the execution
228 m_exe_ctx = m_interpreter.GetExecutionContext();
229
230 const uint32_t flags = GetFlags().Get();
231 if (flags & (eFlagRequiresTarget |
232 eFlagRequiresProcess |
233 eFlagRequiresThread |
234 eFlagRequiresFrame |
235 eFlagTryTargetAPILock ))
236 {
237
238 if ((flags & eFlagRequiresTarget) && !m_exe_ctx.HasTargetScope())
239 {
240 result.AppendError (GetInvalidTargetDescription());
241 return false;
242 }
243
244 if ((flags & eFlagRequiresProcess) && !m_exe_ctx.HasProcessScope())
245 {
246 result.AppendError (GetInvalidProcessDescription());
247 return false;
248 }
249
250 if ((flags & eFlagRequiresThread) && !m_exe_ctx.HasThreadScope())
251 {
252 result.AppendError (GetInvalidThreadDescription());
253 return false;
254 }
255
256 if ((flags & eFlagRequiresFrame) && !m_exe_ctx.HasFrameScope())
257 {
258 result.AppendError (GetInvalidFrameDescription());
259 return false;
260 }
261
262 if ((flags & eFlagRequiresRegContext) && (m_exe_ctx.GetRegisterContext() == NULL))
263 {
264 result.AppendError (GetInvalidRegContextDescription());
265 return false;
266 }
267
268 if (flags & eFlagTryTargetAPILock)
269 {
270 Target *target = m_exe_ctx.GetTargetPtr();
271 if (target)
272 {
273 if (m_api_locker.TryLock (target->GetAPIMutex(), NULL) == false)
274 {
275 result.AppendError ("failed to get API lock");
276 return false;
277 }
278 }
279 }
280 }
281
Greg Claytone71e2582011-02-04 01:58:07 +0000282 if (GetFlags().AnySet (CommandObject::eFlagProcessMustBeLaunched | CommandObject::eFlagProcessMustBePaused))
Chris Lattner24943d22010-06-08 16:52:24 +0000283 {
Greg Clayton567e7f32011-09-22 04:58:26 +0000284 Process *process = m_interpreter.GetExecutionContext().GetProcessPtr();
Greg Claytone71e2582011-02-04 01:58:07 +0000285 if (process == NULL)
Chris Lattner24943d22010-06-08 16:52:24 +0000286 {
Jim Ingham8cc3f692011-07-09 00:55:34 +0000287 // A process that is not running is considered paused.
288 if (GetFlags().Test(CommandObject::eFlagProcessMustBeLaunched))
289 {
290 result.AppendError ("Process must exist.");
291 result.SetStatus (eReturnStatusFailed);
292 return false;
293 }
Chris Lattner24943d22010-06-08 16:52:24 +0000294 }
Greg Claytone71e2582011-02-04 01:58:07 +0000295 else
Chris Lattner24943d22010-06-08 16:52:24 +0000296 {
Greg Claytone71e2582011-02-04 01:58:07 +0000297 StateType state = process->GetState();
Greg Claytone71e2582011-02-04 01:58:07 +0000298 switch (state)
Chris Lattner24943d22010-06-08 16:52:24 +0000299 {
Greg Clayton4fdf7602011-03-20 04:57:14 +0000300 case eStateInvalid:
Greg Claytone71e2582011-02-04 01:58:07 +0000301 case eStateSuspended:
302 case eStateCrashed:
303 case eStateStopped:
304 break;
305
306 case eStateConnected:
307 case eStateAttaching:
308 case eStateLaunching:
309 case eStateDetached:
310 case eStateExited:
311 case eStateUnloaded:
312 if (GetFlags().Test(CommandObject::eFlagProcessMustBeLaunched))
313 {
314 result.AppendError ("Process must be launched.");
315 result.SetStatus (eReturnStatusFailed);
316 return false;
317 }
318 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000319
Greg Claytone71e2582011-02-04 01:58:07 +0000320 case eStateRunning:
321 case eStateStepping:
322 if (GetFlags().Test(CommandObject::eFlagProcessMustBePaused))
323 {
324 result.AppendError ("Process is running. Use 'process interrupt' to pause execution.");
325 result.SetStatus (eReturnStatusFailed);
326 return false;
327 }
Chris Lattner24943d22010-06-08 16:52:24 +0000328 }
329 }
330 }
Jim Inghamda26bd22012-06-08 21:56:10 +0000331 return true;
Chris Lattner24943d22010-06-08 16:52:24 +0000332}
333
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000334void
335CommandObject::Cleanup ()
336{
337 m_exe_ctx.Clear();
338 m_api_locker.Unlock();
339}
340
341
Chris Lattner24943d22010-06-08 16:52:24 +0000342class CommandDictCommandPartialMatch
343{
344 public:
345 CommandDictCommandPartialMatch (const char *match_str)
346 {
347 m_match_str = match_str;
348 }
349 bool operator() (const std::pair<std::string, lldb::CommandObjectSP> map_element) const
350 {
351 // A NULL or empty string matches everything.
352 if (m_match_str == NULL || *m_match_str == '\0')
Greg Clayton36da2aa2013-01-25 18:06:21 +0000353 return true;
Chris Lattner24943d22010-06-08 16:52:24 +0000354
Greg Clayton36da2aa2013-01-25 18:06:21 +0000355 return map_element.first.find (m_match_str, 0) == 0;
Chris Lattner24943d22010-06-08 16:52:24 +0000356 }
357
358 private:
359 const char *m_match_str;
360};
361
362int
363CommandObject::AddNamesMatchingPartialString (CommandObject::CommandMap &in_map, const char *cmd_str,
364 StringList &matches)
365{
366 int number_added = 0;
367 CommandDictCommandPartialMatch matcher(cmd_str);
368
369 CommandObject::CommandMap::iterator matching_cmds = std::find_if (in_map.begin(), in_map.end(), matcher);
370
371 while (matching_cmds != in_map.end())
372 {
373 ++number_added;
374 matches.AppendString((*matching_cmds).first.c_str());
375 matching_cmds = std::find_if (++matching_cmds, in_map.end(), matcher);;
376 }
377 return number_added;
378}
379
380int
381CommandObject::HandleCompletion
382(
383 Args &input,
384 int &cursor_index,
385 int &cursor_char_position,
386 int match_start_point,
387 int max_return_elements,
Jim Ingham802f8b02010-06-30 05:02:46 +0000388 bool &word_complete,
Chris Lattner24943d22010-06-08 16:52:24 +0000389 StringList &matches
390)
391{
Johnny Chen8042eed2012-01-20 00:59:19 +0000392 // Default implmentation of WantsCompletion() is !WantsRawCommandString().
393 // Subclasses who want raw command string but desire, for example,
394 // argument completion should override WantsCompletion() to return true,
395 // instead.
Johnny Chen120d94d2012-01-19 22:16:06 +0000396 if (WantsRawCommandString() && !WantsCompletion())
Chris Lattner24943d22010-06-08 16:52:24 +0000397 {
398 // FIXME: Abstract telling the completion to insert the completion character.
399 matches.Clear();
400 return -1;
401 }
402 else
403 {
404 // Can we do anything generic with the options?
405 Options *cur_options = GetOptions();
406 CommandReturnObject result;
407 OptionElementVector opt_element_vector;
408
409 if (cur_options != NULL)
410 {
411 // Re-insert the dummy command name string which will have been
412 // stripped off:
413 input.Unshift ("dummy-string");
414 cursor_index++;
415
416
417 // I stick an element on the end of the input, because if the last element is
Greg Clayton3f2f7412013-04-04 20:35:24 +0000418 // option that requires an argument, getopt_long_only will freak out.
Chris Lattner24943d22010-06-08 16:52:24 +0000419
420 input.AppendArgument ("<FAKE-VALUE>");
421
Jim Inghamadb84292010-06-24 20:31:04 +0000422 input.ParseArgsForCompletion (*cur_options, opt_element_vector, cursor_index);
Chris Lattner24943d22010-06-08 16:52:24 +0000423
424 input.DeleteArgumentAtIndex(input.GetArgumentCount() - 1);
425
426 bool handled_by_options;
Greg Claytonf15996e2011-04-07 22:46:35 +0000427 handled_by_options = cur_options->HandleOptionCompletion (input,
Greg Clayton63094e02010-06-23 01:19:29 +0000428 opt_element_vector,
429 cursor_index,
430 cursor_char_position,
431 match_start_point,
432 max_return_elements,
Jim Ingham802f8b02010-06-30 05:02:46 +0000433 word_complete,
Greg Clayton63094e02010-06-23 01:19:29 +0000434 matches);
Chris Lattner24943d22010-06-08 16:52:24 +0000435 if (handled_by_options)
436 return matches.GetSize();
437 }
438
439 // If we got here, the last word is not an option or an option argument.
Greg Clayton238c0a12010-09-18 01:14:36 +0000440 return HandleArgumentCompletion (input,
Greg Clayton63094e02010-06-23 01:19:29 +0000441 cursor_index,
442 cursor_char_position,
443 opt_element_vector,
444 match_start_point,
445 max_return_elements,
Jim Ingham802f8b02010-06-30 05:02:46 +0000446 word_complete,
Greg Clayton63094e02010-06-23 01:19:29 +0000447 matches);
Chris Lattner24943d22010-06-08 16:52:24 +0000448 }
449}
450
Chris Lattner24943d22010-06-08 16:52:24 +0000451bool
Greg Clayton238c0a12010-09-18 01:14:36 +0000452CommandObject::HelpTextContainsWord (const char *search_word)
Chris Lattner24943d22010-06-08 16:52:24 +0000453{
Chris Lattner24943d22010-06-08 16:52:24 +0000454 std::string options_usage_help;
455
Chris Lattner24943d22010-06-08 16:52:24 +0000456 bool found_word = false;
457
Greg Clayton13193d52012-10-13 02:07:45 +0000458 const char *short_help = GetHelp();
459 const char *long_help = GetHelpLong();
460 const char *syntax_help = GetSyntax();
Chris Lattner24943d22010-06-08 16:52:24 +0000461
Greg Clayton13193d52012-10-13 02:07:45 +0000462 if (short_help && strcasestr (short_help, search_word))
Chris Lattner24943d22010-06-08 16:52:24 +0000463 found_word = true;
Greg Clayton13193d52012-10-13 02:07:45 +0000464 else if (long_help && strcasestr (long_help, search_word))
Chris Lattner24943d22010-06-08 16:52:24 +0000465 found_word = true;
Greg Clayton13193d52012-10-13 02:07:45 +0000466 else if (syntax_help && strcasestr (syntax_help, search_word))
Chris Lattner24943d22010-06-08 16:52:24 +0000467 found_word = true;
468
469 if (!found_word
470 && GetOptions() != NULL)
471 {
472 StreamString usage_help;
Greg Claytonf15996e2011-04-07 22:46:35 +0000473 GetOptions()->GenerateOptionUsage (usage_help, this);
Chris Lattner24943d22010-06-08 16:52:24 +0000474 if (usage_help.GetSize() > 0)
475 {
476 const char *usage_text = usage_help.GetData();
Caroline Tice34391782010-10-12 22:16:53 +0000477 if (strcasestr (usage_text, search_word))
Chris Lattner24943d22010-06-08 16:52:24 +0000478 found_word = true;
479 }
480 }
481
482 return found_word;
483}
Caroline Ticefb355112010-10-01 17:46:38 +0000484
485int
486CommandObject::GetNumArgumentEntries ()
487{
488 return m_arguments.size();
489}
490
491CommandObject::CommandArgumentEntry *
492CommandObject::GetArgumentEntryAtIndex (int idx)
493{
494 if (idx < m_arguments.size())
495 return &(m_arguments[idx]);
496
497 return NULL;
498}
499
500CommandObject::ArgumentTableEntry *
501CommandObject::FindArgumentDataByType (CommandArgumentType arg_type)
502{
503 const ArgumentTableEntry *table = CommandObject::GetArgumentTable();
504
505 for (int i = 0; i < eArgTypeLastArg; ++i)
506 if (table[i].arg_type == arg_type)
507 return (ArgumentTableEntry *) &(table[i]);
508
509 return NULL;
510}
511
512void
513CommandObject::GetArgumentHelp (Stream &str, CommandArgumentType arg_type, CommandInterpreter &interpreter)
514{
515 const ArgumentTableEntry* table = CommandObject::GetArgumentTable();
516 ArgumentTableEntry *entry = (ArgumentTableEntry *) &(table[arg_type]);
517
518 // The table is *supposed* to be kept in arg_type order, but someone *could* have messed it up...
519
520 if (entry->arg_type != arg_type)
521 entry = CommandObject::FindArgumentDataByType (arg_type);
522
523 if (!entry)
524 return;
525
526 StreamString name_str;
527 name_str.Printf ("<%s>", entry->arg_name);
528
Enrico Granataff782382011-07-08 02:51:01 +0000529 if (entry->help_function)
Enrico Granata1bba6e52011-07-07 00:38:40 +0000530 {
Enrico Granataff782382011-07-08 02:51:01 +0000531 const char* help_text = entry->help_function();
Enrico Granata1bba6e52011-07-07 00:38:40 +0000532 if (!entry->help_function.self_formatting)
533 {
534 interpreter.OutputFormattedHelpText (str, name_str.GetData(), "--", help_text,
535 name_str.GetSize());
536 }
537 else
538 {
539 interpreter.OutputHelpText(str, name_str.GetData(), "--", help_text,
540 name_str.GetSize());
541 }
542 }
Caroline Ticefb355112010-10-01 17:46:38 +0000543 else
544 interpreter.OutputFormattedHelpText (str, name_str.GetData(), "--", entry->help_text, name_str.GetSize());
545}
546
547const char *
548CommandObject::GetArgumentName (CommandArgumentType arg_type)
549{
Caroline Tice4d6675c2010-10-01 19:59:14 +0000550 ArgumentTableEntry *entry = (ArgumentTableEntry *) &(CommandObject::GetArgumentTable()[arg_type]);
551
552 // The table is *supposed* to be kept in arg_type order, but someone *could* have messed it up...
553
554 if (entry->arg_type != arg_type)
555 entry = CommandObject::FindArgumentDataByType (arg_type);
556
Johnny Chen25ca9842010-10-08 22:01:52 +0000557 if (entry)
558 return entry->arg_name;
559
560 StreamString str;
561 str << "Arg name for type (" << arg_type << ") not in arg table!";
562 return str.GetData();
Caroline Ticefb355112010-10-01 17:46:38 +0000563}
564
Caroline Tice43b014a2010-10-04 22:28:36 +0000565bool
Greg Claytonb3448432011-03-24 21:19:54 +0000566CommandObject::IsPairType (ArgumentRepetitionType arg_repeat_type)
Caroline Tice43b014a2010-10-04 22:28:36 +0000567{
568 if ((arg_repeat_type == eArgRepeatPairPlain)
569 || (arg_repeat_type == eArgRepeatPairOptional)
570 || (arg_repeat_type == eArgRepeatPairPlus)
571 || (arg_repeat_type == eArgRepeatPairStar)
572 || (arg_repeat_type == eArgRepeatPairRange)
573 || (arg_repeat_type == eArgRepeatPairRangeOptional))
574 return true;
575
576 return false;
577}
578
Johnny Chen6183fcc2012-02-08 01:13:31 +0000579static CommandObject::CommandArgumentEntry
580OptSetFiltered(uint32_t opt_set_mask, CommandObject::CommandArgumentEntry &cmd_arg_entry)
581{
582 CommandObject::CommandArgumentEntry ret_val;
583 for (unsigned i = 0; i < cmd_arg_entry.size(); ++i)
584 if (opt_set_mask & cmd_arg_entry[i].arg_opt_set_association)
585 ret_val.push_back(cmd_arg_entry[i]);
586 return ret_val;
587}
588
589// Default parameter value of opt_set_mask is LLDB_OPT_SET_ALL, which means take
590// all the argument data into account. On rare cases where some argument sticks
591// with certain option sets, this function returns the option set filtered args.
Caroline Ticefb355112010-10-01 17:46:38 +0000592void
Johnny Chen6183fcc2012-02-08 01:13:31 +0000593CommandObject::GetFormattedCommandArguments (Stream &str, uint32_t opt_set_mask)
Caroline Ticefb355112010-10-01 17:46:38 +0000594{
595 int num_args = m_arguments.size();
596 for (int i = 0; i < num_args; ++i)
597 {
598 if (i > 0)
599 str.Printf (" ");
Johnny Chen6183fcc2012-02-08 01:13:31 +0000600 CommandArgumentEntry arg_entry =
601 opt_set_mask == LLDB_OPT_SET_ALL ? m_arguments[i]
602 : OptSetFiltered(opt_set_mask, m_arguments[i]);
Caroline Ticefb355112010-10-01 17:46:38 +0000603 int num_alternatives = arg_entry.size();
Caroline Tice43b014a2010-10-04 22:28:36 +0000604
605 if ((num_alternatives == 2)
606 && IsPairType (arg_entry[0].arg_repetition))
Caroline Ticefb355112010-10-01 17:46:38 +0000607 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000608 const char *first_name = GetArgumentName (arg_entry[0].arg_type);
609 const char *second_name = GetArgumentName (arg_entry[1].arg_type);
610 switch (arg_entry[0].arg_repetition)
611 {
612 case eArgRepeatPairPlain:
613 str.Printf ("<%s> <%s>", first_name, second_name);
614 break;
615 case eArgRepeatPairOptional:
616 str.Printf ("[<%s> <%s>]", first_name, second_name);
617 break;
618 case eArgRepeatPairPlus:
619 str.Printf ("<%s> <%s> [<%s> <%s> [...]]", first_name, second_name, first_name, second_name);
620 break;
621 case eArgRepeatPairStar:
622 str.Printf ("[<%s> <%s> [<%s> <%s> [...]]]", first_name, second_name, first_name, second_name);
623 break;
624 case eArgRepeatPairRange:
625 str.Printf ("<%s_1> <%s_1> ... <%s_n> <%s_n>", first_name, second_name, first_name, second_name);
626 break;
627 case eArgRepeatPairRangeOptional:
628 str.Printf ("[<%s_1> <%s_1> ... <%s_n> <%s_n>]", first_name, second_name, first_name, second_name);
629 break;
Caroline Ticeb5772842011-03-23 22:31:13 +0000630 // Explicitly test for all the rest of the cases, so if new types get added we will notice the
631 // missing case statement(s).
632 case eArgRepeatPlain:
633 case eArgRepeatOptional:
634 case eArgRepeatPlus:
635 case eArgRepeatStar:
636 case eArgRepeatRange:
637 // These should not be reached, as they should fail the IsPairType test above.
638 break;
Caroline Tice43b014a2010-10-04 22:28:36 +0000639 }
Caroline Ticefb355112010-10-01 17:46:38 +0000640 }
Caroline Tice43b014a2010-10-04 22:28:36 +0000641 else
Caroline Ticefb355112010-10-01 17:46:38 +0000642 {
Caroline Tice43b014a2010-10-04 22:28:36 +0000643 StreamString names;
644 for (int j = 0; j < num_alternatives; ++j)
645 {
646 if (j > 0)
647 names.Printf (" | ");
648 names.Printf ("%s", GetArgumentName (arg_entry[j].arg_type));
649 }
650 switch (arg_entry[0].arg_repetition)
651 {
652 case eArgRepeatPlain:
653 str.Printf ("<%s>", names.GetData());
654 break;
655 case eArgRepeatPlus:
656 str.Printf ("<%s> [<%s> [...]]", names.GetData(), names.GetData());
657 break;
658 case eArgRepeatStar:
659 str.Printf ("[<%s> [<%s> [...]]]", names.GetData(), names.GetData());
660 break;
661 case eArgRepeatOptional:
662 str.Printf ("[<%s>]", names.GetData());
663 break;
664 case eArgRepeatRange:
Jason Molenda7e5fa7f2011-09-20 21:44:10 +0000665 str.Printf ("<%s_1> .. <%s_n>", names.GetData(), names.GetData());
Caroline Ticeb5772842011-03-23 22:31:13 +0000666 break;
667 // Explicitly test for all the rest of the cases, so if new types get added we will notice the
668 // missing case statement(s).
669 case eArgRepeatPairPlain:
670 case eArgRepeatPairOptional:
671 case eArgRepeatPairPlus:
672 case eArgRepeatPairStar:
673 case eArgRepeatPairRange:
674 case eArgRepeatPairRangeOptional:
675 // These should not be hit, as they should pass the IsPairType test above, and control should
676 // have gone into the other branch of the if statement.
677 break;
Caroline Tice43b014a2010-10-04 22:28:36 +0000678 }
Caroline Ticefb355112010-10-01 17:46:38 +0000679 }
680 }
681}
682
Stephen Wilson47f07852011-03-23 02:12:10 +0000683CommandArgumentType
Caroline Ticefb355112010-10-01 17:46:38 +0000684CommandObject::LookupArgumentName (const char *arg_name)
685{
686 CommandArgumentType return_type = eArgTypeLastArg;
687
688 std::string arg_name_str (arg_name);
689 size_t len = arg_name_str.length();
690 if (arg_name[0] == '<'
691 && arg_name[len-1] == '>')
692 arg_name_str = arg_name_str.substr (1, len-2);
693
Johnny Chen309c89d2011-07-14 22:20:12 +0000694 const ArgumentTableEntry *table = GetArgumentTable();
Caroline Ticefb355112010-10-01 17:46:38 +0000695 for (int i = 0; i < eArgTypeLastArg; ++i)
Johnny Chen309c89d2011-07-14 22:20:12 +0000696 if (arg_name_str.compare (table[i].arg_name) == 0)
Caroline Ticefb355112010-10-01 17:46:38 +0000697 return_type = g_arguments_data[i].arg_type;
698
699 return return_type;
700}
701
702static const char *
Jim Ingham811708c2012-08-23 23:37:31 +0000703RegisterNameHelpTextCallback ()
704{
705 return "Register names can be specified using the architecture specific names. "
Jim Inghamff72cd02012-08-23 23:47:08 +0000706 "They can also be specified using generic names. Not all generic entities have "
707 "registers backing them on all architectures. When they don't the generic name "
708 "will return an error.\n"
Jim Ingham811708c2012-08-23 23:37:31 +0000709 "The generic names defined in lldb are:\n"
710 "\n"
711 "pc - program counter register\n"
712 "ra - return address register\n"
713 "fp - frame pointer register\n"
714 "sp - stack pointer register\n"
Jim Inghamff72cd02012-08-23 23:47:08 +0000715 "flags - the flags register\n"
Jim Ingham811708c2012-08-23 23:37:31 +0000716 "arg{1-6} - integer argument passing registers.\n";
717}
718
719static const char *
Caroline Ticefb355112010-10-01 17:46:38 +0000720BreakpointIDHelpTextCallback ()
721{
Greg Clayton9c236732011-10-26 00:56:27 +0000722 return "Breakpoint ID's consist major and minor numbers; the major number "
723 "corresponds to the single entity that was created with a 'breakpoint set' "
724 "command; the minor numbers correspond to all the locations that were actually "
725 "found/set based on the major breakpoint. A full breakpoint ID might look like "
726 "3.14, meaning the 14th location set for the 3rd breakpoint. You can specify "
727 "all the locations of a breakpoint by just indicating the major breakpoint "
728 "number. A valid breakpoint id consists either of just the major id number, "
729 "or the major number, a dot, and the location number (e.g. 3 or 3.2 could "
730 "both be valid breakpoint ids).";
Caroline Ticefb355112010-10-01 17:46:38 +0000731}
732
733static const char *
734BreakpointIDRangeHelpTextCallback ()
735{
Greg Clayton9c236732011-10-26 00:56:27 +0000736 return "A 'breakpoint id list' is a manner of specifying multiple breakpoints. "
737 "This can be done through several mechanisms. The easiest way is to just "
738 "enter a space-separated list of breakpoint ids. To specify all the "
739 "breakpoint locations under a major breakpoint, you can use the major "
740 "breakpoint number followed by '.*', eg. '5.*' means all the locations under "
741 "breakpoint 5. You can also indicate a range of breakpoints by using "
742 "<start-bp-id> - <end-bp-id>. The start-bp-id and end-bp-id for a range can "
743 "be any valid breakpoint ids. It is not legal, however, to specify a range "
744 "using specific locations that cross major breakpoint numbers. I.e. 3.2 - 3.7"
745 " is legal; 2 - 5 is legal; but 3.2 - 4.4 is not legal.";
Caroline Ticefb355112010-10-01 17:46:38 +0000746}
747
Enrico Granata886bc3e2011-07-02 00:25:22 +0000748static const char *
Greg Clayton9c236732011-10-26 00:56:27 +0000749GDBFormatHelpTextCallback ()
750{
Greg Clayton966096b2011-10-26 18:35:21 +0000751 return "A GDB format consists of a repeat count, a format letter and a size letter. "
752 "The repeat count is optional and defaults to 1. The format letter is optional "
753 "and defaults to the previous format that was used. The size letter is optional "
754 "and defaults to the previous size that was used.\n"
755 "\n"
756 "Format letters include:\n"
757 "o - octal\n"
758 "x - hexadecimal\n"
759 "d - decimal\n"
760 "u - unsigned decimal\n"
761 "t - binary\n"
762 "f - float\n"
763 "a - address\n"
764 "i - instruction\n"
765 "c - char\n"
766 "s - string\n"
767 "T - OSType\n"
768 "A - float as hex\n"
769 "\n"
770 "Size letters include:\n"
771 "b - 1 byte (byte)\n"
772 "h - 2 bytes (halfword)\n"
773 "w - 4 bytes (word)\n"
774 "g - 8 bytes (giant)\n"
775 "\n"
776 "Example formats:\n"
777 "32xb - show 32 1 byte hexadecimal integer values\n"
778 "16xh - show 16 2 byte hexadecimal integer values\n"
779 "64 - show 64 2 byte hexadecimal integer values (format and size from the last format)\n"
780 "dw - show 1 4 byte decimal integer value\n"
781 ;
Greg Clayton9c236732011-10-26 00:56:27 +0000782}
783
784static const char *
Enrico Granata886bc3e2011-07-02 00:25:22 +0000785FormatHelpTextCallback ()
786{
Enrico Granata1bba6e52011-07-07 00:38:40 +0000787
788 static char* help_text_ptr = NULL;
789
790 if (help_text_ptr)
791 return help_text_ptr;
792
Enrico Granata886bc3e2011-07-02 00:25:22 +0000793 StreamString sstr;
794 sstr << "One of the format names (or one-character names) that can be used to show a variable's value:\n";
795 for (Format f = eFormatDefault; f < kNumFormats; f = Format(f+1))
796 {
Enrico Granata1bba6e52011-07-07 00:38:40 +0000797 if (f != eFormatDefault)
798 sstr.PutChar('\n');
799
Enrico Granata886bc3e2011-07-02 00:25:22 +0000800 char format_char = FormatManager::GetFormatAsFormatChar(f);
801 if (format_char)
802 sstr.Printf("'%c' or ", format_char);
803
Enrico Granata1bba6e52011-07-07 00:38:40 +0000804 sstr.Printf ("\"%s\"", FormatManager::GetFormatAsCString(f));
Enrico Granata886bc3e2011-07-02 00:25:22 +0000805 }
806
807 sstr.Flush();
808
809 std::string data = sstr.GetString();
810
Enrico Granata1bba6e52011-07-07 00:38:40 +0000811 help_text_ptr = new char[data.length()+1];
Enrico Granata886bc3e2011-07-02 00:25:22 +0000812
Enrico Granata1bba6e52011-07-07 00:38:40 +0000813 data.copy(help_text_ptr, data.length());
Enrico Granata886bc3e2011-07-02 00:25:22 +0000814
Enrico Granata1bba6e52011-07-07 00:38:40 +0000815 return help_text_ptr;
Enrico Granata886bc3e2011-07-02 00:25:22 +0000816}
817
818static const char *
Sean Callanan61ff3a32012-10-23 00:50:09 +0000819LanguageTypeHelpTextCallback ()
820{
821 static char* help_text_ptr = NULL;
822
823 if (help_text_ptr)
824 return help_text_ptr;
825
826 StreamString sstr;
827 sstr << "One of the following languages:\n";
828
Daniel Malea25b21092012-12-04 00:23:45 +0000829 for (unsigned int l = eLanguageTypeUnknown; l < eNumLanguageTypes; ++l)
Sean Callanan61ff3a32012-10-23 00:50:09 +0000830 {
Daniel Malea25b21092012-12-04 00:23:45 +0000831 sstr << " " << LanguageRuntime::GetNameForLanguageType(static_cast<LanguageType>(l)) << "\n";
Sean Callanan61ff3a32012-10-23 00:50:09 +0000832 }
833
834 sstr.Flush();
835
836 std::string data = sstr.GetString();
837
838 help_text_ptr = new char[data.length()+1];
839
840 data.copy(help_text_ptr, data.length());
841
842 return help_text_ptr;
843}
844
845static const char *
Enrico Granata1bba6e52011-07-07 00:38:40 +0000846SummaryStringHelpTextCallback()
Enrico Granata886bc3e2011-07-02 00:25:22 +0000847{
Enrico Granata1bba6e52011-07-07 00:38:40 +0000848 return
849 "A summary string is a way to extract information from variables in order to present them using a summary.\n"
850 "Summary strings contain static text, variables, scopes and control sequences:\n"
851 " - Static text can be any sequence of non-special characters, i.e. anything but '{', '}', '$', or '\\'.\n"
852 " - Variables are sequences of characters beginning with ${, ending with } and that contain symbols in the format described below.\n"
853 " - Scopes are any sequence of text between { and }. Anything included in a scope will only appear in the output summary if there were no errors.\n"
854 " - Control sequences are the usual C/C++ '\\a', '\\n', ..., plus '\\$', '\\{' and '\\}'.\n"
855 "A summary string works by copying static text verbatim, turning control sequences into their character counterpart, expanding variables and trying to expand scopes.\n"
856 "A variable is expanded by giving it a value other than its textual representation, and the way this is done depends on what comes after the ${ marker.\n"
857 "The most common sequence if ${var followed by an expression path, which is the text one would type to access a member of an aggregate types, given a variable of that type"
858 " (e.g. if type T has a member named x, which has a member named y, and if t is of type T, the expression path would be .x.y and the way to fit that into a summary string would be"
Enrico Granata91544802011-09-06 19:20:51 +0000859 " ${var.x.y}). You can also use ${*var followed by an expression path and in that case the object referred by the path will be dereferenced before being displayed."
860 " If the object is not a pointer, doing so will cause an error. For additional details on expression paths, you can type 'help expr-path'. \n"
Enrico Granata1bba6e52011-07-07 00:38:40 +0000861 "By default, summary strings attempt to display the summary for any variable they reference, and if that fails the value. If neither can be shown, nothing is displayed."
862 "In a summary string, you can also use an array index [n], or a slice-like range [n-m]. This can have two different meanings depending on what kind of object the expression"
863 " path refers to:\n"
864 " - if it is a scalar type (any basic type like int, float, ...) the expression is a bitfield, i.e. the bits indicated by the indexing operator are extracted out of the number"
865 " and displayed as an individual variable\n"
866 " - if it is an array or pointer the array items indicated by the indexing operator are shown as the result of the variable. if the expression is an array, real array items are"
867 " printed; if it is a pointer, the pointer-as-array syntax is used to obtain the values (this means, the latter case can have no range checking)\n"
Enrico Granata91544802011-09-06 19:20:51 +0000868 "If you are trying to display an array for which the size is known, you can also use [] instead of giving an exact range. This has the effect of showing items 0 thru size - 1.\n"
869 "Additionally, a variable can contain an (optional) format code, as in ${var.x.y%code}, where code can be any of the valid formats described in 'help format', or one of the"
870 " special symbols only allowed as part of a variable:\n"
871 " %V: show the value of the object by default\n"
872 " %S: show the summary of the object by default\n"
873 " %@: show the runtime-provided object description (for Objective-C, it calls NSPrintForDebugger; for C/C++ it does nothing)\n"
874 " %L: show the location of the object (memory address or a register name)\n"
875 " %#: show the number of children of the object\n"
876 " %T: show the type of the object\n"
877 "Another variable that you can use in summary strings is ${svar . This sequence works exactly like ${var, including the fact that ${*svar is an allowed sequence, but uses"
878 " the object's synthetic children provider instead of the actual objects. For instance, if you are using STL synthetic children providers, the following summary string would"
879 " count the number of actual elements stored in an std::list:\n"
880 "type summary add -s \"${svar%#}\" -x \"std::list<\"";
881}
882
883static const char *
884ExprPathHelpTextCallback()
885{
886 return
887 "An expression path is the sequence of symbols that is used in C/C++ to access a member variable of an aggregate object (class).\n"
888 "For instance, given a class:\n"
889 " class foo {\n"
890 " int a;\n"
891 " int b; .\n"
892 " foo* next;\n"
893 " };\n"
894 "the expression to read item b in the item pointed to by next for foo aFoo would be aFoo.next->b.\n"
895 "Given that aFoo could just be any object of type foo, the string '.next->b' is the expression path, because it can be attached to any foo instance to achieve the effect.\n"
896 "Expression paths in LLDB include dot (.) and arrow (->) operators, and most commands using expression paths have ways to also accept the star (*) operator.\n"
897 "The meaning of these operators is the same as the usual one given to them by the C/C++ standards.\n"
898 "LLDB also has support for indexing ([ ]) in expression paths, and extends the traditional meaning of the square brackets operator to allow bitfield extraction:\n"
899 "for objects of native types (int, float, char, ...) saying '[n-m]' as an expression path (where n and m are any positive integers, e.g. [3-5]) causes LLDB to extract"
900 " bits n thru m from the value of the variable. If n == m, [n] is also allowed as a shortcut syntax. For arrays and pointers, expression paths can only contain one index"
901 " and the meaning of the operation is the same as the one defined by C/C++ (item extraction). Some commands extend bitfield-like syntax for arrays and pointers with the"
902 " meaning of array slicing (taking elements n thru m inside the array or pointed-to memory).";
Enrico Granata886bc3e2011-07-02 00:25:22 +0000903}
904
Johnny Chen0576c242011-09-21 01:00:02 +0000905void
Johnny Chencacedfb2011-09-22 22:34:09 +0000906CommandObject::AddIDsArgumentData(CommandArgumentEntry &arg, CommandArgumentType ID, CommandArgumentType IDRange)
Johnny Chen0576c242011-09-21 01:00:02 +0000907{
908 CommandArgumentData id_arg;
909 CommandArgumentData id_range_arg;
910
911 // Create the first variant for the first (and only) argument for this command.
Johnny Chencacedfb2011-09-22 22:34:09 +0000912 id_arg.arg_type = ID;
Johnny Chen0576c242011-09-21 01:00:02 +0000913 id_arg.arg_repetition = eArgRepeatOptional;
914
915 // Create the second variant for the first (and only) argument for this command.
Johnny Chencacedfb2011-09-22 22:34:09 +0000916 id_range_arg.arg_type = IDRange;
Johnny Chen0576c242011-09-21 01:00:02 +0000917 id_range_arg.arg_repetition = eArgRepeatOptional;
918
Johnny Chenf0734cc2011-09-21 01:04:49 +0000919 // The first (and only) argument for this command could be either an id or an id_range.
Johnny Chen0576c242011-09-21 01:00:02 +0000920 // Push both variants into the entry for the first argument for this command.
921 arg.push_back(id_arg);
922 arg.push_back(id_range_arg);
923}
924
Greg Claytonaa378b12011-02-20 02:15:07 +0000925const char *
926CommandObject::GetArgumentTypeAsCString (const lldb::CommandArgumentType arg_type)
927{
928 if (arg_type >=0 && arg_type < eArgTypeLastArg)
929 return g_arguments_data[arg_type].arg_name;
930 return NULL;
931
932}
933
934const char *
935CommandObject::GetArgumentDescriptionAsCString (const lldb::CommandArgumentType arg_type)
936{
937 if (arg_type >=0 && arg_type < eArgTypeLastArg)
938 return g_arguments_data[arg_type].help_text;
939 return NULL;
940}
941
Jim Inghamda26bd22012-06-08 21:56:10 +0000942bool
943CommandObjectParsed::Execute (const char *args_string, CommandReturnObject &result)
944{
945 CommandOverrideCallback command_callback = GetOverrideCallback();
946 bool handled = false;
947 Args cmd_args (args_string);
948 if (command_callback)
949 {
950 Args full_args (GetCommandName ());
951 full_args.AppendArguments(cmd_args);
952 handled = command_callback (GetOverrideCallbackBaton(), full_args.GetConstArgumentVector());
953 }
954 if (!handled)
955 {
956 for (size_t i = 0; i < cmd_args.GetArgumentCount(); ++i)
957 {
958 const char *tmp_str = cmd_args.GetArgumentAtIndex (i);
959 if (tmp_str[0] == '`') // back-quote
960 cmd_args.ReplaceArgumentAtIndex (i, m_interpreter.ProcessEmbeddedScriptCommands (tmp_str));
961 }
962
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000963 if (CheckRequirements(result))
964 {
965 if (ParseOptions (cmd_args, result))
966 {
967 // Call the command-specific version of 'Execute', passing it the already processed arguments.
968 handled = DoExecute (cmd_args, result);
969 }
970 }
Jim Inghamda26bd22012-06-08 21:56:10 +0000971
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000972 Cleanup();
Jim Inghamda26bd22012-06-08 21:56:10 +0000973 }
974 return handled;
975}
976
977bool
978CommandObjectRaw::Execute (const char *args_string, CommandReturnObject &result)
979{
980 CommandOverrideCallback command_callback = GetOverrideCallback();
981 bool handled = false;
982 if (command_callback)
983 {
984 std::string full_command (GetCommandName ());
985 full_command += ' ';
986 full_command += args_string;
987 const char *argv[2] = { NULL, NULL };
988 argv[0] = full_command.c_str();
989 handled = command_callback (GetOverrideCallbackBaton(), argv);
990 }
991 if (!handled)
992 {
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000993 if (CheckRequirements(result))
Jim Inghamda26bd22012-06-08 21:56:10 +0000994 handled = DoExecute (args_string, result);
Greg Claytonea0bb4d2013-01-09 19:44:40 +0000995
996 Cleanup();
Jim Inghamda26bd22012-06-08 21:56:10 +0000997 }
998 return handled;
999}
1000
Johnny Chen746323a2012-05-26 00:32:39 +00001001static
1002const char *arch_helper()
1003{
Greg Claytondc43bbf2012-05-26 17:21:14 +00001004 static StreamString g_archs_help;
Johnny Chene23940f2012-05-29 20:04:10 +00001005 if (g_archs_help.Empty())
Greg Claytondc43bbf2012-05-26 17:21:14 +00001006 {
1007 StringList archs;
1008 ArchSpec::AutoComplete(NULL, archs);
1009 g_archs_help.Printf("These are the supported architecture names:\n");
Johnny Chene23940f2012-05-29 20:04:10 +00001010 archs.Join("\n", g_archs_help);
Greg Claytondc43bbf2012-05-26 17:21:14 +00001011 }
1012 return g_archs_help.GetData();
Johnny Chen746323a2012-05-26 00:32:39 +00001013}
1014
Caroline Ticefb355112010-10-01 17:46:38 +00001015CommandObject::ArgumentTableEntry
1016CommandObject::g_arguments_data[] =
1017{
Enrico Granata9ae9fd32011-07-07 15:49:54 +00001018 { eArgTypeAddress, "address", CommandCompletions::eNoCompletion, { NULL, false }, "A valid address in the target program's execution space." },
Enrico Granata16481ab2013-01-29 02:46:04 +00001019 { eArgTypeAddressOrExpression, "address-expression", CommandCompletions::eNoCompletion, { NULL, false }, "An expression that resolves to an address." },
Enrico Granata9ae9fd32011-07-07 15:49:54 +00001020 { eArgTypeAliasName, "alias-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of an abbreviation (alias) for a debugger command." },
1021 { eArgTypeAliasOptions, "options-for-aliased-command", CommandCompletions::eNoCompletion, { NULL, false }, "Command options to be used as part of an alias (abbreviation) definition. (See 'help commands alias' for more information.)" },
Johnny Chen746323a2012-05-26 00:32:39 +00001022 { eArgTypeArchitecture, "arch", CommandCompletions::eArchitectureCompletion, { arch_helper, true }, "The architecture name, e.g. i386 or x86_64." },
Enrico Granata9ae9fd32011-07-07 15:49:54 +00001023 { eArgTypeBoolean, "boolean", CommandCompletions::eNoCompletion, { NULL, false }, "A Boolean value: 'true' or 'false'" },
1024 { eArgTypeBreakpointID, "breakpt-id", CommandCompletions::eNoCompletion, { BreakpointIDHelpTextCallback, false }, NULL },
1025 { eArgTypeBreakpointIDRange, "breakpt-id-list", CommandCompletions::eNoCompletion, { BreakpointIDRangeHelpTextCallback, false }, NULL },
1026 { eArgTypeByteSize, "byte-size", CommandCompletions::eNoCompletion, { NULL, false }, "Number of bytes to use." },
1027 { eArgTypeClassName, "class-name", CommandCompletions::eNoCompletion, { NULL, false }, "Then name of a class from the debug information in the program." },
1028 { eArgTypeCommandName, "cmd-name", CommandCompletions::eNoCompletion, { NULL, false }, "A debugger command (may be multiple words), without any options or arguments." },
1029 { eArgTypeCount, "count", CommandCompletions::eNoCompletion, { NULL, false }, "An unsigned integer." },
Sean Callanan9a91ef62012-10-24 01:12:14 +00001030 { eArgTypeDirectoryName, "directory", CommandCompletions::eDiskDirectoryCompletion, { NULL, false }, "A directory name." },
Jim Ingham7d408382013-03-02 00:26:47 +00001031 { eArgTypeDisassemblyFlavor, "disassembly-flavor", CommandCompletions::eNoCompletion, { NULL, false }, "A disassembly flavor recognized by your disassembly plugin. Currently the only valid options are \"att\" and \"intel\" for Intel targets" },
Enrico Granata9ae9fd32011-07-07 15:49:54 +00001032 { eArgTypeEndAddress, "end-address", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
1033 { eArgTypeExpression, "expr", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
Enrico Granata91544802011-09-06 19:20:51 +00001034 { eArgTypeExpressionPath, "expr-path", CommandCompletions::eNoCompletion, { ExprPathHelpTextCallback, true }, NULL },
Enrico Granata9ae9fd32011-07-07 15:49:54 +00001035 { eArgTypeExprFormat, "expression-format", CommandCompletions::eNoCompletion, { NULL, false }, "[ [bool|b] | [bin] | [char|c] | [oct|o] | [dec|i|d|u] | [hex|x] | [float|f] | [cstr|s] ]" },
1036 { eArgTypeFilename, "filename", CommandCompletions::eDiskFileCompletion, { NULL, false }, "The name of a file (can include path)." },
1037 { eArgTypeFormat, "format", CommandCompletions::eNoCompletion, { FormatHelpTextCallback, true }, NULL },
1038 { eArgTypeFrameIndex, "frame-index", CommandCompletions::eNoCompletion, { NULL, false }, "Index into a thread's list of frames." },
1039 { eArgTypeFullName, "fullname", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
1040 { eArgTypeFunctionName, "function-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a function." },
Sean Callanan3bfaad62012-09-13 21:11:40 +00001041 { eArgTypeFunctionOrSymbol, "function-or-symbol", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a function or symbol." },
Greg Clayton9c236732011-10-26 00:56:27 +00001042 { eArgTypeGDBFormat, "gdb-format", CommandCompletions::eNoCompletion, { GDBFormatHelpTextCallback, true }, NULL },
Enrico Granata9ae9fd32011-07-07 15:49:54 +00001043 { eArgTypeIndex, "index", CommandCompletions::eNoCompletion, { NULL, false }, "An index into a list." },
Sean Callanan61ff3a32012-10-23 00:50:09 +00001044 { eArgTypeLanguage, "language", CommandCompletions::eNoCompletion, { LanguageTypeHelpTextCallback, true }, NULL },
Enrico Granata9ae9fd32011-07-07 15:49:54 +00001045 { eArgTypeLineNum, "linenum", CommandCompletions::eNoCompletion, { NULL, false }, "Line number in a source file." },
1046 { eArgTypeLogCategory, "log-category", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a category within a log channel, e.g. all (try \"log list\" to see a list of all channels and their categories." },
1047 { eArgTypeLogChannel, "log-channel", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a log channel, e.g. process.gdb-remote (try \"log list\" to see a list of all channels and their categories)." },
1048 { eArgTypeMethod, "method", CommandCompletions::eNoCompletion, { NULL, false }, "A C++ method name." },
1049 { eArgTypeName, "name", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
1050 { eArgTypeNewPathPrefix, "new-path-prefix", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
1051 { eArgTypeNumLines, "num-lines", CommandCompletions::eNoCompletion, { NULL, false }, "The number of lines to use." },
1052 { eArgTypeNumberPerLine, "number-per-line", CommandCompletions::eNoCompletion, { NULL, false }, "The number of items per line to display." },
1053 { eArgTypeOffset, "offset", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
1054 { eArgTypeOldPathPrefix, "old-path-prefix", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
1055 { eArgTypeOneLiner, "one-line-command", CommandCompletions::eNoCompletion, { NULL, false }, "A command that is entered as a single line of text." },
Enrico Granata9ae9fd32011-07-07 15:49:54 +00001056 { eArgTypePid, "pid", CommandCompletions::eNoCompletion, { NULL, false }, "The process ID number." },
1057 { eArgTypePlugin, "plugin", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
1058 { eArgTypeProcessName, "process-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of the process." },
Enrico Granata91544802011-09-06 19:20:51 +00001059 { eArgTypePythonClass, "python-class", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a Python class." },
1060 { eArgTypePythonFunction, "python-function", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a Python function." },
1061 { eArgTypePythonScript, "python-script", CommandCompletions::eNoCompletion, { NULL, false }, "Source code written in Python." },
Enrico Granata9ae9fd32011-07-07 15:49:54 +00001062 { eArgTypeQueueName, "queue-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of the thread queue." },
Jim Ingham811708c2012-08-23 23:37:31 +00001063 { eArgTypeRegisterName, "register-name", CommandCompletions::eNoCompletion, { RegisterNameHelpTextCallback, true }, NULL },
Enrico Granata9ae9fd32011-07-07 15:49:54 +00001064 { eArgTypeRegularExpression, "regular-expression", CommandCompletions::eNoCompletion, { NULL, false }, "A regular expression." },
1065 { eArgTypeRunArgs, "run-args", CommandCompletions::eNoCompletion, { NULL, false }, "Arguments to be passed to the target program when it starts executing." },
1066 { eArgTypeRunMode, "run-mode", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
Enrico Granata6010ace2011-11-07 22:57:04 +00001067 { eArgTypeScriptedCommandSynchronicity, "script-cmd-synchronicity", CommandCompletions::eNoCompletion, { NULL, false }, "The synchronicity to use to run scripted commands with regard to LLDB event system." },
Enrico Granata9ae9fd32011-07-07 15:49:54 +00001068 { eArgTypeScriptLang, "script-language", CommandCompletions::eNoCompletion, { NULL, false }, "The scripting language to be used for script-based commands. Currently only Python is valid." },
1069 { eArgTypeSearchWord, "search-word", CommandCompletions::eNoCompletion, { NULL, false }, "The word for which you wish to search for information about." },
1070 { eArgTypeSelector, "selector", CommandCompletions::eNoCompletion, { NULL, false }, "An Objective-C selector name." },
1071 { eArgTypeSettingIndex, "setting-index", CommandCompletions::eNoCompletion, { NULL, false }, "An index into a settings variable that is an array (try 'settings list' to see all the possible settings variables and their types)." },
1072 { eArgTypeSettingKey, "setting-key", CommandCompletions::eNoCompletion, { NULL, false }, "A key into a settings variables that is a dictionary (try 'settings list' to see all the possible settings variables and their types)." },
1073 { eArgTypeSettingPrefix, "setting-prefix", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a settable internal debugger variable up to a dot ('.'), e.g. 'target.process.'" },
1074 { eArgTypeSettingVariableName, "setting-variable-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a settable internal debugger variable. Type 'settings list' to see a complete list of such variables." },
1075 { eArgTypeShlibName, "shlib-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a shared library." },
1076 { eArgTypeSourceFile, "source-file", CommandCompletions::eSourceFileCompletion, { NULL, false }, "The name of a source file.." },
1077 { eArgTypeSortOrder, "sort-order", CommandCompletions::eNoCompletion, { NULL, false }, "Specify a sort order when dumping lists." },
1078 { eArgTypeStartAddress, "start-address", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
1079 { eArgTypeSummaryString, "summary-string", CommandCompletions::eNoCompletion, { SummaryStringHelpTextCallback, true }, NULL },
1080 { eArgTypeSymbol, "symbol", CommandCompletions::eSymbolCompletion, { NULL, false }, "Any symbol name (function name, variable, argument, etc.)" },
1081 { eArgTypeThreadID, "thread-id", CommandCompletions::eNoCompletion, { NULL, false }, "Thread ID number." },
1082 { eArgTypeThreadIndex, "thread-index", CommandCompletions::eNoCompletion, { NULL, false }, "Index into the process' list of threads." },
1083 { eArgTypeThreadName, "thread-name", CommandCompletions::eNoCompletion, { NULL, false }, "The thread's name." },
Johnny Chen309c89d2011-07-14 22:20:12 +00001084 { eArgTypeUnsignedInteger, "unsigned-integer", CommandCompletions::eNoCompletion, { NULL, false }, "An unsigned integer." },
Enrico Granata9ae9fd32011-07-07 15:49:54 +00001085 { eArgTypeUnixSignal, "unix-signal", CommandCompletions::eNoCompletion, { NULL, false }, "A valid Unix signal name or number (e.g. SIGKILL, KILL or 9)." },
1086 { eArgTypeVarName, "variable-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a variable in your program." },
1087 { eArgTypeValue, "value", CommandCompletions::eNoCompletion, { NULL, false }, "A value could be anything, depending on where and how it is used." },
1088 { eArgTypeWidth, "width", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
1089 { eArgTypeNone, "none", CommandCompletions::eNoCompletion, { NULL, false }, "No help available for this." },
Johnny Chen58dba3c2011-09-09 23:25:26 +00001090 { eArgTypePlatform, "platform-name", CommandCompletions::ePlatformPluginCompletion, { NULL, false }, "The name of an installed platform plug-in . Type 'platform list' to see a complete list of installed platforms." },
Johnny Chencacedfb2011-09-22 22:34:09 +00001091 { eArgTypeWatchpointID, "watchpt-id", CommandCompletions::eNoCompletion, { NULL, false }, "Watchpoint IDs are positive integers." },
1092 { eArgTypeWatchpointIDRange, "watchpt-id-list", CommandCompletions::eNoCompletion, { NULL, false }, "For example, '1-3' or '1 to 3'." },
Johnny Chen34bbf852011-09-12 23:38:44 +00001093 { eArgTypeWatchType, "watch-type", CommandCompletions::eNoCompletion, { NULL, false }, "Specify the type for a watchpoint." }
Caroline Ticefb355112010-10-01 17:46:38 +00001094};
1095
1096const CommandObject::ArgumentTableEntry*
1097CommandObject::GetArgumentTable ()
1098{
Greg Claytonaa378b12011-02-20 02:15:07 +00001099 // If this assertion fires, then the table above is out of date with the CommandArgumentType enumeration
1100 assert ((sizeof (CommandObject::g_arguments_data) / sizeof (CommandObject::ArgumentTableEntry)) == eArgTypeLastArg);
Caroline Ticefb355112010-10-01 17:46:38 +00001101 return CommandObject::g_arguments_data;
1102}
1103
1104