Skip to content
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
22 changes: 13 additions & 9 deletions lldb/tools/lldb-dap/Breakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#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>
Expand All @@ -30,13 +29,16 @@ void Breakpoint::SetHitCondition() {
m_bp.SetIgnoreCount(hitCount - 1);
}

void Breakpoint::CreateJsonObject(llvm::json::Object &object) {
protocol::Breakpoint Breakpoint::ToProtocolBreakpoint() {
protocol::Breakpoint breakpoint;

// 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 (!m_bp.IsValid())
return;
object.try_emplace("verified", m_bp.GetNumResolvedLocations() > 0);
object.try_emplace("id", m_bp.GetID());
return breakpoint;

breakpoint.verified = m_bp.GetNumResolvedLocations() > 0;
breakpoint.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
Expand All @@ -60,16 +62,18 @@ void Breakpoint::CreateJsonObject(llvm::json::Object &object) {
if (bp_addr.IsValid()) {
std::string formatted_addr =
"0x" + llvm::utohexstr(bp_addr.GetLoadAddress(m_bp.GetTarget()));
object.try_emplace("instructionReference", formatted_addr);
breakpoint.instructionReference = formatted_addr;
auto line_entry = bp_addr.GetLineEntry();
const auto line = line_entry.GetLine();
if (line != UINT32_MAX)
object.try_emplace("line", line);
breakpoint.line = line;
const auto column = line_entry.GetColumn();
if (column != 0)
object.try_emplace("column", column);
object.try_emplace("source", CreateSource(line_entry));
breakpoint.column = column;
breakpoint.source = CreateSource(line_entry);
}

return breakpoint;
}

bool Breakpoint::MatchesName(const char *name) {
Expand Down
6 changes: 4 additions & 2 deletions lldb/tools/lldb-dap/Breakpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ namespace lldb_dap {

class Breakpoint : public BreakpointBase {
public:
Breakpoint(DAP &d, const llvm::json::Object &obj) : BreakpointBase(d, obj) {}
Breakpoint(DAP &d, const std::optional<std::string> &condition,
const std::optional<std::string> &hit_condition)
: BreakpointBase(d, condition, hit_condition) {}
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;
void CreateJsonObject(llvm::json::Object &object) override;
protocol::Breakpoint ToProtocolBreakpoint() override;

bool MatchesName(const char *name);
void SetBreakpoint();
Expand Down
12 changes: 5 additions & 7 deletions lldb/tools/lldb-dap/BreakpointBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@
//===----------------------------------------------------------------------===//

#include "BreakpointBase.h"
#include "JSONUtils.h"
#include "llvm/ADT/StringRef.h"

using namespace lldb_dap;

BreakpointBase::BreakpointBase(DAP &d, const llvm::json::Object &obj)
: m_dap(d),
m_condition(std::string(GetString(obj, "condition").value_or(""))),
m_hit_condition(
std::string(GetString(obj, "hitCondition").value_or(""))) {}
BreakpointBase::BreakpointBase(DAP &d,
const std::optional<std::string> &condition,
const std::optional<std::string> &hit_condition)
: m_dap(d), m_condition(condition.value_or("")),
m_hit_condition(hit_condition.value_or("")) {}

void BreakpointBase::UpdateBreakpoint(const BreakpointBase &request_bp) {
if (m_condition != request_bp.m_condition) {
Expand Down
8 changes: 5 additions & 3 deletions lldb/tools/lldb-dap/BreakpointBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@
#define LLDB_TOOLS_LLDB_DAP_BREAKPOINTBASE_H

#include "DAPForward.h"
#include "llvm/ADT/StringRef.h"
#include "Protocol/ProtocolTypes.h"
#include <optional>
#include <string>

namespace lldb_dap {

class BreakpointBase {
public:
explicit BreakpointBase(DAP &d) : m_dap(d) {}
BreakpointBase(DAP &d, const llvm::json::Object &obj);
BreakpointBase(DAP &d, const std::optional<std::string> &condition,
const std::optional<std::string> &hit_condition);
virtual ~BreakpointBase() = default;

virtual void SetCondition() = 0;
virtual void SetHitCondition() = 0;
virtual void CreateJsonObject(llvm::json::Object &object) = 0;
virtual protocol::Breakpoint ToProtocolBreakpoint() = 0;

void UpdateBreakpoint(const BreakpointBase &request_bp);

Expand Down
13 changes: 9 additions & 4 deletions lldb/tools/lldb-dap/DAP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <chrono>
#include <condition_variable>
#include <cstdarg>
#include <cstdint>
#include <cstdio>
#include <fstream>
#include <future>
Expand Down Expand Up @@ -552,9 +553,7 @@ lldb::SBThread DAP::GetLLDBThread(const llvm::json::Object &arguments) {
return target.GetProcess().GetThreadByID(tid);
}

lldb::SBFrame DAP::GetLLDBFrame(const llvm::json::Object &arguments) {
const uint64_t frame_id =
GetInteger<uint64_t>(arguments, "frameId").value_or(UINT64_MAX);
lldb::SBFrame DAP::GetLLDBFrame(uint64_t frame_id) {
lldb::SBProcess process = target.GetProcess();
// Upper 32 bits is the thread index ID
lldb::SBThread thread =
Expand All @@ -563,6 +562,12 @@ lldb::SBFrame DAP::GetLLDBFrame(const llvm::json::Object &arguments) {
return thread.GetFrameAtIndex(GetLLDBFrameID(frame_id));
}

lldb::SBFrame DAP::GetLLDBFrame(const llvm::json::Object &arguments) {
const auto frame_id =
GetInteger<uint64_t>(arguments, "frameId").value_or(UINT64_MAX);
return GetLLDBFrame(frame_id);
}

llvm::json::Value DAP::CreateTopLevelScopes() {
llvm::json::Array scopes;
scopes.emplace_back(
Expand Down Expand Up @@ -1602,7 +1607,7 @@ void DAP::EventThread() {
// avoids sending paths that should be source mapped. Note that
// CreateBreakpoint doesn't apply source mapping and certain
// implementation ignore the source part of this event anyway.
llvm::json::Value source_bp = CreateBreakpoint(&bp);
llvm::json::Value source_bp = bp.ToProtocolBreakpoint();
source_bp.getAsObject()->erase("source");

llvm::json::Object body;
Expand Down
1 change: 1 addition & 0 deletions lldb/tools/lldb-dap/DAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ struct DAP {
lldb::SBThread GetLLDBThread(lldb::tid_t id);
lldb::SBThread GetLLDBThread(const llvm::json::Object &arguments);

lldb::SBFrame GetLLDBFrame(uint64_t frame_id);
lldb::SBFrame GetLLDBFrame(const llvm::json::Object &arguments);

llvm::json::Value CreateTopLevelScopes();
Expand Down
8 changes: 4 additions & 4 deletions lldb/tools/lldb-dap/FunctionBreakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

#include "FunctionBreakpoint.h"
#include "DAP.h"
#include "JSONUtils.h"
#include "lldb/API/SBMutex.h"
#include <mutex>

namespace lldb_dap {

FunctionBreakpoint::FunctionBreakpoint(DAP &d, const llvm::json::Object &obj)
: Breakpoint(d, obj),
m_function_name(std::string(GetString(obj, "name").value_or(""))) {}
FunctionBreakpoint::FunctionBreakpoint(
DAP &d, const protocol::FunctionBreakpoint &breakpoint)
: Breakpoint(d, breakpoint.condition, breakpoint.hitCondition),
m_function_name(breakpoint.name) {}

void FunctionBreakpoint::SetBreakpoint() {
lldb::SBMutex lock = m_dap.GetAPIMutex();
Expand Down
3 changes: 2 additions & 1 deletion lldb/tools/lldb-dap/FunctionBreakpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@

#include "Breakpoint.h"
#include "DAPForward.h"
#include "Protocol/ProtocolTypes.h"

namespace lldb_dap {

class FunctionBreakpoint : public Breakpoint {
public:
FunctionBreakpoint(DAP &dap, const llvm::json::Object &obj);
FunctionBreakpoint(DAP &dap, const protocol::FunctionBreakpoint &breakpoint);

/// Set this breakpoint in LLDB as a new breakpoint.
void SetBreakpoint();
Expand Down
Loading
Loading