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
9#include "../lldb-python.h"
10
13#include "lldb/Target/Target.h"
14#include "lldb/Utility/Log.h"
16
17#include "../SWIGPythonBridge.h"
20
21using namespace lldb;
22using namespace lldb_private;
23using namespace lldb_private::python;
24
28
29llvm::Expected<StructuredData::GenericSP>
31 const ScriptedMetadata &scripted_metadata, lldb::TargetSP target_sp) {
32 StructuredDataImpl args_sp(scripted_metadata.GetArgsSP());
33 return ScriptedPythonInterface::CreatePluginObject(scripted_metadata, nullptr,
34 target_sp, args_sp);
35}
36
37llvm::Expected<bool>
39 lldb::StreamSP& output_sp) {
40 ExecutionContextRefSP exe_ctx_ref_sp =
41 std::make_shared<ExecutionContextRef>(exe_ctx);
43 StructuredData::ObjectSP obj = Dispatch("handle_stop", error, exe_ctx_ref_sp, output_sp);
44
45 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
46 error)) {
47 if (!obj)
48 return true;
49 return error.ToError();
50 }
51
52 return obj->GetBooleanValue();
53}
54
55
57 const std::vector<llvm::StringRef> ci_usages = {
58 "target stop-hook add -P <script-name> [-k key -v value ...]"};
59 const std::vector<llvm::StringRef> api_usages = {};
62 llvm::StringRef("Perform actions whenever the process stops, before control is returned to the user."),
63 CreateInstance, eScriptLanguagePython, {ci_usages, api_usages});
64}
65
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)
StructuredData::DictionarySP GetArgsSP() const
ScriptedPythonInterface(ScriptInterpreterPythonImpl &interpreter)
T Dispatch(llvm::StringRef method_name, Status &error, Args &&...args)
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(const ScriptedMetadata &scripted_metadata, StructuredData::Generic *script_obj, Args... args)
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(const ScriptedMetadata &scripted_metadata, lldb::TargetSP target_sp) override
ScriptedStopHookPythonInterface(ScriptInterpreterPythonImpl &interpreter)
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