ScriptInterpreter.h revision f7a9b14c2c02d2fa9fad586c19f29d77533fcc09
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 void (*SWIGInitCallback) (void);
24
25    typedef bool (*SWIGBreakpointCallbackFunction) (const char *python_function_name,
26                                                    const char *session_dictionary_name,
27                                                    const lldb::StackFrameSP& frame_sp,
28                                                    const lldb::BreakpointLocationSP &bp_loc_sp);
29
30    typedef
31
32    typedef std::string (*SWIGPythonTypeScriptCallbackFunction) (const char *python_function_name,
33                                                                 const char *session_dictionary_name,
34                                                                 const lldb::ValueObjectSP& valobj_sp);
35
36    typedef enum
37    {
38        eCharPtr,
39        eBool,
40        eShortInt,
41        eShortIntUnsigned,
42        eInt,
43        eIntUnsigned,
44        eLongInt,
45        eLongIntUnsigned,
46        eLongLong,
47        eLongLongUnsigned,
48        eFloat,
49        eDouble,
50        eChar
51    } ReturnType;
52
53
54    ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang);
55
56    virtual ~ScriptInterpreter ();
57
58    virtual bool
59    ExecuteOneLine (const char *command, CommandReturnObject *result) = 0;
60
61    virtual void
62    ExecuteInterpreterLoop () = 0;
63
64    virtual bool
65    ExecuteOneLineWithReturn (const char *in_string, ReturnType return_type, void *ret_value)
66    {
67        return true;
68    }
69
70    virtual bool
71    ExecuteMultipleLines (const char *in_string)
72    {
73        return true;
74    }
75
76    virtual bool
77    ExportFunctionDefinitionToInterpreter (StringList &function_def)
78    {
79        return false;
80    }
81
82    virtual bool
83    GenerateBreakpointCommandCallbackData (StringList &input, StringList &output)
84    {
85        return false;
86    }
87
88    virtual bool
89    GenerateTypeScriptFunction (StringList &input, StringList &output)
90    {
91        return false;
92    }
93
94    // use this if the function code is just a one-liner script
95    virtual bool
96    GenerateTypeScriptFunction (const char* oneliner, StringList &output)
97    {
98        return false;
99    }
100
101    virtual bool
102    GenerateFunction(std::string& signature, StringList &input, StringList &output)
103    {
104        return false;
105    }
106
107    virtual void
108    CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options,
109                                             CommandReturnObject &result);
110
111    /// Set a one-liner as the callback for the breakpoint.
112    virtual void
113    SetBreakpointCommandCallback (BreakpointOptions *bp_options,
114                                  const char *oneliner)
115    {
116        return;
117    }
118
119    const char *
120    GetScriptInterpreterPtyName ();
121
122    int
123    GetMasterFileDescriptor ();
124
125	CommandInterpreter &
126	GetCommandInterpreter ();
127
128     static std::string
129    LanguageToString (lldb::ScriptLanguage language);
130
131    static void
132    InitializeInterpreter (SWIGInitCallback python_swig_init_callback,
133                           SWIGBreakpointCallbackFunction python_swig_breakpoint_callback,
134                           SWIGPythonTypeScriptCallbackFunction python_swig_typescript_callback);
135
136    static void
137    TerminateInterpreter ();
138
139    virtual void
140    ResetOutputFileHandle (FILE *new_fh) { } //By default, do nothing.
141
142protected:
143    CommandInterpreter &m_interpreter;
144    lldb::ScriptLanguage m_script_lang;
145
146    // Scripting languages may need to use stdin for their interactive loops;
147    // however we don't want them to grab the real system stdin because that
148    // resource needs to be shared among the debugger UI, the inferior process and these
149    // embedded scripting loops.  Therefore we need to set up a pseudoterminal and use that
150    // as stdin for the script interpreter interactive loops/prompts.
151
152    lldb_utility::PseudoTerminal m_interpreter_pty; // m_session_pty
153    std::string m_pty_slave_name;                   //m_session_pty_slave_name
154
155private:
156
157};
158
159} // namespace lldb_private
160
161#endif // #ifndef liblldb_ScriptInterpreter_h_
162