LLDB mainline
ScriptedHookPythonInterface.h
Go to the documentation of this file.
1//===-- ScriptedHookPythonInterface.h ---------------------------*- C++ -*-===//
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#ifndef LLDB_SOURCE_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDHOOKPYTHONINTERFACE_H
10#define LLDB_SOURCE_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDHOOKPYTHONINTERFACE_H
11
13
15
16namespace lldb_private {
19 public PluginInterface {
20public:
22
23 llvm::Expected<StructuredData::GenericSP>
24 CreatePluginObject(const ScriptedMetadata &scripted_metadata,
25 lldb::TargetSP target_sp) override;
26
27 /// `handle_stop` is required so a hook can always be attached via
28 /// `target stop-hook add -P`. `handle_module_loaded` and
29 /// `handle_module_unloaded` are optional; if a hook doesn't implement
30 /// them, the corresponding events are simply not delivered.
31 llvm::SmallVector<AbstractMethodRequirement>
33 return llvm::SmallVector<AbstractMethodRequirement>({{"handle_stop", 2}});
34 }
35
36 llvm::SmallVector<llvm::StringLiteral> GetOptionalMethods() const override {
37 return {"handle_module_loaded", "handle_module_unloaded"};
38 }
39
40 /// Check which of the three hook methods the Python class implements.
41 SupportedHookMethods GetSupportedMethods() override;
42
43 llvm::Error HandleModuleLoaded(lldb::StreamSP &output_sp) override;
44 llvm::Error HandleModuleUnloaded(lldb::StreamSP &output_sp) override;
45 llvm::Expected<bool> HandleStop(ExecutionContext &exe_ctx,
46 lldb::StreamSP &output_sp) override;
47
48 static void Initialize();
49 static void Terminate();
50
51 static llvm::StringRef GetPluginNameStatic() {
52 return "ScriptedHookPythonInterface";
53 }
54
55 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
56};
57} // namespace lldb_private
58
59#endif // LLDB_SOURCE_PLUGINS_SCRIPTINTERPRETER_PYTHON_INTERFACES_SCRIPTEDHOOKPYTHONINTERFACE_H
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
SupportedHookMethods GetSupportedMethods() override
Check which of the three hook methods the Python class implements.
llvm::SmallVector< AbstractMethodRequirement > GetAbstractMethodRequirements() const override
handle_stop is required so a hook can always be attached via target stop-hook add -P.
llvm::SmallVector< llvm::StringLiteral > GetOptionalMethods() const override
Methods a script may legitimately leave out, for which LLDB has a documented answer.
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(const ScriptedMetadata &scripted_metadata, lldb::TargetSP target_sp) override
llvm::Expected< bool > HandleStop(ExecutionContext &exe_ctx, lldb::StreamSP &output_sp) override
Called when the process stops.
ScriptedHookPythonInterface(ScriptInterpreterPythonImpl &interpreter)
llvm::Error HandleModuleUnloaded(lldb::StreamSP &output_sp) override
Called when modules are unloaded from the target. Optional.
llvm::Error HandleModuleLoaded(lldb::StreamSP &output_sp) override
Called when modules are loaded into the target.
ScriptedPythonInterface(ScriptInterpreterPythonImpl &interpreter)
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::Stream > StreamSP
std::shared_ptr< lldb_private::Target > TargetSP