2010-06-08 16:52:24 +00:00
|
|
|
//===-- ScriptInterpreter.cpp -----------------------------------*- C++ -*-===//
|
|
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-08 16:52:24 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "lldb/Interpreter/ScriptInterpreter.h"
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2017-02-16 19:38:21 +00:00
|
|
|
#include "lldb/Host/PseudoTerminal.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
2017-05-12 04:51:55 +00:00
|
|
|
#include "lldb/Utility/Status.h"
|
2017-02-02 21:39:50 +00:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2017-03-21 18:25:04 +00:00
|
|
|
#include "lldb/Utility/StringList.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
2019-04-26 17:58:19 +00:00
|
|
|
ScriptInterpreter::ScriptInterpreter(Debugger &debugger,
|
2011-01-14 00:29:16 +00:00
|
|
|
lldb::ScriptLanguage script_lang)
|
2019-04-26 17:58:19 +00:00
|
|
|
: m_debugger(debugger), m_script_lang(script_lang) {}
|
2010-06-08 16:52:24 +00:00
|
|
|
|
|
|
|
|
ScriptInterpreter::~ScriptInterpreter() {}
|
|
|
|
|
|
|
|
|
|
void ScriptInterpreter::CollectDataForBreakpointCommandCallback(
|
2014-08-29 17:34:17 +00:00
|
|
|
std::vector<BreakpointOptions *> &bp_options_vec,
|
2010-06-08 16:52:24 +00:00
|
|
|
CommandReturnObject &result) {
|
|
|
|
|
result.SetStatus(eReturnStatusFailed);
|
|
|
|
|
result.AppendError(
|
2019-12-21 22:33:01 -08:00
|
|
|
"This script interpreter does not support breakpoint callbacks.");
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
2012-08-09 23:09:42 +00:00
|
|
|
void ScriptInterpreter::CollectDataForWatchpointCommandCallback(
|
|
|
|
|
WatchpointOptions *bp_options, CommandReturnObject &result) {
|
|
|
|
|
result.SetStatus(eReturnStatusFailed);
|
|
|
|
|
result.AppendError(
|
2019-12-21 22:33:01 -08:00
|
|
|
"This script interpreter does not support watchpoint callbacks.");
|
2012-08-09 23:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
2019-12-22 16:46:01 -08:00
|
|
|
bool ScriptInterpreter::LoadScriptingModule(
|
2019-12-22 21:35:05 -08:00
|
|
|
const char *filename, bool init_session, lldb_private::Status &error,
|
|
|
|
|
StructuredData::ObjectSP *module_sp) {
|
2019-12-22 16:46:01 -08:00
|
|
|
error.SetErrorString(
|
|
|
|
|
"This script interpreter does not support importing modules.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-04 00:03:46 +00:00
|
|
|
std::string ScriptInterpreter::LanguageToString(lldb::ScriptLanguage language) {
|
|
|
|
|
switch (language) {
|
|
|
|
|
case eScriptLanguageNone:
|
2019-12-21 21:54:44 -08:00
|
|
|
return "None";
|
2010-09-04 00:03:46 +00:00
|
|
|
case eScriptLanguagePython:
|
2019-12-21 21:54:44 -08:00
|
|
|
return "Python";
|
|
|
|
|
case eScriptLanguageLua:
|
|
|
|
|
return "Lua";
|
2016-09-26 19:47:37 +00:00
|
|
|
case eScriptLanguageUnknown:
|
2019-12-21 21:54:44 -08:00
|
|
|
return "Unknown";
|
2010-09-04 00:03:46 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-01-14 00:29:16 +00:00
|
|
|
|
2016-09-26 19:47:37 +00:00
|
|
|
lldb::ScriptLanguage
|
|
|
|
|
ScriptInterpreter::StringToLanguage(const llvm::StringRef &language) {
|
|
|
|
|
if (language.equals_lower(LanguageToString(eScriptLanguageNone)))
|
|
|
|
|
return eScriptLanguageNone;
|
2017-09-03 19:27:56 +00:00
|
|
|
if (language.equals_lower(LanguageToString(eScriptLanguagePython)))
|
2016-09-26 19:47:37 +00:00
|
|
|
return eScriptLanguagePython;
|
2019-12-21 21:54:44 -08:00
|
|
|
if (language.equals_lower(LanguageToString(eScriptLanguageLua)))
|
|
|
|
|
return eScriptLanguageLua;
|
2017-09-03 19:27:56 +00:00
|
|
|
return eScriptLanguageUnknown;
|
2016-09-26 19:47:37 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status ScriptInterpreter::SetBreakpointCommandCallback(
|
2014-08-29 17:34:17 +00:00
|
|
|
std::vector<BreakpointOptions *> &bp_options_vec,
|
|
|
|
|
const char *callback_text) {
|
2017-05-12 04:51:55 +00:00
|
|
|
Status return_error;
|
2014-08-29 17:34:17 +00:00
|
|
|
for (BreakpointOptions *bp_options : bp_options_vec) {
|
|
|
|
|
return_error = SetBreakpointCommandCallback(bp_options, callback_text);
|
|
|
|
|
if (return_error.Success())
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return return_error;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 14:05:07 -07:00
|
|
|
Status ScriptInterpreter::SetBreakpointCommandCallbackFunction(
|
2019-12-21 21:54:44 -08:00
|
|
|
std::vector<BreakpointOptions *> &bp_options_vec, const char *function_name,
|
2019-10-25 14:05:07 -07:00
|
|
|
StructuredData::ObjectSP extra_args_sp) {
|
|
|
|
|
Status error;
|
2014-08-29 17:34:17 +00:00
|
|
|
for (BreakpointOptions *bp_options : bp_options_vec) {
|
2019-12-21 21:54:44 -08:00
|
|
|
error = SetBreakpointCommandCallbackFunction(bp_options, function_name,
|
|
|
|
|
extra_args_sp);
|
2019-10-25 14:05:07 -07:00
|
|
|
if (!error.Success())
|
|
|
|
|
return error;
|
2014-08-29 17:34:17 +00:00
|
|
|
}
|
2019-10-25 14:05:07 -07:00
|
|
|
return error;
|
2014-08-29 17:34:17 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-18 22:45:39 +00:00
|
|
|
std::unique_ptr<ScriptInterpreterLocker>
|
2013-03-27 22:38:11 +00:00
|
|
|
ScriptInterpreter::AcquireInterpreterLock() {
|
2013-04-18 22:45:39 +00:00
|
|
|
return std::unique_ptr<ScriptInterpreterLocker>(
|
|
|
|
|
new ScriptInterpreterLocker());
|
2013-03-27 22:38:11 +00:00
|
|
|
}
|