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