130fdc8d8SChris Lattner //===-- CommandObject.cpp ---------------------------------------*- C++ -*-===//
230fdc8d8SChris Lattner //
330fdc8d8SChris Lattner //                     The LLVM Compiler Infrastructure
430fdc8d8SChris Lattner //
530fdc8d8SChris Lattner // This file is distributed under the University of Illinois Open Source
630fdc8d8SChris Lattner // License. See LICENSE.TXT for details.
730fdc8d8SChris Lattner //
830fdc8d8SChris Lattner //===----------------------------------------------------------------------===//
930fdc8d8SChris Lattner 
1030fdc8d8SChris Lattner #include "lldb/Interpreter/CommandObject.h"
1130fdc8d8SChris Lattner 
1230fdc8d8SChris Lattner #include <string>
1330fdc8d8SChris Lattner #include <map>
1430fdc8d8SChris Lattner 
1530fdc8d8SChris Lattner #include <getopt.h>
1630fdc8d8SChris Lattner #include <stdlib.h>
1730fdc8d8SChris Lattner #include <ctype.h>
1830fdc8d8SChris Lattner 
1930fdc8d8SChris Lattner #include "lldb/Core/Address.h"
2040af72e1SJim Ingham #include "lldb/Interpreter/Options.h"
2130fdc8d8SChris Lattner 
2230fdc8d8SChris Lattner // These are for the Sourcename completers.
2330fdc8d8SChris Lattner // FIXME: Make a separate file for the completers.
2453239f00SGreg Clayton #include "lldb/Host/FileSpec.h"
2530fdc8d8SChris Lattner #include "lldb/Core/FileSpecList.h"
2630fdc8d8SChris Lattner #include "lldb/Target/Process.h"
2730fdc8d8SChris Lattner #include "lldb/Target/Target.h"
2830fdc8d8SChris Lattner 
2930fdc8d8SChris Lattner #include "lldb/Interpreter/CommandInterpreter.h"
3030fdc8d8SChris Lattner #include "lldb/Interpreter/CommandReturnObject.h"
3130fdc8d8SChris Lattner #include "lldb/Interpreter/ScriptInterpreter.h"
3230fdc8d8SChris Lattner #include "lldb/Interpreter/ScriptInterpreterPython.h"
3330fdc8d8SChris Lattner 
3430fdc8d8SChris Lattner using namespace lldb;
3530fdc8d8SChris Lattner using namespace lldb_private;
3630fdc8d8SChris Lattner 
3730fdc8d8SChris Lattner //-------------------------------------------------------------------------
3830fdc8d8SChris Lattner // CommandObject
3930fdc8d8SChris Lattner //-------------------------------------------------------------------------
4030fdc8d8SChris Lattner 
41a7015092SGreg Clayton CommandObject::CommandObject
42a7015092SGreg Clayton (
43a7015092SGreg Clayton     CommandInterpreter &interpreter,
44a7015092SGreg Clayton     const char *name,
45a7015092SGreg Clayton     const char *help,
46a7015092SGreg Clayton     const char *syntax,
47a7015092SGreg Clayton     uint32_t flags
48a7015092SGreg Clayton ) :
49a7015092SGreg Clayton     m_interpreter (interpreter),
5030fdc8d8SChris Lattner     m_cmd_name (name),
5130fdc8d8SChris Lattner     m_cmd_help_short (),
5230fdc8d8SChris Lattner     m_cmd_help_long (),
5330fdc8d8SChris Lattner     m_cmd_syntax (),
54279a6c26SJim Ingham     m_is_alias (false),
55e139cf23SCaroline Tice     m_flags (flags),
56e139cf23SCaroline Tice     m_arguments()
5730fdc8d8SChris Lattner {
5830fdc8d8SChris Lattner     if (help && help[0])
5930fdc8d8SChris Lattner         m_cmd_help_short = help;
6030fdc8d8SChris Lattner     if (syntax && syntax[0])
6130fdc8d8SChris Lattner         m_cmd_syntax = syntax;
6230fdc8d8SChris Lattner }
6330fdc8d8SChris Lattner 
6430fdc8d8SChris Lattner CommandObject::~CommandObject ()
6530fdc8d8SChris Lattner {
6630fdc8d8SChris Lattner }
6730fdc8d8SChris Lattner 
6830fdc8d8SChris Lattner const char *
6930fdc8d8SChris Lattner CommandObject::GetHelp ()
7030fdc8d8SChris Lattner {
7130fdc8d8SChris Lattner     return m_cmd_help_short.c_str();
7230fdc8d8SChris Lattner }
7330fdc8d8SChris Lattner 
7430fdc8d8SChris Lattner const char *
7530fdc8d8SChris Lattner CommandObject::GetHelpLong ()
7630fdc8d8SChris Lattner {
7730fdc8d8SChris Lattner     return m_cmd_help_long.c_str();
7830fdc8d8SChris Lattner }
7930fdc8d8SChris Lattner 
8030fdc8d8SChris Lattner const char *
8130fdc8d8SChris Lattner CommandObject::GetSyntax ()
8230fdc8d8SChris Lattner {
83e139cf23SCaroline Tice     if (m_cmd_syntax.length() == 0)
84e139cf23SCaroline Tice     {
85e139cf23SCaroline Tice         StreamString syntax_str;
86e139cf23SCaroline Tice         syntax_str.Printf ("%s", GetCommandName());
87e139cf23SCaroline Tice         if (GetOptions() != NULL)
88e139cf23SCaroline Tice             syntax_str.Printf (" <cmd-options>");
89e139cf23SCaroline Tice         if (m_arguments.size() > 0)
90e139cf23SCaroline Tice         {
91e139cf23SCaroline Tice             syntax_str.Printf (" ");
92e139cf23SCaroline Tice             GetFormattedCommandArguments (syntax_str);
93e139cf23SCaroline Tice         }
94e139cf23SCaroline Tice         m_cmd_syntax = syntax_str.GetData ();
95e139cf23SCaroline Tice     }
96e139cf23SCaroline Tice 
9730fdc8d8SChris Lattner     return m_cmd_syntax.c_str();
9830fdc8d8SChris Lattner }
9930fdc8d8SChris Lattner 
10030fdc8d8SChris Lattner const char *
10130fdc8d8SChris Lattner CommandObject::Translate ()
10230fdc8d8SChris Lattner {
10330fdc8d8SChris Lattner     //return m_cmd_func_name.c_str();
10430fdc8d8SChris Lattner     return "This function is currently not implemented.";
10530fdc8d8SChris Lattner }
10630fdc8d8SChris Lattner 
10730fdc8d8SChris Lattner const char *
10830fdc8d8SChris Lattner CommandObject::GetCommandName ()
10930fdc8d8SChris Lattner {
11030fdc8d8SChris Lattner     return m_cmd_name.c_str();
11130fdc8d8SChris Lattner }
11230fdc8d8SChris Lattner 
11330fdc8d8SChris Lattner void
11430fdc8d8SChris Lattner CommandObject::SetCommandName (const char *name)
11530fdc8d8SChris Lattner {
11630fdc8d8SChris Lattner     m_cmd_name = name;
11730fdc8d8SChris Lattner }
11830fdc8d8SChris Lattner 
11930fdc8d8SChris Lattner void
12030fdc8d8SChris Lattner CommandObject::SetHelp (const char *cstr)
12130fdc8d8SChris Lattner {
12230fdc8d8SChris Lattner     m_cmd_help_short = cstr;
12330fdc8d8SChris Lattner }
12430fdc8d8SChris Lattner 
12530fdc8d8SChris Lattner void
12630fdc8d8SChris Lattner CommandObject::SetHelpLong (const char *cstr)
12730fdc8d8SChris Lattner {
12830fdc8d8SChris Lattner     m_cmd_help_long = cstr;
12930fdc8d8SChris Lattner }
13030fdc8d8SChris Lattner 
13130fdc8d8SChris Lattner void
13230fdc8d8SChris Lattner CommandObject::SetSyntax (const char *cstr)
13330fdc8d8SChris Lattner {
13430fdc8d8SChris Lattner     m_cmd_syntax = cstr;
13530fdc8d8SChris Lattner }
13630fdc8d8SChris Lattner 
13730fdc8d8SChris Lattner Options *
13830fdc8d8SChris Lattner CommandObject::GetOptions ()
13930fdc8d8SChris Lattner {
14030fdc8d8SChris Lattner     // By default commands don't have options unless this virtual function
14130fdc8d8SChris Lattner     // is overridden by base classes.
14230fdc8d8SChris Lattner     return NULL;
14330fdc8d8SChris Lattner }
14430fdc8d8SChris Lattner 
14530fdc8d8SChris Lattner Flags&
14630fdc8d8SChris Lattner CommandObject::GetFlags()
14730fdc8d8SChris Lattner {
14830fdc8d8SChris Lattner     return m_flags;
14930fdc8d8SChris Lattner }
15030fdc8d8SChris Lattner 
15130fdc8d8SChris Lattner const Flags&
15230fdc8d8SChris Lattner CommandObject::GetFlags() const
15330fdc8d8SChris Lattner {
15430fdc8d8SChris Lattner     return m_flags;
15530fdc8d8SChris Lattner }
15630fdc8d8SChris Lattner 
15730fdc8d8SChris Lattner bool
15830fdc8d8SChris Lattner CommandObject::ExecuteCommandString
15930fdc8d8SChris Lattner (
16030fdc8d8SChris Lattner     const char *command_line,
16130fdc8d8SChris Lattner     CommandReturnObject &result
16230fdc8d8SChris Lattner )
16330fdc8d8SChris Lattner {
16430fdc8d8SChris Lattner     Args command_args(command_line);
165a7015092SGreg Clayton     return ExecuteWithOptions (command_args, result);
16630fdc8d8SChris Lattner }
16730fdc8d8SChris Lattner 
16830fdc8d8SChris Lattner bool
16930fdc8d8SChris Lattner CommandObject::ParseOptions
17030fdc8d8SChris Lattner (
17130fdc8d8SChris Lattner     Args& args,
17230fdc8d8SChris Lattner     CommandReturnObject &result
17330fdc8d8SChris Lattner )
17430fdc8d8SChris Lattner {
17530fdc8d8SChris Lattner     // See if the subclass has options?
17630fdc8d8SChris Lattner     Options *options = GetOptions();
17730fdc8d8SChris Lattner     if (options != NULL)
17830fdc8d8SChris Lattner     {
17930fdc8d8SChris Lattner         Error error;
180f6b8b581SGreg Clayton         options->NotifyOptionParsingStarting();
18130fdc8d8SChris Lattner 
18230fdc8d8SChris Lattner         // ParseOptions calls getopt_long, which always skips the zero'th item in the array and starts at position 1,
18330fdc8d8SChris Lattner         // so we need to push a dummy value into position zero.
18430fdc8d8SChris Lattner         args.Unshift("dummy_string");
18530fdc8d8SChris Lattner         error = args.ParseOptions (*options);
18630fdc8d8SChris Lattner 
18730fdc8d8SChris Lattner         // The "dummy_string" will have already been removed by ParseOptions,
18830fdc8d8SChris Lattner         // so no need to remove it.
18930fdc8d8SChris Lattner 
190f6b8b581SGreg Clayton         if (error.Success())
191f6b8b581SGreg Clayton             error = options->NotifyOptionParsingFinished();
192f6b8b581SGreg Clayton 
193f6b8b581SGreg Clayton         if (error.Success())
194f6b8b581SGreg Clayton         {
195f6b8b581SGreg Clayton             if (options->VerifyOptions (result))
196f6b8b581SGreg Clayton                 return true;
197f6b8b581SGreg Clayton         }
198f6b8b581SGreg Clayton         else
19930fdc8d8SChris Lattner         {
20030fdc8d8SChris Lattner             const char *error_cstr = error.AsCString();
20130fdc8d8SChris Lattner             if (error_cstr)
20230fdc8d8SChris Lattner             {
20330fdc8d8SChris Lattner                 // We got an error string, lets use that
20430fdc8d8SChris Lattner                 result.GetErrorStream().PutCString(error_cstr);
20530fdc8d8SChris Lattner             }
20630fdc8d8SChris Lattner             else
20730fdc8d8SChris Lattner             {
20830fdc8d8SChris Lattner                 // No error string, output the usage information into result
209eb0103f2SGreg Clayton                 options->GenerateOptionUsage (result.GetErrorStream(), this);
21030fdc8d8SChris Lattner             }
211f6b8b581SGreg Clayton         }
21230fdc8d8SChris Lattner         result.SetStatus (eReturnStatusFailed);
21330fdc8d8SChris Lattner         return false;
21430fdc8d8SChris Lattner     }
21530fdc8d8SChris Lattner     return true;
21630fdc8d8SChris Lattner }
21730fdc8d8SChris Lattner bool
218a7015092SGreg Clayton CommandObject::ExecuteWithOptions (Args& args, CommandReturnObject &result)
21930fdc8d8SChris Lattner {
22030fdc8d8SChris Lattner     for (size_t i = 0; i < args.GetArgumentCount();  ++i)
22130fdc8d8SChris Lattner     {
22230fdc8d8SChris Lattner         const char *tmp_str = args.GetArgumentAtIndex (i);
22330fdc8d8SChris Lattner         if (tmp_str[0] == '`')  // back-quote
224a7015092SGreg Clayton             args.ReplaceArgumentAtIndex (i, m_interpreter.ProcessEmbeddedScriptCommands (tmp_str));
22530fdc8d8SChris Lattner     }
22630fdc8d8SChris Lattner 
227b766a73dSGreg Clayton     if (GetFlags().AnySet (CommandObject::eFlagProcessMustBeLaunched | CommandObject::eFlagProcessMustBePaused))
228b766a73dSGreg Clayton     {
2298b82f087SGreg Clayton         Process *process = m_interpreter.GetExecutionContext().process;
23030fdc8d8SChris Lattner         if (process == NULL)
23130fdc8d8SChris Lattner         {
23230fdc8d8SChris Lattner             result.AppendError ("Process must exist.");
23330fdc8d8SChris Lattner             result.SetStatus (eReturnStatusFailed);
23430fdc8d8SChris Lattner             return false;
23530fdc8d8SChris Lattner         }
23630fdc8d8SChris Lattner         else
23730fdc8d8SChris Lattner         {
23830fdc8d8SChris Lattner             StateType state = process->GetState();
23930fdc8d8SChris Lattner 
24030fdc8d8SChris Lattner             switch (state)
24130fdc8d8SChris Lattner             {
2427a5388bfSGreg Clayton             case eStateInvalid:
24330fdc8d8SChris Lattner             case eStateSuspended:
24430fdc8d8SChris Lattner             case eStateCrashed:
24530fdc8d8SChris Lattner             case eStateStopped:
24630fdc8d8SChris Lattner                 break;
24730fdc8d8SChris Lattner 
248b766a73dSGreg Clayton             case eStateConnected:
249b766a73dSGreg Clayton             case eStateAttaching:
250b766a73dSGreg Clayton             case eStateLaunching:
25130fdc8d8SChris Lattner             case eStateDetached:
25230fdc8d8SChris Lattner             case eStateExited:
25330fdc8d8SChris Lattner             case eStateUnloaded:
25473b472d4SGreg Clayton                 if (GetFlags().Test(CommandObject::eFlagProcessMustBeLaunched))
25530fdc8d8SChris Lattner                 {
25630fdc8d8SChris Lattner                     result.AppendError ("Process must be launched.");
25730fdc8d8SChris Lattner                     result.SetStatus (eReturnStatusFailed);
25830fdc8d8SChris Lattner                     return false;
25930fdc8d8SChris Lattner                 }
26030fdc8d8SChris Lattner                 break;
26130fdc8d8SChris Lattner 
26230fdc8d8SChris Lattner             case eStateRunning:
26330fdc8d8SChris Lattner             case eStateStepping:
26473b472d4SGreg Clayton                 if (GetFlags().Test(CommandObject::eFlagProcessMustBePaused))
26530fdc8d8SChris Lattner                 {
26630fdc8d8SChris Lattner                     result.AppendError ("Process is running.  Use 'process interrupt' to pause execution.");
26730fdc8d8SChris Lattner                     result.SetStatus (eReturnStatusFailed);
26830fdc8d8SChris Lattner                     return false;
26930fdc8d8SChris Lattner                 }
27030fdc8d8SChris Lattner             }
27130fdc8d8SChris Lattner         }
272b766a73dSGreg Clayton     }
27330fdc8d8SChris Lattner 
274a7015092SGreg Clayton     if (!ParseOptions (args, result))
27530fdc8d8SChris Lattner         return false;
27630fdc8d8SChris Lattner 
27730fdc8d8SChris Lattner     // Call the command-specific version of 'Execute', passing it the already processed arguments.
278a7015092SGreg Clayton     return Execute (args, result);
27930fdc8d8SChris Lattner }
28030fdc8d8SChris Lattner 
28130fdc8d8SChris Lattner class CommandDictCommandPartialMatch
28230fdc8d8SChris Lattner {
28330fdc8d8SChris Lattner     public:
28430fdc8d8SChris Lattner         CommandDictCommandPartialMatch (const char *match_str)
28530fdc8d8SChris Lattner         {
28630fdc8d8SChris Lattner             m_match_str = match_str;
28730fdc8d8SChris Lattner         }
28830fdc8d8SChris Lattner         bool operator() (const std::pair<std::string, lldb::CommandObjectSP> map_element) const
28930fdc8d8SChris Lattner         {
29030fdc8d8SChris Lattner             // A NULL or empty string matches everything.
29130fdc8d8SChris Lattner             if (m_match_str == NULL || *m_match_str == '\0')
29230fdc8d8SChris Lattner                 return 1;
29330fdc8d8SChris Lattner 
29430fdc8d8SChris Lattner             size_t found = map_element.first.find (m_match_str, 0);
29530fdc8d8SChris Lattner             if (found == std::string::npos)
29630fdc8d8SChris Lattner                 return 0;
29730fdc8d8SChris Lattner             else
29830fdc8d8SChris Lattner                 return found == 0;
29930fdc8d8SChris Lattner         }
30030fdc8d8SChris Lattner 
30130fdc8d8SChris Lattner     private:
30230fdc8d8SChris Lattner         const char *m_match_str;
30330fdc8d8SChris Lattner };
30430fdc8d8SChris Lattner 
30530fdc8d8SChris Lattner int
30630fdc8d8SChris Lattner CommandObject::AddNamesMatchingPartialString (CommandObject::CommandMap &in_map, const char *cmd_str,
30730fdc8d8SChris Lattner                                               StringList &matches)
30830fdc8d8SChris Lattner {
30930fdc8d8SChris Lattner     int number_added = 0;
31030fdc8d8SChris Lattner     CommandDictCommandPartialMatch matcher(cmd_str);
31130fdc8d8SChris Lattner 
31230fdc8d8SChris Lattner     CommandObject::CommandMap::iterator matching_cmds = std::find_if (in_map.begin(), in_map.end(), matcher);
31330fdc8d8SChris Lattner 
31430fdc8d8SChris Lattner     while (matching_cmds != in_map.end())
31530fdc8d8SChris Lattner     {
31630fdc8d8SChris Lattner         ++number_added;
31730fdc8d8SChris Lattner         matches.AppendString((*matching_cmds).first.c_str());
31830fdc8d8SChris Lattner         matching_cmds = std::find_if (++matching_cmds, in_map.end(), matcher);;
31930fdc8d8SChris Lattner     }
32030fdc8d8SChris Lattner     return number_added;
32130fdc8d8SChris Lattner }
32230fdc8d8SChris Lattner 
32330fdc8d8SChris Lattner int
32430fdc8d8SChris Lattner CommandObject::HandleCompletion
32530fdc8d8SChris Lattner (
32630fdc8d8SChris Lattner     Args &input,
32730fdc8d8SChris Lattner     int &cursor_index,
32830fdc8d8SChris Lattner     int &cursor_char_position,
32930fdc8d8SChris Lattner     int match_start_point,
33030fdc8d8SChris Lattner     int max_return_elements,
331558ce124SJim Ingham     bool &word_complete,
33230fdc8d8SChris Lattner     StringList &matches
33330fdc8d8SChris Lattner )
33430fdc8d8SChris Lattner {
33530fdc8d8SChris Lattner     if (WantsRawCommandString())
33630fdc8d8SChris Lattner     {
33730fdc8d8SChris Lattner         // FIXME: Abstract telling the completion to insert the completion character.
33830fdc8d8SChris Lattner         matches.Clear();
33930fdc8d8SChris Lattner         return -1;
34030fdc8d8SChris Lattner     }
34130fdc8d8SChris Lattner     else
34230fdc8d8SChris Lattner     {
34330fdc8d8SChris Lattner         // Can we do anything generic with the options?
34430fdc8d8SChris Lattner         Options *cur_options = GetOptions();
34530fdc8d8SChris Lattner         CommandReturnObject result;
34630fdc8d8SChris Lattner         OptionElementVector opt_element_vector;
34730fdc8d8SChris Lattner 
34830fdc8d8SChris Lattner         if (cur_options != NULL)
34930fdc8d8SChris Lattner         {
35030fdc8d8SChris Lattner             // Re-insert the dummy command name string which will have been
35130fdc8d8SChris Lattner             // stripped off:
35230fdc8d8SChris Lattner             input.Unshift ("dummy-string");
35330fdc8d8SChris Lattner             cursor_index++;
35430fdc8d8SChris Lattner 
35530fdc8d8SChris Lattner 
35630fdc8d8SChris Lattner             // I stick an element on the end of the input, because if the last element is
35730fdc8d8SChris Lattner             // option that requires an argument, getopt_long will freak out.
35830fdc8d8SChris Lattner 
35930fdc8d8SChris Lattner             input.AppendArgument ("<FAKE-VALUE>");
36030fdc8d8SChris Lattner 
361d43e0094SJim Ingham             input.ParseArgsForCompletion (*cur_options, opt_element_vector, cursor_index);
36230fdc8d8SChris Lattner 
36330fdc8d8SChris Lattner             input.DeleteArgumentAtIndex(input.GetArgumentCount() - 1);
36430fdc8d8SChris Lattner 
36530fdc8d8SChris Lattner             bool handled_by_options;
366eb0103f2SGreg Clayton             handled_by_options = cur_options->HandleOptionCompletion (input,
36730fdc8d8SChris Lattner                                                                       opt_element_vector,
36830fdc8d8SChris Lattner                                                                       cursor_index,
36930fdc8d8SChris Lattner                                                                       cursor_char_position,
37030fdc8d8SChris Lattner                                                                       match_start_point,
37130fdc8d8SChris Lattner                                                                       max_return_elements,
372558ce124SJim Ingham                                                                       word_complete,
37330fdc8d8SChris Lattner                                                                       matches);
37430fdc8d8SChris Lattner             if (handled_by_options)
37530fdc8d8SChris Lattner                 return matches.GetSize();
37630fdc8d8SChris Lattner         }
37730fdc8d8SChris Lattner 
37830fdc8d8SChris Lattner         // If we got here, the last word is not an option or an option argument.
379a7015092SGreg Clayton         return HandleArgumentCompletion (input,
38030fdc8d8SChris Lattner                                          cursor_index,
38130fdc8d8SChris Lattner                                          cursor_char_position,
38230fdc8d8SChris Lattner                                          opt_element_vector,
38330fdc8d8SChris Lattner                                          match_start_point,
38430fdc8d8SChris Lattner                                          max_return_elements,
385558ce124SJim Ingham                                          word_complete,
38630fdc8d8SChris Lattner                                          matches);
38730fdc8d8SChris Lattner     }
38830fdc8d8SChris Lattner }
38930fdc8d8SChris Lattner 
39030fdc8d8SChris Lattner bool
391a7015092SGreg Clayton CommandObject::HelpTextContainsWord (const char *search_word)
39230fdc8d8SChris Lattner {
39330fdc8d8SChris Lattner     const char *short_help;
39430fdc8d8SChris Lattner     const char *long_help;
39530fdc8d8SChris Lattner     const char *syntax_help;
39630fdc8d8SChris Lattner     std::string options_usage_help;
39730fdc8d8SChris Lattner 
39830fdc8d8SChris Lattner 
39930fdc8d8SChris Lattner     bool found_word = false;
40030fdc8d8SChris Lattner 
40130fdc8d8SChris Lattner     short_help = GetHelp();
40230fdc8d8SChris Lattner     long_help = GetHelpLong();
40330fdc8d8SChris Lattner     syntax_help = GetSyntax();
40430fdc8d8SChris Lattner 
4054b6fbf37SCaroline Tice     if (strcasestr (short_help, search_word))
40630fdc8d8SChris Lattner         found_word = true;
4074b6fbf37SCaroline Tice     else if (strcasestr (long_help, search_word))
40830fdc8d8SChris Lattner         found_word = true;
4094b6fbf37SCaroline Tice     else if (strcasestr (syntax_help, search_word))
41030fdc8d8SChris Lattner         found_word = true;
41130fdc8d8SChris Lattner 
41230fdc8d8SChris Lattner     if (!found_word
41330fdc8d8SChris Lattner         && GetOptions() != NULL)
41430fdc8d8SChris Lattner     {
41530fdc8d8SChris Lattner         StreamString usage_help;
416eb0103f2SGreg Clayton         GetOptions()->GenerateOptionUsage (usage_help, this);
41730fdc8d8SChris Lattner         if (usage_help.GetSize() > 0)
41830fdc8d8SChris Lattner         {
41930fdc8d8SChris Lattner             const char *usage_text = usage_help.GetData();
4204b6fbf37SCaroline Tice             if (strcasestr (usage_text, search_word))
42130fdc8d8SChris Lattner               found_word = true;
42230fdc8d8SChris Lattner         }
42330fdc8d8SChris Lattner     }
42430fdc8d8SChris Lattner 
42530fdc8d8SChris Lattner     return found_word;
42630fdc8d8SChris Lattner }
427e139cf23SCaroline Tice 
428e139cf23SCaroline Tice int
429e139cf23SCaroline Tice CommandObject::GetNumArgumentEntries  ()
430e139cf23SCaroline Tice {
431e139cf23SCaroline Tice     return m_arguments.size();
432e139cf23SCaroline Tice }
433e139cf23SCaroline Tice 
434e139cf23SCaroline Tice CommandObject::CommandArgumentEntry *
435e139cf23SCaroline Tice CommandObject::GetArgumentEntryAtIndex (int idx)
436e139cf23SCaroline Tice {
437e139cf23SCaroline Tice     if (idx < m_arguments.size())
438e139cf23SCaroline Tice         return &(m_arguments[idx]);
439e139cf23SCaroline Tice 
440e139cf23SCaroline Tice     return NULL;
441e139cf23SCaroline Tice }
442e139cf23SCaroline Tice 
443e139cf23SCaroline Tice CommandObject::ArgumentTableEntry *
444e139cf23SCaroline Tice CommandObject::FindArgumentDataByType (CommandArgumentType arg_type)
445e139cf23SCaroline Tice {
446e139cf23SCaroline Tice     const ArgumentTableEntry *table = CommandObject::GetArgumentTable();
447e139cf23SCaroline Tice 
448e139cf23SCaroline Tice     for (int i = 0; i < eArgTypeLastArg; ++i)
449e139cf23SCaroline Tice         if (table[i].arg_type == arg_type)
450e139cf23SCaroline Tice             return (ArgumentTableEntry *) &(table[i]);
451e139cf23SCaroline Tice 
452e139cf23SCaroline Tice     return NULL;
453e139cf23SCaroline Tice }
454e139cf23SCaroline Tice 
455e139cf23SCaroline Tice void
456e139cf23SCaroline Tice CommandObject::GetArgumentHelp (Stream &str, CommandArgumentType arg_type, CommandInterpreter &interpreter)
457e139cf23SCaroline Tice {
458e139cf23SCaroline Tice     const ArgumentTableEntry* table = CommandObject::GetArgumentTable();
459e139cf23SCaroline Tice     ArgumentTableEntry *entry = (ArgumentTableEntry *) &(table[arg_type]);
460e139cf23SCaroline Tice 
461e139cf23SCaroline Tice     // The table is *supposed* to be kept in arg_type order, but someone *could* have messed it up...
462e139cf23SCaroline Tice 
463e139cf23SCaroline Tice     if (entry->arg_type != arg_type)
464e139cf23SCaroline Tice         entry = CommandObject::FindArgumentDataByType (arg_type);
465e139cf23SCaroline Tice 
466e139cf23SCaroline Tice     if (!entry)
467e139cf23SCaroline Tice         return;
468e139cf23SCaroline Tice 
469e139cf23SCaroline Tice     StreamString name_str;
470e139cf23SCaroline Tice     name_str.Printf ("<%s>", entry->arg_name);
471e139cf23SCaroline Tice 
472*fc7a7f3bSEnrico Granata     if (entry->help_function)
47382a7d983SEnrico Granata     {
474*fc7a7f3bSEnrico Granata         const char* help_text = entry->help_function();
47582a7d983SEnrico Granata         if (!entry->help_function.self_formatting)
47682a7d983SEnrico Granata         {
47782a7d983SEnrico Granata             interpreter.OutputFormattedHelpText (str, name_str.GetData(), "--", help_text,
478e139cf23SCaroline Tice                                                  name_str.GetSize());
47982a7d983SEnrico Granata         }
48082a7d983SEnrico Granata         else
48182a7d983SEnrico Granata         {
48282a7d983SEnrico Granata             interpreter.OutputHelpText(str, name_str.GetData(), "--", help_text,
48382a7d983SEnrico Granata                                        name_str.GetSize());
48482a7d983SEnrico Granata         }
48582a7d983SEnrico Granata     }
486e139cf23SCaroline Tice     else
487e139cf23SCaroline Tice         interpreter.OutputFormattedHelpText (str, name_str.GetData(), "--", entry->help_text, name_str.GetSize());
488e139cf23SCaroline Tice }
489e139cf23SCaroline Tice 
490e139cf23SCaroline Tice const char *
491e139cf23SCaroline Tice CommandObject::GetArgumentName (CommandArgumentType arg_type)
492e139cf23SCaroline Tice {
493deaab222SCaroline Tice     ArgumentTableEntry *entry = (ArgumentTableEntry *) &(CommandObject::GetArgumentTable()[arg_type]);
494deaab222SCaroline Tice 
495deaab222SCaroline Tice     // The table is *supposed* to be kept in arg_type order, but someone *could* have messed it up...
496deaab222SCaroline Tice 
497deaab222SCaroline Tice     if (entry->arg_type != arg_type)
498deaab222SCaroline Tice         entry = CommandObject::FindArgumentDataByType (arg_type);
499deaab222SCaroline Tice 
500e6acf355SJohnny Chen     if (entry)
501deaab222SCaroline Tice         return entry->arg_name;
502e6acf355SJohnny Chen 
503e6acf355SJohnny Chen     StreamString str;
504e6acf355SJohnny Chen     str << "Arg name for type (" << arg_type << ") not in arg table!";
505e6acf355SJohnny Chen     return str.GetData();
506e139cf23SCaroline Tice }
507e139cf23SCaroline Tice 
508405fe67fSCaroline Tice bool
509e0d378b3SGreg Clayton CommandObject::IsPairType (ArgumentRepetitionType arg_repeat_type)
510405fe67fSCaroline Tice {
511405fe67fSCaroline Tice     if ((arg_repeat_type == eArgRepeatPairPlain)
512405fe67fSCaroline Tice         ||  (arg_repeat_type == eArgRepeatPairOptional)
513405fe67fSCaroline Tice         ||  (arg_repeat_type == eArgRepeatPairPlus)
514405fe67fSCaroline Tice         ||  (arg_repeat_type == eArgRepeatPairStar)
515405fe67fSCaroline Tice         ||  (arg_repeat_type == eArgRepeatPairRange)
516405fe67fSCaroline Tice         ||  (arg_repeat_type == eArgRepeatPairRangeOptional))
517405fe67fSCaroline Tice         return true;
518405fe67fSCaroline Tice 
519405fe67fSCaroline Tice     return false;
520405fe67fSCaroline Tice }
521405fe67fSCaroline Tice 
522e139cf23SCaroline Tice void
523e139cf23SCaroline Tice CommandObject::GetFormattedCommandArguments (Stream &str)
524e139cf23SCaroline Tice {
525e139cf23SCaroline Tice     int num_args = m_arguments.size();
526e139cf23SCaroline Tice     for (int i = 0; i < num_args; ++i)
527e139cf23SCaroline Tice     {
528e139cf23SCaroline Tice         if (i > 0)
529e139cf23SCaroline Tice             str.Printf (" ");
530e139cf23SCaroline Tice         CommandArgumentEntry arg_entry = m_arguments[i];
531e139cf23SCaroline Tice         int num_alternatives = arg_entry.size();
532405fe67fSCaroline Tice 
533405fe67fSCaroline Tice         if ((num_alternatives == 2)
534405fe67fSCaroline Tice             && IsPairType (arg_entry[0].arg_repetition))
535405fe67fSCaroline Tice         {
536405fe67fSCaroline Tice             const char *first_name = GetArgumentName (arg_entry[0].arg_type);
537405fe67fSCaroline Tice             const char *second_name = GetArgumentName (arg_entry[1].arg_type);
538405fe67fSCaroline Tice             switch (arg_entry[0].arg_repetition)
539405fe67fSCaroline Tice             {
540405fe67fSCaroline Tice                 case eArgRepeatPairPlain:
541405fe67fSCaroline Tice                     str.Printf ("<%s> <%s>", first_name, second_name);
542405fe67fSCaroline Tice                     break;
543405fe67fSCaroline Tice                 case eArgRepeatPairOptional:
544405fe67fSCaroline Tice                     str.Printf ("[<%s> <%s>]", first_name, second_name);
545405fe67fSCaroline Tice                     break;
546405fe67fSCaroline Tice                 case eArgRepeatPairPlus:
547405fe67fSCaroline Tice                     str.Printf ("<%s> <%s> [<%s> <%s> [...]]", first_name, second_name, first_name, second_name);
548405fe67fSCaroline Tice                     break;
549405fe67fSCaroline Tice                 case eArgRepeatPairStar:
550405fe67fSCaroline Tice                     str.Printf ("[<%s> <%s> [<%s> <%s> [...]]]", first_name, second_name, first_name, second_name);
551405fe67fSCaroline Tice                     break;
552405fe67fSCaroline Tice                 case eArgRepeatPairRange:
553405fe67fSCaroline Tice                     str.Printf ("<%s_1> <%s_1> ... <%s_n> <%s_n>", first_name, second_name, first_name, second_name);
554405fe67fSCaroline Tice                     break;
555405fe67fSCaroline Tice                 case eArgRepeatPairRangeOptional:
556405fe67fSCaroline Tice                     str.Printf ("[<%s_1> <%s_1> ... <%s_n> <%s_n>]", first_name, second_name, first_name, second_name);
557405fe67fSCaroline Tice                     break;
558ca1176aaSCaroline Tice                 // Explicitly test for all the rest of the cases, so if new types get added we will notice the
559ca1176aaSCaroline Tice                 // missing case statement(s).
560ca1176aaSCaroline Tice                 case eArgRepeatPlain:
561ca1176aaSCaroline Tice                 case eArgRepeatOptional:
562ca1176aaSCaroline Tice                 case eArgRepeatPlus:
563ca1176aaSCaroline Tice                 case eArgRepeatStar:
564ca1176aaSCaroline Tice                 case eArgRepeatRange:
565ca1176aaSCaroline Tice                     // These should not be reached, as they should fail the IsPairType test above.
566ca1176aaSCaroline Tice                     break;
567405fe67fSCaroline Tice             }
568405fe67fSCaroline Tice         }
569405fe67fSCaroline Tice         else
570405fe67fSCaroline Tice         {
571e139cf23SCaroline Tice             StreamString names;
572e139cf23SCaroline Tice             for (int j = 0; j < num_alternatives; ++j)
573e139cf23SCaroline Tice             {
574e139cf23SCaroline Tice                 if (j > 0)
575e139cf23SCaroline Tice                     names.Printf (" | ");
576e139cf23SCaroline Tice                 names.Printf ("%s", GetArgumentName (arg_entry[j].arg_type));
577e139cf23SCaroline Tice             }
578e139cf23SCaroline Tice             switch (arg_entry[0].arg_repetition)
579e139cf23SCaroline Tice             {
580e139cf23SCaroline Tice                 case eArgRepeatPlain:
581e139cf23SCaroline Tice                     str.Printf ("<%s>", names.GetData());
582e139cf23SCaroline Tice                     break;
583e139cf23SCaroline Tice                 case eArgRepeatPlus:
584e139cf23SCaroline Tice                     str.Printf ("<%s> [<%s> [...]]", names.GetData(), names.GetData());
585e139cf23SCaroline Tice                     break;
586e139cf23SCaroline Tice                 case eArgRepeatStar:
587e139cf23SCaroline Tice                     str.Printf ("[<%s> [<%s> [...]]]", names.GetData(), names.GetData());
588e139cf23SCaroline Tice                     break;
589e139cf23SCaroline Tice                 case eArgRepeatOptional:
590e139cf23SCaroline Tice                     str.Printf ("[<%s>]", names.GetData());
591e139cf23SCaroline Tice                     break;
592405fe67fSCaroline Tice                 case eArgRepeatRange:
593405fe67fSCaroline Tice                     str.Printf ("<%s_1> .. <%s_n>", names.GetData());
594ca1176aaSCaroline Tice                     break;
595ca1176aaSCaroline Tice                 // Explicitly test for all the rest of the cases, so if new types get added we will notice the
596ca1176aaSCaroline Tice                 // missing case statement(s).
597ca1176aaSCaroline Tice                 case eArgRepeatPairPlain:
598ca1176aaSCaroline Tice                 case eArgRepeatPairOptional:
599ca1176aaSCaroline Tice                 case eArgRepeatPairPlus:
600ca1176aaSCaroline Tice                 case eArgRepeatPairStar:
601ca1176aaSCaroline Tice                 case eArgRepeatPairRange:
602ca1176aaSCaroline Tice                 case eArgRepeatPairRangeOptional:
603ca1176aaSCaroline Tice                     // These should not be hit, as they should pass the IsPairType test above, and control should
604ca1176aaSCaroline Tice                     // have gone into the other branch of the if statement.
605ca1176aaSCaroline Tice                     break;
606405fe67fSCaroline Tice             }
607e139cf23SCaroline Tice         }
608e139cf23SCaroline Tice     }
609e139cf23SCaroline Tice }
610e139cf23SCaroline Tice 
6110c16aa6dSStephen Wilson CommandArgumentType
612e139cf23SCaroline Tice CommandObject::LookupArgumentName (const char *arg_name)
613e139cf23SCaroline Tice {
614e139cf23SCaroline Tice     CommandArgumentType return_type = eArgTypeLastArg;
615e139cf23SCaroline Tice 
616e139cf23SCaroline Tice     std::string arg_name_str (arg_name);
617e139cf23SCaroline Tice     size_t len = arg_name_str.length();
618e139cf23SCaroline Tice     if (arg_name[0] == '<'
619e139cf23SCaroline Tice         && arg_name[len-1] == '>')
620e139cf23SCaroline Tice         arg_name_str = arg_name_str.substr (1, len-2);
621e139cf23SCaroline Tice 
622e139cf23SCaroline Tice     for (int i = 0; i < eArgTypeLastArg; ++i)
623e139cf23SCaroline Tice         if (arg_name_str.compare (g_arguments_data[i].arg_name) == 0)
624e139cf23SCaroline Tice             return_type = g_arguments_data[i].arg_type;
625e139cf23SCaroline Tice 
626e139cf23SCaroline Tice     return return_type;
627e139cf23SCaroline Tice }
628e139cf23SCaroline Tice 
629e139cf23SCaroline Tice static const char *
630e139cf23SCaroline Tice BreakpointIDHelpTextCallback ()
631e139cf23SCaroline Tice {
632e139cf23SCaroline Tice     return "Breakpoint ID's consist major and minor numbers;  the major number corresponds to the single entity that was created with a 'breakpoint set' command; the minor numbers correspond to all the locations that were actually found/set based on the major breakpoint.  A full breakpoint ID might look like 3.14, meaning the 14th location set for the 3rd breakpoint.  You can specify all the locations of a breakpoint by just indicating the major breakpoint number. A valid breakpoint id consists either of just the major id number, or the major number, a dot, and the location number (e.g. 3 or 3.2 could both be valid breakpoint ids).";
633e139cf23SCaroline Tice }
634e139cf23SCaroline Tice 
635e139cf23SCaroline Tice static const char *
636e139cf23SCaroline Tice BreakpointIDRangeHelpTextCallback ()
637e139cf23SCaroline Tice {
638405fe67fSCaroline Tice     return "A 'breakpoint id list' is a manner of specifying multiple breakpoints. This can be done  through several mechanisms.  The easiest way is to just enter a space-separated list of breakpoint ids.  To specify all the breakpoint locations under a major breakpoint, you can use the major breakpoint number followed by '.*', eg. '5.*' means all the locations under breakpoint 5.  You can also indicate a range of breakpoints by using <start-bp-id> - <end-bp-id>.  The start-bp-id and end-bp-id for a range can be any valid breakpoint ids.  It is not legal, however, to specify a range using specific locations that cross major breakpoint numbers.  I.e. 3.2 - 3.7 is legal; 2 - 5 is legal; but 3.2 - 4.4 is not legal.";
639e139cf23SCaroline Tice }
640e139cf23SCaroline Tice 
6410a3958e0SEnrico Granata static const char *
6420a3958e0SEnrico Granata FormatHelpTextCallback ()
6430a3958e0SEnrico Granata {
64482a7d983SEnrico Granata 
64582a7d983SEnrico Granata     static char* help_text_ptr = NULL;
64682a7d983SEnrico Granata 
64782a7d983SEnrico Granata     if (help_text_ptr)
64882a7d983SEnrico Granata         return help_text_ptr;
64982a7d983SEnrico Granata 
6500a3958e0SEnrico Granata     StreamString sstr;
6510a3958e0SEnrico Granata     sstr << "One of the format names (or one-character names) that can be used to show a variable's value:\n";
6520a3958e0SEnrico Granata     for (Format f = eFormatDefault; f < kNumFormats; f = Format(f+1))
6530a3958e0SEnrico Granata     {
65482a7d983SEnrico Granata         if (f != eFormatDefault)
65582a7d983SEnrico Granata             sstr.PutChar('\n');
65682a7d983SEnrico Granata 
6570a3958e0SEnrico Granata         char format_char = FormatManager::GetFormatAsFormatChar(f);
6580a3958e0SEnrico Granata         if (format_char)
6590a3958e0SEnrico Granata             sstr.Printf("'%c' or ", format_char);
6600a3958e0SEnrico Granata 
66182a7d983SEnrico Granata         sstr.Printf ("\"%s\"", FormatManager::GetFormatAsCString(f));
6620a3958e0SEnrico Granata     }
6630a3958e0SEnrico Granata 
6640a3958e0SEnrico Granata     sstr.Flush();
6650a3958e0SEnrico Granata 
6660a3958e0SEnrico Granata     std::string data = sstr.GetString();
6670a3958e0SEnrico Granata 
66882a7d983SEnrico Granata     help_text_ptr = new char[data.length()+1];
6690a3958e0SEnrico Granata 
67082a7d983SEnrico Granata     data.copy(help_text_ptr, data.length());
6710a3958e0SEnrico Granata 
67282a7d983SEnrico Granata     return help_text_ptr;
6730a3958e0SEnrico Granata }
6740a3958e0SEnrico Granata 
6750a3958e0SEnrico Granata static const char *
67682a7d983SEnrico Granata SummaryStringHelpTextCallback()
6770a3958e0SEnrico Granata {
67882a7d983SEnrico Granata     return
67982a7d983SEnrico Granata         "A summary string is a way to extract information from variables in order to present them using a summary.\n"
68082a7d983SEnrico Granata         "Summary strings contain static text, variables, scopes and control sequences:\n"
68182a7d983SEnrico Granata         "  - Static text can be any sequence of non-special characters, i.e. anything but '{', '}', '$', or '\\'.\n"
68282a7d983SEnrico Granata         "  - Variables are sequences of characters beginning with ${, ending with } and that contain symbols in the format described below.\n"
68382a7d983SEnrico Granata         "  - 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"
68482a7d983SEnrico Granata         "  - Control sequences are the usual C/C++ '\\a', '\\n', ..., plus '\\$', '\\{' and '\\}'.\n"
68582a7d983SEnrico Granata         "A summary string works by copying static text verbatim, turning control sequences into their character counterpart, expanding variables and trying to expand scopes.\n"
68682a7d983SEnrico Granata         "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"
68782a7d983SEnrico Granata         "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"
68882a7d983SEnrico Granata         " (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"
68982a7d983SEnrico Granata         " ${var.x.y}). In expression paths you can use either . or -> without any difference in meaning. You can also use ${*var followed by an expression path and in that case"
69082a7d983SEnrico Granata         " the object referred by the path will be dereferenced before being displayed. If the object is not a pointer, doing so will cause an error.\n"
69182a7d983SEnrico Granata         "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."
69282a7d983SEnrico Granata         "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"
69382a7d983SEnrico Granata         " path refers to:\n"
69482a7d983SEnrico Granata         "  - 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"
69582a7d983SEnrico Granata         " and displayed as an individual variable\n"
69682a7d983SEnrico Granata         "  - 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"
69782a7d983SEnrico Granata         " 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"
69882a7d983SEnrico Granata         "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.";
6990a3958e0SEnrico Granata }
7000a3958e0SEnrico Granata 
7019d0402b1SGreg Clayton const char *
7029d0402b1SGreg Clayton CommandObject::GetArgumentTypeAsCString (const lldb::CommandArgumentType arg_type)
7039d0402b1SGreg Clayton {
7049d0402b1SGreg Clayton     if (arg_type >=0 && arg_type < eArgTypeLastArg)
7059d0402b1SGreg Clayton         return g_arguments_data[arg_type].arg_name;
7069d0402b1SGreg Clayton     return NULL;
7079d0402b1SGreg Clayton 
7089d0402b1SGreg Clayton }
7099d0402b1SGreg Clayton 
7109d0402b1SGreg Clayton const char *
7119d0402b1SGreg Clayton CommandObject::GetArgumentDescriptionAsCString (const lldb::CommandArgumentType arg_type)
7129d0402b1SGreg Clayton {
7139d0402b1SGreg Clayton     if (arg_type >=0 && arg_type < eArgTypeLastArg)
7149d0402b1SGreg Clayton         return g_arguments_data[arg_type].help_text;
7159d0402b1SGreg Clayton     return NULL;
7169d0402b1SGreg Clayton }
7179d0402b1SGreg Clayton 
718e139cf23SCaroline Tice CommandObject::ArgumentTableEntry
719e139cf23SCaroline Tice CommandObject::g_arguments_data[] =
720e139cf23SCaroline Tice {
7217f941d95SEnrico Granata     { eArgTypeAddress, "address", CommandCompletions::eNoCompletion, { NULL, false }, "A valid address in the target program's execution space." },
7227f941d95SEnrico Granata     { eArgTypeAliasName, "alias-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of an abbreviation (alias) for a debugger command." },
7237f941d95SEnrico Granata     { 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.)" },
7247f941d95SEnrico Granata     { eArgTypeArchitecture, "arch", CommandCompletions::eArchitectureCompletion, { NULL, false }, "The architecture name, e.g. i386 or x86_64." },
7257f941d95SEnrico Granata     { eArgTypeBoolean, "boolean", CommandCompletions::eNoCompletion, { NULL, false }, "A Boolean value: 'true' or 'false'" },
7267f941d95SEnrico Granata     { eArgTypeBreakpointID, "breakpt-id", CommandCompletions::eNoCompletion, { BreakpointIDHelpTextCallback, false }, NULL },
7277f941d95SEnrico Granata     { eArgTypeBreakpointIDRange, "breakpt-id-list", CommandCompletions::eNoCompletion, { BreakpointIDRangeHelpTextCallback, false }, NULL },
7287f941d95SEnrico Granata     { eArgTypeByteSize, "byte-size", CommandCompletions::eNoCompletion, { NULL, false }, "Number of bytes to use." },
7297f941d95SEnrico Granata     { eArgTypeClassName, "class-name", CommandCompletions::eNoCompletion, { NULL, false }, "Then name of a class from the debug information in the program." },
7307f941d95SEnrico Granata     { eArgTypeCommandName, "cmd-name", CommandCompletions::eNoCompletion, { NULL, false }, "A debugger command (may be multiple words), without any options or arguments." },
7317f941d95SEnrico Granata     { eArgTypeCount, "count", CommandCompletions::eNoCompletion, { NULL, false }, "An unsigned integer." },
7327f941d95SEnrico Granata     { eArgTypeEndAddress, "end-address", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
7337f941d95SEnrico Granata     { eArgTypeExpression, "expr", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
7347f941d95SEnrico Granata     { eArgTypeExprFormat, "expression-format", CommandCompletions::eNoCompletion, { NULL, false }, "[ [bool|b] | [bin] | [char|c] | [oct|o] | [dec|i|d|u] | [hex|x] | [float|f] | [cstr|s] ]" },
7357f941d95SEnrico Granata     { eArgTypeFilename, "filename", CommandCompletions::eDiskFileCompletion, { NULL, false }, "The name of a file (can include path)." },
7367f941d95SEnrico Granata     { eArgTypeFormat, "format", CommandCompletions::eNoCompletion, { FormatHelpTextCallback, true }, NULL },
7377f941d95SEnrico Granata     { eArgTypeFrameIndex, "frame-index", CommandCompletions::eNoCompletion, { NULL, false }, "Index into a thread's list of frames." },
7387f941d95SEnrico Granata     { eArgTypeFullName, "fullname", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
7397f941d95SEnrico Granata     { eArgTypeFunctionName, "function-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a function." },
7407f941d95SEnrico Granata     { eArgTypeIndex, "index", CommandCompletions::eNoCompletion, { NULL, false }, "An index into a list." },
7417f941d95SEnrico Granata     { eArgTypeLineNum, "linenum", CommandCompletions::eNoCompletion, { NULL, false }, "Line number in a source file." },
7427f941d95SEnrico Granata     { 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." },
7437f941d95SEnrico Granata     { 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)." },
7447f941d95SEnrico Granata     { eArgTypeMethod, "method", CommandCompletions::eNoCompletion, { NULL, false }, "A C++ method name." },
7457f941d95SEnrico Granata     { eArgTypeName, "name", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
7467f941d95SEnrico Granata     { eArgTypeNewPathPrefix, "new-path-prefix", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
7477f941d95SEnrico Granata     { eArgTypeNumLines, "num-lines", CommandCompletions::eNoCompletion, { NULL, false }, "The number of lines to use." },
7487f941d95SEnrico Granata     { eArgTypeNumberPerLine, "number-per-line", CommandCompletions::eNoCompletion, { NULL, false }, "The number of items per line to display." },
7497f941d95SEnrico Granata     { eArgTypeOffset, "offset", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
7507f941d95SEnrico Granata     { eArgTypeOldPathPrefix, "old-path-prefix", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
7517f941d95SEnrico Granata     { eArgTypeOneLiner, "one-line-command", CommandCompletions::eNoCompletion, { NULL, false }, "A command that is entered as a single line of text." },
7527f941d95SEnrico Granata     { eArgTypePath, "path", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
7537f941d95SEnrico Granata     { eArgTypePid, "pid", CommandCompletions::eNoCompletion, { NULL, false }, "The process ID number." },
7547f941d95SEnrico Granata     { eArgTypePlugin, "plugin", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
7557f941d95SEnrico Granata     { eArgTypeProcessName, "process-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of the process." },
7567f941d95SEnrico Granata     { eArgTypeQueueName, "queue-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of the thread queue." },
7577f941d95SEnrico Granata     { eArgTypeRegisterName, "register-name", CommandCompletions::eNoCompletion, { NULL, false }, "A register name." },
7587f941d95SEnrico Granata     { eArgTypeRegularExpression, "regular-expression", CommandCompletions::eNoCompletion, { NULL, false }, "A regular expression." },
7597f941d95SEnrico Granata     { eArgTypeRunArgs, "run-args", CommandCompletions::eNoCompletion, { NULL, false }, "Arguments to be passed to the target program when it starts executing." },
7607f941d95SEnrico Granata     { eArgTypeRunMode, "run-mode", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
7617f941d95SEnrico Granata     { eArgTypeScriptLang, "script-language", CommandCompletions::eNoCompletion, { NULL, false }, "The scripting language to be used for script-based commands.  Currently only Python is valid." },
7627f941d95SEnrico Granata     { eArgTypeSearchWord, "search-word", CommandCompletions::eNoCompletion, { NULL, false }, "The word for which you wish to search for information about." },
7637f941d95SEnrico Granata     { eArgTypeSelector, "selector", CommandCompletions::eNoCompletion, { NULL, false }, "An Objective-C selector name." },
7647f941d95SEnrico Granata     { 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)." },
7657f941d95SEnrico Granata     { 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)." },
7667f941d95SEnrico Granata     { eArgTypeSettingPrefix, "setting-prefix", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a settable internal debugger variable up to a dot ('.'), e.g. 'target.process.'" },
7677f941d95SEnrico Granata     { 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." },
7687f941d95SEnrico Granata     { eArgTypeShlibName, "shlib-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a shared library." },
7697f941d95SEnrico Granata     { eArgTypeSourceFile, "source-file", CommandCompletions::eSourceFileCompletion, { NULL, false }, "The name of a source file.." },
7707f941d95SEnrico Granata     { eArgTypeSortOrder, "sort-order", CommandCompletions::eNoCompletion, { NULL, false }, "Specify a sort order when dumping lists." },
7717f941d95SEnrico Granata     { eArgTypeStartAddress, "start-address", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
7727f941d95SEnrico Granata     { eArgTypeSummaryString, "summary-string", CommandCompletions::eNoCompletion, { SummaryStringHelpTextCallback, true }, NULL },
7737f941d95SEnrico Granata     { eArgTypeSymbol, "symbol", CommandCompletions::eSymbolCompletion, { NULL, false }, "Any symbol name (function name, variable, argument, etc.)" },
7747f941d95SEnrico Granata     { eArgTypeThreadID, "thread-id", CommandCompletions::eNoCompletion, { NULL, false }, "Thread ID number." },
7757f941d95SEnrico Granata     { eArgTypeThreadIndex, "thread-index", CommandCompletions::eNoCompletion, { NULL, false }, "Index into the process' list of threads." },
7767f941d95SEnrico Granata     { eArgTypeThreadName, "thread-name", CommandCompletions::eNoCompletion, { NULL, false }, "The thread's name." },
7777f941d95SEnrico Granata     { eArgTypeUnixSignal, "unix-signal", CommandCompletions::eNoCompletion, { NULL, false }, "A valid Unix signal name or number (e.g. SIGKILL, KILL or 9)." },
7787f941d95SEnrico Granata     { eArgTypeVarName, "variable-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a variable in your program." },
7797f941d95SEnrico Granata     { eArgTypeValue, "value", CommandCompletions::eNoCompletion, { NULL, false }, "A value could be anything, depending on where and how it is used." },
7807f941d95SEnrico Granata     { eArgTypeWidth, "width", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
7817f941d95SEnrico Granata     { eArgTypeNone, "none", CommandCompletions::eNoCompletion, { NULL, false }, "No help available for this." },
7827f941d95SEnrico Granata     { 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." }
783e139cf23SCaroline Tice };
784e139cf23SCaroline Tice 
785e139cf23SCaroline Tice const CommandObject::ArgumentTableEntry*
786e139cf23SCaroline Tice CommandObject::GetArgumentTable ()
787e139cf23SCaroline Tice {
7889d0402b1SGreg Clayton     // If this assertion fires, then the table above is out of date with the CommandArgumentType enumeration
7899d0402b1SGreg Clayton     assert ((sizeof (CommandObject::g_arguments_data) / sizeof (CommandObject::ArgumentTableEntry)) == eArgTypeLastArg);
790e139cf23SCaroline Tice     return CommandObject::g_arguments_data;
791e139cf23SCaroline Tice }
792e139cf23SCaroline Tice 
793e139cf23SCaroline Tice 
794