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