blob: 0f7e1f8d74f4033bc1ce11ccfaffd37ed101843c [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include <stdio.h>
Kate Stoneb9c1b512016-09-06 20:57:50 +000013#include <stdlib.h>
14#include <string>
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015
Zachary Turner24ae6292017-02-16 19:38:21 +000016#include "lldb/Host/PseudoTerminal.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "lldb/Interpreter/CommandReturnObject.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000018#include "lldb/Utility/Error.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000019#include "lldb/Utility/Stream.h"
Zachary Turner573ab902017-03-21 18:25:04 +000020#include "lldb/Utility/StringList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000021
22using namespace lldb;
23using namespace lldb_private;
24
Kate Stoneb9c1b512016-09-06 20:57:50 +000025ScriptInterpreter::ScriptInterpreter(CommandInterpreter &interpreter,
26 lldb::ScriptLanguage script_lang)
27 : m_interpreter(interpreter), m_script_lang(script_lang) {}
28
29ScriptInterpreter::~ScriptInterpreter() {}
30
31CommandInterpreter &ScriptInterpreter::GetCommandInterpreter() {
32 return m_interpreter;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033}
34
Kate Stoneb9c1b512016-09-06 20:57:50 +000035void ScriptInterpreter::CollectDataForBreakpointCommandCallback(
Jim Inghamb5796cb2014-08-29 17:34:17 +000036 std::vector<BreakpointOptions *> &bp_options_vec,
Kate Stoneb9c1b512016-09-06 20:57:50 +000037 CommandReturnObject &result) {
38 result.SetStatus(eReturnStatusFailed);
39 result.AppendError(
40 "ScriptInterpreter::GetScriptCommands(StringList &) is not implemented.");
Chris Lattner30fdc8d2010-06-08 16:52:24 +000041}
42
Kate Stoneb9c1b512016-09-06 20:57:50 +000043void ScriptInterpreter::CollectDataForWatchpointCommandCallback(
44 WatchpointOptions *bp_options, CommandReturnObject &result) {
45 result.SetStatus(eReturnStatusFailed);
46 result.AppendError(
47 "ScriptInterpreter::GetScriptCommands(StringList &) is not implemented.");
Johnny Chene9a56272012-08-09 23:09:42 +000048}
49
Kate Stoneb9c1b512016-09-06 20:57:50 +000050std::string ScriptInterpreter::LanguageToString(lldb::ScriptLanguage language) {
51 std::string return_value;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000052
Kate Stoneb9c1b512016-09-06 20:57:50 +000053 switch (language) {
54 case eScriptLanguageNone:
55 return_value = "None";
56 break;
57 case eScriptLanguagePython:
58 return_value = "Python";
59 break;
Jim Inghamf7e07252016-09-26 19:47:37 +000060 case eScriptLanguageUnknown:
61 return_value = "Unknown";
62 break;
Kate Stoneb9c1b512016-09-06 20:57:50 +000063 }
Caroline Tice3df9a8d2010-09-04 00:03:46 +000064
Kate Stoneb9c1b512016-09-06 20:57:50 +000065 return return_value;
Caroline Tice3df9a8d2010-09-04 00:03:46 +000066}
Caroline Tice2f88aad2011-01-14 00:29:16 +000067
Jim Inghamf7e07252016-09-26 19:47:37 +000068lldb::ScriptLanguage
69ScriptInterpreter::StringToLanguage(const llvm::StringRef &language) {
70 if (language.equals_lower(LanguageToString(eScriptLanguageNone)))
71 return eScriptLanguageNone;
72 else if (language.equals_lower(LanguageToString(eScriptLanguagePython)))
73 return eScriptLanguagePython;
74 else
75 return eScriptLanguageUnknown;
76}
77
Kate Stoneb9c1b512016-09-06 20:57:50 +000078Error ScriptInterpreter::SetBreakpointCommandCallback(
79 std::vector<BreakpointOptions *> &bp_options_vec,
80 const char *callback_text) {
81 Error return_error;
82 for (BreakpointOptions *bp_options : bp_options_vec) {
83 return_error = SetBreakpointCommandCallback(bp_options, callback_text);
84 if (return_error.Success())
85 break;
86 }
87 return return_error;
Jim Inghamb5796cb2014-08-29 17:34:17 +000088}
89
Kate Stoneb9c1b512016-09-06 20:57:50 +000090void ScriptInterpreter::SetBreakpointCommandCallbackFunction(
91 std::vector<BreakpointOptions *> &bp_options_vec,
92 const char *function_name) {
93 for (BreakpointOptions *bp_options : bp_options_vec) {
94 SetBreakpointCommandCallbackFunction(bp_options, function_name);
95 }
Jim Inghamb5796cb2014-08-29 17:34:17 +000096}
97
Greg Clayton7b0992d2013-04-18 22:45:39 +000098std::unique_ptr<ScriptInterpreterLocker>
Kate Stoneb9c1b512016-09-06 20:57:50 +000099ScriptInterpreter::AcquireInterpreterLock() {
100 return std::unique_ptr<ScriptInterpreterLocker>(
101 new ScriptInterpreterLocker());
Enrico Granata360cc312013-03-27 22:38:11 +0000102}