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 
24 using namespace lldb;
25 using namespace lldb_private;
26 
27 // BreakpointResolverScripted:
28 BreakpointResolverScripted::BreakpointResolverScripted(
29  const BreakpointSP &bkpt, const llvm::StringRef class_name,
30  lldb::SearchDepth depth, StructuredDataImpl *args_data)
31  : BreakpointResolver(bkpt, BreakpointResolver::PythonResolver),
32  m_class_name(std::string(class_name)), m_depth(depth),
33  m_args_ptr(args_data) {
34  CreateImplementationIfNeeded(bkpt);
35 }
36 
38  BreakpointSP breakpoint_sp) {
40  return;
41 
42  if (m_class_name.empty())
43  return;
44 
45  if (!breakpoint_sp)
46  return;
47 
48  TargetSP target_sp = breakpoint_sp->GetTargetSP();
49  ScriptInterpreter *script_interp = target_sp->GetDebugger()
50  .GetScriptInterpreter();
51  if (!script_interp)
52  return;
53 
55  m_class_name.c_str(), m_args_ptr, breakpoint_sp);
56 }
57 
60 }
61 
64  const BreakpointSP &bkpt, const StructuredData::Dictionary &options_dict,
65  Status &error) {
66  llvm::StringRef class_name;
67  bool success;
68 
69  success = options_dict.GetValueForKeyAsString(
71  if (!success) {
72  error.SetErrorString("BRFL::CFSD: Couldn't find class name entry.");
73  return nullptr;
74  }
75  // The Python function will actually provide the search depth, this is a
76  // placeholder.
78 
79  StructuredDataImpl *args_data_impl = new StructuredDataImpl();
80  StructuredData::Dictionary *args_dict = nullptr;
81  success = options_dict.GetValueForKeyAsDictionary(
82  GetKey(OptionNames::ScriptArgs), args_dict);
83  if (success) {
84  args_data_impl->SetObjectSP(args_dict->shared_from_this());
85  }
86  return new BreakpointResolverScripted(bkpt, class_name, depth,
87  args_data_impl);
88 }
89 
92  StructuredData::DictionarySP options_dict_sp(
94 
95  options_dict_sp->AddStringItem(GetKey(OptionNames::PythonClassName),
96  m_class_name);
97  if (m_args_ptr->IsValid())
98  options_dict_sp->AddItem(GetKey(OptionNames::ScriptArgs),
100 
101  return WrapOptionsDict(options_dict_sp);
102 }
103 
105  return GetBreakpoint()->GetTarget().GetDebugger().GetScriptInterpreter();
106 }
107 
109  SearchFilter &filter, SymbolContext &context, Address *addr) {
110  bool should_continue = true;
111  if (!m_implementation_sp)
113 
115  should_continue = interp->ScriptedBreakpointResolverSearchCallback(
117  &context);
118  if (should_continue)
120 
122 }
123 
127  if (m_implementation_sp) {
131  }
132  return depth;
133 }
134 
136  StructuredData::GenericSP generic_sp;
137  std::string short_help;
138 
139  if (m_implementation_sp) {
142  short_help);
143  }
144  if (!short_help.empty())
145  s->PutCString(short_help.c_str());
146  else
147  s->Printf("python class = %s", m_class_name.c_str());
148 }
149 
151 
152 lldb::BreakpointResolverSP
154  // FIXME: Have to make a copy of the arguments from the m_args_ptr and then
155  // pass that to the new resolver.
156  lldb::BreakpointResolverSP ret_sp(
158  nullptr));
159  return ret_sp;
160 }
lldb_private::StructuredData::Dictionary
Definition: StructuredData.h:352
lldb::SearchDepth
SearchDepth
Definition: lldb-enumerations.h:283
lldb_private::StructuredData::GenericSP
std::shared_ptr< Generic > GenericSP
Definition: StructuredData.h:68
lldb_private::ScriptInterpreter::ScriptedBreakpointResolverSearchDepth
virtual lldb::SearchDepth ScriptedBreakpointResolverSearchDepth(StructuredData::GenericSP implementor_sp)
Definition: ScriptInterpreter.h:301
lldb::eSearchDepthTarget
@ eSearchDepthTarget
Definition: lldb-enumerations.h:285
lldb_private::BreakpointResolverScripted::m_depth
lldb::SearchDepth m_depth
Definition: BreakpointResolverScripted.h:66
lldb_private::BreakpointResolver::OptionNames::ScriptArgs
@ ScriptArgs
lldb_private::StructuredDataImpl::GetObjectSP
StructuredData::ObjectSP GetObjectSP()
Definition: StructuredDataImpl.h:87
lldb_private::BreakpointResolver::OptionNames::PythonClassName
@ PythonClassName
Module.h
lldb_private::BreakpointResolverScripted::BreakpointResolverScripted
BreakpointResolverScripted(const lldb::BreakpointSP &bkpt, const llvm::StringRef class_name, lldb::SearchDepth depth, StructuredDataImpl *args_data)
BreakpointLocation.h
lldb_private::Stream
Definition: Stream.h:28
lldb_private::ScriptInterpreter::ScriptedBreakpointResolverSearchCallback
virtual bool ScriptedBreakpointResolverSearchCallback(StructuredData::GenericSP implementor_sp, SymbolContext *sym_ctx)
Definition: ScriptInterpreter.h:294
Debugger.h
lldb_private::SymbolContext
Definition: SymbolContext.h:33
Section.h
Process.h
Target.h
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::SearchFilter
General Outline: Provides the callback and search depth for the SearchFilter search.
Definition: SearchFilter.h:83
Log.h
lldb_private::StructuredData::ObjectSP
std::shared_ptr< Object > ObjectSP
Definition: StructuredData.h:59
StreamString.h
lldb_private::Searcher::CallbackReturn
CallbackReturn
Definition: SearchFilter.h:44
lldb_private::StructuredDataImpl
Definition: StructuredDataImpl.h:26
lldb_private::BreakpointResolverScripted::m_implementation_sp
StructuredData::GenericSP m_implementation_sp
Definition: BreakpointResolverScripted.h:71
lldb_private::StructuredData::DictionarySP
std::shared_ptr< Dictionary > DictionarySP
Definition: StructuredData.h:67
lldb_private::BreakpointResolverScripted::GetScriptInterpreter
ScriptInterpreter * GetScriptInterpreter()
Definition: BreakpointResolverScripted.cpp:104
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:38
lldb_private::StructuredDataImpl::SetObjectSP
void SetObjectSP(const StructuredData::ObjectSP &obj)
Definition: StructuredDataImpl.h:89
lldb_private::Searcher::eCallbackReturnStop
@ eCallbackReturnStop
Definition: SearchFilter.h:45
lldb_private::ScriptInterpreter::CreateScriptedBreakpointResolver
virtual StructuredData::GenericSP CreateScriptedBreakpointResolver(const char *class_name, StructuredDataImpl *args_data, lldb::BreakpointSP &bkpt_sp)
Definition: ScriptInterpreter.h:287
lldb::eSearchDepthModule
@ eSearchDepthModule
Definition: lldb-enumerations.h:286
lldb_private::BreakpointResolver
General Outline: The BreakpointResolver is a Searcher.
Definition: BreakpointResolver.h:35
lldb_private::BreakpointResolver::WrapOptionsDict
StructuredData::DictionarySP WrapOptionsDict(StructuredData::DictionarySP options_dict_sp)
Definition: BreakpointResolver.cpp:150
lldb_private::ScriptInterpreter::GetShortHelpForCommandObject
virtual bool GetShortHelpForCommandObject(StructuredData::GenericSP cmd_obj_sp, std::string &dest)
Definition: ScriptInterpreter.h:493
lldb_private::Status
Definition: Status.h:44
lldb_private::BreakpointResolverScripted::GetDescription
void GetDescription(Stream *s) override
Prints a canonical description for the breakpoint to the stream s.
Definition: BreakpointResolverScripted.cpp:135
lldb_private::Address
Definition: Address.h:59
lldb_private::BreakpointResolverScripted::SerializeToStructuredData
StructuredData::ObjectSP SerializeToStructuredData() override
Definition: BreakpointResolverScripted.cpp:91
lldb_private::BreakpointResolver::GetKey
static const char * GetKey(OptionNames enum_value)
Definition: BreakpointResolver.h:193
lldb_private::BreakpointResolverScripted::Dump
void Dump(Stream *s) const override
Standard "Dump" method. At present it does nothing.
Definition: BreakpointResolverScripted.cpp:150
lldb_private::BreakpointResolverScripted::SearchCallback
Searcher::CallbackReturn SearchCallback(SearchFilter &filter, SymbolContext &context, Address *addr) override
Definition: BreakpointResolverScripted.cpp:108
lldb_private::ScriptInterpreter
Definition: ScriptInterpreter.h:69
StructuredDataImpl.h
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:107
lldb_private::BreakpointResolverScripted::m_args_ptr
StructuredDataImpl * m_args_ptr
Definition: BreakpointResolverScripted.h:67
lldb_private::StructuredDataImpl::IsValid
bool IsValid() const
Definition: StructuredDataImpl.h:42
lldb_private::BreakpointResolverScripted::CreateFromStructuredData
static BreakpointResolver * CreateFromStructuredData(const lldb::BreakpointSP &bkpt, const StructuredData::Dictionary &options_dict, Status &error)
Definition: BreakpointResolverScripted.cpp:63
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::StructuredData::Dictionary::GetValueForKeyAsDictionary
bool GetValueForKeyAsDictionary(llvm::StringRef key, Dictionary *&result) const
Definition: StructuredData.h:467
lldb_private::BreakpointResolverScripted::m_class_name
std::string m_class_name
Definition: BreakpointResolverScripted.h:65
lldb_private::BreakpointResolverScripted::NotifyBreakpointSet
void NotifyBreakpointSet() override
Definition: BreakpointResolverScripted.cpp:58
CommandInterpreter.h
lldb_private::BreakpointResolverScripted::CreateImplementationIfNeeded
void CreateImplementationIfNeeded(lldb::BreakpointSP bkpt)
Definition: BreakpointResolverScripted.cpp:37
lldb_private::Stream::PutCString
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
lldb_private::StructuredData::Dictionary::GetValueForKeyAsString
bool GetValueForKeyAsString(llvm::StringRef key, llvm::StringRef &result) const
Definition: StructuredData.h:423
BreakpointResolverScripted.h
ScriptInterpreter.h
lldb
Definition: SBAddress.h:15
lldb_private::BreakpointResolver::GetBreakpoint
lldb::BreakpointSP GetBreakpoint() const
This gets the breakpoint for this resolver.
Definition: BreakpointResolver.h:62
lldb_private::BreakpointResolverScripted::CopyForBreakpoint
lldb::BreakpointResolverSP CopyForBreakpoint(lldb::BreakpointSP &breakpoint) override
Definition: BreakpointResolverScripted.cpp:153
lldb_private::BreakpointResolverScripted::GetDepth
lldb::SearchDepth GetDepth() override
Definition: BreakpointResolverScripted.cpp:125
lldb_private::Searcher::eCallbackReturnContinue
@ eCallbackReturnContinue
Definition: SearchFilter.h:46