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
9#include "../lldb-python.h"
10
17#include "lldb/Utility/Log.h"
19
20#include "../SWIGPythonBridge.h"
23
24using namespace lldb;
25using namespace lldb_private;
26using namespace lldb_private::python;
27
31
32llvm::Expected<StructuredData::GenericSP>
34 const ScriptedMetadata &scripted_metadata, lldb::BreakpointSP break_sp) {
36 scripted_metadata, nullptr, break_sp, scripted_metadata.GetArgsSP());
37}
38
40 Target &target, StructuredDataImpl &resolver_data) {
41 TargetSP target_sp = target.shared_from_this();
42
44 LogAndDefault(Dispatch("overrides_resolver", target_sp, resolver_data),
45 LLVM_PRETTY_FUNCTION);
46 if (!obj)
47 return false;
48
49 return obj->GetBooleanValue();
50}
51
53 lldb::BreakpointSP break_sp) {
54 LogAndDefault(Dispatch("set_breakpoint", break_sp), LLVM_PRETTY_FUNCTION);
55}
56
58 SymbolContext sym_ctx) {
60 LogAndDefault(Dispatch("__callback__", sym_ctx), LLVM_PRETTY_FUNCTION);
61 if (!obj)
62 return true;
63
64 return obj->GetBooleanValue();
65}
66
69 LogAndDefault(Dispatch("__get_depth__"), LLVM_PRETTY_FUNCTION);
70 if (!obj)
72
73 uint64_t value = obj->GetUnsignedIntegerValue();
74 if (value <= lldb::kLastSearchDepthKind)
75 return (lldb::SearchDepth)value;
76 // This is what we were doing on error before, though I'm not sure that's
77 // better than returning eSearchDepthInvalid.
79}
80
83 LogAndDefault(Dispatch("get_short_help"), LLVM_PRETTY_FUNCTION);
84 if (!obj)
85 return {};
86
87 return obj->GetStringValue().str();
88}
89
92 llvm::Expected<lldb::BreakpointLocationSP> loc_or_err =
93 Dispatch<lldb::BreakpointLocationSP>("was_hit", frame_sp, bp_loc_sp);
94 if (!loc_or_err) {
95 LLDB_LOG_ERROR(GetLog(LLDBLog::Script), loc_or_err.takeError(),
96 "Error calling was_hit method: {0}");
97 return bp_loc_sp;
98 }
99
100 return *loc_or_err;
101}
102
103std::optional<std::string>
107 LogAndDefault(Dispatch("get_location_description", bp_loc_sp, level),
108 LLVM_PRETTY_FUNCTION);
109 if (!obj)
110 return {};
111
112 return obj->GetStringValue().str();
113}
114
116 const std::vector<llvm::StringRef> ci_usages = {
117 "breakpoint set -P classname [-k key -v value ...]"};
118 const std::vector<llvm::StringRef> api_usages = {
119 "SBTarget.BreakpointCreateFromScript"};
122 llvm::StringRef("Create a breakpoint that chooses locations based on "
123 "user-created callbacks"),
125 eScriptLanguagePython, {ci_usages, api_usages});
126}
127
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:405
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(const ScriptedMetadata &scripted_metadata, lldb::BreakpointSP break_sp) override
bool OverridesResolver(Target &target, StructuredDataImpl &resolver_data) override
ScriptedBreakpointPythonInterface(ScriptInterpreterPythonImpl &interpreter)
bool ResolverCallback(SymbolContext sym_ctx) override
"ResolverCallback" will get called when a new module is loaded.
lldb::BreakpointLocationSP WasHit(lldb::StackFrameSP frame_sp, lldb::BreakpointLocationSP bp_loc_sp) override
WasHit returns the breakpoint location SP for the location that was "hit".
virtual std::optional< std::string > GetLocationDescription(lldb::BreakpointLocationSP bp_loc_sp, lldb::DescriptionLevel level) override
static bool CreateInstance(lldb::ScriptLanguage language, ScriptedInterfaceUsages usages)
StructuredData::DictionarySP GetArgsSP() const
static T LogAndDefault(llvm::Expected< T > value_or_err, llvm::StringRef caller)
Log the failure in value_or_err and fall back to a default-constructed T.
ScriptedPythonInterface(ScriptInterpreterPythonImpl &interpreter)
llvm::Expected< T > Dispatch(llvm::StringRef method_name, Args &&...args)
Call method_name on the scripted object.
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(const ScriptedMetadata &scripted_metadata, StructuredData::Generic *script_obj, Args... args)
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:338
@ eScriptLanguagePython
@ eScriptedExtensionScriptedBreakpointResolver
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
std::shared_ptr< lldb_private::BreakpointLocation > BreakpointLocationSP
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
@ kLastSearchDepthKind
std::shared_ptr< lldb_private::Target > TargetSP