SBCommandInterpreter.h revision 254729
190075Sobrien//===-- SBCommandInterpreter.h ----------------------------------*- C++ -*-===//
290075Sobrien//
390075Sobrien//                     The LLVM Compiler Infrastructure
490075Sobrien//
590075Sobrien// This file is distributed under the University of Illinois Open Source
690075Sobrien// License. See LICENSE.TXT for details.
790075Sobrien//
8110611Skan//===----------------------------------------------------------------------===//
990075Sobrien
1090075Sobrien#ifndef LLDB_SBCommandInterpreter_h_
1190075Sobrien#define LLDB_SBCommandInterpreter_h_
1290075Sobrien
1390075Sobrien#include "lldb/API/SBDefines.h"
1490075Sobrien#include "lldb/API/SBDebugger.h"
1590075Sobrien
1690075Sobriennamespace lldb {
1790075Sobrien
1890075Sobrienclass SBCommandInterpreter
1990075Sobrien{
2090075Sobrienpublic:
2190075Sobrien    enum
2290075Sobrien    {
2390075Sobrien        eBroadcastBitThreadShouldExit       = (1 << 0),
2490075Sobrien        eBroadcastBitResetPrompt            = (1 << 1),
2590075Sobrien        eBroadcastBitQuitCommandReceived    = (1 << 2),           // User entered quit
2690075Sobrien        eBroadcastBitAsynchronousOutputData = (1 << 3),
2790075Sobrien        eBroadcastBitAsynchronousErrorData  = (1 << 4)
2890075Sobrien    };
2990075Sobrien
3090075Sobrien    SBCommandInterpreter (const lldb::SBCommandInterpreter &rhs);
3190075Sobrien
3290075Sobrien    const lldb::SBCommandInterpreter &
3390075Sobrien    operator = (const lldb::SBCommandInterpreter &rhs);
3490075Sobrien
3590075Sobrien    ~SBCommandInterpreter ();
3690075Sobrien
3790075Sobrien    static const char *
3890075Sobrien    GetArgumentTypeAsCString (const lldb::CommandArgumentType arg_type);
3990075Sobrien
4090075Sobrien    static const char *
4190075Sobrien    GetArgumentDescriptionAsCString (const lldb::CommandArgumentType arg_type);
4290075Sobrien
43110611Skan    bool
4490075Sobrien    IsValid() const;
4590075Sobrien
4690075Sobrien    bool
4790075Sobrien    CommandExists (const char *cmd);
4890075Sobrien
4990075Sobrien    bool
5090075Sobrien    AliasExists (const char *cmd);
5190075Sobrien
5290075Sobrien    lldb::SBBroadcaster
5390075Sobrien    GetBroadcaster ();
5490075Sobrien
5590075Sobrien    static const char *
5690075Sobrien    GetBroadcasterClass ();
5790075Sobrien
5890075Sobrien    bool
5990075Sobrien    HasCommands ();
6090075Sobrien
6190075Sobrien    bool
6290075Sobrien    HasAliases ();
6390075Sobrien
6490075Sobrien    bool
6590075Sobrien    HasAliasOptions ();
6690075Sobrien
6790075Sobrien    lldb::SBProcess
6890075Sobrien    GetProcess ();
6990075Sobrien
7090075Sobrien    lldb::SBDebugger
7190075Sobrien    GetDebugger ();
7290075Sobrien
7390075Sobrien    lldb::SBCommand
7490075Sobrien    AddMultiwordCommand (const char* name, const char* help);
7590075Sobrien
7690075Sobrien    lldb::SBCommand
7790075Sobrien    AddCommand (const char* name, lldb::SBCommandPluginInterface *impl, const char* help);
7890075Sobrien
7990075Sobrien    void
8090075Sobrien    SourceInitFileInHomeDirectory (lldb::SBCommandReturnObject &result);
8190075Sobrien
8290075Sobrien    void
8390075Sobrien    SourceInitFileInCurrentWorkingDirectory (lldb::SBCommandReturnObject &result);
8490075Sobrien
8590075Sobrien    lldb::ReturnStatus
8690075Sobrien    HandleCommand (const char *command_line, lldb::SBCommandReturnObject &result, bool add_to_history = false);
8790075Sobrien
8890075Sobrien    // The pointer based interface is not useful in SWIG, since the cursor & last_char arguments are string pointers INTO current_line
8990075Sobrien    // and you can't do that in a scripting language interface in general...
9090075Sobrien
9190075Sobrien    // In either case, the way this works is that the you give it a line and cursor position in the line.  The function
9290075Sobrien    // will return the number of completions.  The matches list will contain number_of_completions + 1 elements.  The first
9390075Sobrien    // element is the common substring after the cursor position for all the matches.  The rest of the elements are the
9490075Sobrien    // matches.  The first element is useful if you are emulating the common shell behavior where the tab completes
9590075Sobrien    // to the string that is common among all the matches, then you should first check if the first element is non-empty,
9690075Sobrien    // and if so just insert it and move the cursor to the end of the insertion.  The next tab will return an empty
9790075Sobrien    // common substring, and a list of choices (if any), at which point you should display the choices and let the user
9890075Sobrien    // type further to disambiguate.
9990075Sobrien
10090075Sobrien    int
10190075Sobrien    HandleCompletion (const char *current_line,
10290075Sobrien                      const char *cursor,
10390075Sobrien                      const char *last_char,
10490075Sobrien                      int match_start_point,
10590075Sobrien                      int max_return_elements,
10690075Sobrien                      lldb::SBStringList &matches);
10790075Sobrien
10890075Sobrien    int
10990075Sobrien    HandleCompletion (const char *current_line,
11090075Sobrien                      uint32_t cursor_pos,
11190075Sobrien                      int match_start_point,
11290075Sobrien                      int max_return_elements,
11390075Sobrien                      lldb::SBStringList &matches);
11490075Sobrien
11590075Sobrien    // Catch commands before they execute by registering a callback that will
11690075Sobrien    // get called when the command gets executed. This allows GUI or command
11790075Sobrien    // line interfaces to intercept a command and stop it from happening
11890075Sobrien    bool
11990075Sobrien    SetCommandOverrideCallback (const char *command_name,
12090075Sobrien                                lldb::CommandOverrideCallback callback,
12190075Sobrien                                void *baton);
12290075Sobrien
12390075Sobrien    SBCommandInterpreter (lldb_private::CommandInterpreter *interpreter_ptr = NULL);   // Access using SBDebugger::GetCommandInterpreter();
12490075Sobrien
12590075Sobrienprotected:
12690075Sobrien
12790075Sobrien    lldb_private::CommandInterpreter &
12890075Sobrien    ref ();
12990075Sobrien
130110611Skan    lldb_private::CommandInterpreter *
13190075Sobrien    get ();
13290075Sobrien
13390075Sobrien    void
13490075Sobrien    reset (lldb_private::CommandInterpreter *);
13590075Sobrienprivate:
13690075Sobrien    friend class SBDebugger;
13790075Sobrien
13890075Sobrien    static void
13990075Sobrien    InitializeSWIG ();
14090075Sobrien
14190075Sobrien    lldb_private::CommandInterpreter *m_opaque_ptr;
14290075Sobrien};
14390075Sobrien
14490075Sobrienclass SBCommandPluginInterface
14590075Sobrien{
14690075Sobrienpublic:
14790075Sobrien    virtual bool
148110611Skan    DoExecute (lldb::SBDebugger debugger,
149110611Skan               char** command,
150110611Skan               lldb::SBCommandReturnObject &result)
15190075Sobrien    {
15290075Sobrien        return false;
15390075Sobrien    }
15490075Sobrien
15590075Sobrien    virtual
15690075Sobrien    ~SBCommandPluginInterface ()
157    {}
158};
159
160class SBCommand
161{
162public:
163
164    SBCommand ();
165
166    bool
167    IsValid ();
168
169    const char*
170    GetName ();
171
172    const char*
173    GetHelp ();
174
175    lldb::SBCommand
176    AddMultiwordCommand (const char* name, const char* help = NULL);
177
178    lldb::SBCommand
179    AddCommand (const char* name, lldb::SBCommandPluginInterface* impl, const char* help = NULL);
180
181private:
182
183    friend class SBDebugger;
184    friend class SBCommandInterpreter;
185
186    SBCommand (lldb::CommandObjectSP cmd_sp);
187
188    lldb::CommandObjectSP m_opaque_sp;
189};
190
191} // namespace lldb
192
193#endif // LLDB_SBCommandInterpreter_h_
194