ScriptInterpreter.h revision 0aa2e55f0e9422405ad33675adc1e35044537adb
1//===-- ScriptInterpreter.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 liblldb_ScriptInterpreter_h_
11#define liblldb_ScriptInterpreter_h_
12
13#include "lldb/lldb-private.h"
14#include "lldb/Core/Broadcaster.h"
15#include "lldb/Utility/PseudoTerminal.h"
16
17namespace lldb_private {
18
19class ScriptInterpreter
20{
21public:
22
23    typedef enum
24    {
25        eCharPtr,
26        eBool,
27        eShortInt,
28        eShortIntUnsigned,
29        eInt,
30        eIntUnsigned,
31        eLongInt,
32        eLongIntUnsigned,
33        eLongLong,
34        eLongLongUnsigned,
35        eFloat,
36        eDouble,
37        eChar
38    } ReturnType;
39
40
41    ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang);
42
43    virtual ~ScriptInterpreter ();
44
45    virtual bool
46    ExecuteOneLine (const char *command, CommandReturnObject *result) = 0;
47
48    virtual void
49    ExecuteInterpreterLoop () = 0;
50
51    virtual bool
52    ExecuteOneLineWithReturn (const char *in_string, ReturnType return_type, void *ret_value)
53    {
54        return true;
55    }
56
57    virtual bool
58    ExecuteMultipleLines (const char *in_string)
59    {
60        return true;
61    }
62
63    virtual bool
64    ExportFunctionDefinitionToInterpreter (StringList &function_def)
65    {
66        return false;
67    }
68
69    virtual bool
70    GenerateBreakpointCommandCallbackData (StringList &input, StringList &output)
71    {
72        return false;
73    }
74
75    virtual void
76    CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options,
77                                             CommandReturnObject &result);
78
79    /// Set a one-liner as the callback for the breakpoint.
80    virtual void
81    SetBreakpointCommandCallback (BreakpointOptions *bp_options,
82                                  const char *oneliner)
83    {
84        return;
85    }
86
87    const char *
88    GetScriptInterpreterPtyName ();
89
90    int
91    GetMasterFileDescriptor ();
92
93	CommandInterpreter &
94	GetCommandInterpreter ();
95
96     static std::string
97    LanguageToString (lldb::ScriptLanguage language);
98
99    static void
100    Initialize ();
101
102    static void
103    Terminate ();
104
105    virtual void
106    ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing.
107
108protected:
109    CommandInterpreter &m_interpreter;
110    lldb::ScriptLanguage m_script_lang;
111
112    // Scripting languages may need to use stdin for their interactive loops;
113    // however we don't want them to grab the real system stdin because that
114    // resource needs to be shared among the debugger UI, the inferior process and these
115    // embedded scripting loops.  Therefore we need to set up a pseudoterminal and use that
116    // as stdin for the script interpreter interactive loops/prompts.
117
118    lldb_utility::PseudoTerminal m_interpreter_pty; // m_session_pty
119    std::string m_pty_slave_name;                   //m_session_pty_slave_name
120
121private:
122
123};
124
125} // namespace lldb_private
126
127#endif // #ifndef liblldb_ScriptInterpreter_h_
128