Skip to content

Commit aeb9f46

Browse files
committed
decouple JSON from DAP Breakpoint classes
1 parent fd473c7 commit aeb9f46

File tree

11 files changed

+55
-48
lines changed

11 files changed

+55
-48
lines changed

lldb/tools/lldb-dap/Breakpoint.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ 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(); }

lldb/tools/lldb-dap/BreakpointBase.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
using namespace lldb_dap;
1414

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(""))) {}
15+
BreakpointBase::BreakpointBase(DAP &d,
16+
const std::optional<std::string> &condition,
17+
const std::optional<std::string> &hit_condition)
18+
: m_dap(d), m_condition(condition.value_or("")),
19+
m_hit_condition(hit_condition.value_or("")) {}
2020

2121
void BreakpointBase::UpdateBreakpoint(const BreakpointBase &request_bp) {
2222
if (m_condition != request_bp.m_condition) {

lldb/tools/lldb-dap/BreakpointBase.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ namespace lldb_dap {
1818
class BreakpointBase {
1919
public:
2020
explicit BreakpointBase(DAP &d) : m_dap(d) {}
21-
BreakpointBase(DAP &d, const llvm::json::Object &obj);
21+
BreakpointBase(DAP &d, const std::optional<std::string> &condition,
22+
const std::optional<std::string> &hit_condition);
2223
virtual ~BreakpointBase() = default;
2324

2425
virtual void SetCondition() = 0;

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();

lldb/tools/lldb-dap/InstructionBreakpoint.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@
99

1010
#include "InstructionBreakpoint.h"
1111
#include "DAP.h"
12-
#include "JSONUtils.h"
1312
#include "lldb/API/SBBreakpoint.h"
1413
#include "lldb/API/SBTarget.h"
1514
#include "llvm/ADT/StringRef.h"
1615

1716
namespace lldb_dap {
1817

19-
InstructionBreakpoint::InstructionBreakpoint(DAP &d,
20-
const llvm::json::Object &obj)
21-
: Breakpoint(d, obj), m_instruction_address_reference(LLDB_INVALID_ADDRESS),
22-
m_offset(GetInteger<int64_t>(obj, "offset").value_or(0)) {
23-
GetString(obj, "instructionReference")
24-
.value_or("")
25-
.getAsInteger(0, m_instruction_address_reference);
18+
InstructionBreakpoint::InstructionBreakpoint(
19+
DAP &d, const protocol::InstructionBreakpoint &breakpoint)
20+
: Breakpoint(d, breakpoint.condition, breakpoint.hitCondition),
21+
m_instruction_address_reference(LLDB_INVALID_ADDRESS),
22+
m_offset(breakpoint.offset.value_or(0)) {
23+
llvm::StringRef instruction_reference(breakpoint.instructionReference);
24+
instruction_reference.getAsInteger(0, m_instruction_address_reference);
2625
m_instruction_address_reference += m_offset;
2726
}
2827

lldb/tools/lldb-dap/InstructionBreakpoint.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "Breakpoint.h"
1414
#include "DAPForward.h"
15+
#include "Protocol/ProtocolTypes.h"
1516
#include "lldb/lldb-types.h"
1617
#include <cstdint>
1718

@@ -20,7 +21,8 @@ namespace lldb_dap {
2021
/// Instruction Breakpoint
2122
class InstructionBreakpoint : public Breakpoint {
2223
public:
23-
InstructionBreakpoint(DAP &d, const llvm::json::Object &obj);
24+
InstructionBreakpoint(DAP &d,
25+
const protocol::InstructionBreakpoint &breakpoint);
2426

2527
/// Set instruction breakpoint in LLDB as a new breakpoint.
2628
void SetBreakpoint();

lldb/tools/lldb-dap/Protocol/ProtocolRequests.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,9 @@ bool fromJSON(const llvm::json::Value &, SetBreakpointsArguments &,
398398

399399
/// Response to `setBreakpoints` request.
400400
/// Returned is information about each breakpoint created by this request.
401-
/// This includes the actual code location and whether the breakpoint could be verified.
402-
/// The breakpoints returned are in the same order as the elements of the breakpoints
403-
/// (or the deprecated lines) array in the arguments.
401+
/// This includes the actual code location and whether the breakpoint could be
402+
/// verified. The breakpoints returned are in the same order as the elements of
403+
/// the breakpoints (or the deprecated lines) array in the arguments.
404404
struct SetBreakpointsResponseBody {
405405
/// Information about the breakpoints.
406406
/// The array elements are in the same order as the elements of the

lldb/tools/lldb-dap/Protocol/ProtocolTypes.h

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,9 @@ enum SteppingGranularity : unsigned {
322322
bool fromJSON(const llvm::json::Value &, SteppingGranularity &,
323323
llvm::json::Path);
324324

325-
/// Information about a breakpoint created in `setBreakpoints`, `setFunctionBreakpoints`, `setInstructionBreakpoints`, or `setDataBreakpoints` requests.
325+
/// Information about a breakpoint created in `setBreakpoints`,
326+
/// `setFunctionBreakpoints`, `setInstructionBreakpoints`, or
327+
/// `setDataBreakpoints` requests.
326328
struct Breakpoint {
327329
/// A machine-readable explanation of why a breakpoint may not be verified.
328330
enum class Reason : unsigned {
@@ -343,8 +345,8 @@ struct Breakpoint {
343345
bool verified;
344346

345347
/// A message about the state of the breakpoint.
346-
/// This is shown to the user and can be used to explain why a breakpoint could
347-
/// not be verified.
348+
/// This is shown to the user and can be used to explain why a breakpoint
349+
/// could not be verified.
348350
std::optional<std::string> message;
349351

350352
/// The source where the breakpoint is located.
@@ -362,18 +364,17 @@ struct Breakpoint {
362364
std::optional<uint32_t> endLine;
363365

364366
/// End position of the source range covered by the breakpoint. It is measured
365-
/// in UTF-16 code units and the client capability `columnsStartAt1` determines
366-
/// whether it is 0- or 1-based.
367-
/// If no end line is given, then the end column is assumed to be in the start
368-
/// line.
367+
/// in UTF-16 code units and the client capability `columnsStartAt1`
368+
/// determines whether it is 0- or 1-based. If no end line is given, then the
369+
/// end column is assumed to be in the start line.
369370
std::optional<uint32_t> endColumn;
370371

371372
/// A memory reference to where the breakpoint is set.
372373
std::optional<std::string> instructionReference;
373374

374375
/// The offset from the instruction reference.
375376
/// This can be negative.
376-
std::optional<int64_t> offset;
377+
std::optional<int32_t> offset;
377378

378379
/// A machine-readable explanation of why a breakpoint may not be verified. If
379380
/// a breakpoint is verified or a specific reason is not known, the adapter
@@ -382,7 +383,8 @@ struct Breakpoint {
382383
};
383384
llvm::json::Value toJSON(const Breakpoint &);
384385

385-
/// Properties of a breakpoint or logpoint passed to the `setBreakpoints` request
386+
/// Properties of a breakpoint or logpoint passed to the `setBreakpoints`
387+
/// request
386388
struct SourceBreakpoint {
387389
/// The source line of the breakpoint or logpoint.
388390
uint32_t line;
@@ -419,8 +421,7 @@ struct SourceBreakpoint {
419421
/// `breakpointModes` the debug adapter advertised in its `Capabilities`.
420422
std::optional<std::string> mode;
421423
};
422-
bool fromJSON(const llvm::json::Value &, SourceBreakpoint &,
423-
llvm::json::Path);
424+
bool fromJSON(const llvm::json::Value &, SourceBreakpoint &, llvm::json::Path);
424425

425426
/// Properties of a breakpoint passed to the `setFunctionBreakpoints` request.
426427
struct FunctionBreakpoint {
@@ -441,7 +442,8 @@ struct FunctionBreakpoint {
441442
bool fromJSON(const llvm::json::Value &, FunctionBreakpoint &,
442443
llvm::json::Path);
443444

444-
/// This enumeration defines all possible access types for data breakpoints. Values: ‘read’, ‘write’, ‘readWrite’
445+
/// This enumeration defines all possible access types for data breakpoints.
446+
/// Values: ‘read’, ‘write’, ‘readWrite’
445447
enum DataBreakpointAccessType : unsigned {
446448
eDataBreakpointAccessTypeRead,
447449
eDataBreakpointAccessTypeWrite,
@@ -479,7 +481,7 @@ struct InstructionBreakpoint {
479481

480482
/// The offset from the instruction reference in bytes.
481483
/// This can be negative.
482-
std::optional<int64_t> offset;
484+
std::optional<int32_t> offset;
483485

484486
/// An expression for conditional breakpoints.
485487
/// It is only honored by a debug adapter if the corresponding capability
@@ -499,7 +501,8 @@ struct InstructionBreakpoint {
499501
bool fromJSON(const llvm::json::Value &, InstructionBreakpoint &,
500502
llvm::json::Path);
501503

502-
/// An ExceptionFilterOptions is used to specify an exception filter together with a condition for the `setExceptionBreakpoints` request.
504+
/// An ExceptionFilterOptions is used to specify an exception filter together
505+
/// with a condition for the `setExceptionBreakpoints` request.
503506
struct ExceptionFilterOptions {
504507
/// ID of an exception filter returned by the `exceptionBreakpointFilters`
505508
/// capability.
@@ -557,8 +560,7 @@ struct ExceptionOptions {
557560
/// Condition when a thrown exception should result in a break.
558561
ExceptionBreakMode breakMode;
559562
};
560-
bool fromJSON(const llvm::json::Value &, ExceptionOptions &,
561-
llvm::json::Path);
563+
bool fromJSON(const llvm::json::Value &, ExceptionOptions &, llvm::json::Path);
562564

563565
} // namespace lldb_dap::protocol
564566

lldb/tools/lldb-dap/SourceBreakpoint.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@
2626

2727
namespace lldb_dap {
2828

29-
SourceBreakpoint::SourceBreakpoint(DAP &dap, const llvm::json::Object &obj)
30-
: Breakpoint(dap, obj),
31-
m_log_message(GetString(obj, "logMessage").value_or("").str()),
32-
m_line(
33-
GetInteger<uint64_t>(obj, "line").value_or(LLDB_INVALID_LINE_NUMBER)),
34-
m_column(GetInteger<uint64_t>(obj, "column")
35-
.value_or(LLDB_INVALID_COLUMN_NUMBER)) {}
29+
SourceBreakpoint::SourceBreakpoint(DAP &dap,
30+
const protocol::SourceBreakpoint &breakpoint)
31+
: Breakpoint(dap, breakpoint.condition, breakpoint.hitCondition),
32+
m_log_message(breakpoint.logMessage.value_or("")),
33+
m_line(breakpoint.line),
34+
m_column(breakpoint.column.value_or(LLDB_INVALID_COLUMN_NUMBER)) {}
3635

3736
void SourceBreakpoint::SetBreakpoint(const llvm::StringRef source_path) {
3837
lldb::SBMutex lock = m_dap.GetAPIMutex();

0 commit comments

Comments
 (0)