LLDB mainline
BreakpointResolverScripted.cpp
Go to the documentation of this file.
1//===-- BreakpointResolverScripted.cpp ------------------------------------===//
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
11
13#include "lldb/Core/Debugger.h"
14#include "lldb/Core/Module.h"
15#include "lldb/Core/Section.h"
19#include "lldb/Target/Process.h"
20#include "lldb/Target/Target.h"
21#include "lldb/Utility/Log.h"
23
24using namespace lldb;
25using namespace lldb_private;
26
27// BreakpointResolverScripted:
29 const BreakpointSP &bkpt, const llvm::StringRef class_name,
30 lldb::SearchDepth depth, const StructuredDataImpl &args_data)
32 m_class_name(std::string(class_name)), m_depth(depth), m_args(args_data) {
34}
35
37 BreakpointSP breakpoint_sp) {
39 return;
40
41 if (m_class_name.empty())
42 return;
43
44 if (!breakpoint_sp)
45 return;
46
47 TargetSP target_sp = breakpoint_sp->GetTargetSP();
48 ScriptInterpreter *script_interp = target_sp->GetDebugger()
49 .GetScriptInterpreter();
50 if (!script_interp)
51 return;
52
54 if (!m_interface_sp) {
56 "BreakpointResolverScripted::%s () - ERROR: %s", __FUNCTION__,
57 "Script interpreter couldn't create Scripted Breakpoint Interface");
58 return;
59 }
60
61 auto obj_or_err =
62 m_interface_sp->CreatePluginObject(m_class_name, breakpoint_sp, m_args);
63 if (!obj_or_err) {
64 m_error = Status::FromError(obj_or_err.takeError());
65 return;
66 }
67
68 StructuredData::ObjectSP object_sp = *obj_or_err;
69 if (!object_sp || !object_sp->IsValid()) {
71 "ScriptedBreakpoint::%s () - ERROR: %s", __FUNCTION__,
72 "Failed to create valid script object");
73 }
74}
75
79
81 const StructuredData::Dictionary &options_dict, Status &error) {
82 llvm::StringRef class_name;
83 bool success;
84
85 success = options_dict.GetValueForKeyAsString(
87 if (!success) {
88 error =
89 Status::FromErrorString("BRFL::CFSD: Couldn't find class name entry.");
90 return nullptr;
91 }
92 // The Python function will actually provide the search depth, this is a
93 // placeholder.
95
96 StructuredDataImpl args_data_impl;
97 StructuredData::Dictionary *args_dict = nullptr;
99 args_dict))
100 args_data_impl.SetObjectSP(args_dict->shared_from_this());
101 return std::make_shared<BreakpointResolverScripted>(nullptr, class_name,
102 depth, args_data_impl);
103}
104
107 StructuredData::DictionarySP options_dict_sp(
109
110 options_dict_sp->AddStringItem(GetKey(OptionNames::PythonClassName),
112 if (m_args.IsValid())
113 options_dict_sp->AddItem(GetKey(OptionNames::ScriptArgs),
114 m_args.GetObjectSP());
115
116 return WrapOptionsDict(options_dict_sp);
117}
118
120 return GetBreakpoint()->GetTarget().GetDebugger().GetScriptInterpreter();
121}
122
124 SearchFilter &filter, SymbolContext &context, Address *addr) {
125 bool should_continue = true;
126 if (!m_interface_sp)
128
129 should_continue = m_interface_sp->ResolverCallback(context);
130 if (should_continue)
132
134}
135
139 if (m_interface_sp)
140 depth = m_interface_sp->GetDepth();
141
142 return depth;
143}
144
146 StructuredData::GenericSP generic_sp;
147 std::optional<std::string> short_help;
148
149 if (m_interface_sp) {
150 short_help = m_interface_sp->GetShortHelp();
151 }
152 if (short_help && !short_help->empty())
153 s->PutCString(short_help->c_str());
154 else
155 s->Printf("python class = %s", m_class_name.c_str());
156}
157
159
162 return std::make_shared<BreakpointResolverScripted>(breakpoint, m_class_name,
163 m_depth, m_args);
164}
static llvm::raw_ostream & error(Stream &strm)
A section + offset based address class.
Definition Address.h:62
BreakpointResolverScripted(const lldb::BreakpointSP &bkpt, const llvm::StringRef class_name, lldb::SearchDepth depth, const StructuredDataImpl &args_data)
lldb::BreakpointResolverSP CopyForBreakpoint(lldb::BreakpointSP &breakpoint) override
void GetDescription(Stream *s) override
Prints a canonical description for the breakpoint to the stream s.
StructuredData::ObjectSP SerializeToStructuredData() override
void Dump(Stream *s) const override
Standard "Dump" method. At present it does nothing.
Searcher::CallbackReturn SearchCallback(SearchFilter &filter, SymbolContext &context, Address *addr) override
void CreateImplementationIfNeeded(lldb::BreakpointSP bkpt)
lldb::ScriptedBreakpointInterfaceSP m_interface_sp
static lldb::BreakpointResolverSP CreateFromStructuredData(const StructuredData::Dictionary &options_dict, Status &error)
static const char * GetKey(OptionNames enum_value)
StructuredData::DictionarySP WrapOptionsDict(StructuredData::DictionarySP options_dict_sp)
lldb::BreakpointSP GetBreakpoint() const
This gets the breakpoint for this resolver.
BreakpointResolver(const lldb::BreakpointSP &bkpt, unsigned char resolverType, lldb::addr_t offset=0, bool offset_is_insn_count=false)
The breakpoint resolver need to have a breakpoint for "ResolveBreakpoint to make sense.
virtual lldb::ScriptedBreakpointInterfaceSP CreateScriptedBreakpointInterface()
General Outline: Provides the callback and search depth for the SearchFilter search.
An error handling class.
Definition Status.h:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
Definition Status.cpp:137
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:65
void SetObjectSP(const StructuredData::ObjectSP &obj)
bool GetValueForKeyAsString(llvm::StringRef key, llvm::StringRef &result) const
bool GetValueForKeyAsDictionary(llvm::StringRef key, Dictionary *&result) const
std::shared_ptr< Generic > GenericSP
std::shared_ptr< Dictionary > DictionarySP
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.
std::shared_ptr< lldb_private::BreakpointResolver > BreakpointResolverSP
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
std::shared_ptr< lldb_private::Target > TargetSP