[Lldb-commits] [lldb] [lldb] Convert Breakpoint & Watchpoints structs to classes (NFC) (PR #133780)
Jonas Devlieghere via lldb-commits
lldb-commits at lists.llvm.org
Mon Mar 31 11:55:50 PDT 2025
https://github.com/JDevlieghere created https://github.com/llvm/llvm-project/pull/133780
Convert Breakpoint & Watchpoints structs to classes to provide proper access control. This is in preparation for adopting SBMutex to protect the underlying SBBreakpoint and SBWatchpoint.
>From 2f22b24840ec0f3cb650da97ad0bd2caea0a8cef Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <jonas at devlieghere.com>
Date: Mon, 31 Mar 2025 11:47:02 -0700
Subject: [PATCH] [lldb] Convert Breakpoint & Watchpoints structs to classes
(NFC)
Convert Breakpoint & Watchpoints structs to classes to provide proper
access control. This is in preparation for adopting SBMutex to protect
the underlying SBBreakpoint and SBWatchpoint.
---
lldb/tools/lldb-dap/Breakpoint.cpp | 24 +++++----
lldb/tools/lldb-dap/Breakpoint.h | 14 +++--
lldb/tools/lldb-dap/BreakpointBase.h | 23 ++++----
lldb/tools/lldb-dap/DAP.cpp | 8 +--
lldb/tools/lldb-dap/DAP.h | 2 +-
lldb/tools/lldb-dap/DAPForward.h | 16 +++---
lldb/tools/lldb-dap/ExceptionBreakpoint.cpp | 18 +++----
lldb/tools/lldb-dap/ExceptionBreakpoint.h | 28 ++++++----
lldb/tools/lldb-dap/FunctionBreakpoint.cpp | 6 +--
lldb/tools/lldb-dap/FunctionBreakpoint.h | 12 +++--
.../Handler/ExceptionInfoRequestHandler.cpp | 4 +-
.../Handler/SetBreakpointsRequestHandler.cpp | 7 +--
.../SetDataBreakpointsRequestHandler.cpp | 4 +-
.../SetExceptionBreakpointsRequestHandler.cpp | 4 +-
.../SetFunctionBreakpointsRequestHandler.cpp | 8 +--
...etInstructionBreakpointsRequestHandler.cpp | 6 +--
lldb/tools/lldb-dap/InstructionBreakpoint.cpp | 11 ++--
lldb/tools/lldb-dap/InstructionBreakpoint.h | 19 ++++---
lldb/tools/lldb-dap/JSONUtils.cpp | 8 +--
lldb/tools/lldb-dap/SourceBreakpoint.cpp | 6 +--
lldb/tools/lldb-dap/SourceBreakpoint.h | 52 ++++++++++---------
lldb/tools/lldb-dap/Watchpoint.cpp | 21 ++++----
lldb/tools/lldb-dap/Watchpoint.h | 22 ++++----
23 files changed, 180 insertions(+), 143 deletions(-)
diff --git a/lldb/tools/lldb-dap/Breakpoint.cpp b/lldb/tools/lldb-dap/Breakpoint.cpp
index eba534dcc51c7..188a51909f111 100644
--- a/lldb/tools/lldb-dap/Breakpoint.cpp
+++ b/lldb/tools/lldb-dap/Breakpoint.cpp
@@ -19,21 +19,21 @@
using namespace lldb_dap;
-void Breakpoint::SetCondition() { bp.SetCondition(condition.c_str()); }
+void Breakpoint::SetCondition() { m_bp.SetCondition(condition.c_str()); }
void Breakpoint::SetHitCondition() {
uint64_t hitCount = 0;
if (llvm::to_integer(hitCondition, hitCount))
- bp.SetIgnoreCount(hitCount - 1);
+ m_bp.SetIgnoreCount(hitCount - 1);
}
void Breakpoint::CreateJsonObject(llvm::json::Object &object) {
// Each breakpoint location is treated as a separate breakpoint for VS code.
// They don't have the notion of a single breakpoint with multiple locations.
- if (!bp.IsValid())
+ if (!m_bp.IsValid())
return;
- object.try_emplace("verified", bp.GetNumResolvedLocations() > 0);
- object.try_emplace("id", bp.GetID());
+ object.try_emplace("verified", m_bp.GetNumResolvedLocations() > 0);
+ object.try_emplace("id", m_bp.GetID());
// VS Code DAP doesn't currently allow one breakpoint to have multiple
// locations so we just report the first one. If we report all locations
// then the IDE starts showing the wrong line numbers and locations for
@@ -43,20 +43,20 @@ void Breakpoint::CreateJsonObject(llvm::json::Object &object) {
// this as the breakpoint location since it will have a complete location
// that is at least loaded in the current process.
lldb::SBBreakpointLocation bp_loc;
- const auto num_locs = bp.GetNumLocations();
+ const auto num_locs = m_bp.GetNumLocations();
for (size_t i = 0; i < num_locs; ++i) {
- bp_loc = bp.GetLocationAtIndex(i);
+ bp_loc = m_bp.GetLocationAtIndex(i);
if (bp_loc.IsResolved())
break;
}
// If not locations are resolved, use the first location.
if (!bp_loc.IsResolved())
- bp_loc = bp.GetLocationAtIndex(0);
+ bp_loc = m_bp.GetLocationAtIndex(0);
auto bp_addr = bp_loc.GetAddress();
if (bp_addr.IsValid()) {
std::string formatted_addr =
- "0x" + llvm::utohexstr(bp_addr.GetLoadAddress(bp.GetTarget()));
+ "0x" + llvm::utohexstr(bp_addr.GetLoadAddress(m_bp.GetTarget()));
object.try_emplace("instructionReference", formatted_addr);
auto line_entry = bp_addr.GetLineEntry();
const auto line = line_entry.GetLine();
@@ -69,10 +69,12 @@ void Breakpoint::CreateJsonObject(llvm::json::Object &object) {
}
}
-bool Breakpoint::MatchesName(const char *name) { return bp.MatchesName(name); }
+bool Breakpoint::MatchesName(const char *name) {
+ return m_bp.MatchesName(name);
+}
void Breakpoint::SetBreakpoint() {
- bp.AddName(kDAPBreakpointLabel);
+ m_bp.AddName(kDAPBreakpointLabel);
if (!condition.empty())
SetCondition();
if (!hitCondition.empty())
diff --git a/lldb/tools/lldb-dap/Breakpoint.h b/lldb/tools/lldb-dap/Breakpoint.h
index a726f27e59ee0..580017125af44 100644
--- a/lldb/tools/lldb-dap/Breakpoint.h
+++ b/lldb/tools/lldb-dap/Breakpoint.h
@@ -15,12 +15,12 @@
namespace lldb_dap {
-struct Breakpoint : public BreakpointBase {
- // The LLDB breakpoint associated wit this source breakpoint
- lldb::SBBreakpoint bp;
-
+class Breakpoint : public BreakpointBase {
+public:
Breakpoint(DAP &d, const llvm::json::Object &obj) : BreakpointBase(d, obj) {}
- Breakpoint(DAP &d, lldb::SBBreakpoint bp) : BreakpointBase(d), bp(bp) {}
+ Breakpoint(DAP &d, lldb::SBBreakpoint bp) : BreakpointBase(d), m_bp(bp) {}
+
+ lldb::break_id_t GetID() const { return m_bp.GetID(); }
void SetCondition() override;
void SetHitCondition() override;
@@ -28,6 +28,10 @@ struct Breakpoint : public BreakpointBase {
bool MatchesName(const char *name);
void SetBreakpoint();
+
+protected:
+ /// The LLDB breakpoint associated wit this source breakpoint.
+ lldb::SBBreakpoint m_bp;
};
} // namespace lldb_dap
diff --git a/lldb/tools/lldb-dap/BreakpointBase.h b/lldb/tools/lldb-dap/BreakpointBase.h
index 0b036dd1985b3..07133dc44828b 100644
--- a/lldb/tools/lldb-dap/BreakpointBase.h
+++ b/lldb/tools/lldb-dap/BreakpointBase.h
@@ -15,16 +15,8 @@
namespace lldb_dap {
-struct BreakpointBase {
- // Associated DAP session.
- DAP &dap;
-
- // An optional expression for conditional breakpoints.
- std::string condition;
- // An optional expression that controls how many hits of the breakpoint are
- // ignored. The backend is expected to interpret the expression as needed
- std::string hitCondition;
-
+class BreakpointBase {
+public:
explicit BreakpointBase(DAP &d) : dap(d) {}
BreakpointBase(DAP &d, const llvm::json::Object &obj);
virtual ~BreakpointBase() = default;
@@ -49,6 +41,17 @@ struct BreakpointBase {
/// breakpoint in one of the DAP breakpoints that we should report changes
/// for.
static constexpr const char *kDAPBreakpointLabel = "dap";
+
+protected:
+ /// Associated DAP session.
+ DAP &dap;
+
+ /// An optional expression for conditional breakpoints.
+ std::string condition;
+
+ /// An optional expression that controls how many hits of the breakpoint are
+ /// ignored. The backend is expected to interpret the expression as needed
+ std::string hitCondition;
};
} // namespace lldb_dap
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index 512cabdf77880..8951384212f11 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -162,7 +162,7 @@ void DAP::PopulateExceptionBreakpoints() {
});
}
-ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const std::string &filter) {
+ExceptionBreakpoint *DAP::GetExceptionBreakpoint(llvm::StringRef filter) {
// PopulateExceptionBreakpoints() is called after g_dap.debugger is created
// in a request-initialize.
//
@@ -181,7 +181,7 @@ ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const std::string &filter) {
PopulateExceptionBreakpoints();
for (auto &bp : *exception_breakpoints) {
- if (bp.filter == filter)
+ if (bp.GetFilter() == filter)
return &bp;
}
return nullptr;
@@ -192,7 +192,7 @@ ExceptionBreakpoint *DAP::GetExceptionBreakpoint(const lldb::break_id_t bp_id) {
PopulateExceptionBreakpoints();
for (auto &bp : *exception_breakpoints) {
- if (bp.bp.GetID() == bp_id)
+ if (bp.GetID() == bp_id)
return &bp;
}
return nullptr;
@@ -1066,7 +1066,7 @@ void DAP::SetThreadFormat(llvm::StringRef format) {
InstructionBreakpoint *
DAP::GetInstructionBreakpoint(const lldb::break_id_t bp_id) {
for (auto &bp : instruction_breakpoints) {
- if (bp.second.bp.GetID() == bp_id)
+ if (bp.second.GetID() == bp_id)
return &bp.second;
}
return nullptr;
diff --git a/lldb/tools/lldb-dap/DAP.h b/lldb/tools/lldb-dap/DAP.h
index 6689980806047..4357bdd5cc80f 100644
--- a/lldb/tools/lldb-dap/DAP.h
+++ b/lldb/tools/lldb-dap/DAP.h
@@ -236,7 +236,7 @@ struct DAP {
void operator=(const DAP &rhs) = delete;
/// @}
- ExceptionBreakpoint *GetExceptionBreakpoint(const std::string &filter);
+ ExceptionBreakpoint *GetExceptionBreakpoint(llvm::StringRef filter);
ExceptionBreakpoint *GetExceptionBreakpoint(const lldb::break_id_t bp_id);
/// Redirect stdout and stderr fo the IDE's console output.
diff --git a/lldb/tools/lldb-dap/DAPForward.h b/lldb/tools/lldb-dap/DAPForward.h
index 58e034ed1cc77..6620d5fd33642 100644
--- a/lldb/tools/lldb-dap/DAPForward.h
+++ b/lldb/tools/lldb-dap/DAPForward.h
@@ -12,16 +12,16 @@
// IWYU pragma: begin_exports
namespace lldb_dap {
-struct BreakpointBase;
-struct ExceptionBreakpoint;
-struct FunctionBreakpoint;
-struct SourceBreakpoint;
-struct Watchpoint;
-struct InstructionBreakpoint;
-struct DAP;
-class Log;
class BaseRequestHandler;
+class BreakpointBase;
+class ExceptionBreakpoint;
+class FunctionBreakpoint;
+class InstructionBreakpoint;
+class Log;
class ResponseHandler;
+class SourceBreakpoint;
+class Watchpoint;
+struct DAP;
} // namespace lldb_dap
namespace lldb {
diff --git a/lldb/tools/lldb-dap/ExceptionBreakpoint.cpp b/lldb/tools/lldb-dap/ExceptionBreakpoint.cpp
index 15aee55ad923e..d8109daf89129 100644
--- a/lldb/tools/lldb-dap/ExceptionBreakpoint.cpp
+++ b/lldb/tools/lldb-dap/ExceptionBreakpoint.cpp
@@ -14,20 +14,20 @@
namespace lldb_dap {
void ExceptionBreakpoint::SetBreakpoint() {
- if (bp.IsValid())
+ if (m_bp.IsValid())
return;
- bool catch_value = filter.find("_catch") != std::string::npos;
- bool throw_value = filter.find("_throw") != std::string::npos;
- bp = dap.target.BreakpointCreateForException(language, catch_value,
- throw_value);
- bp.AddName(BreakpointBase::kDAPBreakpointLabel);
+ bool catch_value = m_filter.find("_catch") != std::string::npos;
+ bool throw_value = m_filter.find("_throw") != std::string::npos;
+ m_bp = m_dap.target.BreakpointCreateForException(m_language, catch_value,
+ throw_value);
+ m_bp.AddName(BreakpointBase::kDAPBreakpointLabel);
}
void ExceptionBreakpoint::ClearBreakpoint() {
- if (!bp.IsValid())
+ if (!m_bp.IsValid())
return;
- dap.target.BreakpointDelete(bp.GetID());
- bp = lldb::SBBreakpoint();
+ m_dap.target.BreakpointDelete(m_bp.GetID());
+ m_bp = lldb::SBBreakpoint();
}
} // namespace lldb_dap
diff --git a/lldb/tools/lldb-dap/ExceptionBreakpoint.h b/lldb/tools/lldb-dap/ExceptionBreakpoint.h
index b83c5ef777352..49a338fdbc6ee 100644
--- a/lldb/tools/lldb-dap/ExceptionBreakpoint.h
+++ b/lldb/tools/lldb-dap/ExceptionBreakpoint.h
@@ -12,25 +12,35 @@
#include "DAPForward.h"
#include "lldb/API/SBBreakpoint.h"
#include "lldb/lldb-enumerations.h"
+#include "llvm/ADT/StringRef.h"
#include <string>
#include <utility>
namespace lldb_dap {
-struct ExceptionBreakpoint {
- DAP &dap;
- std::string filter;
- std::string label;
- lldb::LanguageType language;
- bool default_value = false;
- lldb::SBBreakpoint bp;
+class ExceptionBreakpoint {
+public:
ExceptionBreakpoint(DAP &d, std::string f, std::string l,
lldb::LanguageType lang)
- : dap(d), filter(std::move(f)), label(std::move(l)), language(lang),
- bp() {}
+ : m_dap(d), m_filter(std::move(f)), m_label(std::move(l)),
+ m_language(lang), m_bp() {}
void SetBreakpoint();
void ClearBreakpoint();
+ void CreateJsonObject(llvm::json::Object &object);
+
+ lldb::break_id_t GetID() const { return m_bp.GetID(); }
+ llvm::StringRef GetFilter() const { return m_filter; }
+ llvm::StringRef GetLabel() const { return m_label; }
+
+ static constexpr bool kDefaultValue = false;
+
+protected:
+ DAP &m_dap;
+ std::string m_filter;
+ std::string m_label;
+ lldb::LanguageType m_language;
+ lldb::SBBreakpoint m_bp;
};
} // namespace lldb_dap
diff --git a/lldb/tools/lldb-dap/FunctionBreakpoint.cpp b/lldb/tools/lldb-dap/FunctionBreakpoint.cpp
index cafae32b662f2..6a4fff4a50f94 100644
--- a/lldb/tools/lldb-dap/FunctionBreakpoint.cpp
+++ b/lldb/tools/lldb-dap/FunctionBreakpoint.cpp
@@ -14,12 +14,12 @@ namespace lldb_dap {
FunctionBreakpoint::FunctionBreakpoint(DAP &d, const llvm::json::Object &obj)
: Breakpoint(d, obj),
- functionName(std::string(GetString(obj, "name").value_or(""))) {}
+ m_function_name(std::string(GetString(obj, "name").value_or(""))) {}
void FunctionBreakpoint::SetBreakpoint() {
- if (functionName.empty())
+ if (m_function_name.empty())
return;
- bp = dap.target.BreakpointCreateByName(functionName.c_str());
+ m_bp = dap.target.BreakpointCreateByName(m_function_name.c_str());
Breakpoint::SetBreakpoint();
}
diff --git a/lldb/tools/lldb-dap/FunctionBreakpoint.h b/lldb/tools/lldb-dap/FunctionBreakpoint.h
index 93f0b93b35291..7100360cd7ec1 100644
--- a/lldb/tools/lldb-dap/FunctionBreakpoint.h
+++ b/lldb/tools/lldb-dap/FunctionBreakpoint.h
@@ -14,13 +14,17 @@
namespace lldb_dap {
-struct FunctionBreakpoint : public Breakpoint {
- std::string functionName;
-
+class FunctionBreakpoint : public Breakpoint {
+public:
FunctionBreakpoint(DAP &dap, const llvm::json::Object &obj);
- // Set this breakpoint in LLDB as a new breakpoint
+ /// Set this breakpoint in LLDB as a new breakpoint.
void SetBreakpoint();
+
+ llvm::StringRef GetFunctionName() const { return m_function_name; }
+
+protected:
+ std::string m_function_name;
};
} // namespace lldb_dap
diff --git a/lldb/tools/lldb-dap/Handler/ExceptionInfoRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/ExceptionInfoRequestHandler.cpp
index 2f4d4efd1b189..924ea63ed1593 100644
--- a/lldb/tools/lldb-dap/Handler/ExceptionInfoRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/ExceptionInfoRequestHandler.cpp
@@ -125,8 +125,8 @@ void ExceptionInfoRequestHandler::operator()(
else if (stopReason == lldb::eStopReasonBreakpoint) {
ExceptionBreakpoint *exc_bp = dap.GetExceptionBPFromStopReason(thread);
if (exc_bp) {
- EmplaceSafeString(body, "exceptionId", exc_bp->filter);
- EmplaceSafeString(body, "description", exc_bp->label);
+ EmplaceSafeString(body, "exceptionId", exc_bp->GetFilter());
+ EmplaceSafeString(body, "description", exc_bp->GetLabel());
} else {
body.try_emplace("exceptionId", "exception");
}
diff --git a/lldb/tools/lldb-dap/Handler/SetBreakpointsRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/SetBreakpointsRequestHandler.cpp
index 5ca2c9c01965e..dc0368852101f 100644
--- a/lldb/tools/lldb-dap/Handler/SetBreakpointsRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/SetBreakpointsRequestHandler.cpp
@@ -143,7 +143,8 @@ void SetBreakpointsRequestHandler::operator()(
const auto *bp_obj = bp.getAsObject();
if (bp_obj) {
SourceBreakpoint src_bp(dap, *bp_obj);
- std::pair<uint32_t, uint32_t> bp_pos(src_bp.line, src_bp.column);
+ std::pair<uint32_t, uint32_t> bp_pos(src_bp.GetLine(),
+ src_bp.GetColumn());
request_bps.try_emplace(bp_pos, src_bp);
const auto [iv, inserted] =
dap.source_breakpoints[path].try_emplace(bp_pos, src_bp);
@@ -153,7 +154,7 @@ void SetBreakpointsRequestHandler::operator()(
else
iv->getSecond().UpdateBreakpoint(src_bp);
AppendBreakpoint(&iv->getSecond(), response_breakpoints, path,
- src_bp.line);
+ src_bp.GetLine());
}
}
}
@@ -167,7 +168,7 @@ void SetBreakpointsRequestHandler::operator()(
auto request_pos = request_bps.find(old_bp.first);
if (request_pos == request_bps.end()) {
// This breakpoint no longer exists in this source file, delete it
- dap.target.BreakpointDelete(old_bp.second.bp.GetID());
+ dap.target.BreakpointDelete(old_bp.second.GetID());
old_src_bp_pos->second.erase(old_bp.first);
}
}
diff --git a/lldb/tools/lldb-dap/Handler/SetDataBreakpointsRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/SetDataBreakpointsRequestHandler.cpp
index 87310131255e1..365c9f0d722d4 100644
--- a/lldb/tools/lldb-dap/Handler/SetDataBreakpointsRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/SetDataBreakpointsRequestHandler.cpp
@@ -97,9 +97,9 @@ void SetDataBreakpointsRequestHandler::operator()(
// backward.
std::set<lldb::addr_t> addresses;
for (auto iter = watchpoints.rbegin(); iter != watchpoints.rend(); ++iter) {
- if (addresses.count(iter->addr) == 0) {
+ if (addresses.count(iter->GetAddress()) == 0) {
iter->SetWatchpoint();
- addresses.insert(iter->addr);
+ addresses.insert(iter->GetAddress());
}
}
for (auto wp : watchpoints)
diff --git a/lldb/tools/lldb-dap/Handler/SetExceptionBreakpointsRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/SetExceptionBreakpointsRequestHandler.cpp
index 8be5d870a070f..09d4fea2a9a22 100644
--- a/lldb/tools/lldb-dap/Handler/SetExceptionBreakpointsRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/SetExceptionBreakpointsRequestHandler.cpp
@@ -70,9 +70,9 @@ void SetExceptionBreakpointsRequestHandler::operator()(
const auto *filters = arguments->getArray("filters");
// Keep a list of any exception breakpoint filter names that weren't set
// so we can clear any exception breakpoints if needed.
- std::set<std::string> unset_filters;
+ std::set<llvm::StringRef> unset_filters;
for (const auto &bp : *dap.exception_breakpoints)
- unset_filters.insert(bp.filter);
+ unset_filters.insert(bp.GetFilter());
for (const auto &value : *filters) {
const auto filter = GetAsString(value);
diff --git a/lldb/tools/lldb-dap/Handler/SetFunctionBreakpointsRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/SetFunctionBreakpointsRequestHandler.cpp
index 945df68936bac..c45dc0d0d6553 100644
--- a/lldb/tools/lldb-dap/Handler/SetFunctionBreakpointsRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/SetFunctionBreakpointsRequestHandler.cpp
@@ -110,15 +110,15 @@ void SetFunctionBreakpointsRequestHandler::operator()(
if (!bp_obj)
continue;
FunctionBreakpoint fn_bp(dap, *bp_obj);
- const auto [it, inserted] =
- dap.function_breakpoints.try_emplace(fn_bp.functionName, dap, *bp_obj);
+ const auto [it, inserted] = dap.function_breakpoints.try_emplace(
+ fn_bp.GetFunctionName(), dap, *bp_obj);
if (inserted)
it->second.SetBreakpoint();
else
it->second.UpdateBreakpoint(fn_bp);
AppendBreakpoint(&it->second, response_breakpoints);
- seen.erase(fn_bp.functionName);
+ seen.erase(fn_bp.GetFunctionName());
}
// Remove any breakpoints that are no longer in our list
@@ -126,7 +126,7 @@ void SetFunctionBreakpointsRequestHandler::operator()(
auto fn_bp = dap.function_breakpoints.find(name);
if (fn_bp == dap.function_breakpoints.end())
continue;
- dap.target.BreakpointDelete(fn_bp->second.bp.GetID());
+ dap.target.BreakpointDelete(fn_bp->second.GetID());
dap.function_breakpoints.erase(name);
}
diff --git a/lldb/tools/lldb-dap/Handler/SetInstructionBreakpointsRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/SetInstructionBreakpointsRequestHandler.cpp
index b1e47942de8e6..4e555ad605a26 100644
--- a/lldb/tools/lldb-dap/Handler/SetInstructionBreakpointsRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/SetInstructionBreakpointsRequestHandler.cpp
@@ -223,20 +223,20 @@ void SetInstructionBreakpointsRequestHandler::operator()(
// Read instruction breakpoint request.
InstructionBreakpoint inst_bp(dap, *bp_obj);
const auto [iv, inserted] = dap.instruction_breakpoints.try_emplace(
- inst_bp.instructionAddressReference, dap, *bp_obj);
+ inst_bp.GetInstructionAddressReference(), dap, *bp_obj);
if (inserted)
iv->second.SetBreakpoint();
else
iv->second.UpdateBreakpoint(inst_bp);
AppendBreakpoint(&iv->second, response_breakpoints);
- seen.erase(inst_bp.instructionAddressReference);
+ seen.erase(inst_bp.GetInstructionAddressReference());
}
for (const auto &addr : seen) {
auto inst_bp = dap.instruction_breakpoints.find(addr);
if (inst_bp == dap.instruction_breakpoints.end())
continue;
- dap.target.BreakpointDelete(inst_bp->second.bp.GetID());
+ dap.target.BreakpointDelete(inst_bp->second.GetID());
dap.instruction_breakpoints.erase(addr);
}
diff --git a/lldb/tools/lldb-dap/InstructionBreakpoint.cpp b/lldb/tools/lldb-dap/InstructionBreakpoint.cpp
index 710787625ec58..265da61e513c1 100644
--- a/lldb/tools/lldb-dap/InstructionBreakpoint.cpp
+++ b/lldb/tools/lldb-dap/InstructionBreakpoint.cpp
@@ -16,19 +16,18 @@
namespace lldb_dap {
-// Instruction Breakpoint
InstructionBreakpoint::InstructionBreakpoint(DAP &d,
const llvm::json::Object &obj)
- : Breakpoint(d, obj), instructionAddressReference(LLDB_INVALID_ADDRESS),
- offset(GetInteger<int64_t>(obj, "offset").value_or(0)) {
+ : Breakpoint(d, obj), m_instruction_address_reference(LLDB_INVALID_ADDRESS),
+ m_offset(GetInteger<int64_t>(obj, "offset").value_or(0)) {
GetString(obj, "instructionReference")
.value_or("")
- .getAsInteger(0, instructionAddressReference);
- instructionAddressReference += offset;
+ .getAsInteger(0, m_instruction_address_reference);
+ m_instruction_address_reference += m_offset;
}
void InstructionBreakpoint::SetBreakpoint() {
- bp = dap.target.BreakpointCreateByAddress(instructionAddressReference);
+ m_bp = dap.target.BreakpointCreateByAddress(m_instruction_address_reference);
Breakpoint::SetBreakpoint();
}
diff --git a/lldb/tools/lldb-dap/InstructionBreakpoint.h b/lldb/tools/lldb-dap/InstructionBreakpoint.h
index b2e66a9db9e20..6ed980e00d038 100644
--- a/lldb/tools/lldb-dap/InstructionBreakpoint.h
+++ b/lldb/tools/lldb-dap/InstructionBreakpoint.h
@@ -17,16 +17,21 @@
namespace lldb_dap {
-// Instruction Breakpoint
-struct InstructionBreakpoint : public Breakpoint {
-
- lldb::addr_t instructionAddressReference;
- int32_t offset;
-
+/// Instruction Breakpoint
+class InstructionBreakpoint : public Breakpoint {
+public:
InstructionBreakpoint(DAP &d, const llvm::json::Object &obj);
- // Set instruction breakpoint in LLDB as a new breakpoint
+ /// Set instruction breakpoint in LLDB as a new breakpoint.
void SetBreakpoint();
+
+ lldb::addr_t GetInstructionAddressReference() const {
+ return m_instruction_address_reference;
+ }
+
+protected:
+ lldb::addr_t m_instruction_address_reference;
+ int32_t m_offset;
};
} // namespace lldb_dap
diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp b/lldb/tools/lldb-dap/JSONUtils.cpp
index 9773b91a35a45..590137e48199d 100644
--- a/lldb/tools/lldb-dap/JSONUtils.cpp
+++ b/lldb/tools/lldb-dap/JSONUtils.cpp
@@ -560,9 +560,9 @@ llvm::json::Object CreateEventObject(const llvm::StringRef event_name) {
protocol::ExceptionBreakpointsFilter
CreateExceptionBreakpointFilter(const ExceptionBreakpoint &bp) {
protocol::ExceptionBreakpointsFilter filter;
- filter.filter = bp.filter;
- filter.label = bp.label;
- filter.defaultState = bp.default_value;
+ filter.filter = bp.GetFilter();
+ filter.label = bp.GetLabel();
+ filter.defaultState = ExceptionBreakpoint::kDefaultValue;
return filter;
}
@@ -940,7 +940,7 @@ llvm::json::Value CreateThreadStopped(DAP &dap, lldb::SBThread &thread,
ExceptionBreakpoint *exc_bp = dap.GetExceptionBPFromStopReason(thread);
if (exc_bp) {
body.try_emplace("reason", "exception");
- EmplaceSafeString(body, "description", exc_bp->label);
+ EmplaceSafeString(body, "description", exc_bp->GetLabel());
} else {
InstructionBreakpoint *inst_bp =
dap.GetInstructionBPFromStopReason(thread);
diff --git a/lldb/tools/lldb-dap/SourceBreakpoint.cpp b/lldb/tools/lldb-dap/SourceBreakpoint.cpp
index 4c6b36119c84f..53a0557df8958 100644
--- a/lldb/tools/lldb-dap/SourceBreakpoint.cpp
+++ b/lldb/tools/lldb-dap/SourceBreakpoint.cpp
@@ -34,8 +34,8 @@ SourceBreakpoint::SourceBreakpoint(DAP &dap, const llvm::json::Object &obj)
void SourceBreakpoint::SetBreakpoint(const llvm::StringRef source_path) {
lldb::SBFileSpecList module_list;
- bp = dap.target.BreakpointCreateByLocation(source_path.str().c_str(), line,
- column, 0, module_list);
+ m_bp = dap.target.BreakpointCreateByLocation(source_path.str().c_str(), line,
+ column, 0, module_list);
if (!logMessage.empty())
SetLogMessage();
Breakpoint::SetBreakpoint();
@@ -288,7 +288,7 @@ void SourceBreakpoint::SetLogMessage() {
}
}
- bp.SetCallback(BreakpointHitCallback, this);
+ m_bp.SetCallback(BreakpointHitCallback, this);
}
void SourceBreakpoint::NotifyLogMessageError(llvm::StringRef error) {
diff --git a/lldb/tools/lldb-dap/SourceBreakpoint.h b/lldb/tools/lldb-dap/SourceBreakpoint.h
index 064bd29d9fc79..f9b9cf27fd91a 100644
--- a/lldb/tools/lldb-dap/SourceBreakpoint.h
+++ b/lldb/tools/lldb-dap/SourceBreakpoint.h
@@ -19,23 +19,8 @@
namespace lldb_dap {
-struct SourceBreakpoint : public Breakpoint {
- // logMessage part can be either a raw text or an expression.
- struct LogMessagePart {
- LogMessagePart(llvm::StringRef text, bool is_expr)
- : text(text), is_expr(is_expr) {}
- std::string text;
- bool is_expr;
- };
- // If this attribute exists and is non-empty, the backend must not 'break'
- // (stop) but log the message instead. Expressions within {} are
- // interpolated.
- std::string logMessage;
- std::vector<LogMessagePart> logMessageParts;
-
- uint32_t line; ///< The source line of the breakpoint or logpoint
- uint32_t column; ///< An optional source column of the breakpoint
-
+class SourceBreakpoint : public Breakpoint {
+public:
SourceBreakpoint(DAP &d, const llvm::json::Object &obj);
// Set this breakpoint in LLDB as a new breakpoint
@@ -52,14 +37,33 @@ struct SourceBreakpoint : public Breakpoint {
static bool BreakpointHitCallback(void *baton, lldb::SBProcess &process,
lldb::SBThread &thread,
lldb::SBBreakpointLocation &location);
-};
-inline bool operator<(const SourceBreakpoint &lhs,
- const SourceBreakpoint &rhs) {
- if (lhs.line == rhs.line)
- return lhs.column < rhs.column;
- return lhs.line < rhs.line;
-}
+ inline bool operator<(const SourceBreakpoint &rhs) {
+ if (line == rhs.line)
+ return column < rhs.column;
+ return line < rhs.line;
+ }
+
+ uint32_t GetLine() const { return line; }
+ uint32_t GetColumn() const { return column; }
+
+protected:
+ // logMessage part can be either a raw text or an expression.
+ struct LogMessagePart {
+ LogMessagePart(llvm::StringRef text, bool is_expr)
+ : text(text), is_expr(is_expr) {}
+ std::string text;
+ bool is_expr;
+ };
+ // If this attribute exists and is non-empty, the backend must not 'break'
+ // (stop) but log the message instead. Expressions within {} are
+ // interpolated.
+ std::string logMessage;
+ std::vector<LogMessagePart> logMessageParts;
+
+ uint32_t line; ///< The source line of the breakpoint or logpoint
+ uint32_t column; ///< An optional source column of the breakpoint
+};
} // namespace lldb_dap
diff --git a/lldb/tools/lldb-dap/Watchpoint.cpp b/lldb/tools/lldb-dap/Watchpoint.cpp
index 8681057c8d3f2..cce1c887320c9 100644
--- a/lldb/tools/lldb-dap/Watchpoint.cpp
+++ b/lldb/tools/lldb-dap/Watchpoint.cpp
@@ -23,33 +23,34 @@ Watchpoint::Watchpoint(DAP &d, const llvm::json::Object &obj)
llvm::StringRef dataId = GetString(obj, "dataId").value_or("");
std::string accessType = GetString(obj, "accessType").value_or("").str();
auto [addr_str, size_str] = dataId.split('/');
- llvm::to_integer(addr_str, addr, 16);
- llvm::to_integer(size_str, size);
- options.SetWatchpointTypeRead(accessType != "write");
+ llvm::to_integer(addr_str, m_addr, 16);
+ llvm::to_integer(size_str, m_size);
+ m_options.SetWatchpointTypeRead(accessType != "write");
if (accessType != "read")
- options.SetWatchpointTypeWrite(lldb::eWatchpointWriteTypeOnModify);
+ m_options.SetWatchpointTypeWrite(lldb::eWatchpointWriteTypeOnModify);
}
-void Watchpoint::SetCondition() { wp.SetCondition(condition.c_str()); }
+void Watchpoint::SetCondition() { m_wp.SetCondition(condition.c_str()); }
void Watchpoint::SetHitCondition() {
uint64_t hitCount = 0;
if (llvm::to_integer(hitCondition, hitCount))
- wp.SetIgnoreCount(hitCount - 1);
+ m_wp.SetIgnoreCount(hitCount - 1);
}
void Watchpoint::CreateJsonObject(llvm::json::Object &object) {
- if (!error.IsValid() || error.Fail()) {
+ if (!m_error.IsValid() || m_error.Fail()) {
object.try_emplace("verified", false);
- if (error.Fail())
- EmplaceSafeString(object, "message", error.GetCString());
+ if (m_error.Fail())
+ EmplaceSafeString(object, "message", m_error.GetCString());
} else {
object.try_emplace("verified", true);
}
}
void Watchpoint::SetWatchpoint() {
- wp = dap.target.WatchpointCreateByAddress(addr, size, options, error);
+ m_wp =
+ dap.target.WatchpointCreateByAddress(m_addr, m_size, m_options, m_error);
if (!condition.empty())
SetCondition();
if (!hitCondition.empty())
diff --git a/lldb/tools/lldb-dap/Watchpoint.h b/lldb/tools/lldb-dap/Watchpoint.h
index 77cea67bb9781..bf52b41281f29 100644
--- a/lldb/tools/lldb-dap/Watchpoint.h
+++ b/lldb/tools/lldb-dap/Watchpoint.h
@@ -19,22 +19,26 @@
namespace lldb_dap {
-struct Watchpoint : public BreakpointBase {
- lldb::addr_t addr;
- size_t size;
- lldb::SBWatchpointOptions options;
- // The LLDB breakpoint associated wit this watchpoint.
- lldb::SBWatchpoint wp;
- lldb::SBError error;
-
+class Watchpoint : public BreakpointBase {
+public:
Watchpoint(DAP &d, const llvm::json::Object &obj);
- Watchpoint(DAP &d, lldb::SBWatchpoint wp) : BreakpointBase(d), wp(wp) {}
+ Watchpoint(DAP &d, lldb::SBWatchpoint wp) : BreakpointBase(d), m_wp(wp) {}
void SetCondition() override;
void SetHitCondition() override;
void CreateJsonObject(llvm::json::Object &object) override;
void SetWatchpoint();
+
+ lldb::addr_t GetAddress() const { return m_addr; }
+
+protected:
+ lldb::addr_t m_addr;
+ size_t m_size;
+ lldb::SBWatchpointOptions m_options;
+ /// The LLDB breakpoint associated wit this watchpoint.
+ lldb::SBWatchpoint m_wp;
+ lldb::SBError m_error;
};
} // namespace lldb_dap
More information about the lldb-commits
mailing list