LLDB mainline
ScriptedBreakpointPythonInterface.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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"
13#include "lldb/Utility/Log.h"
15
16#if LLDB_ENABLE_PYTHON
17
18// LLDB Python header must be included first
19#include "../lldb-python.h"
20
21#include "../SWIGPythonBridge.h"
24
25using namespace lldb;
26using namespace lldb_private;
27using namespace lldb_private::python;
28
29ScriptedBreakpointPythonInterface::ScriptedBreakpointPythonInterface(
30 ScriptInterpreterPythonImpl &interpreter)
31 : ScriptedBreakpointInterface(), ScriptedPythonInterface(interpreter) {}
32
33llvm::Expected<StructuredData::GenericSP>
34ScriptedBreakpointPythonInterface::CreatePluginObject(
35 llvm::StringRef class_name, lldb::BreakpointSP break_sp,
36 const StructuredDataImpl &args_sp) {
37 return ScriptedPythonInterface::CreatePluginObject(class_name, nullptr,
38 break_sp, args_sp);
39}
40
41bool ScriptedBreakpointPythonInterface::ResolverCallback(
42 SymbolContext sym_ctx) {
44
45 StructuredData::ObjectSP obj = Dispatch("__callback__", error, sym_ctx);
46
47 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
48 error)) {
50 LLDB_LOG(log, "Error calling __callback__ method: {1}", error);
51 return true;
52 }
53 return obj->GetBooleanValue();
54}
55
56lldb::SearchDepth ScriptedBreakpointPythonInterface::GetDepth() {
58 StructuredData::ObjectSP obj = Dispatch("__get_depth__", error);
59
60 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
61 error)) {
63 }
64 uint64_t value = obj->GetUnsignedIntegerValue();
65 if (value <= lldb::kLastSearchDepthKind)
66 return (lldb::SearchDepth)value;
67 // This is what we were doing on error before, though I'm not sure that's
68 // better than returning eSearchDepthInvalid.
70}
71
72std::optional<std::string> ScriptedBreakpointPythonInterface::GetShortHelp() {
74 StructuredData::ObjectSP obj = Dispatch("get_short_help", error);
75
76 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
77 error)) {
78 return {};
79 }
80
81 return obj->GetAsString()->GetValue().str();
82}
83
84void ScriptedBreakpointPythonInterface::Initialize() {
85 const std::vector<llvm::StringRef> ci_usages = {
86 "breakpoint set -P classname [-k key -v value ...]"};
87 const std::vector<llvm::StringRef> api_usages = {
88 "SBTarget.BreakpointCreateFromScript"};
90 GetPluginNameStatic(),
91 llvm::StringRef("Create a breakpoint that chooses locations based on "
92 "user-created callbacks"),
93 CreateInstance, eScriptLanguagePython, {ci_usages, api_usages});
94}
95
96void ScriptedBreakpointPythonInterface::Terminate() {
97 PluginManager::UnregisterPlugin(CreateInstance);
98}
99
100#endif
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:369
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)
std::shared_ptr< Object > ObjectSP
Defines a symbol context baton that can be handed other debug core functions.
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:332
@ eScriptLanguagePython
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
@ kLastSearchDepthKind