1254721Semaste//===-- CommandObjectSyntax.cpp ---------------------------------*- C++ -*-===// 2254721Semaste// 3254721Semaste// The LLVM Compiler Infrastructure 4254721Semaste// 5254721Semaste// This file is distributed under the University of Illinois Open Source 6254721Semaste// License. See LICENSE.TXT for details. 7254721Semaste// 8254721Semaste//===----------------------------------------------------------------------===// 9254721Semaste 10254721Semaste#include "lldb/lldb-python.h" 11254721Semaste 12254721Semaste#include "CommandObjectSyntax.h" 13254721Semaste 14254721Semaste// C Includes 15254721Semaste// C++ Includes 16254721Semaste// Other libraries and framework includes 17254721Semaste// Project includes 18254721Semaste#include "lldb/Interpreter/Args.h" 19254721Semaste#include "lldb/Interpreter/Options.h" 20254721Semaste 21254721Semaste#include "lldb/Interpreter/CommandInterpreter.h" 22254721Semaste#include "lldb/Interpreter/CommandReturnObject.h" 23254721Semaste#include "lldb/Interpreter/CommandObjectMultiword.h" 24254721Semaste 25254721Semasteusing namespace lldb; 26254721Semasteusing namespace lldb_private; 27254721Semaste 28254721Semaste//------------------------------------------------------------------------- 29254721Semaste// CommandObjectSyntax 30254721Semaste//------------------------------------------------------------------------- 31254721Semaste 32254721SemasteCommandObjectSyntax::CommandObjectSyntax (CommandInterpreter &interpreter) : 33254721Semaste CommandObjectParsed (interpreter, 34254721Semaste "syntax", 35254721Semaste "Shows the correct syntax for a given debugger command.", 36254721Semaste "syntax <command>") 37254721Semaste{ 38254721Semaste CommandArgumentEntry arg; 39254721Semaste CommandArgumentData command_arg; 40254721Semaste 41254721Semaste // Define the first (and only) variant of this arg. 42254721Semaste command_arg.arg_type = eArgTypeCommandName; 43254721Semaste command_arg.arg_repetition = eArgRepeatPlain; 44254721Semaste 45254721Semaste // There is only one variant this argument could be; put it into the argument entry. 46254721Semaste arg.push_back (command_arg); 47254721Semaste 48254721Semaste // Push the data for the first argument into the m_arguments vector. 49254721Semaste m_arguments.push_back (arg); 50254721Semaste} 51254721Semaste 52254721SemasteCommandObjectSyntax::~CommandObjectSyntax() 53254721Semaste{ 54254721Semaste} 55254721Semaste 56254721Semaste 57254721Semastebool 58254721SemasteCommandObjectSyntax::DoExecute (Args& command, CommandReturnObject &result) 59254721Semaste{ 60254721Semaste CommandObject::CommandMap::iterator pos; 61254721Semaste CommandObject *cmd_obj; 62254721Semaste const size_t argc = command.GetArgumentCount(); 63254721Semaste 64254721Semaste if (argc > 0) 65254721Semaste { 66254721Semaste cmd_obj = m_interpreter.GetCommandObject (command.GetArgumentAtIndex(0)); 67254721Semaste bool all_okay = true; 68254721Semaste for (size_t i = 1; i < argc; ++i) 69254721Semaste { 70254721Semaste std::string sub_command = command.GetArgumentAtIndex (i); 71254721Semaste if (!cmd_obj->IsMultiwordObject()) 72254721Semaste all_okay = false; 73254721Semaste else 74254721Semaste { 75254721Semaste cmd_obj = cmd_obj->GetSubcommandObject(sub_command.c_str()); 76254721Semaste if (!cmd_obj) 77254721Semaste all_okay = false; 78254721Semaste } 79254721Semaste } 80254721Semaste 81254721Semaste if (all_okay && (cmd_obj != NULL)) 82254721Semaste { 83254721Semaste Stream &output_strm = result.GetOutputStream(); 84254721Semaste if (cmd_obj->GetOptions() != NULL) 85254721Semaste { 86254721Semaste output_strm.Printf ("\nSyntax: %s\n", cmd_obj->GetSyntax()); 87254721Semaste output_strm.Printf ("(Try 'help %s' for more information on command options syntax.)\n", 88254721Semaste cmd_obj->GetCommandName()); 89254721Semaste result.SetStatus (eReturnStatusSuccessFinishNoResult); 90254721Semaste } 91254721Semaste else 92254721Semaste { 93254721Semaste output_strm.Printf ("\nSyntax: %s\n", cmd_obj->GetSyntax()); 94254721Semaste result.SetStatus (eReturnStatusSuccessFinishNoResult); 95254721Semaste } 96254721Semaste } 97254721Semaste else 98254721Semaste { 99254721Semaste std::string cmd_string; 100254721Semaste command.GetCommandString (cmd_string); 101254721Semaste result.AppendErrorWithFormat ("'%s' is not a known command.\n", cmd_string.c_str()); 102254721Semaste result.AppendError ("Try 'help' to see a current list of commands."); 103254721Semaste result.SetStatus (eReturnStatusFailed); 104254721Semaste } 105254721Semaste } 106254721Semaste else 107254721Semaste { 108254721Semaste result.AppendError ("Must call 'syntax' with a valid command."); 109254721Semaste result.SetStatus (eReturnStatusFailed); 110254721Semaste } 111254721Semaste 112254721Semaste return result.Succeeded(); 113254721Semaste} 114