SBCommandInterpreter.h revision 6d101887bb427b3c879c0c06775ab4dcb1cd265b
1//===-- SBCommandInterpreter.h ----------------------------------*- 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#ifndef LLDB_SBCommandInterpreter_h_
11#define LLDB_SBCommandInterpreter_h_
12
13#include "lldb/API/SBDefines.h"
14#include "lldb/API/SBDebugger.h"
15
16namespace lldb {
17
18class SBCommandInterpreter
19{
20public:
21    enum
22    {
23        eBroadcastBitThreadShouldExit       = (1 << 0),
24        eBroadcastBitResetPrompt            = (1 << 1),
25        eBroadcastBitQuitCommandReceived    = (1 << 2),           // User entered quit
26        eBroadcastBitAsynchronousOutputData = (1 << 3),
27        eBroadcastBitAsynchronousErrorData  = (1 << 4)
28    };
29
30    SBCommandInterpreter (const lldb::SBCommandInterpreter &rhs);
31
32    const lldb::SBCommandInterpreter &
33    operator = (const lldb::SBCommandInterpreter &rhs);
34
35    ~SBCommandInterpreter ();
36
37    static const char *
38    GetArgumentTypeAsCString (const lldb::CommandArgumentType arg_type);
39
40    static const char *
41    GetArgumentDescriptionAsCString (const lldb::CommandArgumentType arg_type);
42
43    bool
44    IsValid() const;
45
46    bool
47    CommandExists (const char *cmd);
48
49    bool
50    AliasExists (const char *cmd);
51
52    lldb::SBBroadcaster
53    GetBroadcaster ();
54
55    static const char *
56    GetBroadcasterClass ();
57
58    bool
59    HasCommands ();
60
61    bool
62    HasAliases ();
63
64    bool
65    HasAliasOptions ();
66
67    lldb::SBProcess
68    GetProcess ();
69
70    lldb::SBDebugger
71    GetDebugger ();
72
73    lldb::SBCommand
74    AddMultiwordCommand (const char* name, const char* help);
75
76    lldb::SBCommand
77    AddCommand (const char* name, lldb::SBCommandPluginInterface *impl, const char* help);
78
79    void
80    SourceInitFileInHomeDirectory (lldb::SBCommandReturnObject &result);
81
82    void
83    SourceInitFileInCurrentWorkingDirectory (lldb::SBCommandReturnObject &result);
84
85    lldb::ReturnStatus
86    HandleCommand (const char *command_line, lldb::SBCommandReturnObject &result, bool add_to_history = false);
87
88    // This interface is not useful in SWIG, since the cursor & last_char arguments are string pointers INTO current_line
89    // and you can't do that in a scripting language interface in general...
90    int
91    HandleCompletion (const char *current_line,
92                      const char *cursor,
93                      const char *last_char,
94                      int match_start_point,
95                      int max_return_elements,
96                      lldb::SBStringList &matches);
97
98    int
99    HandleCompletion (const char *current_line,
100                      uint32_t cursor_pos,
101                      int match_start_point,
102                      int max_return_elements,
103                      lldb::SBStringList &matches);
104
105    // Catch commands before they execute by registering a callback that will
106    // get called when the command gets executed. This allows GUI or command
107    // line interfaces to intercept a command and stop it from happening
108    bool
109    SetCommandOverrideCallback (const char *command_name,
110                                lldb::CommandOverrideCallback callback,
111                                void *baton);
112
113    SBCommandInterpreter (lldb_private::CommandInterpreter *interpreter_ptr = NULL);   // Access using SBDebugger::GetCommandInterpreter();
114
115protected:
116
117    lldb_private::CommandInterpreter &
118    ref ();
119
120    lldb_private::CommandInterpreter *
121    get ();
122
123    void
124    reset (lldb_private::CommandInterpreter *);
125private:
126    friend class SBDebugger;
127
128    static void
129    InitializeSWIG ();
130
131    lldb_private::CommandInterpreter *m_opaque_ptr;
132};
133
134class SBCommandPluginInterface
135{
136public:
137    virtual bool
138    DoExecute (lldb::SBDebugger debugger,
139               char** command,
140               lldb::SBCommandReturnObject &result)
141    {
142        return false;
143    }
144
145    virtual
146    ~SBCommandPluginInterface ()
147    {}
148};
149
150class SBCommand
151{
152public:
153
154    SBCommand ();
155
156    bool
157    IsValid ();
158
159    const char*
160    GetName ();
161
162    const char*
163    GetHelp ();
164
165    lldb::SBCommand
166    AddMultiwordCommand (const char* name, const char* help = NULL);
167
168    lldb::SBCommand
169    AddCommand (const char* name, lldb::SBCommandPluginInterface* impl, const char* help = NULL);
170
171private:
172
173    friend class SBDebugger;
174    friend class SBCommandInterpreter;
175
176    SBCommand (lldb::CommandObjectSP cmd_sp);
177
178    lldb::CommandObjectSP m_opaque_sp;
179};
180
181} // namespace lldb
182
183#endif // LLDB_SBCommandInterpreter_h_
184