2018-09-14 05:59:16 +08:00
|
|
|
//===-- BreakpointResolverScripted.cpp ---------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-09-14 05:59:16 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Breakpoint/BreakpointResolverScripted.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "lldb/Breakpoint/BreakpointLocation.h"
|
|
|
|
#include "lldb/Core/Debugger.h"
|
|
|
|
#include "lldb/Core/Module.h"
|
|
|
|
#include "lldb/Core/Section.h"
|
|
|
|
#include "lldb/Core/StructuredDataImpl.h"
|
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
|
|
|
#include "lldb/Interpreter/ScriptInterpreter.h"
|
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Target/Target.h"
|
|
|
|
#include "lldb/Utility/Log.h"
|
|
|
|
#include "lldb/Utility/StreamString.h"
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
// BreakpointResolverScripted:
|
|
|
|
BreakpointResolverScripted::BreakpointResolverScripted(
|
|
|
|
Breakpoint *bkpt,
|
|
|
|
const llvm::StringRef class_name,
|
|
|
|
lldb::SearchDepth depth,
|
2019-10-11 01:44:50 +08:00
|
|
|
StructuredDataImpl *args_data)
|
2018-09-14 05:59:16 +08:00
|
|
|
: BreakpointResolver(bkpt, BreakpointResolver::PythonResolver),
|
|
|
|
m_class_name(class_name), m_depth(depth), m_args_ptr(args_data) {
|
|
|
|
CreateImplementationIfNeeded();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointResolverScripted::CreateImplementationIfNeeded() {
|
|
|
|
if (m_implementation_sp)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (m_class_name.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (m_breakpoint) {
|
|
|
|
TargetSP target_sp = m_breakpoint->GetTargetSP();
|
|
|
|
ScriptInterpreter *script_interp = target_sp->GetDebugger()
|
|
|
|
.GetScriptInterpreter();
|
|
|
|
if (!script_interp)
|
|
|
|
return;
|
|
|
|
lldb::BreakpointSP bkpt_sp(m_breakpoint->shared_from_this());
|
|
|
|
m_implementation_sp = script_interp->CreateScriptedBreakpointResolver(
|
|
|
|
m_class_name.c_str(), m_args_ptr, bkpt_sp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointResolverScripted::NotifyBreakpointSet() {
|
|
|
|
CreateImplementationIfNeeded();
|
|
|
|
}
|
|
|
|
|
|
|
|
BreakpointResolverScripted::~BreakpointResolverScripted() {}
|
|
|
|
|
|
|
|
BreakpointResolver *
|
|
|
|
BreakpointResolverScripted::CreateFromStructuredData(
|
|
|
|
Breakpoint *bkpt, const StructuredData::Dictionary &options_dict,
|
|
|
|
Status &error) {
|
|
|
|
llvm::StringRef class_name;
|
|
|
|
bool success;
|
|
|
|
|
|
|
|
success = options_dict.GetValueForKeyAsString(
|
|
|
|
GetKey(OptionNames::PythonClassName), class_name);
|
|
|
|
if (!success) {
|
|
|
|
error.SetErrorString("BRFL::CFSD: Couldn't find class name entry.");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-10-11 01:44:50 +08:00
|
|
|
// The Python function will actually provide the search depth, this is a
|
|
|
|
// placeholder.
|
|
|
|
lldb::SearchDepth depth = lldb::eSearchDepthTarget;
|
2018-09-14 05:59:16 +08:00
|
|
|
|
|
|
|
StructuredDataImpl *args_data_impl = new StructuredDataImpl();
|
2019-10-08 23:56:02 +08:00
|
|
|
StructuredData::Dictionary *args_dict = nullptr;
|
2018-09-14 05:59:16 +08:00
|
|
|
success = options_dict.GetValueForKeyAsDictionary(
|
|
|
|
GetKey(OptionNames::ScriptArgs), args_dict);
|
|
|
|
if (success) {
|
2019-10-11 01:44:50 +08:00
|
|
|
args_data_impl->SetObjectSP(args_dict->shared_from_this());
|
2018-09-14 05:59:16 +08:00
|
|
|
}
|
2019-10-11 01:44:50 +08:00
|
|
|
return new BreakpointResolverScripted(bkpt, class_name, depth,
|
|
|
|
args_data_impl);
|
2018-09-14 05:59:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
StructuredData::ObjectSP
|
|
|
|
BreakpointResolverScripted::SerializeToStructuredData() {
|
|
|
|
StructuredData::DictionarySP options_dict_sp(
|
|
|
|
new StructuredData::Dictionary());
|
|
|
|
|
|
|
|
options_dict_sp->AddStringItem(GetKey(OptionNames::PythonClassName),
|
|
|
|
m_class_name);
|
2019-10-11 01:44:50 +08:00
|
|
|
if (m_args_ptr->IsValid())
|
|
|
|
options_dict_sp->AddItem(GetKey(OptionNames::ScriptArgs),
|
|
|
|
m_args_ptr->GetObjectSP());
|
|
|
|
|
2018-09-14 05:59:16 +08:00
|
|
|
return WrapOptionsDict(options_dict_sp);
|
|
|
|
}
|
|
|
|
|
|
|
|
ScriptInterpreter *BreakpointResolverScripted::GetScriptInterpreter() {
|
2019-04-27 06:43:16 +08:00
|
|
|
return m_breakpoint->GetTarget().GetDebugger().GetScriptInterpreter();
|
2018-09-14 05:59:16 +08:00
|
|
|
}
|
|
|
|
|
2019-10-10 19:26:51 +08:00
|
|
|
Searcher::CallbackReturn BreakpointResolverScripted::SearchCallback(
|
|
|
|
SearchFilter &filter, SymbolContext &context, Address *addr) {
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
assert(m_breakpoint != nullptr);
|
2018-09-14 05:59:16 +08:00
|
|
|
bool should_continue = true;
|
|
|
|
if (!m_implementation_sp)
|
|
|
|
return Searcher::eCallbackReturnStop;
|
|
|
|
|
|
|
|
ScriptInterpreter *interp = GetScriptInterpreter();
|
|
|
|
should_continue = interp->ScriptedBreakpointResolverSearchCallback(
|
|
|
|
m_implementation_sp,
|
|
|
|
&context);
|
|
|
|
if (should_continue)
|
|
|
|
return Searcher::eCallbackReturnContinue;
|
|
|
|
else
|
|
|
|
return Searcher::eCallbackReturnStop;
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::SearchDepth
|
|
|
|
BreakpointResolverScripted::GetDepth() {
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
assert(m_breakpoint != nullptr);
|
2018-09-14 05:59:16 +08:00
|
|
|
lldb::SearchDepth depth = lldb::eSearchDepthModule;
|
|
|
|
if (m_implementation_sp) {
|
|
|
|
ScriptInterpreter *interp = GetScriptInterpreter();
|
|
|
|
depth = interp->ScriptedBreakpointResolverSearchDepth(
|
|
|
|
m_implementation_sp);
|
|
|
|
}
|
|
|
|
return depth;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointResolverScripted::GetDescription(Stream *s) {
|
|
|
|
StructuredData::GenericSP generic_sp;
|
|
|
|
std::string short_help;
|
|
|
|
|
|
|
|
if (m_implementation_sp) {
|
|
|
|
ScriptInterpreter *interp = GetScriptInterpreter();
|
|
|
|
interp->GetShortHelpForCommandObject(m_implementation_sp,
|
|
|
|
short_help);
|
|
|
|
}
|
|
|
|
if (!short_help.empty())
|
|
|
|
s->PutCString(short_help.c_str());
|
|
|
|
else
|
|
|
|
s->Printf("python class = %s", m_class_name.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointResolverScripted::Dump(Stream *s) const {}
|
|
|
|
|
|
|
|
lldb::BreakpointResolverSP
|
|
|
|
BreakpointResolverScripted::CopyForBreakpoint(Breakpoint &breakpoint) {
|
|
|
|
// FIXME: Have to make a copy of the arguments from the m_args_ptr and then
|
|
|
|
// pass that to the new resolver.
|
|
|
|
lldb::BreakpointResolverSP ret_sp(
|
2019-10-11 01:44:50 +08:00
|
|
|
new BreakpointResolverScripted(&breakpoint, m_class_name, m_depth,
|
|
|
|
nullptr));
|
2018-09-14 05:59:16 +08:00
|
|
|
return ret_sp;
|
|
|
|
}
|