1 //===-- ScriptInterpreter.cpp -----------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "lldb/Interpreter/ScriptInterpreter.h" 10 11 #include <stdio.h> 12 #include <stdlib.h> 13 #include <string> 14 15 #include "lldb/Host/PseudoTerminal.h" 16 #include "lldb/Interpreter/CommandReturnObject.h" 17 #include "lldb/Utility/Status.h" 18 #include "lldb/Utility/Stream.h" 19 #include "lldb/Utility/StringList.h" 20 21 using namespace lldb; 22 using namespace lldb_private; 23 24 ScriptInterpreter::ScriptInterpreter(CommandInterpreter &interpreter, 25 lldb::ScriptLanguage script_lang) 26 : m_interpreter(interpreter), m_script_lang(script_lang) {} 27 28 ScriptInterpreter::~ScriptInterpreter() {} 29 30 CommandInterpreter &ScriptInterpreter::GetCommandInterpreter() { 31 return m_interpreter; 32 } 33 34 void ScriptInterpreter::CollectDataForBreakpointCommandCallback( 35 std::vector<BreakpointOptions *> &bp_options_vec, 36 CommandReturnObject &result) { 37 result.SetStatus(eReturnStatusFailed); 38 result.AppendError( 39 "ScriptInterpreter::GetScriptCommands(StringList &) is not implemented."); 40 } 41 42 void ScriptInterpreter::CollectDataForWatchpointCommandCallback( 43 WatchpointOptions *bp_options, CommandReturnObject &result) { 44 result.SetStatus(eReturnStatusFailed); 45 result.AppendError( 46 "ScriptInterpreter::GetScriptCommands(StringList &) is not implemented."); 47 } 48 49 std::string ScriptInterpreter::LanguageToString(lldb::ScriptLanguage language) { 50 std::string return_value; 51 52 switch (language) { 53 case eScriptLanguageNone: 54 return_value = "None"; 55 break; 56 case eScriptLanguagePython: 57 return_value = "Python"; 58 break; 59 case eScriptLanguageUnknown: 60 return_value = "Unknown"; 61 break; 62 } 63 64 return return_value; 65 } 66 67 lldb::ScriptLanguage 68 ScriptInterpreter::StringToLanguage(const llvm::StringRef &language) { 69 if (language.equals_lower(LanguageToString(eScriptLanguageNone))) 70 return eScriptLanguageNone; 71 if (language.equals_lower(LanguageToString(eScriptLanguagePython))) 72 return eScriptLanguagePython; 73 return eScriptLanguageUnknown; 74 } 75 76 Status ScriptInterpreter::SetBreakpointCommandCallback( 77 std::vector<BreakpointOptions *> &bp_options_vec, 78 const char *callback_text) { 79 Status return_error; 80 for (BreakpointOptions *bp_options : bp_options_vec) { 81 return_error = SetBreakpointCommandCallback(bp_options, callback_text); 82 if (return_error.Success()) 83 break; 84 } 85 return return_error; 86 } 87 88 void ScriptInterpreter::SetBreakpointCommandCallbackFunction( 89 std::vector<BreakpointOptions *> &bp_options_vec, 90 const char *function_name) { 91 for (BreakpointOptions *bp_options : bp_options_vec) { 92 SetBreakpointCommandCallbackFunction(bp_options, function_name); 93 } 94 } 95 96 std::unique_ptr<ScriptInterpreterLocker> 97 ScriptInterpreter::AcquireInterpreterLock() { 98 return std::unique_ptr<ScriptInterpreterLocker>( 99 new ScriptInterpreterLocker()); 100 } 101