Skip to content

Commit 3a012ac

Browse files
committed
[lldb-dap] Support persistent assembly breakpoints
1 parent 6201761 commit 3a012ac

File tree

6 files changed

+106
-4
lines changed

6 files changed

+106
-4
lines changed

lldb/tools/lldb-dap/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ add_lldb_library(lldbDAP
6666
Handler/ThreadsRequestHandler.cpp
6767
Handler/VariablesRequestHandler.cpp
6868
Handler/WriteMemoryRequestHandler.cpp
69-
69+
70+
Protocol/DAPTypes.cpp
7071
Protocol/ProtocolBase.cpp
7172
Protocol/ProtocolEvents.cpp
7273
Protocol/ProtocolTypes.cpp

lldb/tools/lldb-dap/Handler/SetBreakpointsRequestHandler.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "DAP.h"
1010
#include "Protocol/ProtocolRequests.h"
1111
#include "RequestHandler.h"
12-
#include <vector>
1312

1413
namespace lldb_dap {
1514

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "Protocol/DAPTypes.h"
2+
// #include "llvm/Support/JSON.h"
3+
4+
using namespace llvm;
5+
6+
namespace lldb_dap::protocol {
7+
8+
bool fromJSON(const llvm::json::Value &Params, AssemblyBreakpointData &ABD,
9+
llvm::json::Path P) {
10+
json::ObjectMapper O(Params, P);
11+
return O && O.mapOptional("module", ABD.module) &&
12+
O.mapOptional("symbol_mangled_name", ABD.symbol_mangled_name) &&
13+
O.mapOptional("offset", ABD.offset);
14+
}
15+
16+
llvm::json::Value toJSON(const AssemblyBreakpointData &ABD) {
17+
json::Object result{
18+
{"module", ABD.module},
19+
{"symbol_mangled_name", ABD.symbol_mangled_name},
20+
{"offset", ABD.offset},
21+
};
22+
23+
return result;
24+
}
25+
26+
bool fromJSON(const llvm::json::Value &Params, SourceLLDBData &SLD,
27+
llvm::json::Path P) {
28+
json::ObjectMapper O(Params, P);
29+
return O && O.mapOptional("assembly_breakpoint", SLD.assembly_breakpoint);
30+
}
31+
32+
llvm::json::Value toJSON(const SourceLLDBData &SLD) {
33+
json::Object result;
34+
if (SLD.assembly_breakpoint)
35+
result.insert({"assembly_breakpoint", SLD.assembly_breakpoint});
36+
return result;
37+
}
38+
39+
} // namespace lldb_dap::protocol
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//===-- ProtocolTypes.h ---------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file contains private DAP types used in the protocol.
10+
//
11+
// Each struct has a toJSON and fromJSON function, that converts between
12+
// the struct and a JSON representation. (See JSON.h)
13+
//
14+
//===----------------------------------------------------------------------===//
15+
16+
#ifndef LLDB_TOOLS_LLDB_DAP_PROTOCOL_DAP_TYPES_H
17+
#define LLDB_TOOLS_LLDB_DAP_PROTOCOL_DAP_TYPES_H
18+
19+
#include "lldb/lldb-types.h"
20+
#include "llvm/Support/JSON.h"
21+
#include <optional>
22+
#include <string>
23+
24+
namespace lldb_dap::protocol {
25+
26+
/// Data used to help lldb-dap resolve assembly breakpoints across different
27+
/// sessions.
28+
struct AssemblyBreakpointData {
29+
/// The source module path.
30+
std::string module;
31+
32+
/// The symbol unique name.
33+
std::string symbol_mangled_name;
34+
35+
/// The breakpoint offset from the symbol resolved address.
36+
lldb::addr_t offset;
37+
};
38+
bool fromJSON(const llvm::json::Value &, AssemblyBreakpointData &,
39+
llvm::json::Path);
40+
llvm::json::Value toJSON(const AssemblyBreakpointData &);
41+
42+
/// Custom source data used by lldb-dap.
43+
/// This data should help lldb-dap identify sources correctly across different
44+
/// sessions.
45+
struct SourceLLDBData {
46+
/// Assembly breakpoint data.
47+
std::optional<AssemblyBreakpointData> assembly_breakpoint;
48+
};
49+
bool fromJSON(const llvm::json::Value &, SourceLLDBData &, llvm::json::Path);
50+
llvm::json::Value toJSON(const SourceLLDBData &);
51+
52+
} // namespace lldb_dap::protocol
53+
54+
#endif

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ bool fromJSON(const json::Value &Params, Source &S, json::Path P) {
4646
json::ObjectMapper O(Params, P);
4747
return O && O.map("name", S.name) && O.map("path", S.path) &&
4848
O.map("presentationHint", S.presentationHint) &&
49-
O.map("sourceReference", S.sourceReference);
49+
O.map("sourceReference", S.sourceReference) &&
50+
O.map("adapterData", S.adapterData);
5051
}
5152

5253
llvm::json::Value toJSON(Source::PresentationHint hint) {
@@ -71,6 +72,8 @@ llvm::json::Value toJSON(const Source &S) {
7172
result.insert({"sourceReference", *S.sourceReference});
7273
if (S.presentationHint)
7374
result.insert({"presentationHint", *S.presentationHint});
75+
if (S.adapterData)
76+
result.insert({"adapterData", *S.adapterData});
7477

7578
return result;
7679
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#ifndef LLDB_TOOLS_LLDB_DAP_PROTOCOL_PROTOCOL_TYPES_H
2121
#define LLDB_TOOLS_LLDB_DAP_PROTOCOL_PROTOCOL_TYPES_H
2222

23+
#include "Protocol/DAPTypes.h"
2324
#include "lldb/lldb-defines.h"
2425
#include "llvm/ADT/DenseSet.h"
2526
#include "llvm/Support/JSON.h"
@@ -336,7 +337,12 @@ struct Source {
336337
/// skipped on stepping.
337338
std::optional<PresentationHint> presentationHint;
338339

339-
// unsupported keys: origin, sources, adapterData, checksums
340+
/// Additional data that a debug adapter might want to loop through the
341+
/// client. The client should leave the data intact and persist it across
342+
/// sessions. The client should not interpret the data.
343+
std::optional<SourceLLDBData> adapterData;
344+
345+
// unsupported keys: origin, sources, checksums
340346
};
341347
bool fromJSON(const llvm::json::Value &, Source::PresentationHint &,
342348
llvm::json::Path);

0 commit comments

Comments
 (0)