LLDB mainline
ScriptedStopHookPythonInterface.cpp
Go to the documentation of this file.
1//===-- ScriptedStopHookPythonInterface.cpp -------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
11#include "lldb/Utility/Log.h"
13
14// clang-format off
15// LLDB Python header must be included first
16#include "../lldb-python.h"
17//clang-format on
18
19#include "../SWIGPythonBridge.h"
22
23using namespace lldb;
24using namespace lldb_private;
25using namespace lldb_private::python;
26
30
31llvm::Expected<StructuredData::GenericSP>
33 lldb::TargetSP target_sp,
34 const StructuredDataImpl &args_sp) {
35 return ScriptedPythonInterface::CreatePluginObject(class_name, nullptr,
36 target_sp, args_sp);
37}
38
39llvm::Expected<bool>
41 lldb::StreamSP& output_sp) {
42 ExecutionContextRefSP exe_ctx_ref_sp =
43 std::make_shared<ExecutionContextRef>(exe_ctx);
45 StructuredData::ObjectSP obj = Dispatch("handle_stop", error, exe_ctx_ref_sp, output_sp);
46
47 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
48 error)) {
49 if (!obj)
50 return true;
51 return error.ToError();
52 }
53
54 return obj->GetBooleanValue();
55}
56
57
59 const std::vector<llvm::StringRef> ci_usages = {
60 "target stop-hook add -P <script-name> [-k key -v value ...]"};
61 const std::vector<llvm::StringRef> api_usages = {};
64 llvm::StringRef("Perform actions whenever the process stops, before control is returned to the user."),
65 CreateInstance, eScriptLanguagePython, {ci_usages, api_usages});
66}
67
static llvm::raw_ostream & error(Stream &strm)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
static bool CheckStructuredDataObject(llvm::StringRef caller, T obj, Status &error)
static bool CreateInstance(lldb::ScriptLanguage language, ScriptedInterfaceUsages usages)
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(llvm::StringRef class_name, StructuredData::Generic *script_obj, Args... args)
ScriptedPythonInterface(ScriptInterpreterPythonImpl &interpreter)
T Dispatch(llvm::StringRef method_name, Status &error, Args &&...args)
ScriptedStopHookPythonInterface(ScriptInterpreterPythonImpl &interpreter)
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(llvm::StringRef class_name, lldb::TargetSP target_sp, const StructuredDataImpl &args_sp) override
llvm::Expected< bool > HandleStop(ExecutionContext &exe_ctx, lldb::StreamSP &output_sp) override
"handle_stop" will return a bool with the meaning "should_stop"... If nothing is returned,...
An error handling class.
Definition Status.h:118
std::shared_ptr< Object > ObjectSP
A class that represents a running process on the host machine.
@ eScriptLanguagePython
std::shared_ptr< lldb_private::Stream > StreamSP
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::ExecutionContextRef > ExecutionContextRefSP