blob: 28736cd16ec0decb2688eae81de4644f1be5a75f [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- CommandObjectRemove.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 "CommandObjectRemove.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
16#include "lldb/Interpreter/CommandInterpreter.h"
17#include "lldb/Interpreter/CommandReturnObject.h"
18
19using namespace lldb;
20using namespace lldb_private;
21
22//-------------------------------------------------------------------------
23// CommandObjectRemove
24//-------------------------------------------------------------------------
25
26CommandObjectRemove::CommandObjectRemove () :
27 CommandObject ("remove",
28 "Allows the user to remove/delete user-defined command functions (script functions).",
29 "remove <command-name-to-be-removed>")
30{
31}
32
33CommandObjectRemove::~CommandObjectRemove()
34{
35}
36
37
38bool
39CommandObjectRemove::Execute (Args& args, CommandContext *context, CommandInterpreter *interpreter,
40 CommandReturnObject &result)
41{
42 CommandObject::CommandMap::iterator pos;
43 CommandObject *cmd_obj;
44
45 if (args.GetArgumentCount() != 0)
46 {
47 const char *command_name = args.GetArgumentAtIndex(0);
48 cmd_obj = interpreter->GetCommandObject(command_name);
49 if (cmd_obj)
50 {
51 if (interpreter->CommandExists (command_name))
52 {
53 result.AppendErrorWithFormat ("'%s' is a permanent debugger command and cannot be removed.\n",
54 command_name);
55 result.SetStatus (eReturnStatusFailed);
56 }
57 else
58 {
59
60 if (interpreter->RemoveUser (command_name) == false)
61 {
62 if (interpreter->UserCommandExists (command_name))
63 result.AppendErrorWithFormat ("Unknown error occurred; unable to remove command '%s'.\n",
64 command_name);
65 else
66 result.AppendErrorWithFormat ("'%s' is not a user-defined command/function name.\n",
67 command_name);
68 result.SetStatus (eReturnStatusFailed);
69 }
70 else
71 result.SetStatus (eReturnStatusSuccessFinishNoResult);
72 }
73 }
74 else
75 {
76 result.AppendErrorWithFormat ("'%s' is not a known command.\nTry 'help' to see a current list of commands.\n",
77 command_name);
78 result.SetStatus (eReturnStatusFailed);
79 }
80 }
81 else
82 {
83 result.AppendError ("must call remove with a valid command");
84 result.SetStatus (eReturnStatusFailed);
85 }
86
87 return result.Succeeded();
88}
89