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
10#include "lldb/Host/Config.h"
12#include "lldb/Utility/Log.h"
14
15#if LLDB_ENABLE_PYTHON
16
17// clang-format off
18// LLDB Python header must be included first
19#include "../lldb-python.h"
20//clang-format on
21
22#include "../SWIGPythonBridge.h"
23#include "../ScriptInterpreterPythonImpl.h"
25
26using namespace lldb;
27using namespace lldb_private;
28using namespace lldb_private::python;
29
30ScriptedStopHookPythonInterface::ScriptedStopHookPythonInterface(
31 ScriptInterpreterPythonImpl &interpreter)
32 : ScriptedStopHookInterface(), ScriptedPythonInterface(interpreter) {}
33
34llvm::Expected<StructuredData::GenericSP>
35ScriptedStopHookPythonInterface::CreatePluginObject(llvm::StringRef class_name,
36 lldb::TargetSP target_sp,
37 const StructuredDataImpl &args_sp) {
38 return ScriptedPythonInterface::CreatePluginObject(class_name, nullptr,
39 target_sp, args_sp);
40}
41
42llvm::Expected<bool>
43ScriptedStopHookPythonInterface::HandleStop(ExecutionContext &exe_ctx,
44 lldb::StreamSP& output_sp) {
45 ExecutionContextRefSP exe_ctx_ref_sp =
46 std::make_shared<ExecutionContextRef>(exe_ctx);
48 StructuredData::ObjectSP obj = Dispatch("handle_stop", error, exe_ctx_ref_sp, output_sp);
49
50 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
51 error)) {
52 if (!obj)
53 return true;
54 return error.ToError();
55 }
56
57 return obj->GetBooleanValue();
58}
59
60
61void ScriptedStopHookPythonInterface::Initialize() {
62 const std::vector<llvm::StringRef> ci_usages = {
63 "target stop-hook add -P <script-name> [-k key -v value ...]"};
64 const std::vector<llvm::StringRef> api_usages = {};
65 PluginManager::RegisterPlugin(
66 GetPluginNameStatic(),
67 llvm::StringRef("Perform actions whenever the process stops, before control is returned to the user."),
68 CreateInstance, eScriptLanguagePython, {ci_usages, api_usages});
69}
70
71void ScriptedStopHookPythonInterface::Terminate() {
72 PluginManager::UnregisterPlugin(CreateInstance);
73}
74
75#endif
static llvm::raw_ostream & error(Stream &strm)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
An error handling class.
Definition: Status.h:118
std::shared_ptr< Object > ObjectSP
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::Stream > StreamSP
Definition: lldb-forward.h:432
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:448
std::shared_ptr< lldb_private::ExecutionContextRef > ExecutionContextRefSP
Definition: lldb-forward.h:350