1ac7ddfbfSEd Maste //===-- ScriptInterpreter.cpp -----------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste //                     The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste 
10ac7ddfbfSEd Maste #include "lldb/Interpreter/ScriptInterpreter.h"
11ac7ddfbfSEd Maste 
12ac7ddfbfSEd Maste #include <stdio.h>
13435933ddSDimitry Andric #include <stdlib.h>
14435933ddSDimitry Andric #include <string>
15ac7ddfbfSEd Maste 
16f678e45dSDimitry Andric #include "lldb/Host/PseudoTerminal.h"
17ac7ddfbfSEd Maste #include "lldb/Interpreter/CommandReturnObject.h"
185517e702SDimitry Andric #include "lldb/Utility/Status.h"
19f678e45dSDimitry Andric #include "lldb/Utility/Stream.h"
20f678e45dSDimitry Andric #include "lldb/Utility/StringList.h"
21ac7ddfbfSEd Maste 
22ac7ddfbfSEd Maste using namespace lldb;
23ac7ddfbfSEd Maste using namespace lldb_private;
24ac7ddfbfSEd Maste 
ScriptInterpreter(CommandInterpreter & interpreter,lldb::ScriptLanguage script_lang)25435933ddSDimitry Andric ScriptInterpreter::ScriptInterpreter(CommandInterpreter &interpreter,
26435933ddSDimitry Andric                                      lldb::ScriptLanguage script_lang)
27435933ddSDimitry Andric     : m_interpreter(interpreter), m_script_lang(script_lang) {}
28ac7ddfbfSEd Maste 
~ScriptInterpreter()29435933ddSDimitry Andric ScriptInterpreter::~ScriptInterpreter() {}
30ac7ddfbfSEd Maste 
GetCommandInterpreter()31435933ddSDimitry Andric CommandInterpreter &ScriptInterpreter::GetCommandInterpreter() {
32ac7ddfbfSEd Maste   return m_interpreter;
33ac7ddfbfSEd Maste }
34ac7ddfbfSEd Maste 
CollectDataForBreakpointCommandCallback(std::vector<BreakpointOptions * > & bp_options_vec,CommandReturnObject & result)35435933ddSDimitry Andric void ScriptInterpreter::CollectDataForBreakpointCommandCallback(
360127ef0fSEd Maste     std::vector<BreakpointOptions *> &bp_options_vec,
37435933ddSDimitry Andric     CommandReturnObject &result) {
38ac7ddfbfSEd Maste   result.SetStatus(eReturnStatusFailed);
39435933ddSDimitry Andric   result.AppendError(
40435933ddSDimitry Andric       "ScriptInterpreter::GetScriptCommands(StringList &) is not implemented.");
41ac7ddfbfSEd Maste }
42ac7ddfbfSEd Maste 
CollectDataForWatchpointCommandCallback(WatchpointOptions * bp_options,CommandReturnObject & result)43435933ddSDimitry Andric void ScriptInterpreter::CollectDataForWatchpointCommandCallback(
44435933ddSDimitry Andric     WatchpointOptions *bp_options, CommandReturnObject &result) {
45ac7ddfbfSEd Maste   result.SetStatus(eReturnStatusFailed);
46435933ddSDimitry Andric   result.AppendError(
47435933ddSDimitry Andric       "ScriptInterpreter::GetScriptCommands(StringList &) is not implemented.");
48ac7ddfbfSEd Maste }
49ac7ddfbfSEd Maste 
LanguageToString(lldb::ScriptLanguage language)50435933ddSDimitry Andric std::string ScriptInterpreter::LanguageToString(lldb::ScriptLanguage language) {
51ac7ddfbfSEd Maste   std::string return_value;
52ac7ddfbfSEd Maste 
53435933ddSDimitry Andric   switch (language) {
54ac7ddfbfSEd Maste   case eScriptLanguageNone:
55ac7ddfbfSEd Maste     return_value = "None";
56ac7ddfbfSEd Maste     break;
57ac7ddfbfSEd Maste   case eScriptLanguagePython:
58ac7ddfbfSEd Maste     return_value = "Python";
59ac7ddfbfSEd Maste     break;
60435933ddSDimitry Andric   case eScriptLanguageUnknown:
61435933ddSDimitry Andric     return_value = "Unknown";
62435933ddSDimitry Andric     break;
63ac7ddfbfSEd Maste   }
64ac7ddfbfSEd Maste 
65ac7ddfbfSEd Maste   return return_value;
66ac7ddfbfSEd Maste }
67ac7ddfbfSEd Maste 
68435933ddSDimitry Andric lldb::ScriptLanguage
StringToLanguage(const llvm::StringRef & language)69435933ddSDimitry Andric ScriptInterpreter::StringToLanguage(const llvm::StringRef &language) {
70435933ddSDimitry Andric   if (language.equals_lower(LanguageToString(eScriptLanguageNone)))
71435933ddSDimitry Andric     return eScriptLanguageNone;
72*acac075bSDimitry Andric   if (language.equals_lower(LanguageToString(eScriptLanguagePython)))
73435933ddSDimitry Andric     return eScriptLanguagePython;
74435933ddSDimitry Andric   return eScriptLanguageUnknown;
75435933ddSDimitry Andric }
76435933ddSDimitry Andric 
SetBreakpointCommandCallback(std::vector<BreakpointOptions * > & bp_options_vec,const char * callback_text)775517e702SDimitry Andric Status ScriptInterpreter::SetBreakpointCommandCallback(
78435933ddSDimitry Andric     std::vector<BreakpointOptions *> &bp_options_vec,
79435933ddSDimitry Andric     const char *callback_text) {
805517e702SDimitry Andric   Status return_error;
81435933ddSDimitry Andric   for (BreakpointOptions *bp_options : bp_options_vec) {
820127ef0fSEd Maste     return_error = SetBreakpointCommandCallback(bp_options, callback_text);
830127ef0fSEd Maste     if (return_error.Success())
840127ef0fSEd Maste       break;
850127ef0fSEd Maste   }
860127ef0fSEd Maste   return return_error;
870127ef0fSEd Maste }
880127ef0fSEd Maste 
SetBreakpointCommandCallbackFunction(std::vector<BreakpointOptions * > & bp_options_vec,const char * function_name)89435933ddSDimitry Andric void ScriptInterpreter::SetBreakpointCommandCallbackFunction(
90435933ddSDimitry Andric     std::vector<BreakpointOptions *> &bp_options_vec,
91435933ddSDimitry Andric     const char *function_name) {
92435933ddSDimitry Andric   for (BreakpointOptions *bp_options : bp_options_vec) {
930127ef0fSEd Maste     SetBreakpointCommandCallbackFunction(bp_options, function_name);
940127ef0fSEd Maste   }
950127ef0fSEd Maste }
960127ef0fSEd Maste 
97ac7ddfbfSEd Maste std::unique_ptr<ScriptInterpreterLocker>
AcquireInterpreterLock()98435933ddSDimitry Andric ScriptInterpreter::AcquireInterpreterLock() {
99435933ddSDimitry Andric   return std::unique_ptr<ScriptInterpreterLocker>(
100435933ddSDimitry Andric       new ScriptInterpreterLocker());
101ac7ddfbfSEd Maste }
102