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
12#include "lldb/Utility/Log.h"
14
15// LLDB Python header must be included first
16#include "../lldb-python.h"
17
18#include "../SWIGPythonBridge.h"
21
22using namespace lldb;
23using namespace lldb_private;
24using namespace lldb_private::python;
25
29
30llvm::Expected<StructuredData::GenericSP>
32 llvm::StringRef class_name, lldb::BreakpointSP break_sp,
33 const StructuredDataImpl &args_sp) {
34 return ScriptedPythonInterface::CreatePluginObject(class_name, nullptr,
35 break_sp, args_sp);
36}
37
39 SymbolContext sym_ctx) {
41
42 StructuredData::ObjectSP obj = Dispatch("__callback__", error, sym_ctx);
43
44 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
45 error)) {
47 LLDB_LOG(log, "Error calling __callback__ method: {1}", error);
48 return true;
49 }
50 return obj->GetBooleanValue();
51}
52
55 StructuredData::ObjectSP obj = Dispatch("__get_depth__", error);
56
57 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
58 error)) {
60 }
61 uint64_t value = obj->GetUnsignedIntegerValue();
62 if (value <= lldb::kLastSearchDepthKind)
63 return (lldb::SearchDepth)value;
64 // This is what we were doing on error before, though I'm not sure that's
65 // better than returning eSearchDepthInvalid.
67}
68
71 StructuredData::ObjectSP obj = Dispatch("get_short_help", error);
72
73 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
74 error)) {
75 return {};
76 }
77
78 return obj->GetAsString()->GetValue().str();
79}
80
83 Status py_error;
85 "was_hit", py_error, frame_sp, bp_loc_sp);
86
87 if (py_error.Fail())
88 return bp_loc_sp;
89
90 return loc_sp;
91}
92
93std::optional<std::string>
98 Dispatch("get_location_description", error, bp_loc_sp, level);
99
100 if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,
101 error))
102 return {};
103
104 return obj->GetAsString()->GetValue().str();
105}
106
108 const std::vector<llvm::StringRef> ci_usages = {
109 "breakpoint set -P classname [-k key -v value ...]"};
110 const std::vector<llvm::StringRef> api_usages = {
111 "SBTarget.BreakpointCreateFromScript"};
114 llvm::StringRef("Create a breakpoint that chooses locations based on "
115 "user-created callbacks"),
116 CreateInstance, eScriptLanguagePython, {ci_usages, api_usages});
117}
118
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)
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".
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(llvm::StringRef class_name, lldb::BreakpointSP break_sp, const StructuredDataImpl &args_sp) override
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)
llvm::Expected< StructuredData::GenericSP > CreatePluginObject(llvm::StringRef class_name, StructuredData::Generic *script_obj, Args... args)
ScriptedPythonInterface(ScriptInterpreterPythonImpl &interpreter)
T Dispatch(llvm::StringRef method_name, Status &error, Args &&...args)
An error handling class.
Definition Status.h:118
bool Fail() const
Test for error condition.
Definition Status.cpp:294
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::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