2010-06-09 00:52:24 +08:00
|
|
|
//===-- ScriptInterpreter.cpp -----------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08: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-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Interpreter/ScriptInterpreter.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string>
|
|
|
|
|
2017-02-17 03:38:21 +08:00
|
|
|
#include "lldb/Host/PseudoTerminal.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
2017-05-12 12:51:55 +08:00
|
|
|
#include "lldb/Utility/Status.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/Stream.h"
|
2017-03-22 02:25:04 +08:00
|
|
|
#include "lldb/Utility/StringList.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2019-04-27 01:58:19 +08:00
|
|
|
ScriptInterpreter::ScriptInterpreter(Debugger &debugger,
|
2011-01-14 08:29:16 +08:00
|
|
|
lldb::ScriptLanguage script_lang)
|
2019-04-27 01:58:19 +08:00
|
|
|
: m_debugger(debugger), m_script_lang(script_lang) {}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
ScriptInterpreter::~ScriptInterpreter() {}
|
|
|
|
|
|
|
|
void ScriptInterpreter::CollectDataForBreakpointCommandCallback(
|
2014-08-30 01:34:17 +08:00
|
|
|
std::vector<BreakpointOptions *> &bp_options_vec,
|
2010-06-09 00:52:24 +08:00
|
|
|
CommandReturnObject &result) {
|
|
|
|
result.SetStatus(eReturnStatusFailed);
|
|
|
|
result.AppendError(
|
|
|
|
"ScriptInterpreter::GetScriptCommands(StringList &) is not implemented.");
|
|
|
|
}
|
|
|
|
|
2012-08-10 07:09:42 +08:00
|
|
|
void ScriptInterpreter::CollectDataForWatchpointCommandCallback(
|
|
|
|
WatchpointOptions *bp_options, CommandReturnObject &result) {
|
|
|
|
result.SetStatus(eReturnStatusFailed);
|
|
|
|
result.AppendError(
|
|
|
|
"ScriptInterpreter::GetScriptCommands(StringList &) is not implemented.");
|
|
|
|
}
|
|
|
|
|
2010-09-04 08:03:46 +08:00
|
|
|
std::string ScriptInterpreter::LanguageToString(lldb::ScriptLanguage language) {
|
|
|
|
switch (language) {
|
|
|
|
case eScriptLanguageNone:
|
2019-12-22 13:54:44 +08:00
|
|
|
return "None";
|
2010-09-04 08:03:46 +08:00
|
|
|
case eScriptLanguagePython:
|
2019-12-22 13:54:44 +08:00
|
|
|
return "Python";
|
|
|
|
case eScriptLanguageLua:
|
|
|
|
return "Lua";
|
2016-09-27 03:47:37 +08:00
|
|
|
case eScriptLanguageUnknown:
|
2019-12-22 13:54:44 +08:00
|
|
|
return "Unknown";
|
2010-09-04 08:03:46 +08:00
|
|
|
}
|
|
|
|
}
|
2011-01-14 08:29:16 +08:00
|
|
|
|
2016-09-27 03:47:37 +08:00
|
|
|
lldb::ScriptLanguage
|
|
|
|
ScriptInterpreter::StringToLanguage(const llvm::StringRef &language) {
|
|
|
|
if (language.equals_lower(LanguageToString(eScriptLanguageNone)))
|
|
|
|
return eScriptLanguageNone;
|
2017-09-04 03:27:56 +08:00
|
|
|
if (language.equals_lower(LanguageToString(eScriptLanguagePython)))
|
2016-09-27 03:47:37 +08:00
|
|
|
return eScriptLanguagePython;
|
2019-12-22 13:54:44 +08:00
|
|
|
if (language.equals_lower(LanguageToString(eScriptLanguageLua)))
|
|
|
|
return eScriptLanguageLua;
|
2017-09-04 03:27:56 +08:00
|
|
|
return eScriptLanguageUnknown;
|
2016-09-27 03:47:37 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status ScriptInterpreter::SetBreakpointCommandCallback(
|
2014-08-30 01:34:17 +08:00
|
|
|
std::vector<BreakpointOptions *> &bp_options_vec,
|
|
|
|
const char *callback_text) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status return_error;
|
2014-08-30 01:34:17 +08: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-26 05:05:07 +08:00
|
|
|
Status ScriptInterpreter::SetBreakpointCommandCallbackFunction(
|
2019-12-22 13:54:44 +08:00
|
|
|
std::vector<BreakpointOptions *> &bp_options_vec, const char *function_name,
|
2019-10-26 05:05:07 +08:00
|
|
|
StructuredData::ObjectSP extra_args_sp) {
|
|
|
|
Status error;
|
2014-08-30 01:34:17 +08:00
|
|
|
for (BreakpointOptions *bp_options : bp_options_vec) {
|
2019-12-22 13:54:44 +08:00
|
|
|
error = SetBreakpointCommandCallbackFunction(bp_options, function_name,
|
|
|
|
extra_args_sp);
|
2019-10-26 05:05:07 +08:00
|
|
|
if (!error.Success())
|
|
|
|
return error;
|
2014-08-30 01:34:17 +08:00
|
|
|
}
|
2019-10-26 05:05:07 +08:00
|
|
|
return error;
|
2014-08-30 01:34:17 +08:00
|
|
|
}
|
|
|
|
|
2013-04-19 06:45:39 +08:00
|
|
|
std::unique_ptr<ScriptInterpreterLocker>
|
2013-03-28 06:38:11 +08:00
|
|
|
ScriptInterpreter::AcquireInterpreterLock() {
|
2013-04-19 06:45:39 +08:00
|
|
|
return std::unique_ptr<ScriptInterpreterLocker>(
|
|
|
|
new ScriptInterpreterLocker());
|
2013-03-28 06:38:11 +08:00
|
|
|
}
|