blob: 64308aac5e54707de4688e9b95a916aa9e6d8290 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- 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
Jim Ingham84cdc152010-06-15 19:49:27 +000016#include "lldb/Interpreter/Args.h"
17#include "lldb/Interpreter/Options.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018
19#include "lldb/Interpreter/CommandInterpreter.h"
20#include "lldb/Interpreter/CommandReturnObject.h"
21#include "lldb/Interpreter/CommandObjectMultiword.h"
22
23using namespace lldb;
24using namespace lldb_private;
25
26//-------------------------------------------------------------------------
27// CommandObjectSyntax
28//-------------------------------------------------------------------------
29
Greg Clayton238c0a12010-09-18 01:14:36 +000030CommandObjectSyntax::CommandObjectSyntax (CommandInterpreter &interpreter) :
Jim Inghamda26bd22012-06-08 21:56:10 +000031 CommandObjectParsed (interpreter,
32 "syntax",
33 "Shows the correct syntax for a given debugger command.",
34 "syntax <command>")
Chris Lattner24943d22010-06-08 16:52:24 +000035{
Caroline Tice43b014a2010-10-04 22:28:36 +000036 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);
Chris Lattner24943d22010-06-08 16:52:24 +000048}
49
50CommandObjectSyntax::~CommandObjectSyntax()
51{
52}
53
54
55bool
Jim Inghamda26bd22012-06-08 21:56:10 +000056CommandObjectSyntax::DoExecute (Args& command, CommandReturnObject &result)
Chris Lattner24943d22010-06-08 16:52:24 +000057{
Chris Lattner24943d22010-06-08 16:52:24 +000058 CommandObject::CommandMap::iterator pos;
59 CommandObject *cmd_obj;
60 const int argc = command.GetArgumentCount();
61
62 if (argc > 0)
63 {
Greg Clayton238c0a12010-09-18 01:14:36 +000064 cmd_obj = m_interpreter.GetCommandObject (command.GetArgumentAtIndex(0));
Chris Lattner24943d22010-06-08 16:52:24 +000065 bool all_okay = true;
66 for (int i = 1; i < argc; ++i)
67 {
68 std::string sub_command = command.GetArgumentAtIndex (i);
Greg Clayton13193d52012-10-13 02:07:45 +000069 if (!cmd_obj->IsMultiwordObject())
Chris Lattner24943d22010-06-08 16:52:24 +000070 all_okay = false;
71 else
72 {
Greg Clayton13193d52012-10-13 02:07:45 +000073 cmd_obj = cmd_obj->GetSubcommandObject(sub_command.c_str());
74 if (!cmd_obj)
Chris Lattner24943d22010-06-08 16:52:24 +000075 all_okay = false;
76 }
77 }
78
79 if (all_okay && (cmd_obj != NULL))
80 {
81 Stream &output_strm = result.GetOutputStream();
82 if (cmd_obj->GetOptions() != NULL)
83 {
84 output_strm.Printf ("\nSyntax: %s\n", cmd_obj->GetSyntax());
Chris Lattner24943d22010-06-08 16:52:24 +000085 output_strm.Printf ("(Try 'help %s' for more information on command options syntax.)\n",
86 cmd_obj->GetCommandName());
87 result.SetStatus (eReturnStatusSuccessFinishNoResult);
88 }
89 else
90 {
91 output_strm.Printf ("\nSyntax: %s\n", cmd_obj->GetSyntax());
92 result.SetStatus (eReturnStatusSuccessFinishNoResult);
93 }
94 }
95 else
96 {
97 std::string cmd_string;
98 command.GetCommandString (cmd_string);
99 result.AppendErrorWithFormat ("'%s' is not a known command.\n", cmd_string.c_str());
100 result.AppendError ("Try 'help' to see a current list of commands.");
101 result.SetStatus (eReturnStatusFailed);
102 }
103 }
104 else
105 {
106 result.AppendError ("Must call 'syntax' with a valid command.");
107 result.SetStatus (eReturnStatusFailed);
108 }
109
110 return result.Succeeded();
111}