LLDB
mainline
llvm-project
lldb
source
Plugins
ScriptInterpreter
Python
Interfaces
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/Core/PluginManager.h
"
10
#include "
lldb/Target/ExecutionContext.h
"
11
#include "
lldb/Utility/Log.h
"
12
#include "
lldb/lldb-enumerations.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
"
20
#include "
../ScriptInterpreterPythonImpl.h
"
21
#include "
ScriptedStopHookPythonInterface.h
"
22
23
using namespace
lldb
;
24
using namespace
lldb_private
;
25
using namespace
lldb_private::python
;
26
27
ScriptedStopHookPythonInterface::ScriptedStopHookPythonInterface
(
28
ScriptInterpreterPythonImpl
&interpreter)
29
:
ScriptedStopHookInterface
(),
ScriptedPythonInterface
(interpreter) {}
30
31
llvm::Expected<StructuredData::GenericSP>
32
ScriptedStopHookPythonInterface::CreatePluginObject
(llvm::StringRef class_name,
33
lldb::TargetSP
target_sp,
34
const
StructuredDataImpl
&args_sp) {
35
return
ScriptedPythonInterface::CreatePluginObject
(class_name,
nullptr
,
36
target_sp, args_sp);
37
}
38
39
llvm::Expected<bool>
40
ScriptedStopHookPythonInterface::HandleStop
(
ExecutionContext
&exe_ctx,
41
lldb::StreamSP
& output_sp) {
42
ExecutionContextRefSP
exe_ctx_ref_sp =
43
std::make_shared<ExecutionContextRef>(exe_ctx);
44
Status
error
;
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
58
void
ScriptedStopHookPythonInterface::Initialize
() {
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 = {};
62
PluginManager::RegisterPlugin
(
63
GetPluginNameStatic
(),
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
68
void
ScriptedStopHookPythonInterface::Terminate
() {
69
PluginManager::UnregisterPlugin
(
CreateInstance
);
70
}
error
static llvm::raw_ostream & error(Stream &strm)
Definition
CommandReturnObject.cpp:18
ExecutionContext.h
Log.h
PluginManager.h
SWIGPythonBridge.h
ScriptInterpreterPythonImpl.h
ScriptedStopHookPythonInterface.h
lldb_private::ExecutionContext
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
Definition
ExecutionContext.h:317
lldb_private::PluginManager::RegisterPlugin
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
Definition
PluginManager.cpp:626
lldb_private::PluginManager::UnregisterPlugin
static bool UnregisterPlugin(ABICreateInstance create_callback)
Definition
PluginManager.cpp:632
lldb_private::ScriptInterpreterPythonImpl
Definition
ScriptInterpreterPythonImpl.h:25
lldb_private::ScriptedInterface::CheckStructuredDataObject
static bool CheckStructuredDataObject(llvm::StringRef caller, T obj, Status &error)
Definition
ScriptedInterface.h:75
lldb_private::ScriptedInterface::CreateInstance
static bool CreateInstance(lldb::ScriptLanguage language, ScriptedInterfaceUsages usages)
Definition
ScriptedInterface.h:92
lldb_private::ScriptedPythonInterface::CreatePluginObject
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(llvm::StringRef class_name, StructuredData::Generic *script_obj, Args... args)
Definition
ScriptedPythonInterface.h:171
lldb_private::ScriptedPythonInterface::ScriptedPythonInterface
ScriptedPythonInterface(ScriptInterpreterPythonImpl &interpreter)
Definition
ScriptedPythonInterface.cpp:25
lldb_private::ScriptedPythonInterface::Dispatch
T Dispatch(llvm::StringRef method_name, Status &error, Args &&...args)
Definition
ScriptedPythonInterface.h:500
lldb_private::ScriptedStopHookInterface
Definition
ScriptedStopHookInterface.h:17
lldb_private::ScriptedStopHookPythonInterface::GetPluginNameStatic
static llvm::StringRef GetPluginNameStatic()
Definition
ScriptedStopHookPythonInterface.h:39
lldb_private::ScriptedStopHookPythonInterface::Initialize
static void Initialize()
Definition
ScriptedStopHookPythonInterface.cpp:58
lldb_private::ScriptedStopHookPythonInterface::ScriptedStopHookPythonInterface
ScriptedStopHookPythonInterface(ScriptInterpreterPythonImpl &interpreter)
Definition
ScriptedStopHookPythonInterface.cpp:27
lldb_private::ScriptedStopHookPythonInterface::CreatePluginObject
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(llvm::StringRef class_name, lldb::TargetSP target_sp, const StructuredDataImpl &args_sp) override
Definition
ScriptedStopHookPythonInterface.cpp:32
lldb_private::ScriptedStopHookPythonInterface::HandleStop
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,...
Definition
ScriptedStopHookPythonInterface.cpp:40
lldb_private::ScriptedStopHookPythonInterface::Terminate
static void Terminate()
Definition
ScriptedStopHookPythonInterface.cpp:68
lldb_private::Status
An error handling class.
Definition
Status.h:118
lldb_private::StructuredDataImpl
Definition
StructuredDataImpl.h:26
lldb_private::StructuredData::ObjectSP
std::shared_ptr< Object > ObjectSP
Definition
StructuredData.h:66
lldb-enumerations.h
lldb-python.h
lldb_private::python
Definition
SBBreakpoint.h:18
lldb_private
A class that represents a running process on the host machine.
Definition
SBAddressRange.h:14
lldb
Definition
SBAddress.h:15
lldb::eScriptLanguagePython
@ eScriptLanguagePython
Definition
lldb-enumerations.h:228
lldb::StreamSP
std::shared_ptr< lldb_private::Stream > StreamSP
Definition
lldb-forward.h:449
lldb::TargetSP
std::shared_ptr< lldb_private::Target > TargetSP
Definition
lldb-forward.h:467
lldb::ExecutionContextRefSP
std::shared_ptr< lldb_private::ExecutionContextRef > ExecutionContextRefSP
Definition
lldb-forward.h:357
Generated on
for LLDB by
1.14.0