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