]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Commands/CommandObjectSyntax.cpp
Merge ^/head r285793 through r285923.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Commands / CommandObjectSyntax.cpp
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
10 #include "CommandObjectSyntax.h"
11
12 // C Includes
13 // C++ Includes
14 // Other libraries and framework includes
15 // Project includes
16 #include "lldb/Interpreter/Args.h"
17 #include "lldb/Interpreter/Options.h"
18
19 #include "lldb/Interpreter/CommandInterpreter.h"
20 #include "lldb/Interpreter/CommandReturnObject.h"
21 #include "lldb/Interpreter/CommandObjectMultiword.h"
22
23 using namespace lldb;
24 using namespace lldb_private;
25
26 //-------------------------------------------------------------------------
27 // CommandObjectSyntax
28 //-------------------------------------------------------------------------
29
30 CommandObjectSyntax::CommandObjectSyntax (CommandInterpreter &interpreter) :
31     CommandObjectParsed (interpreter,
32                          "syntax",
33                          "Shows the correct syntax for a given debugger command.",
34                          "syntax <command>")
35 {
36     CommandArgumentEntry arg;
37     CommandArgumentData command_arg;
38
39     // Define the first (and only) variant of this arg.
40     command_arg.arg_type = eArgTypeCommandName;
41     command_arg.arg_repetition = eArgRepeatPlain;
42
43     // There is only one variant this argument could be; put it into the argument entry.
44     arg.push_back (command_arg);
45
46     // Push the data for the first argument into the m_arguments vector.
47     m_arguments.push_back (arg);
48 }
49
50 CommandObjectSyntax::~CommandObjectSyntax()
51 {
52 }
53
54
55 bool
56 CommandObjectSyntax::DoExecute (Args& command, CommandReturnObject &result)
57 {
58     CommandObject::CommandMap::iterator pos;
59     CommandObject *cmd_obj;
60     const size_t argc = command.GetArgumentCount();
61
62     if (argc > 0)
63     {
64         cmd_obj = m_interpreter.GetCommandObject (command.GetArgumentAtIndex(0));
65         bool all_okay = true;
66         for (size_t i = 1; i < argc; ++i)
67         {
68             std::string sub_command = command.GetArgumentAtIndex (i);
69             if (!cmd_obj->IsMultiwordObject())
70             {
71                 all_okay = false;
72                 break;
73             }
74             else
75             {
76                 cmd_obj = cmd_obj->GetSubcommandObject(sub_command.c_str());
77                 if (!cmd_obj)
78                 {
79                     all_okay = false;
80                     break;
81                 }
82             }
83         }
84         
85         if (all_okay && (cmd_obj != NULL))
86         {
87             Stream &output_strm = result.GetOutputStream();
88             if (cmd_obj->GetOptions() != NULL)
89             {
90                 output_strm.Printf ("\nSyntax: %s\n", cmd_obj->GetSyntax());
91                 output_strm.Printf ("(Try 'help %s' for more information on command options syntax.)\n",
92                                     cmd_obj->GetCommandName());
93                 result.SetStatus (eReturnStatusSuccessFinishNoResult);
94             }
95             else
96             {
97                 output_strm.Printf ("\nSyntax: %s\n", cmd_obj->GetSyntax());
98                 result.SetStatus (eReturnStatusSuccessFinishNoResult);
99             }
100         }
101         else
102         {
103             std::string cmd_string;
104             command.GetCommandString (cmd_string);
105             result.AppendErrorWithFormat ("'%s' is not a known command.\n", cmd_string.c_str());
106             result.AppendError ("Try 'help' to see a current list of commands.");
107             result.SetStatus (eReturnStatusFailed);
108         }
109     }
110     else
111     {
112         result.AppendError ("Must call 'syntax' with a valid command.");
113         result.SetStatus (eReturnStatusFailed);
114     }
115
116     return result.Succeeded();
117 }