ScriptInterpreter.h revision dea5ea78ef9bf371a0d19590c6b7c6989cba9a89
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 (lldb::ScriptLanguage script_lang);
42
43    virtual ~ScriptInterpreter ();
44
45    virtual void
46    ExecuteOneLine (const std::string&, FILE *, FILE *) = 0;
47
48    virtual void
49    ExecuteInterpreterLoop (FILE *, FILE *) = 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    const char *
80    GetScriptInterpreterPtyName ();
81
82    int
83    GetMasterFileDescriptor ();
84
85    CommandInterpreter *
86    GetCommandInterpreter ();
87
88private:
89    lldb::ScriptLanguage m_script_lang;
90
91    // Scripting languages may need to use stdin for their interactive loops;
92    // however we don't want them to grab the real system stdin because that
93    // resource needs to be shared among the debugger UI, the inferior process and these
94    // embedded scripting loops.  Therefore we need to set up a pseudoterminal and use that
95    // as stdin for the script interpreter interactive loops/prompts.
96
97    lldb_utility::PseudoTerminal m_interpreter_pty;
98    std::string m_pty_slave_name;
99};
100
101} // namespace lldb_private
102
103#endif // #ifndef liblldb_ScriptInterpreter_h_
104