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