Skip to content

Commit a436d40

Browse files
committed
adding breakpoints protocol types
add all breakpoint requests JSON types decouple JSON from DAP Breakpoint classes forgor exception breakpoint response migrating breakpoint requests migrate breakpoints requests handler implementations remove CreateBreakpoint data breakpoint requests serialization fix GetFrame fix data breakpoint return exception breakpoints list restore exception breakpoints add default values extract breakpoint reason type
1 parent 24db9b5 commit a436d40

28 files changed

+789
-956
lines changed

lldb/tools/lldb-dap/Breakpoint.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "lldb/API/SBLineEntry.h"
1515
#include "lldb/API/SBMutex.h"
1616
#include "llvm/ADT/StringExtras.h"
17-
#include "llvm/Support/JSON.h"
1817
#include <cstddef>
1918
#include <cstdint>
2019
#include <mutex>
@@ -30,13 +29,16 @@ void Breakpoint::SetHitCondition() {
3029
m_bp.SetIgnoreCount(hitCount - 1);
3130
}
3231

33-
void Breakpoint::CreateJsonObject(llvm::json::Object &object) {
32+
protocol::Breakpoint Breakpoint::ToProtocolBreakpoint() {
33+
protocol::Breakpoint breakpoint;
34+
3435
// Each breakpoint location is treated as a separate breakpoint for VS code.
3536
// They don't have the notion of a single breakpoint with multiple locations.
3637
if (!m_bp.IsValid())
37-
return;
38-
object.try_emplace("verified", m_bp.GetNumResolvedLocations() > 0);
39-
object.try_emplace("id", m_bp.GetID());
38+
return breakpoint;
39+
40+
breakpoint.verified = m_bp.GetNumResolvedLocations() > 0;
41+
breakpoint.id = m_bp.GetID();
4042
// VS Code DAP doesn't currently allow one breakpoint to have multiple
4143
// locations so we just report the first one. If we report all locations
4244
// then the IDE starts showing the wrong line numbers and locations for
@@ -60,16 +62,18 @@ void Breakpoint::CreateJsonObject(llvm::json::Object &object) {
6062
if (bp_addr.IsValid()) {
6163
std::string formatted_addr =
6264
"0x" + llvm::utohexstr(bp_addr.GetLoadAddress(m_bp.GetTarget()));
63-
object.try_emplace("instructionReference", formatted_addr);
65+
breakpoint.instructionReference = formatted_addr;
6466
auto line_entry = bp_addr.GetLineEntry();
6567
const auto line = line_entry.GetLine();
6668
if (line != UINT32_MAX)
67-
object.try_emplace("line", line);
69+
breakpoint.line = line;
6870
const auto column = line_entry.GetColumn();
6971
if (column != 0)
70-
object.try_emplace("column", column);
71-
object.try_emplace("source", CreateSource(line_entry));
72+
breakpoint.column = column;
73+
breakpoint.source = CreateSource(line_entry);
7274
}
75+
76+
return breakpoint;
7377
}
7478

7579
bool Breakpoint::MatchesName(const char *name) {

lldb/tools/lldb-dap/Breakpoint.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ namespace lldb_dap {
1717

1818
class Breakpoint : public BreakpointBase {
1919
public:
20-
Breakpoint(DAP &d, const llvm::json::Object &obj) : BreakpointBase(d, obj) {}
20+
Breakpoint(DAP &d, const std::optional<std::string> &condition,
21+
const std::optional<std::string> &hit_condition)
22+
: BreakpointBase(d, condition, hit_condition) {}
2123
Breakpoint(DAP &d, lldb::SBBreakpoint bp) : BreakpointBase(d), m_bp(bp) {}
2224

2325
lldb::break_id_t GetID() const { return m_bp.GetID(); }
2426

2527
void SetCondition() override;
2628
void SetHitCondition() override;
27-
void CreateJsonObject(llvm::json::Object &object) override;
29+
protocol::Breakpoint ToProtocolBreakpoint() override;
2830

2931
bool MatchesName(const char *name);
3032
void SetBreakpoint();

lldb/tools/lldb-dap/BreakpointBase.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "BreakpointBase.h"
10-
#include "JSONUtils.h"
11-
#include "llvm/ADT/StringRef.h"
1210

1311
using namespace lldb_dap;
1412

15-
BreakpointBase::BreakpointBase(DAP &d, const llvm::json::Object &obj)
16-
: m_dap(d),
17-
m_condition(std::string(GetString(obj, "condition").value_or(""))),
18-
m_hit_condition(
19-
std::string(GetString(obj, "hitCondition").value_or(""))) {}
13+
BreakpointBase::BreakpointBase(DAP &d,
14+
const std::optional<std::string> &condition,
15+
const std::optional<std::string> &hit_condition)
16+
: m_dap(d), m_condition(condition.value_or("")),
17+
m_hit_condition(hit_condition.value_or("")) {}
2018

2119
void BreakpointBase::UpdateBreakpoint(const BreakpointBase &request_bp) {
2220
if (m_condition != request_bp.m_condition) {

lldb/tools/lldb-dap/BreakpointBase.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@
1010
#define LLDB_TOOLS_LLDB_DAP_BREAKPOINTBASE_H
1111

1212
#include "DAPForward.h"
13-
#include "llvm/ADT/StringRef.h"
13+
#include "Protocol/ProtocolTypes.h"
14+
#include <optional>
1415
#include <string>
1516

1617
namespace lldb_dap {
1718

1819
class BreakpointBase {
1920
public:
2021
explicit BreakpointBase(DAP &d) : m_dap(d) {}
21-
BreakpointBase(DAP &d, const llvm::json::Object &obj);
22+
BreakpointBase(DAP &d, const std::optional<std::string> &condition,
23+
const std::optional<std::string> &hit_condition);
2224
virtual ~BreakpointBase() = default;
2325

2426
virtual void SetCondition() = 0;
2527
virtual void SetHitCondition() = 0;
26-
virtual void CreateJsonObject(llvm::json::Object &object) = 0;
28+
virtual protocol::Breakpoint ToProtocolBreakpoint() = 0;
2729

2830
void UpdateBreakpoint(const BreakpointBase &request_bp);
2931

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include <chrono>
4848
#include <condition_variable>
4949
#include <cstdarg>
50+
#include <cstdint>
5051
#include <cstdio>
5152
#include <fstream>
5253
#include <future>
@@ -552,9 +553,7 @@ lldb::SBThread DAP::GetLLDBThread(const llvm::json::Object &arguments) {
552553
return target.GetProcess().GetThreadByID(tid);
553554
}
554555

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

565+
lldb::SBFrame DAP::GetLLDBFrame(const llvm::json::Object &arguments) {
566+
const auto frame_id =
567+
GetInteger<uint64_t>(arguments, "frameId").value_or(UINT64_MAX);
568+
return GetLLDBFrame(frame_id);
569+
}
570+
566571
llvm::json::Value DAP::CreateTopLevelScopes() {
567572
llvm::json::Array scopes;
568573
scopes.emplace_back(
@@ -1602,7 +1607,7 @@ void DAP::EventThread() {
16021607
// avoids sending paths that should be source mapped. Note that
16031608
// CreateBreakpoint doesn't apply source mapping and certain
16041609
// implementation ignore the source part of this event anyway.
1605-
llvm::json::Value source_bp = CreateBreakpoint(&bp);
1610+
llvm::json::Value source_bp = bp.ToProtocolBreakpoint();
16061611
source_bp.getAsObject()->erase("source");
16071612

16081613
llvm::json::Object body;

lldb/tools/lldb-dap/DAP.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ struct DAP {
275275
lldb::SBThread GetLLDBThread(lldb::tid_t id);
276276
lldb::SBThread GetLLDBThread(const llvm::json::Object &arguments);
277277

278+
lldb::SBFrame GetLLDBFrame(uint64_t frame_id);
278279
lldb::SBFrame GetLLDBFrame(const llvm::json::Object &arguments);
279280

280281
llvm::json::Value CreateTopLevelScopes();

lldb/tools/lldb-dap/FunctionBreakpoint.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
#include "FunctionBreakpoint.h"
1010
#include "DAP.h"
11-
#include "JSONUtils.h"
1211
#include "lldb/API/SBMutex.h"
1312
#include <mutex>
1413

1514
namespace lldb_dap {
1615

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

2121
void FunctionBreakpoint::SetBreakpoint() {
2222
lldb::SBMutex lock = m_dap.GetAPIMutex();

lldb/tools/lldb-dap/FunctionBreakpoint.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111

1212
#include "Breakpoint.h"
1313
#include "DAPForward.h"
14+
#include "Protocol/ProtocolTypes.h"
1415

1516
namespace lldb_dap {
1617

1718
class FunctionBreakpoint : public Breakpoint {
1819
public:
19-
FunctionBreakpoint(DAP &dap, const llvm::json::Object &obj);
20+
FunctionBreakpoint(DAP &dap, const protocol::FunctionBreakpoint &breakpoint);
2021

2122
/// Set this breakpoint in LLDB as a new breakpoint.
2223
void SetBreakpoint();

0 commit comments

Comments
 (0)