[ELF] Internalize computeCacheDirectedSortOrder. NFC
[llvm-project.git] / lldb / source / Plugins / ScriptInterpreter / Python / Interfaces / ScriptedStopHookPythonInterface.cpp
blobeb052c24bab6da9dc3f24e1968ed31686c0160ec
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 //===----------------------------------------------------------------------===//
9 #include "lldb/Core/PluginManager.h"
10 #include "lldb/Host/Config.h"
11 #include "lldb/Target/ExecutionContext.h"
12 #include "lldb/Utility/Log.h"
13 #include "lldb/lldb-enumerations.h"
15 #if LLDB_ENABLE_PYTHON
17 // clang-format off
18 // LLDB Python header must be included first
19 #include "../lldb-python.h"
20 //clang-format on
22 #include "../SWIGPythonBridge.h"
23 #include "../ScriptInterpreterPythonImpl.h"
24 #include "ScriptedStopHookPythonInterface.h"
26 using namespace lldb;
27 using namespace lldb_private;
28 using namespace lldb_private::python;
30 ScriptedStopHookPythonInterface::ScriptedStopHookPythonInterface(
31 ScriptInterpreterPythonImpl &interpreter)
32 : ScriptedStopHookInterface(), ScriptedPythonInterface(interpreter) {}
34 llvm::Expected<StructuredData::GenericSP>
35 ScriptedStopHookPythonInterface::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);
42 llvm::Expected<bool>
43 ScriptedStopHookPythonInterface::HandleStop(ExecutionContext &exe_ctx,
44 lldb::StreamSP& output_sp) {
45 ExecutionContextRefSP exe_ctx_ref_sp =
46 std::make_shared<ExecutionContextRef>(exe_ctx);
47 Status error;
48 StructuredData::ObjectSP obj = Dispatch("handle_stop", error, exe_ctx_ref_sp, output_sp);
50 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
51 error)) {
52 if (!obj)
53 return true;
54 return error.ToError();
57 return obj->GetBooleanValue();
61 void 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});
71 void ScriptedStopHookPythonInterface::Terminate() {
72 PluginManager::UnregisterPlugin(CreateInstance);
75 #endif