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(Debugger &debugger,
25                                      lldb::ScriptLanguage script_lang)
26     : m_debugger(debugger), m_script_lang(script_lang) {}
27 
28 ScriptInterpreter::~ScriptInterpreter() {}
29 
30 void ScriptInterpreter::CollectDataForBreakpointCommandCallback(
31     std::vector<BreakpointOptions *> &bp_options_vec,
32     CommandReturnObject &result) {
33   result.SetStatus(eReturnStatusFailed);
34   result.AppendError(
35       "ScriptInterpreter::GetScriptCommands(StringList &) is not implemented.");
36 }
37 
38 void ScriptInterpreter::CollectDataForWatchpointCommandCallback(
39     WatchpointOptions *bp_options, CommandReturnObject &result) {
40   result.SetStatus(eReturnStatusFailed);
41   result.AppendError(
42       "ScriptInterpreter::GetScriptCommands(StringList &) is not implemented.");
43 }
44 
45 std::string ScriptInterpreter::LanguageToString(lldb::ScriptLanguage language) {
46   switch (language) {
47   case eScriptLanguageNone:
48     return "None";
49   case eScriptLanguagePython:
50     return "Python";
51   case eScriptLanguageLua:
52     return "Lua";
53   case eScriptLanguageUnknown:
54     return "Unknown";
55   }
56 }
57 
58 lldb::ScriptLanguage
59 ScriptInterpreter::StringToLanguage(const llvm::StringRef &language) {
60   if (language.equals_lower(LanguageToString(eScriptLanguageNone)))
61     return eScriptLanguageNone;
62   if (language.equals_lower(LanguageToString(eScriptLanguagePython)))
63     return eScriptLanguagePython;
64   if (language.equals_lower(LanguageToString(eScriptLanguageLua)))
65     return eScriptLanguageLua;
66   return eScriptLanguageUnknown;
67 }
68 
69 Status ScriptInterpreter::SetBreakpointCommandCallback(
70     std::vector<BreakpointOptions *> &bp_options_vec,
71     const char *callback_text) {
72   Status return_error;
73   for (BreakpointOptions *bp_options : bp_options_vec) {
74     return_error = SetBreakpointCommandCallback(bp_options, callback_text);
75     if (return_error.Success())
76       break;
77   }
78   return return_error;
79 }
80 
81 Status ScriptInterpreter::SetBreakpointCommandCallbackFunction(
82     std::vector<BreakpointOptions *> &bp_options_vec, const char *function_name,
83     StructuredData::ObjectSP extra_args_sp) {
84   Status error;
85   for (BreakpointOptions *bp_options : bp_options_vec) {
86     error = SetBreakpointCommandCallbackFunction(bp_options, function_name,
87                                                  extra_args_sp);
88     if (!error.Success())
89       return error;
90   }
91   return error;
92 }
93 
94 std::unique_ptr<ScriptInterpreterLocker>
95 ScriptInterpreter::AcquireInterpreterLock() {
96   return std::unique_ptr<ScriptInterpreterLocker>(
97       new ScriptInterpreterLocker());
98 }
99