From dfef1af9ef1a65c43937645aad787607e59e2f3c Mon Sep 17 00:00:00 2001 From: Gymee Date: Mon, 11 Apr 2022 09:38:05 +0800 Subject: [PATCH] support watch and conditional breakpoint Signed-off-by: Gymee Change-Id: Ibb802852d5b500f0826e8a339df6447a2a4bf00d --- runtime/include/tooling/debug_interface.h | 3 ++- runtime/tooling/debugger.cpp | 4 ++-- runtime/tooling/debugger.h | 16 ++++++++++++++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/runtime/include/tooling/debug_interface.h b/runtime/include/tooling/debug_interface.h index 59cecef5c6..810e07ce4d 100644 --- a/runtime/include/tooling/debug_interface.h +++ b/runtime/include/tooling/debug_interface.h @@ -398,7 +398,8 @@ public: * @param location Breakpoint location * @return Error if any errors occur */ - virtual std::optional SetBreakpoint(const PtLocation &location) = 0; + virtual std::optional SetBreakpoint(const PtLocation &location, + const std::optional &condition) = 0; /** * \brief Remove breakpoint from \param location diff --git a/runtime/tooling/debugger.cpp b/runtime/tooling/debugger.cpp index 2a49d29620..0a0d9836a6 100644 --- a/runtime/tooling/debugger.cpp +++ b/runtime/tooling/debugger.cpp @@ -64,7 +64,7 @@ std::optional Debugger::SetNotification(PtThread thread, bool enable, PtH return {}; } -std::optional Debugger::SetBreakpoint(const PtLocation &location) +std::optional Debugger::SetBreakpoint(const PtLocation &location, const std::optional &condition) { Method *method = runtime_->GetClassLinker()->GetMethod(location.GetPandaFile(), location.GetMethodId()); if (method == nullptr) { @@ -80,7 +80,7 @@ std::optional Debugger::SetBreakpoint(const PtLocation &location) std::to_string(method->GetCodeSize()) + ")"); } - if (!breakpoints_.emplace(method, location.GetBytecodeOffset()).second) { + if (!breakpoints_.emplace(method, location.GetBytecodeOffset(), condition).second) { return Error(Error::Type::BREAKPOINT_ALREADY_EXISTS, std::string("Breakpoint already exists: bytecode offset ") + std::to_string(location.GetBytecodeOffset())); diff --git a/runtime/tooling/debugger.h b/runtime/tooling/debugger.h index b12d9e551f..7cd0deaf69 100644 --- a/runtime/tooling/debugger.h +++ b/runtime/tooling/debugger.h @@ -41,7 +41,8 @@ namespace panda::tooling { class Breakpoint { public: // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) - Breakpoint(Method *method, uint32_t bcOffset) : method_(method), bc_offset_(bcOffset) {} + Breakpoint(Method *method, uint32_t bcOffset, const std::optional &condition = {}) + : method_(method), bc_offset_(bcOffset), condition_(condition) {} ~Breakpoint() = default; Method *GetMethod() const @@ -49,6 +50,16 @@ public: return method_; } + const std::string &GetCondition() const + { + return condition_.value(); + } + + bool HasCondition() const + { + return condition_.has_value(); + } + uint32_t GetBytecodeOffset() const { return bc_offset_; @@ -65,6 +76,7 @@ public: private: Method *method_; uint32_t bc_offset_; + std::optional condition_; }; class HashBreakpoint { @@ -160,7 +172,7 @@ public: } std::optional SetNotification(PtThread thread, bool enable, PtHookType hookType) override; - std::optional SetBreakpoint(const PtLocation &location) override; + std::optional SetBreakpoint(const PtLocation &location, const std::optional &condition) override; std::optional RemoveBreakpoint(const PtLocation &location) override; -- Gitee