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/lldb-python.h"
11 
12 #include "lldb/Interpreter/ScriptInterpreter.h"
13 
14 #include <string>
15 #include <stdlib.h>
16 #include <stdio.h>
17 
18 #include "lldb/Core/Error.h"
19 #include "lldb/Core/Stream.h"
20 #include "lldb/Core/StringList.h"
21 #include "lldb/Interpreter/CommandReturnObject.h"
22 #include "lldb/Interpreter/ScriptInterpreterPython.h"
23 #include "lldb/Utility/PseudoTerminal.h"
24 
25 using namespace lldb;
26 using namespace lldb_private;
27 
28 ScriptInterpreter::ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang) :
29     m_interpreter (interpreter),
30     m_script_lang (script_lang)
31 {
32 }
33 
34 ScriptInterpreter::~ScriptInterpreter ()
35 {
36 }
37 
38 CommandInterpreter &
39 ScriptInterpreter::GetCommandInterpreter ()
40 {
41     return m_interpreter;
42 }
43 
44 void
45 ScriptInterpreter::CollectDataForBreakpointCommandCallback
46 (
47     std::vector<BreakpointOptions *> &bp_options_vec,
48     CommandReturnObject &result
49 )
50 {
51     result.SetStatus (eReturnStatusFailed);
52     result.AppendError ("ScriptInterpreter::GetScriptCommands(StringList &) is not implemented.");
53 }
54 
55 void
56 ScriptInterpreter::CollectDataForWatchpointCommandCallback
57 (
58     WatchpointOptions *bp_options,
59     CommandReturnObject &result
60 )
61 {
62     result.SetStatus (eReturnStatusFailed);
63     result.AppendError ("ScriptInterpreter::GetScriptCommands(StringList &) is not implemented.");
64 }
65 
66 std::string
67 ScriptInterpreter::LanguageToString (lldb::ScriptLanguage language)
68 {
69     std::string return_value;
70 
71     switch (language)
72     {
73         case eScriptLanguageNone:
74             return_value = "None";
75             break;
76         case eScriptLanguagePython:
77             return_value = "Python";
78             break;
79     }
80 
81     return return_value;
82 }
83 
84 Error
85 ScriptInterpreter::SetBreakpointCommandCallback (std::vector<BreakpointOptions *> &bp_options_vec,
86                                                  const char *callback_text)
87 {
88     Error return_error;
89     for (BreakpointOptions *bp_options : bp_options_vec)
90     {
91         return_error = SetBreakpointCommandCallback(bp_options, callback_text);
92         if (return_error.Success())
93             break;
94     }
95     return return_error;
96 }
97 
98 void
99 ScriptInterpreter::SetBreakpointCommandCallbackFunction (std::vector<BreakpointOptions *> &bp_options_vec,
100                                                          const char *function_name)
101 {
102     for (BreakpointOptions *bp_options : bp_options_vec)
103     {
104         SetBreakpointCommandCallbackFunction(bp_options, function_name);
105     }
106 }
107 
108 std::unique_ptr<ScriptInterpreterLocker>
109 ScriptInterpreter::AcquireInterpreterLock ()
110 {
111     return std::unique_ptr<ScriptInterpreterLocker>(new ScriptInterpreterLocker());
112 }
113 
114 void
115 ScriptInterpreter::InitializeInterpreter (SWIGInitCallback python_swig_init_callback,
116                                           SWIGBreakpointCallbackFunction swig_breakpoint_callback,
117                                           SWIGWatchpointCallbackFunction swig_watchpoint_callback,
118                                           SWIGPythonTypeScriptCallbackFunction swig_typescript_callback,
119                                           SWIGPythonCreateSyntheticProvider swig_synthetic_script,
120                                           SWIGPythonCalculateNumChildren swig_calc_children,
121                                           SWIGPythonGetChildAtIndex swig_get_child_index,
122                                           SWIGPythonGetIndexOfChildWithName swig_get_index_child,
123                                           SWIGPythonCastPyObjectToSBValue swig_cast_to_sbvalue ,
124                                           SWIGPythonGetValueObjectSPFromSBValue swig_get_valobj_sp_from_sbvalue,
125                                           SWIGPythonUpdateSynthProviderInstance swig_update_provider,
126                                           SWIGPythonMightHaveChildrenSynthProviderInstance swig_mighthavechildren_provider,
127                                           SWIGPythonGetValueSynthProviderInstance swig_getvalue_provider,
128                                           SWIGPythonCallCommand swig_call_command,
129                                           SWIGPythonCallModuleInit swig_call_module_init,
130                                           SWIGPythonCreateOSPlugin swig_create_os_plugin,
131                                           SWIGPythonScriptKeyword_Process swig_run_script_keyword_process,
132                                           SWIGPythonScriptKeyword_Thread swig_run_script_keyword_thread,
133                                           SWIGPythonScriptKeyword_Target swig_run_script_keyword_target,
134                                           SWIGPythonScriptKeyword_Frame swig_run_script_keyword_frame,
135                                           SWIGPython_GetDynamicSetting swig_plugin_get,
136                                           SWIGPythonCreateScriptedThreadPlan swig_thread_plan_script,
137                                           SWIGPythonCallThreadPlan swig_call_thread_plan)
138 {
139 #ifndef LLDB_DISABLE_PYTHON
140     ScriptInterpreterPython::InitializeInterpreter (python_swig_init_callback,
141                                                     swig_breakpoint_callback,
142                                                     swig_watchpoint_callback,
143                                                     swig_typescript_callback,
144                                                     swig_synthetic_script,
145                                                     swig_calc_children,
146                                                     swig_get_child_index,
147                                                     swig_get_index_child,
148                                                     swig_cast_to_sbvalue ,
149                                                     swig_get_valobj_sp_from_sbvalue,
150                                                     swig_update_provider,
151                                                     swig_mighthavechildren_provider,
152                                                     swig_getvalue_provider,
153                                                     swig_call_command,
154                                                     swig_call_module_init,
155                                                     swig_create_os_plugin,
156                                                     swig_run_script_keyword_process,
157                                                     swig_run_script_keyword_thread,
158                                                     swig_run_script_keyword_target,
159                                                     swig_run_script_keyword_frame,
160                                                     swig_plugin_get,
161                                                     swig_thread_plan_script,
162                                                     swig_call_thread_plan);
163 #endif // #ifndef LLDB_DISABLE_PYTHON
164 }
165