Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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 | |
Daniel Malea | 93a6430 | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 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" |
Caroline Tice | 2f88aad | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 22 | #include "lldb/Interpreter/ScriptInterpreterPython.h" |
Jason Molenda | a34a0c6 | 2010-06-09 21:28:42 +0000 | [diff] [blame] | 23 | #include "lldb/Utility/PseudoTerminal.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | |
| 25 | using namespace lldb; |
| 26 | using namespace lldb_private; |
| 27 | |
Caroline Tice | 2f88aad | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 28 | ScriptInterpreter::ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang) : |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 29 | m_interpreter (interpreter), |
Greg Clayton | 9ea3fcd | 2012-01-27 00:13:27 +0000 | [diff] [blame] | 30 | m_script_lang (script_lang) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 31 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | ScriptInterpreter::~ScriptInterpreter () |
| 35 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Caroline Tice | 2f88aad | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 38 | CommandInterpreter & |
| 39 | ScriptInterpreter::GetCommandInterpreter () |
| 40 | { |
| 41 | return m_interpreter; |
| 42 | } |
| 43 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 44 | void |
| 45 | ScriptInterpreter::CollectDataForBreakpointCommandCallback |
| 46 | ( |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 47 | BreakpointOptions *bp_options, |
| 48 | CommandReturnObject &result |
| 49 | ) |
| 50 | { |
| 51 | result.SetStatus (eReturnStatusFailed); |
| 52 | result.AppendError ("ScriptInterpreter::GetScriptCommands(StringList &) is not implemented."); |
| 53 | } |
| 54 | |
Johnny Chen | e9a5627 | 2012-08-09 23:09:42 +0000 | [diff] [blame] | 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 | |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 66 | std::string |
| 67 | ScriptInterpreter::LanguageToString (lldb::ScriptLanguage language) |
| 68 | { |
| 69 | std::string return_value; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 70 | |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 71 | switch (language) |
| 72 | { |
| 73 | case eScriptLanguageNone: |
| 74 | return_value = "None"; |
| 75 | break; |
| 76 | case eScriptLanguagePython: |
| 77 | return_value = "Python"; |
| 78 | break; |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | return return_value; |
| 82 | } |
Caroline Tice | 2f88aad | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 83 | |
Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 84 | std::unique_ptr<ScriptInterpreterLocker> |
Enrico Granata | 360cc31 | 2013-03-27 22:38:11 +0000 | [diff] [blame] | 85 | ScriptInterpreter::AcquireInterpreterLock () |
| 86 | { |
Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 87 | return std::unique_ptr<ScriptInterpreterLocker>(new ScriptInterpreterLocker()); |
Enrico Granata | 360cc31 | 2013-03-27 22:38:11 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Caroline Tice | 2f88aad | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 90 | void |
Greg Clayton | 8afa543 | 2013-10-17 00:27:14 +0000 | [diff] [blame] | 91 | ScriptInterpreter::InitializeInterpreter (SWIGInitCallback python_swig_init_callback, |
| 92 | SWIGBreakpointCallbackFunction swig_breakpoint_callback, |
| 93 | SWIGWatchpointCallbackFunction swig_watchpoint_callback, |
| 94 | SWIGPythonTypeScriptCallbackFunction swig_typescript_callback, |
| 95 | SWIGPythonCreateSyntheticProvider swig_synthetic_script, |
| 96 | SWIGPythonCalculateNumChildren swig_calc_children, |
| 97 | SWIGPythonGetChildAtIndex swig_get_child_index, |
| 98 | SWIGPythonGetIndexOfChildWithName swig_get_index_child, |
| 99 | SWIGPythonCastPyObjectToSBValue swig_cast_to_sbvalue , |
| 100 | SWIGPythonGetValueObjectSPFromSBValue swig_get_valobj_sp_from_sbvalue, |
| 101 | SWIGPythonUpdateSynthProviderInstance swig_update_provider, |
| 102 | SWIGPythonMightHaveChildrenSynthProviderInstance swig_mighthavechildren_provider, |
| 103 | SWIGPythonCallCommand swig_call_command, |
| 104 | SWIGPythonCallModuleInit swig_call_module_init, |
| 105 | SWIGPythonCreateOSPlugin swig_create_os_plugin, |
| 106 | SWIGPythonScriptKeyword_Process swig_run_script_keyword_process, |
| 107 | SWIGPythonScriptKeyword_Thread swig_run_script_keyword_thread, |
| 108 | SWIGPythonScriptKeyword_Target swig_run_script_keyword_target, |
| 109 | SWIGPythonScriptKeyword_Frame swig_run_script_keyword_frame, |
| 110 | SWIGPython_GetDynamicSetting swig_plugin_get) |
Caroline Tice | 2f88aad | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 111 | { |
Greg Clayton | dce502e | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 112 | #ifndef LLDB_DISABLE_PYTHON |
Greg Clayton | 8afa543 | 2013-10-17 00:27:14 +0000 | [diff] [blame] | 113 | ScriptInterpreterPython::InitializeInterpreter (python_swig_init_callback, |
| 114 | swig_breakpoint_callback, |
| 115 | swig_watchpoint_callback, |
| 116 | swig_typescript_callback, |
| 117 | swig_synthetic_script, |
| 118 | swig_calc_children, |
| 119 | swig_get_child_index, |
| 120 | swig_get_index_child, |
| 121 | swig_cast_to_sbvalue , |
| 122 | swig_get_valobj_sp_from_sbvalue, |
| 123 | swig_update_provider, |
| 124 | swig_mighthavechildren_provider, |
| 125 | swig_call_command, |
| 126 | swig_call_module_init, |
| 127 | swig_create_os_plugin, |
| 128 | swig_run_script_keyword_process, |
| 129 | swig_run_script_keyword_thread, |
| 130 | swig_run_script_keyword_target, |
| 131 | swig_run_script_keyword_frame, |
| 132 | swig_plugin_get); |
Greg Clayton | dce502e | 2011-11-04 03:34:56 +0000 | [diff] [blame] | 133 | #endif // #ifndef LLDB_DISABLE_PYTHON |
Caroline Tice | 2f88aad | 2011-01-14 00:29:16 +0000 | [diff] [blame] | 134 | } |