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) {
42
43 TargetSP target_sp = target.shared_from_this();
44
46 Dispatch("overrides_resolver", error, target_sp, resolver_data);
47
48 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
49 error)) {
51 LLDB_LOG(log, "Error calling overrides_resolver method: {0}", error);
52 return false;
53 }
54 return obj->GetBooleanValue();
55}
56
58 lldb::BreakpointSP break_sp) {
60 StructuredData::ObjectSP obj = Dispatch("set_breakpoint", error, break_sp);
61 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
62 error)) {
64 LLDB_LOG(log, "Error calling set_breakpoint method: {0}", error);
65 }
66}
67
69 SymbolContext sym_ctx) {
71
72 StructuredData::ObjectSP obj = Dispatch("__callback__", error, sym_ctx);
73
74 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
75 error)) {
77 LLDB_LOG(log, "Error calling __callback__ method: {}", error);
78 return true;
79 }
80 return obj->GetBooleanValue();
81}
82
85 StructuredData::ObjectSP obj = Dispatch("__get_depth__", error);
86
87 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
88 error)) {
90 }
91 uint64_t value = obj->GetUnsignedIntegerValue();
92 if (value <= lldb::kLastSearchDepthKind)
93 return (lldb::SearchDepth)value;
94 // This is what we were doing on error before, though I'm not sure that's
95 // better than returning eSearchDepthInvalid.
97}
98
101 StructuredData::ObjectSP obj = Dispatch("get_short_help", error);
102
103 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
104 error)) {
105 return {};
106 }
107
108 return obj->GetAsString()->GetValue().str();
109}
110
113 Status py_error;
115 "was_hit", py_error, frame_sp, bp_loc_sp);
116
117 if (py_error.Fail())
118 return bp_loc_sp;
119
120 return loc_sp;
121}
122
123std::optional<std::string>
128 Dispatch("get_location_description", error, bp_loc_sp, level);
129
130 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
131 error))
132 return {};
133
134 return obj->GetAsString()->GetValue().str();
135}
136
138 const std::vector<llvm::StringRef> ci_usages = {
139 "breakpoint set -P classname [-k key -v value ...]"};
140 const std::vector<llvm::StringRef> api_usages = {
141 "SBTarget.BreakpointCreateFromScript"};
144 llvm::StringRef("Create a breakpoint that chooses locations based on "
145 "user-created callbacks"),
146 CreateInstance, eScriptLanguagePython, {ci_usages, api_usages});
147}
148
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:364
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 CheckStructuredDataObject(llvm::StringRef caller, T obj, Status &error)
static bool CreateInstance(lldb::ScriptLanguage language, ScriptedInterfaceUsages usages)
StructuredData::DictionarySP GetArgsSP() const
ScriptedPythonInterface(ScriptInterpreterPythonImpl &interpreter)
T Dispatch(llvm::StringRef method_name, Status &error, Args &&...args)
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(const ScriptedMetadata &scripted_metadata, StructuredData::Generic *script_obj, Args... args)
An error handling class.
Definition Status.h:118
bool Fail() const
Test for error condition.
Definition Status.cpp:293
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:327
@ eScriptLanguagePython
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