Path: blob/main/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedStopHookPythonInterface.cpp
213893 views
//===-- ScriptedStopHookPythonInterface.cpp -------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Core/PluginManager.h"9#include "lldb/Host/Config.h"10#include "lldb/Target/ExecutionContext.h"11#include "lldb/Utility/Log.h"12#include "lldb/lldb-enumerations.h"1314#if LLDB_ENABLE_PYTHON1516// clang-format off17// LLDB Python header must be included first18#include "../lldb-python.h"19//clang-format on2021#include "../SWIGPythonBridge.h"22#include "../ScriptInterpreterPythonImpl.h"23#include "ScriptedStopHookPythonInterface.h"2425using namespace lldb;26using namespace lldb_private;27using namespace lldb_private::python;2829ScriptedStopHookPythonInterface::ScriptedStopHookPythonInterface(30ScriptInterpreterPythonImpl &interpreter)31: ScriptedStopHookInterface(), ScriptedPythonInterface(interpreter) {}3233llvm::Expected<StructuredData::GenericSP>34ScriptedStopHookPythonInterface::CreatePluginObject(llvm::StringRef class_name,35lldb::TargetSP target_sp,36const StructuredDataImpl &args_sp) {37return ScriptedPythonInterface::CreatePluginObject(class_name, nullptr,38target_sp, args_sp);39}4041llvm::Expected<bool>42ScriptedStopHookPythonInterface::HandleStop(ExecutionContext &exe_ctx,43lldb::StreamSP& output_sp) {44ExecutionContextRefSP exe_ctx_ref_sp =45std::make_shared<ExecutionContextRef>(exe_ctx);46Status error;47StructuredData::ObjectSP obj = Dispatch("handle_stop", error, exe_ctx_ref_sp, output_sp);4849if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,50error)) {51if (!obj)52return true;53return error.ToError();54}5556return obj->GetBooleanValue();57}585960void ScriptedStopHookPythonInterface::Initialize() {61const std::vector<llvm::StringRef> ci_usages = {62"target stop-hook add -P <script-name> [-k key -v value ...]"};63const std::vector<llvm::StringRef> api_usages = {};64PluginManager::RegisterPlugin(65GetPluginNameStatic(),66llvm::StringRef("Perform actions whenever the process stops, before control is returned to the user."),67CreateInstance, eScriptLanguagePython, {ci_usages, api_usages});68}6970void ScriptedStopHookPythonInterface::Terminate() {71PluginManager::UnregisterPlugin(CreateInstance);72}7374#endif757677