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         {
232b8e8a5f3SJim Ingham             // A process that is not running is considered paused.
233b8e8a5f3SJim Ingham             if (GetFlags().Test(CommandObject::eFlagProcessMustBeLaunched))
234b8e8a5f3SJim Ingham             {
23530fdc8d8SChris Lattner                 result.AppendError ("Process must exist.");
23630fdc8d8SChris Lattner                 result.SetStatus (eReturnStatusFailed);
23730fdc8d8SChris Lattner                 return false;
23830fdc8d8SChris Lattner             }
239b8e8a5f3SJim Ingham         }
24030fdc8d8SChris Lattner         else
24130fdc8d8SChris Lattner         {
24230fdc8d8SChris Lattner             StateType state = process->GetState();
24330fdc8d8SChris Lattner 
24430fdc8d8SChris Lattner             switch (state)
24530fdc8d8SChris Lattner             {
2467a5388bfSGreg Clayton             case eStateInvalid:
24730fdc8d8SChris Lattner             case eStateSuspended:
24830fdc8d8SChris Lattner             case eStateCrashed:
24930fdc8d8SChris Lattner             case eStateStopped:
25030fdc8d8SChris Lattner                 break;
25130fdc8d8SChris Lattner 
252b766a73dSGreg Clayton             case eStateConnected:
253b766a73dSGreg Clayton             case eStateAttaching:
254b766a73dSGreg Clayton             case eStateLaunching:
25530fdc8d8SChris Lattner             case eStateDetached:
25630fdc8d8SChris Lattner             case eStateExited:
25730fdc8d8SChris Lattner             case eStateUnloaded:
25873b472d4SGreg Clayton                 if (GetFlags().Test(CommandObject::eFlagProcessMustBeLaunched))
25930fdc8d8SChris Lattner                 {
26030fdc8d8SChris Lattner                     result.AppendError ("Process must be launched.");
26130fdc8d8SChris Lattner                     result.SetStatus (eReturnStatusFailed);
26230fdc8d8SChris Lattner                     return false;
26330fdc8d8SChris Lattner                 }
26430fdc8d8SChris Lattner                 break;
26530fdc8d8SChris Lattner 
26630fdc8d8SChris Lattner             case eStateRunning:
26730fdc8d8SChris Lattner             case eStateStepping:
26873b472d4SGreg Clayton                 if (GetFlags().Test(CommandObject::eFlagProcessMustBePaused))
26930fdc8d8SChris Lattner                 {
27030fdc8d8SChris Lattner                     result.AppendError ("Process is running.  Use 'process interrupt' to pause execution.");
27130fdc8d8SChris Lattner                     result.SetStatus (eReturnStatusFailed);
27230fdc8d8SChris Lattner                     return false;
27330fdc8d8SChris Lattner                 }
27430fdc8d8SChris Lattner             }
27530fdc8d8SChris Lattner         }
276b766a73dSGreg Clayton     }
27730fdc8d8SChris Lattner 
278a7015092SGreg Clayton     if (!ParseOptions (args, result))
27930fdc8d8SChris Lattner         return false;
28030fdc8d8SChris Lattner 
28130fdc8d8SChris Lattner     // Call the command-specific version of 'Execute', passing it the already processed arguments.
282a7015092SGreg Clayton     return Execute (args, result);
28330fdc8d8SChris Lattner }
28430fdc8d8SChris Lattner 
28530fdc8d8SChris Lattner class CommandDictCommandPartialMatch
28630fdc8d8SChris Lattner {
28730fdc8d8SChris Lattner     public:
28830fdc8d8SChris Lattner         CommandDictCommandPartialMatch (const char *match_str)
28930fdc8d8SChris Lattner         {
29030fdc8d8SChris Lattner             m_match_str = match_str;
29130fdc8d8SChris Lattner         }
29230fdc8d8SChris Lattner         bool operator() (const std::pair<std::string, lldb::CommandObjectSP> map_element) const
29330fdc8d8SChris Lattner         {
29430fdc8d8SChris Lattner             // A NULL or empty string matches everything.
29530fdc8d8SChris Lattner             if (m_match_str == NULL || *m_match_str == '\0')
29630fdc8d8SChris Lattner                 return 1;
29730fdc8d8SChris Lattner 
29830fdc8d8SChris Lattner             size_t found = map_element.first.find (m_match_str, 0);
29930fdc8d8SChris Lattner             if (found == std::string::npos)
30030fdc8d8SChris Lattner                 return 0;
30130fdc8d8SChris Lattner             else
30230fdc8d8SChris Lattner                 return found == 0;
30330fdc8d8SChris Lattner         }
30430fdc8d8SChris Lattner 
30530fdc8d8SChris Lattner     private:
30630fdc8d8SChris Lattner         const char *m_match_str;
30730fdc8d8SChris Lattner };
30830fdc8d8SChris Lattner 
30930fdc8d8SChris Lattner int
31030fdc8d8SChris Lattner CommandObject::AddNamesMatchingPartialString (CommandObject::CommandMap &in_map, const char *cmd_str,
31130fdc8d8SChris Lattner                                               StringList &matches)
31230fdc8d8SChris Lattner {
31330fdc8d8SChris Lattner     int number_added = 0;
31430fdc8d8SChris Lattner     CommandDictCommandPartialMatch matcher(cmd_str);
31530fdc8d8SChris Lattner 
31630fdc8d8SChris Lattner     CommandObject::CommandMap::iterator matching_cmds = std::find_if (in_map.begin(), in_map.end(), matcher);
31730fdc8d8SChris Lattner 
31830fdc8d8SChris Lattner     while (matching_cmds != in_map.end())
31930fdc8d8SChris Lattner     {
32030fdc8d8SChris Lattner         ++number_added;
32130fdc8d8SChris Lattner         matches.AppendString((*matching_cmds).first.c_str());
32230fdc8d8SChris Lattner         matching_cmds = std::find_if (++matching_cmds, in_map.end(), matcher);;
32330fdc8d8SChris Lattner     }
32430fdc8d8SChris Lattner     return number_added;
32530fdc8d8SChris Lattner }
32630fdc8d8SChris Lattner 
32730fdc8d8SChris Lattner int
32830fdc8d8SChris Lattner CommandObject::HandleCompletion
32930fdc8d8SChris Lattner (
33030fdc8d8SChris Lattner     Args &input,
33130fdc8d8SChris Lattner     int &cursor_index,
33230fdc8d8SChris Lattner     int &cursor_char_position,
33330fdc8d8SChris Lattner     int match_start_point,
33430fdc8d8SChris Lattner     int max_return_elements,
335558ce124SJim Ingham     bool &word_complete,
33630fdc8d8SChris Lattner     StringList &matches
33730fdc8d8SChris Lattner )
33830fdc8d8SChris Lattner {
33930fdc8d8SChris Lattner     if (WantsRawCommandString())
34030fdc8d8SChris Lattner     {
34130fdc8d8SChris Lattner         // FIXME: Abstract telling the completion to insert the completion character.
34230fdc8d8SChris Lattner         matches.Clear();
34330fdc8d8SChris Lattner         return -1;
34430fdc8d8SChris Lattner     }
34530fdc8d8SChris Lattner     else
34630fdc8d8SChris Lattner     {
34730fdc8d8SChris Lattner         // Can we do anything generic with the options?
34830fdc8d8SChris Lattner         Options *cur_options = GetOptions();
34930fdc8d8SChris Lattner         CommandReturnObject result;
35030fdc8d8SChris Lattner         OptionElementVector opt_element_vector;
35130fdc8d8SChris Lattner 
35230fdc8d8SChris Lattner         if (cur_options != NULL)
35330fdc8d8SChris Lattner         {
35430fdc8d8SChris Lattner             // Re-insert the dummy command name string which will have been
35530fdc8d8SChris Lattner             // stripped off:
35630fdc8d8SChris Lattner             input.Unshift ("dummy-string");
35730fdc8d8SChris Lattner             cursor_index++;
35830fdc8d8SChris Lattner 
35930fdc8d8SChris Lattner 
36030fdc8d8SChris Lattner             // I stick an element on the end of the input, because if the last element is
36130fdc8d8SChris Lattner             // option that requires an argument, getopt_long will freak out.
36230fdc8d8SChris Lattner 
36330fdc8d8SChris Lattner             input.AppendArgument ("<FAKE-VALUE>");
36430fdc8d8SChris Lattner 
365d43e0094SJim Ingham             input.ParseArgsForCompletion (*cur_options, opt_element_vector, cursor_index);
36630fdc8d8SChris Lattner 
36730fdc8d8SChris Lattner             input.DeleteArgumentAtIndex(input.GetArgumentCount() - 1);
36830fdc8d8SChris Lattner 
36930fdc8d8SChris Lattner             bool handled_by_options;
370eb0103f2SGreg Clayton             handled_by_options = cur_options->HandleOptionCompletion (input,
37130fdc8d8SChris Lattner                                                                       opt_element_vector,
37230fdc8d8SChris Lattner                                                                       cursor_index,
37330fdc8d8SChris Lattner                                                                       cursor_char_position,
37430fdc8d8SChris Lattner                                                                       match_start_point,
37530fdc8d8SChris Lattner                                                                       max_return_elements,
376558ce124SJim Ingham                                                                       word_complete,
37730fdc8d8SChris Lattner                                                                       matches);
37830fdc8d8SChris Lattner             if (handled_by_options)
37930fdc8d8SChris Lattner                 return matches.GetSize();
38030fdc8d8SChris Lattner         }
38130fdc8d8SChris Lattner 
38230fdc8d8SChris Lattner         // If we got here, the last word is not an option or an option argument.
383a7015092SGreg Clayton         return HandleArgumentCompletion (input,
38430fdc8d8SChris Lattner                                          cursor_index,
38530fdc8d8SChris Lattner                                          cursor_char_position,
38630fdc8d8SChris Lattner                                          opt_element_vector,
38730fdc8d8SChris Lattner                                          match_start_point,
38830fdc8d8SChris Lattner                                          max_return_elements,
389558ce124SJim Ingham                                          word_complete,
39030fdc8d8SChris Lattner                                          matches);
39130fdc8d8SChris Lattner     }
39230fdc8d8SChris Lattner }
39330fdc8d8SChris Lattner 
39430fdc8d8SChris Lattner bool
395a7015092SGreg Clayton CommandObject::HelpTextContainsWord (const char *search_word)
39630fdc8d8SChris Lattner {
39730fdc8d8SChris Lattner     const char *short_help;
39830fdc8d8SChris Lattner     const char *long_help;
39930fdc8d8SChris Lattner     const char *syntax_help;
40030fdc8d8SChris Lattner     std::string options_usage_help;
40130fdc8d8SChris Lattner 
40230fdc8d8SChris Lattner 
40330fdc8d8SChris Lattner     bool found_word = false;
40430fdc8d8SChris Lattner 
40530fdc8d8SChris Lattner     short_help = GetHelp();
40630fdc8d8SChris Lattner     long_help = GetHelpLong();
40730fdc8d8SChris Lattner     syntax_help = GetSyntax();
40830fdc8d8SChris Lattner 
4094b6fbf37SCaroline Tice     if (strcasestr (short_help, search_word))
41030fdc8d8SChris Lattner         found_word = true;
4114b6fbf37SCaroline Tice     else if (strcasestr (long_help, search_word))
41230fdc8d8SChris Lattner         found_word = true;
4134b6fbf37SCaroline Tice     else if (strcasestr (syntax_help, search_word))
41430fdc8d8SChris Lattner         found_word = true;
41530fdc8d8SChris Lattner 
41630fdc8d8SChris Lattner     if (!found_word
41730fdc8d8SChris Lattner         && GetOptions() != NULL)
41830fdc8d8SChris Lattner     {
41930fdc8d8SChris Lattner         StreamString usage_help;
420eb0103f2SGreg Clayton         GetOptions()->GenerateOptionUsage (usage_help, this);
42130fdc8d8SChris Lattner         if (usage_help.GetSize() > 0)
42230fdc8d8SChris Lattner         {
42330fdc8d8SChris Lattner             const char *usage_text = usage_help.GetData();
4244b6fbf37SCaroline Tice             if (strcasestr (usage_text, search_word))
42530fdc8d8SChris Lattner               found_word = true;
42630fdc8d8SChris Lattner         }
42730fdc8d8SChris Lattner     }
42830fdc8d8SChris Lattner 
42930fdc8d8SChris Lattner     return found_word;
43030fdc8d8SChris Lattner }
431e139cf23SCaroline Tice 
432e139cf23SCaroline Tice int
433e139cf23SCaroline Tice CommandObject::GetNumArgumentEntries  ()
434e139cf23SCaroline Tice {
435e139cf23SCaroline Tice     return m_arguments.size();
436e139cf23SCaroline Tice }
437e139cf23SCaroline Tice 
438e139cf23SCaroline Tice CommandObject::CommandArgumentEntry *
439e139cf23SCaroline Tice CommandObject::GetArgumentEntryAtIndex (int idx)
440e139cf23SCaroline Tice {
441e139cf23SCaroline Tice     if (idx < m_arguments.size())
442e139cf23SCaroline Tice         return &(m_arguments[idx]);
443e139cf23SCaroline Tice 
444e139cf23SCaroline Tice     return NULL;
445e139cf23SCaroline Tice }
446e139cf23SCaroline Tice 
447e139cf23SCaroline Tice CommandObject::ArgumentTableEntry *
448e139cf23SCaroline Tice CommandObject::FindArgumentDataByType (CommandArgumentType arg_type)
449e139cf23SCaroline Tice {
450e139cf23SCaroline Tice     const ArgumentTableEntry *table = CommandObject::GetArgumentTable();
451e139cf23SCaroline Tice 
452e139cf23SCaroline Tice     for (int i = 0; i < eArgTypeLastArg; ++i)
453e139cf23SCaroline Tice         if (table[i].arg_type == arg_type)
454e139cf23SCaroline Tice             return (ArgumentTableEntry *) &(table[i]);
455e139cf23SCaroline Tice 
456e139cf23SCaroline Tice     return NULL;
457e139cf23SCaroline Tice }
458e139cf23SCaroline Tice 
459e139cf23SCaroline Tice void
460e139cf23SCaroline Tice CommandObject::GetArgumentHelp (Stream &str, CommandArgumentType arg_type, CommandInterpreter &interpreter)
461e139cf23SCaroline Tice {
462e139cf23SCaroline Tice     const ArgumentTableEntry* table = CommandObject::GetArgumentTable();
463e139cf23SCaroline Tice     ArgumentTableEntry *entry = (ArgumentTableEntry *) &(table[arg_type]);
464e139cf23SCaroline Tice 
465e139cf23SCaroline Tice     // The table is *supposed* to be kept in arg_type order, but someone *could* have messed it up...
466e139cf23SCaroline Tice 
467e139cf23SCaroline Tice     if (entry->arg_type != arg_type)
468e139cf23SCaroline Tice         entry = CommandObject::FindArgumentDataByType (arg_type);
469e139cf23SCaroline Tice 
470e139cf23SCaroline Tice     if (!entry)
471e139cf23SCaroline Tice         return;
472e139cf23SCaroline Tice 
473e139cf23SCaroline Tice     StreamString name_str;
474e139cf23SCaroline Tice     name_str.Printf ("<%s>", entry->arg_name);
475e139cf23SCaroline Tice 
476fc7a7f3bSEnrico Granata     if (entry->help_function)
47782a7d983SEnrico Granata     {
478fc7a7f3bSEnrico Granata         const char* help_text = entry->help_function();
47982a7d983SEnrico Granata         if (!entry->help_function.self_formatting)
48082a7d983SEnrico Granata         {
48182a7d983SEnrico Granata             interpreter.OutputFormattedHelpText (str, name_str.GetData(), "--", help_text,
482e139cf23SCaroline Tice                                                  name_str.GetSize());
48382a7d983SEnrico Granata         }
48482a7d983SEnrico Granata         else
48582a7d983SEnrico Granata         {
48682a7d983SEnrico Granata             interpreter.OutputHelpText(str, name_str.GetData(), "--", help_text,
48782a7d983SEnrico Granata                                        name_str.GetSize());
48882a7d983SEnrico Granata         }
48982a7d983SEnrico Granata     }
490e139cf23SCaroline Tice     else
491e139cf23SCaroline Tice         interpreter.OutputFormattedHelpText (str, name_str.GetData(), "--", entry->help_text, name_str.GetSize());
492e139cf23SCaroline Tice }
493e139cf23SCaroline Tice 
494e139cf23SCaroline Tice const char *
495e139cf23SCaroline Tice CommandObject::GetArgumentName (CommandArgumentType arg_type)
496e139cf23SCaroline Tice {
497deaab222SCaroline Tice     ArgumentTableEntry *entry = (ArgumentTableEntry *) &(CommandObject::GetArgumentTable()[arg_type]);
498deaab222SCaroline Tice 
499deaab222SCaroline Tice     // The table is *supposed* to be kept in arg_type order, but someone *could* have messed it up...
500deaab222SCaroline Tice 
501deaab222SCaroline Tice     if (entry->arg_type != arg_type)
502deaab222SCaroline Tice         entry = CommandObject::FindArgumentDataByType (arg_type);
503deaab222SCaroline Tice 
504e6acf355SJohnny Chen     if (entry)
505deaab222SCaroline Tice         return entry->arg_name;
506e6acf355SJohnny Chen 
507e6acf355SJohnny Chen     StreamString str;
508e6acf355SJohnny Chen     str << "Arg name for type (" << arg_type << ") not in arg table!";
509e6acf355SJohnny Chen     return str.GetData();
510e139cf23SCaroline Tice }
511e139cf23SCaroline Tice 
512405fe67fSCaroline Tice bool
513e0d378b3SGreg Clayton CommandObject::IsPairType (ArgumentRepetitionType arg_repeat_type)
514405fe67fSCaroline Tice {
515405fe67fSCaroline Tice     if ((arg_repeat_type == eArgRepeatPairPlain)
516405fe67fSCaroline Tice         ||  (arg_repeat_type == eArgRepeatPairOptional)
517405fe67fSCaroline Tice         ||  (arg_repeat_type == eArgRepeatPairPlus)
518405fe67fSCaroline Tice         ||  (arg_repeat_type == eArgRepeatPairStar)
519405fe67fSCaroline Tice         ||  (arg_repeat_type == eArgRepeatPairRange)
520405fe67fSCaroline Tice         ||  (arg_repeat_type == eArgRepeatPairRangeOptional))
521405fe67fSCaroline Tice         return true;
522405fe67fSCaroline Tice 
523405fe67fSCaroline Tice     return false;
524405fe67fSCaroline Tice }
525405fe67fSCaroline Tice 
526e139cf23SCaroline Tice void
527e139cf23SCaroline Tice CommandObject::GetFormattedCommandArguments (Stream &str)
528e139cf23SCaroline Tice {
529e139cf23SCaroline Tice     int num_args = m_arguments.size();
530e139cf23SCaroline Tice     for (int i = 0; i < num_args; ++i)
531e139cf23SCaroline Tice     {
532e139cf23SCaroline Tice         if (i > 0)
533e139cf23SCaroline Tice             str.Printf (" ");
534e139cf23SCaroline Tice         CommandArgumentEntry arg_entry = m_arguments[i];
535e139cf23SCaroline Tice         int num_alternatives = arg_entry.size();
536405fe67fSCaroline Tice 
537405fe67fSCaroline Tice         if ((num_alternatives == 2)
538405fe67fSCaroline Tice             && IsPairType (arg_entry[0].arg_repetition))
539405fe67fSCaroline Tice         {
540405fe67fSCaroline Tice             const char *first_name = GetArgumentName (arg_entry[0].arg_type);
541405fe67fSCaroline Tice             const char *second_name = GetArgumentName (arg_entry[1].arg_type);
542405fe67fSCaroline Tice             switch (arg_entry[0].arg_repetition)
543405fe67fSCaroline Tice             {
544405fe67fSCaroline Tice                 case eArgRepeatPairPlain:
545405fe67fSCaroline Tice                     str.Printf ("<%s> <%s>", first_name, second_name);
546405fe67fSCaroline Tice                     break;
547405fe67fSCaroline Tice                 case eArgRepeatPairOptional:
548405fe67fSCaroline Tice                     str.Printf ("[<%s> <%s>]", first_name, second_name);
549405fe67fSCaroline Tice                     break;
550405fe67fSCaroline Tice                 case eArgRepeatPairPlus:
551405fe67fSCaroline Tice                     str.Printf ("<%s> <%s> [<%s> <%s> [...]]", first_name, second_name, first_name, second_name);
552405fe67fSCaroline Tice                     break;
553405fe67fSCaroline Tice                 case eArgRepeatPairStar:
554405fe67fSCaroline Tice                     str.Printf ("[<%s> <%s> [<%s> <%s> [...]]]", first_name, second_name, first_name, second_name);
555405fe67fSCaroline Tice                     break;
556405fe67fSCaroline Tice                 case eArgRepeatPairRange:
557405fe67fSCaroline Tice                     str.Printf ("<%s_1> <%s_1> ... <%s_n> <%s_n>", first_name, second_name, first_name, second_name);
558405fe67fSCaroline Tice                     break;
559405fe67fSCaroline Tice                 case eArgRepeatPairRangeOptional:
560405fe67fSCaroline Tice                     str.Printf ("[<%s_1> <%s_1> ... <%s_n> <%s_n>]", first_name, second_name, first_name, second_name);
561405fe67fSCaroline Tice                     break;
562ca1176aaSCaroline Tice                 // Explicitly test for all the rest of the cases, so if new types get added we will notice the
563ca1176aaSCaroline Tice                 // missing case statement(s).
564ca1176aaSCaroline Tice                 case eArgRepeatPlain:
565ca1176aaSCaroline Tice                 case eArgRepeatOptional:
566ca1176aaSCaroline Tice                 case eArgRepeatPlus:
567ca1176aaSCaroline Tice                 case eArgRepeatStar:
568ca1176aaSCaroline Tice                 case eArgRepeatRange:
569ca1176aaSCaroline Tice                     // These should not be reached, as they should fail the IsPairType test above.
570ca1176aaSCaroline Tice                     break;
571405fe67fSCaroline Tice             }
572405fe67fSCaroline Tice         }
573405fe67fSCaroline Tice         else
574405fe67fSCaroline Tice         {
575e139cf23SCaroline Tice             StreamString names;
576e139cf23SCaroline Tice             for (int j = 0; j < num_alternatives; ++j)
577e139cf23SCaroline Tice             {
578e139cf23SCaroline Tice                 if (j > 0)
579e139cf23SCaroline Tice                     names.Printf (" | ");
580e139cf23SCaroline Tice                 names.Printf ("%s", GetArgumentName (arg_entry[j].arg_type));
581e139cf23SCaroline Tice             }
582e139cf23SCaroline Tice             switch (arg_entry[0].arg_repetition)
583e139cf23SCaroline Tice             {
584e139cf23SCaroline Tice                 case eArgRepeatPlain:
585e139cf23SCaroline Tice                     str.Printf ("<%s>", names.GetData());
586e139cf23SCaroline Tice                     break;
587e139cf23SCaroline Tice                 case eArgRepeatPlus:
588e139cf23SCaroline Tice                     str.Printf ("<%s> [<%s> [...]]", names.GetData(), names.GetData());
589e139cf23SCaroline Tice                     break;
590e139cf23SCaroline Tice                 case eArgRepeatStar:
591e139cf23SCaroline Tice                     str.Printf ("[<%s> [<%s> [...]]]", names.GetData(), names.GetData());
592e139cf23SCaroline Tice                     break;
593e139cf23SCaroline Tice                 case eArgRepeatOptional:
594e139cf23SCaroline Tice                     str.Printf ("[<%s>]", names.GetData());
595e139cf23SCaroline Tice                     break;
596405fe67fSCaroline Tice                 case eArgRepeatRange:
597405fe67fSCaroline Tice                     str.Printf ("<%s_1> .. <%s_n>", names.GetData());
598ca1176aaSCaroline Tice                     break;
599ca1176aaSCaroline Tice                 // Explicitly test for all the rest of the cases, so if new types get added we will notice the
600ca1176aaSCaroline Tice                 // missing case statement(s).
601ca1176aaSCaroline Tice                 case eArgRepeatPairPlain:
602ca1176aaSCaroline Tice                 case eArgRepeatPairOptional:
603ca1176aaSCaroline Tice                 case eArgRepeatPairPlus:
604ca1176aaSCaroline Tice                 case eArgRepeatPairStar:
605ca1176aaSCaroline Tice                 case eArgRepeatPairRange:
606ca1176aaSCaroline Tice                 case eArgRepeatPairRangeOptional:
607ca1176aaSCaroline Tice                     // These should not be hit, as they should pass the IsPairType test above, and control should
608ca1176aaSCaroline Tice                     // have gone into the other branch of the if statement.
609ca1176aaSCaroline Tice                     break;
610405fe67fSCaroline Tice             }
611e139cf23SCaroline Tice         }
612e139cf23SCaroline Tice     }
613e139cf23SCaroline Tice }
614e139cf23SCaroline Tice 
6150c16aa6dSStephen Wilson CommandArgumentType
616e139cf23SCaroline Tice CommandObject::LookupArgumentName (const char *arg_name)
617e139cf23SCaroline Tice {
618e139cf23SCaroline Tice     CommandArgumentType return_type = eArgTypeLastArg;
619e139cf23SCaroline Tice 
620e139cf23SCaroline Tice     std::string arg_name_str (arg_name);
621e139cf23SCaroline Tice     size_t len = arg_name_str.length();
622e139cf23SCaroline Tice     if (arg_name[0] == '<'
623e139cf23SCaroline Tice         && arg_name[len-1] == '>')
624e139cf23SCaroline Tice         arg_name_str = arg_name_str.substr (1, len-2);
625e139cf23SCaroline Tice 
626*331eff39SJohnny Chen     const ArgumentTableEntry *table = GetArgumentTable();
627e139cf23SCaroline Tice     for (int i = 0; i < eArgTypeLastArg; ++i)
628*331eff39SJohnny Chen         if (arg_name_str.compare (table[i].arg_name) == 0)
629e139cf23SCaroline Tice             return_type = g_arguments_data[i].arg_type;
630e139cf23SCaroline Tice 
631e139cf23SCaroline Tice     return return_type;
632e139cf23SCaroline Tice }
633e139cf23SCaroline Tice 
634e139cf23SCaroline Tice static const char *
635e139cf23SCaroline Tice BreakpointIDHelpTextCallback ()
636e139cf23SCaroline Tice {
637e139cf23SCaroline 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).";
638e139cf23SCaroline Tice }
639e139cf23SCaroline Tice 
640e139cf23SCaroline Tice static const char *
641e139cf23SCaroline Tice BreakpointIDRangeHelpTextCallback ()
642e139cf23SCaroline Tice {
643405fe67fSCaroline 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.";
644e139cf23SCaroline Tice }
645e139cf23SCaroline Tice 
6460a3958e0SEnrico Granata static const char *
6470a3958e0SEnrico Granata FormatHelpTextCallback ()
6480a3958e0SEnrico Granata {
64982a7d983SEnrico Granata 
65082a7d983SEnrico Granata     static char* help_text_ptr = NULL;
65182a7d983SEnrico Granata 
65282a7d983SEnrico Granata     if (help_text_ptr)
65382a7d983SEnrico Granata         return help_text_ptr;
65482a7d983SEnrico Granata 
6550a3958e0SEnrico Granata     StreamString sstr;
6560a3958e0SEnrico Granata     sstr << "One of the format names (or one-character names) that can be used to show a variable's value:\n";
6570a3958e0SEnrico Granata     for (Format f = eFormatDefault; f < kNumFormats; f = Format(f+1))
6580a3958e0SEnrico Granata     {
65982a7d983SEnrico Granata         if (f != eFormatDefault)
66082a7d983SEnrico Granata             sstr.PutChar('\n');
66182a7d983SEnrico Granata 
6620a3958e0SEnrico Granata         char format_char = FormatManager::GetFormatAsFormatChar(f);
6630a3958e0SEnrico Granata         if (format_char)
6640a3958e0SEnrico Granata             sstr.Printf("'%c' or ", format_char);
6650a3958e0SEnrico Granata 
66682a7d983SEnrico Granata         sstr.Printf ("\"%s\"", FormatManager::GetFormatAsCString(f));
6670a3958e0SEnrico Granata     }
6680a3958e0SEnrico Granata 
6690a3958e0SEnrico Granata     sstr.Flush();
6700a3958e0SEnrico Granata 
6710a3958e0SEnrico Granata     std::string data = sstr.GetString();
6720a3958e0SEnrico Granata 
67382a7d983SEnrico Granata     help_text_ptr = new char[data.length()+1];
6740a3958e0SEnrico Granata 
67582a7d983SEnrico Granata     data.copy(help_text_ptr, data.length());
6760a3958e0SEnrico Granata 
67782a7d983SEnrico Granata     return help_text_ptr;
6780a3958e0SEnrico Granata }
6790a3958e0SEnrico Granata 
6800a3958e0SEnrico Granata static const char *
68182a7d983SEnrico Granata SummaryStringHelpTextCallback()
6820a3958e0SEnrico Granata {
68382a7d983SEnrico Granata     return
68482a7d983SEnrico Granata         "A summary string is a way to extract information from variables in order to present them using a summary.\n"
68582a7d983SEnrico Granata         "Summary strings contain static text, variables, scopes and control sequences:\n"
68682a7d983SEnrico Granata         "  - Static text can be any sequence of non-special characters, i.e. anything but '{', '}', '$', or '\\'.\n"
68782a7d983SEnrico Granata         "  - Variables are sequences of characters beginning with ${, ending with } and that contain symbols in the format described below.\n"
68882a7d983SEnrico 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"
68982a7d983SEnrico Granata         "  - Control sequences are the usual C/C++ '\\a', '\\n', ..., plus '\\$', '\\{' and '\\}'.\n"
69082a7d983SEnrico 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"
69182a7d983SEnrico 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"
69282a7d983SEnrico 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"
69382a7d983SEnrico 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"
69482a7d983SEnrico 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"
69582a7d983SEnrico 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"
69682a7d983SEnrico 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."
69782a7d983SEnrico 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"
69882a7d983SEnrico Granata         " path refers to:\n"
69982a7d983SEnrico 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"
70082a7d983SEnrico Granata         " and displayed as an individual variable\n"
70182a7d983SEnrico 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"
70282a7d983SEnrico 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"
70382a7d983SEnrico 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.";
7040a3958e0SEnrico Granata }
7050a3958e0SEnrico Granata 
7069d0402b1SGreg Clayton const char *
7079d0402b1SGreg Clayton CommandObject::GetArgumentTypeAsCString (const lldb::CommandArgumentType arg_type)
7089d0402b1SGreg Clayton {
7099d0402b1SGreg Clayton     if (arg_type >=0 && arg_type < eArgTypeLastArg)
7109d0402b1SGreg Clayton         return g_arguments_data[arg_type].arg_name;
7119d0402b1SGreg Clayton     return NULL;
7129d0402b1SGreg Clayton 
7139d0402b1SGreg Clayton }
7149d0402b1SGreg Clayton 
7159d0402b1SGreg Clayton const char *
7169d0402b1SGreg Clayton CommandObject::GetArgumentDescriptionAsCString (const lldb::CommandArgumentType arg_type)
7179d0402b1SGreg Clayton {
7189d0402b1SGreg Clayton     if (arg_type >=0 && arg_type < eArgTypeLastArg)
7199d0402b1SGreg Clayton         return g_arguments_data[arg_type].help_text;
7209d0402b1SGreg Clayton     return NULL;
7219d0402b1SGreg Clayton }
7229d0402b1SGreg Clayton 
723e139cf23SCaroline Tice CommandObject::ArgumentTableEntry
724e139cf23SCaroline Tice CommandObject::g_arguments_data[] =
725e139cf23SCaroline Tice {
7267f941d95SEnrico Granata     { eArgTypeAddress, "address", CommandCompletions::eNoCompletion, { NULL, false }, "A valid address in the target program's execution space." },
7277f941d95SEnrico Granata     { eArgTypeAliasName, "alias-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of an abbreviation (alias) for a debugger command." },
7287f941d95SEnrico 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.)" },
7297f941d95SEnrico Granata     { eArgTypeArchitecture, "arch", CommandCompletions::eArchitectureCompletion, { NULL, false }, "The architecture name, e.g. i386 or x86_64." },
7307f941d95SEnrico Granata     { eArgTypeBoolean, "boolean", CommandCompletions::eNoCompletion, { NULL, false }, "A Boolean value: 'true' or 'false'" },
7317f941d95SEnrico Granata     { eArgTypeBreakpointID, "breakpt-id", CommandCompletions::eNoCompletion, { BreakpointIDHelpTextCallback, false }, NULL },
7327f941d95SEnrico Granata     { eArgTypeBreakpointIDRange, "breakpt-id-list", CommandCompletions::eNoCompletion, { BreakpointIDRangeHelpTextCallback, false }, NULL },
7337f941d95SEnrico Granata     { eArgTypeByteSize, "byte-size", CommandCompletions::eNoCompletion, { NULL, false }, "Number of bytes to use." },
7347f941d95SEnrico Granata     { eArgTypeClassName, "class-name", CommandCompletions::eNoCompletion, { NULL, false }, "Then name of a class from the debug information in the program." },
7357f941d95SEnrico Granata     { eArgTypeCommandName, "cmd-name", CommandCompletions::eNoCompletion, { NULL, false }, "A debugger command (may be multiple words), without any options or arguments." },
7367f941d95SEnrico Granata     { eArgTypeCount, "count", CommandCompletions::eNoCompletion, { NULL, false }, "An unsigned integer." },
7377f941d95SEnrico Granata     { eArgTypeEndAddress, "end-address", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
7387f941d95SEnrico Granata     { eArgTypeExpression, "expr", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
7397f941d95SEnrico 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] ]" },
7407f941d95SEnrico Granata     { eArgTypeFilename, "filename", CommandCompletions::eDiskFileCompletion, { NULL, false }, "The name of a file (can include path)." },
7417f941d95SEnrico Granata     { eArgTypeFormat, "format", CommandCompletions::eNoCompletion, { FormatHelpTextCallback, true }, NULL },
7427f941d95SEnrico Granata     { eArgTypeFrameIndex, "frame-index", CommandCompletions::eNoCompletion, { NULL, false }, "Index into a thread's list of frames." },
7437f941d95SEnrico Granata     { eArgTypeFullName, "fullname", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
7447f941d95SEnrico Granata     { eArgTypeFunctionName, "function-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a function." },
7457f941d95SEnrico Granata     { eArgTypeIndex, "index", CommandCompletions::eNoCompletion, { NULL, false }, "An index into a list." },
7467f941d95SEnrico Granata     { eArgTypeLineNum, "linenum", CommandCompletions::eNoCompletion, { NULL, false }, "Line number in a source file." },
7477f941d95SEnrico 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." },
7487f941d95SEnrico 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)." },
7497f941d95SEnrico Granata     { eArgTypeMethod, "method", CommandCompletions::eNoCompletion, { NULL, false }, "A C++ method name." },
7507f941d95SEnrico Granata     { eArgTypeName, "name", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
7517f941d95SEnrico Granata     { eArgTypeNewPathPrefix, "new-path-prefix", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
7527f941d95SEnrico Granata     { eArgTypeNumLines, "num-lines", CommandCompletions::eNoCompletion, { NULL, false }, "The number of lines to use." },
7537f941d95SEnrico Granata     { eArgTypeNumberPerLine, "number-per-line", CommandCompletions::eNoCompletion, { NULL, false }, "The number of items per line to display." },
7547f941d95SEnrico Granata     { eArgTypeOffset, "offset", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
7557f941d95SEnrico Granata     { eArgTypeOldPathPrefix, "old-path-prefix", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
7567f941d95SEnrico Granata     { eArgTypeOneLiner, "one-line-command", CommandCompletions::eNoCompletion, { NULL, false }, "A command that is entered as a single line of text." },
7577f941d95SEnrico Granata     { eArgTypePath, "path", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
7587f941d95SEnrico Granata     { eArgTypePid, "pid", CommandCompletions::eNoCompletion, { NULL, false }, "The process ID number." },
7597f941d95SEnrico Granata     { eArgTypePlugin, "plugin", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
7607f941d95SEnrico Granata     { eArgTypeProcessName, "process-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of the process." },
7617f941d95SEnrico Granata     { eArgTypeQueueName, "queue-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of the thread queue." },
7627f941d95SEnrico Granata     { eArgTypeRegisterName, "register-name", CommandCompletions::eNoCompletion, { NULL, false }, "A register name." },
7637f941d95SEnrico Granata     { eArgTypeRegularExpression, "regular-expression", CommandCompletions::eNoCompletion, { NULL, false }, "A regular expression." },
7647f941d95SEnrico Granata     { eArgTypeRunArgs, "run-args", CommandCompletions::eNoCompletion, { NULL, false }, "Arguments to be passed to the target program when it starts executing." },
7657f941d95SEnrico Granata     { eArgTypeRunMode, "run-mode", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
7667f941d95SEnrico Granata     { eArgTypeScriptLang, "script-language", CommandCompletions::eNoCompletion, { NULL, false }, "The scripting language to be used for script-based commands.  Currently only Python is valid." },
7677f941d95SEnrico Granata     { eArgTypeSearchWord, "search-word", CommandCompletions::eNoCompletion, { NULL, false }, "The word for which you wish to search for information about." },
7687f941d95SEnrico Granata     { eArgTypeSelector, "selector", CommandCompletions::eNoCompletion, { NULL, false }, "An Objective-C selector name." },
7697f941d95SEnrico 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)." },
7707f941d95SEnrico 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)." },
7717f941d95SEnrico Granata     { eArgTypeSettingPrefix, "setting-prefix", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a settable internal debugger variable up to a dot ('.'), e.g. 'target.process.'" },
7727f941d95SEnrico 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." },
7737f941d95SEnrico Granata     { eArgTypeShlibName, "shlib-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a shared library." },
7747f941d95SEnrico Granata     { eArgTypeSourceFile, "source-file", CommandCompletions::eSourceFileCompletion, { NULL, false }, "The name of a source file.." },
7757f941d95SEnrico Granata     { eArgTypeSortOrder, "sort-order", CommandCompletions::eNoCompletion, { NULL, false }, "Specify a sort order when dumping lists." },
7767f941d95SEnrico Granata     { eArgTypeStartAddress, "start-address", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
7777f941d95SEnrico Granata     { eArgTypeSummaryString, "summary-string", CommandCompletions::eNoCompletion, { SummaryStringHelpTextCallback, true }, NULL },
7787f941d95SEnrico Granata     { eArgTypeSymbol, "symbol", CommandCompletions::eSymbolCompletion, { NULL, false }, "Any symbol name (function name, variable, argument, etc.)" },
7797f941d95SEnrico Granata     { eArgTypeThreadID, "thread-id", CommandCompletions::eNoCompletion, { NULL, false }, "Thread ID number." },
7807f941d95SEnrico Granata     { eArgTypeThreadIndex, "thread-index", CommandCompletions::eNoCompletion, { NULL, false }, "Index into the process' list of threads." },
7817f941d95SEnrico Granata     { eArgTypeThreadName, "thread-name", CommandCompletions::eNoCompletion, { NULL, false }, "The thread's name." },
782*331eff39SJohnny Chen     { eArgTypeUnsignedInteger, "unsigned-integer", CommandCompletions::eNoCompletion, { NULL, false }, "An unsigned integer." },
7837f941d95SEnrico Granata     { eArgTypeUnixSignal, "unix-signal", CommandCompletions::eNoCompletion, { NULL, false }, "A valid Unix signal name or number (e.g. SIGKILL, KILL or 9)." },
7847f941d95SEnrico Granata     { eArgTypeVarName, "variable-name", CommandCompletions::eNoCompletion, { NULL, false }, "The name of a variable in your program." },
7857f941d95SEnrico Granata     { eArgTypeValue, "value", CommandCompletions::eNoCompletion, { NULL, false }, "A value could be anything, depending on where and how it is used." },
7867f941d95SEnrico Granata     { eArgTypeWidth, "width", CommandCompletions::eNoCompletion, { NULL, false }, "Help text goes here." },
7877f941d95SEnrico Granata     { eArgTypeNone, "none", CommandCompletions::eNoCompletion, { NULL, false }, "No help available for this." },
7887f941d95SEnrico 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." }
789e139cf23SCaroline Tice };
790e139cf23SCaroline Tice 
791e139cf23SCaroline Tice const CommandObject::ArgumentTableEntry*
792e139cf23SCaroline Tice CommandObject::GetArgumentTable ()
793e139cf23SCaroline Tice {
7949d0402b1SGreg Clayton     // If this assertion fires, then the table above is out of date with the CommandArgumentType enumeration
7959d0402b1SGreg Clayton     assert ((sizeof (CommandObject::g_arguments_data) / sizeof (CommandObject::ArgumentTableEntry)) == eArgTypeLastArg);
796e139cf23SCaroline Tice     return CommandObject::g_arguments_data;
797e139cf23SCaroline Tice }
798e139cf23SCaroline Tice 
799e139cf23SCaroline Tice 
800