Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- CommandObjectSyntax.cpp ---------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Daniel Malea | d891f9b | 2012-12-05 00:20:57 +0000 | [diff] [blame^] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | #include "CommandObjectSyntax.h" |
| 13 | |
| 14 | // C Includes |
| 15 | // C++ Includes |
| 16 | // Other libraries and framework includes |
| 17 | // Project includes |
Jim Ingham | 84cdc15 | 2010-06-15 19:49:27 +0000 | [diff] [blame] | 18 | #include "lldb/Interpreter/Args.h" |
| 19 | #include "lldb/Interpreter/Options.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | |
| 21 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 22 | #include "lldb/Interpreter/CommandReturnObject.h" |
| 23 | #include "lldb/Interpreter/CommandObjectMultiword.h" |
| 24 | |
| 25 | using namespace lldb; |
| 26 | using namespace lldb_private; |
| 27 | |
| 28 | //------------------------------------------------------------------------- |
| 29 | // CommandObjectSyntax |
| 30 | //------------------------------------------------------------------------- |
| 31 | |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 32 | CommandObjectSyntax::CommandObjectSyntax (CommandInterpreter &interpreter) : |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 33 | CommandObjectParsed (interpreter, |
| 34 | "syntax", |
| 35 | "Shows the correct syntax for a given debugger command.", |
| 36 | "syntax <command>") |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 37 | { |
Caroline Tice | 43b014a | 2010-10-04 22:28:36 +0000 | [diff] [blame] | 38 | CommandArgumentEntry arg; |
| 39 | CommandArgumentData command_arg; |
| 40 | |
| 41 | // Define the first (and only) variant of this arg. |
| 42 | command_arg.arg_type = eArgTypeCommandName; |
| 43 | command_arg.arg_repetition = eArgRepeatPlain; |
| 44 | |
| 45 | // There is only one variant this argument could be; put it into the argument entry. |
| 46 | arg.push_back (command_arg); |
| 47 | |
| 48 | // Push the data for the first argument into the m_arguments vector. |
| 49 | m_arguments.push_back (arg); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | CommandObjectSyntax::~CommandObjectSyntax() |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | |
| 57 | bool |
Jim Ingham | da26bd2 | 2012-06-08 21:56:10 +0000 | [diff] [blame] | 58 | CommandObjectSyntax::DoExecute (Args& command, CommandReturnObject &result) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 59 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 60 | CommandObject::CommandMap::iterator pos; |
| 61 | CommandObject *cmd_obj; |
| 62 | const int argc = command.GetArgumentCount(); |
| 63 | |
| 64 | if (argc > 0) |
| 65 | { |
Greg Clayton | 238c0a1 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 66 | cmd_obj = m_interpreter.GetCommandObject (command.GetArgumentAtIndex(0)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 67 | bool all_okay = true; |
| 68 | for (int i = 1; i < argc; ++i) |
| 69 | { |
| 70 | std::string sub_command = command.GetArgumentAtIndex (i); |
Greg Clayton | 13193d5 | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 71 | if (!cmd_obj->IsMultiwordObject()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 72 | all_okay = false; |
| 73 | else |
| 74 | { |
Greg Clayton | 13193d5 | 2012-10-13 02:07:45 +0000 | [diff] [blame] | 75 | cmd_obj = cmd_obj->GetSubcommandObject(sub_command.c_str()); |
| 76 | if (!cmd_obj) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 77 | all_okay = false; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | if (all_okay && (cmd_obj != NULL)) |
| 82 | { |
| 83 | Stream &output_strm = result.GetOutputStream(); |
| 84 | if (cmd_obj->GetOptions() != NULL) |
| 85 | { |
| 86 | output_strm.Printf ("\nSyntax: %s\n", cmd_obj->GetSyntax()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 87 | output_strm.Printf ("(Try 'help %s' for more information on command options syntax.)\n", |
| 88 | cmd_obj->GetCommandName()); |
| 89 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 90 | } |
| 91 | else |
| 92 | { |
| 93 | output_strm.Printf ("\nSyntax: %s\n", cmd_obj->GetSyntax()); |
| 94 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 95 | } |
| 96 | } |
| 97 | else |
| 98 | { |
| 99 | std::string cmd_string; |
| 100 | command.GetCommandString (cmd_string); |
| 101 | result.AppendErrorWithFormat ("'%s' is not a known command.\n", cmd_string.c_str()); |
| 102 | result.AppendError ("Try 'help' to see a current list of commands."); |
| 103 | result.SetStatus (eReturnStatusFailed); |
| 104 | } |
| 105 | } |
| 106 | else |
| 107 | { |
| 108 | result.AppendError ("Must call 'syntax' with a valid command."); |
| 109 | result.SetStatus (eReturnStatusFailed); |
| 110 | } |
| 111 | |
| 112 | return result.Succeeded(); |
| 113 | } |