1 //===-- ScriptInterpreter.cpp -----------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Interpreter/ScriptInterpreter.h"
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"
22 using namespace lldb_private;
24 ScriptInterpreter::ScriptInterpreter(Debugger &debugger,
25 lldb::ScriptLanguage script_lang)
26 : m_debugger(debugger), m_script_lang(script_lang) {}
28 ScriptInterpreter::~ScriptInterpreter() {}
30 void ScriptInterpreter::CollectDataForBreakpointCommandCallback(
31 std::vector<BreakpointOptions *> &bp_options_vec,
32 CommandReturnObject &result) {
33 result.SetStatus(eReturnStatusFailed);
35 "This script interpreter does not support breakpoint callbacks.");
38 void ScriptInterpreter::CollectDataForWatchpointCommandCallback(
39 WatchpointOptions *bp_options, CommandReturnObject &result) {
40 result.SetStatus(eReturnStatusFailed);
42 "This script interpreter does not support watchpoint callbacks.");
45 bool ScriptInterpreter::LoadScriptingModule(
46 const char *filename, bool init_session, lldb_private::Status &error,
47 StructuredData::ObjectSP *module_sp) {
49 "This script interpreter does not support importing modules.");
53 std::string ScriptInterpreter::LanguageToString(lldb::ScriptLanguage language) {
55 case eScriptLanguageNone:
57 case eScriptLanguagePython:
59 case eScriptLanguageLua:
61 case eScriptLanguageUnknown:
64 llvm_unreachable("Unhandled ScriptInterpreter!");
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 if (language.equals_lower(LanguageToString(eScriptLanguageLua)))
74 return eScriptLanguageLua;
75 return eScriptLanguageUnknown;
78 Status ScriptInterpreter::SetBreakpointCommandCallback(
79 std::vector<BreakpointOptions *> &bp_options_vec,
80 const char *callback_text) {
82 for (BreakpointOptions *bp_options : bp_options_vec) {
83 return_error = SetBreakpointCommandCallback(bp_options, callback_text);
84 if (return_error.Success())
90 Status ScriptInterpreter::SetBreakpointCommandCallbackFunction(
91 std::vector<BreakpointOptions *> &bp_options_vec, const char *function_name,
92 StructuredData::ObjectSP extra_args_sp) {
94 for (BreakpointOptions *bp_options : bp_options_vec) {
95 error = SetBreakpointCommandCallbackFunction(bp_options, function_name,
103 std::unique_ptr<ScriptInterpreterLocker>
104 ScriptInterpreter::AcquireInterpreterLock() {
105 return std::unique_ptr<ScriptInterpreterLocker>(
106 new ScriptInterpreterLocker());