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