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)
31 : BreakpointResolver(bkpt, BreakpointResolver::PythonResolver),
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 m_class_name.c_str(), m_args, breakpoint_sp);
55}
56
59}
60
62 const StructuredData::Dictionary &options_dict, Status &error) {
63 llvm::StringRef class_name;
64 bool success;
65
66 success = options_dict.GetValueForKeyAsString(
68 if (!success) {
69 error =
70 Status::FromErrorString("BRFL::CFSD: Couldn't find class name entry.");
71 return nullptr;
72 }
73 // The Python function will actually provide the search depth, this is a
74 // placeholder.
76
77 StructuredDataImpl args_data_impl;
78 StructuredData::Dictionary *args_dict = nullptr;
80 args_dict))
81 args_data_impl.SetObjectSP(args_dict->shared_from_this());
82 return std::make_shared<BreakpointResolverScripted>(nullptr, class_name,
83 depth, args_data_impl);
84}
85
88 StructuredData::DictionarySP options_dict_sp(
90
91 options_dict_sp->AddStringItem(GetKey(OptionNames::PythonClassName),
93 if (m_args.IsValid())
94 options_dict_sp->AddItem(GetKey(OptionNames::ScriptArgs),
96
97 return WrapOptionsDict(options_dict_sp);
98}
99
101 return GetBreakpoint()->GetTarget().GetDebugger().GetScriptInterpreter();
102}
103
105 SearchFilter &filter, SymbolContext &context, Address *addr) {
106 bool should_continue = true;
109
111 should_continue = interp->ScriptedBreakpointResolverSearchCallback(
113 &context);
114 if (should_continue)
116
118}
119
127 }
128 return depth;
129}
130
132 StructuredData::GenericSP generic_sp;
133 std::string short_help;
134
138 short_help);
139 }
140 if (!short_help.empty())
141 s->PutCString(short_help.c_str());
142 else
143 s->Printf("python class = %s", m_class_name.c_str());
144}
145
147
150 return std::make_shared<BreakpointResolverScripted>(breakpoint, m_class_name,
151 m_depth, m_args);
152}
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)
static lldb::BreakpointResolverSP CreateFromStructuredData(const StructuredData::Dictionary &options_dict, Status &error)
General Outline: The BreakpointResolver is a Searcher.
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.
virtual bool ScriptedBreakpointResolverSearchCallback(StructuredData::GenericSP implementor_sp, SymbolContext *sym_ctx)
virtual lldb::SearchDepth ScriptedBreakpointResolverSearchDepth(StructuredData::GenericSP implementor_sp)
virtual bool GetShortHelpForCommandObject(StructuredData::GenericSP cmd_obj_sp, std::string &dest)
virtual StructuredData::GenericSP CreateScriptedBreakpointResolver(const char *class_name, const StructuredDataImpl &args_data, lldb::BreakpointSP &bkpt_sp)
General Outline: Provides the callback and search depth for the SearchFilter search.
Definition: SearchFilter.h:83
An error handling class.
Definition: Status.h:115
static Status FromErrorString(const char *str)
Definition: Status.h:138
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)
StructuredData::ObjectSP GetObjectSP()
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.
Definition: SymbolContext.h:34
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::BreakpointResolver > BreakpointResolverSP
Definition: lldb-forward.h:328
std::shared_ptr< lldb_private::Breakpoint > BreakpointSP
Definition: lldb-forward.h:321
@ eSearchDepthTarget
@ eSearchDepthModule
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:448