ScriptInterpreterPython.h revision 17f5afe9ed10bda3efbce0f26cf0c030331f8b15
1//===-- ScriptInterpreterPython.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
11#ifndef liblldb_ScriptInterpreterPython_h_
12#define liblldb_ScriptInterpreterPython_h_
13
14#if defined (__APPLE__)
15#include <Python/Python.h>
16#else
17#include <Python.h>
18#endif
19
20#include <termios.h>
21
22#include "lldb/lldb-private.h"
23#include "lldb/Interpreter/ScriptInterpreter.h"
24#include "lldb/Core/InputReader.h"
25
26namespace lldb_private {
27
28class ScriptInterpreterPython : public ScriptInterpreter
29{
30public:
31
32    ScriptInterpreterPython (CommandInterpreter &interpreter);
33
34    ~ScriptInterpreterPython ();
35
36    bool
37    ExecuteOneLine (const char *command, CommandReturnObject *result);
38
39    void
40    ExecuteInterpreterLoop ();
41
42    bool
43    ExecuteOneLineWithReturn (const char *in_string,
44                              ScriptInterpreter::ReturnType return_type,
45                              void *ret_value);
46
47    bool
48    ExecuteMultipleLines (const char *in_string);
49
50    bool
51    ExportFunctionDefinitionToInterpreter (StringList &function_def);
52
53    bool
54    GenerateBreakpointCommandCallbackData (StringList &input, StringList &output);
55
56    static size_t
57    GenerateBreakpointOptionsCommandCallback (void *baton,
58                                              InputReader &reader,
59                                              lldb::InputReaderAction notification,
60                                              const char *bytes,
61                                              size_t bytes_len);
62
63    static bool
64    BreakpointCallbackFunction (void *baton,
65                                StoppointCallbackContext *context,
66                                lldb::user_id_t break_id,
67                                lldb::user_id_t break_loc_id);
68
69    void
70    CollectDataForBreakpointCommandCallback (BreakpointOptions *bp_options,
71                                             CommandReturnObject &result);
72
73    /// Set a Python one-liner as the callback for the breakpoint.
74    void
75    SetBreakpointCommandCallback (BreakpointOptions *bp_options,
76                                  const char *oneliner);
77
78    StringList
79    ReadCommandInputFromUser (FILE *in_file);
80
81    virtual void
82    ResetOutputFileHandle (FILE *new_fh);
83
84    static lldb::thread_result_t
85    RunEmbeddedPythonInterpreter (lldb::thread_arg_t baton);
86
87    static void
88    Initialize ();
89
90    static void
91    Terminate ();
92
93protected:
94
95    void
96    EnterSession ();
97
98    void
99    LeaveSession ();
100
101private:
102
103    static size_t
104    InputReaderCallback (void *baton,
105                         InputReader &reader,
106                         lldb::InputReaderAction notification,
107                         const char *bytes,
108                         size_t bytes_len);
109
110
111    lldb_utility::PseudoTerminal m_embedded_python_pty;
112    lldb::InputReaderSP m_embedded_thread_input_reader_sp;
113    FILE *m_dbg_stdout;
114    PyObject *m_new_sysout;
115    std::string m_dictionary_name;
116    struct termios m_termios;
117    bool m_termios_valid;
118    bool m_session_is_active;
119    bool m_pty_slave_is_open;
120    bool m_valid_session;
121
122};
123
124} // namespace lldb_private
125
126
127#endif // #ifndef liblldb_ScriptInterpreterPython_h_
128