Skip to content

[lldb-dap] Protect SetBreakpoint with the API mutex #134030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lldb/tools/lldb-dap/Breakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
//===----------------------------------------------------------------------===//

#include "Breakpoint.h"
#include "DAP.h"
#include "JSONUtils.h"
#include "lldb/API/SBAddress.h"
#include "lldb/API/SBBreakpointLocation.h"
#include "lldb/API/SBLineEntry.h"
#include "lldb/API/SBMutex.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/JSON.h"
#include <cstddef>
#include <cstdint>
#include <mutex>
#include <string>

using namespace lldb_dap;
Expand Down Expand Up @@ -74,6 +77,9 @@ bool Breakpoint::MatchesName(const char *name) {
}

void Breakpoint::SetBreakpoint() {
lldb::SBMutex lock = m_dap.GetAPIMutex();
std::lock_guard<lldb::SBMutex> guard(lock);

m_bp.AddName(kDAPBreakpointLabel);
if (!m_condition.empty())
SetCondition();
Expand Down
3 changes: 3 additions & 0 deletions lldb/tools/lldb-dap/DAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "lldb/API/SBFile.h"
#include "lldb/API/SBFormat.h"
#include "lldb/API/SBFrame.h"
#include "lldb/API/SBMutex.h"
#include "lldb/API/SBTarget.h"
#include "lldb/API/SBThread.h"
#include "lldb/API/SBValue.h"
Expand Down Expand Up @@ -404,6 +405,8 @@ struct DAP {
InstructionBreakpoint *GetInstructionBreakpoint(const lldb::break_id_t bp_id);

InstructionBreakpoint *GetInstructionBPFromStopReason(lldb::SBThread &thread);

lldb::SBMutex GetAPIMutex() const { return target.GetAPIMutex(); }
};

} // namespace lldb_dap
Expand Down
5 changes: 5 additions & 0 deletions lldb/tools/lldb-dap/ExceptionBreakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@
#include "ExceptionBreakpoint.h"
#include "BreakpointBase.h"
#include "DAP.h"
#include "lldb/API/SBMutex.h"
#include "lldb/API/SBTarget.h"
#include <mutex>

namespace lldb_dap {

void ExceptionBreakpoint::SetBreakpoint() {
lldb::SBMutex lock = m_dap.GetAPIMutex();
std::lock_guard<lldb::SBMutex> guard(lock);

if (m_bp.IsValid())
return;
bool catch_value = m_filter.find("_catch") != std::string::npos;
Expand Down
5 changes: 5 additions & 0 deletions lldb/tools/lldb-dap/FunctionBreakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "FunctionBreakpoint.h"
#include "DAP.h"
#include "JSONUtils.h"
#include "lldb/API/SBMutex.h"
#include <mutex>

namespace lldb_dap {

Expand All @@ -17,6 +19,9 @@ FunctionBreakpoint::FunctionBreakpoint(DAP &d, const llvm::json::Object &obj)
m_function_name(std::string(GetString(obj, "name").value_or(""))) {}

void FunctionBreakpoint::SetBreakpoint() {
lldb::SBMutex lock = m_dap.GetAPIMutex();
std::lock_guard<lldb::SBMutex> guard(lock);

if (m_function_name.empty())
return;
m_bp = m_dap.target.BreakpointCreateByName(m_function_name.c_str());
Expand Down
5 changes: 5 additions & 0 deletions lldb/tools/lldb-dap/SourceBreakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
#include "lldb/API/SBBreakpoint.h"
#include "lldb/API/SBFileSpecList.h"
#include "lldb/API/SBFrame.h"
#include "lldb/API/SBMutex.h"
#include "lldb/API/SBTarget.h"
#include "lldb/API/SBThread.h"
#include "lldb/API/SBValue.h"
#include "lldb/lldb-enumerations.h"
#include <cassert>
#include <cctype>
#include <cstdlib>
#include <mutex>
#include <utility>

namespace lldb_dap {
Expand All @@ -33,6 +35,9 @@ SourceBreakpoint::SourceBreakpoint(DAP &dap, const llvm::json::Object &obj)
.value_or(LLDB_INVALID_COLUMN_NUMBER)) {}

void SourceBreakpoint::SetBreakpoint(const llvm::StringRef source_path) {
lldb::SBMutex lock = m_dap.GetAPIMutex();
std::lock_guard<lldb::SBMutex> guard(lock);

lldb::SBFileSpecList module_list;
m_bp = m_dap.target.BreakpointCreateByLocation(
source_path.str().c_str(), m_line, m_column, 0, module_list);
Expand Down