1 //===-- ScriptInterpreter.cpp -----------------------------------*- 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 #include "lldb/Interpreter/ScriptInterpreter.h"
11 
12 #include <string>
13 #include <stdlib.h>
14 #include <stdio.h>
15 
16 #include "lldb/Core/Error.h"
17 #include "lldb/Core/Stream.h"
18 #include "lldb/Core/StringList.h"
19 #include "lldb/Interpreter/CommandReturnObject.h"
20 #include "lldb/Interpreter/ScriptInterpreterPython.h"
21 #include "lldb/Utility/PseudoTerminal.h"
22 
23 using namespace lldb;
24 using namespace lldb_private;
25 
26 ScriptInterpreter::ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang) :
27     m_interpreter (interpreter),
28     m_script_lang (script_lang),
29     m_interpreter_pty (),
30     m_pty_slave_name ()
31 {
32     if (m_interpreter_pty.OpenFirstAvailableMaster (O_RDWR|O_NOCTTY, NULL, 0))
33     {
34         const char *slave_name = m_interpreter_pty.GetSlaveName(NULL, 0);
35         if (slave_name)
36             m_pty_slave_name.assign(slave_name);
37     }
38 }
39 
40 ScriptInterpreter::~ScriptInterpreter ()
41 {
42     m_interpreter_pty.CloseMasterFileDescriptor();
43 }
44 
45 CommandInterpreter &
46 ScriptInterpreter::GetCommandInterpreter ()
47 {
48     return m_interpreter;
49 }
50 
51 const char *
52 ScriptInterpreter::GetScriptInterpreterPtyName ()
53 {
54     return m_pty_slave_name.c_str();
55 }
56 
57 int
58 ScriptInterpreter::GetMasterFileDescriptor ()
59 {
60     return m_interpreter_pty.GetMasterFileDescriptor();
61 }
62 
63 void
64 ScriptInterpreter::CollectDataForBreakpointCommandCallback
65 (
66     BreakpointOptions *bp_options,
67     CommandReturnObject &result
68 )
69 {
70     result.SetStatus (eReturnStatusFailed);
71     result.AppendError ("ScriptInterpreter::GetScriptCommands(StringList &) is not implemented.");
72 }
73 
74 std::string
75 ScriptInterpreter::LanguageToString (lldb::ScriptLanguage language)
76 {
77     std::string return_value;
78 
79     switch (language)
80     {
81         case eScriptLanguageNone:
82             return_value = "None";
83             break;
84         case eScriptLanguagePython:
85             return_value = "Python";
86             break;
87 
88     }
89 
90     return return_value;
91 }
92 
93 void
94 ScriptInterpreter::InitializeInterpreter (SWIGInitCallback python_swig_init_callback,
95                                           SWIGBreakpointCallbackFunction python_swig_breakpoint_callback,
96                                           SWIGPythonTypeScriptCallbackFunction python_swig_typescript_callback,
97                                           SWIGPythonCreateSyntheticProvider python_swig_synthetic_script,
98                                           SWIGPythonCalculateNumChildren python_swig_calc_children,
99                                           SWIGPythonGetChildAtIndex python_swig_get_child_index,
100                                           SWIGPythonGetIndexOfChildWithName python_swig_get_index_child,
101                                           SWIGPythonCastPyObjectToSBValue python_swig_cast_to_sbvalue,
102                                           SWIGPythonUpdateSynthProviderInstance python_swig_update_provider,
103                                           SWIGPythonCallCommand python_swig_call_command)
104 {
105     ScriptInterpreterPython::InitializeInterpreter (python_swig_init_callback,
106                                                     python_swig_breakpoint_callback,
107                                                     python_swig_typescript_callback,
108                                                     python_swig_synthetic_script,
109                                                     python_swig_calc_children,
110                                                     python_swig_get_child_index,
111                                                     python_swig_get_index_child,
112                                                     python_swig_cast_to_sbvalue,
113                                                     python_swig_update_provider,
114                                                     python_swig_call_command);
115 }
116 
117 void
118 ScriptInterpreter::TerminateInterpreter ()
119 {
120     ScriptInterpreterPython::TerminateInterpreter ();
121 }
122 
123