Skip to content

Commit f2212c5

Browse files
committed
remove offset
1 parent dd069cd commit f2212c5

File tree

4 files changed

+75
-56
lines changed

4 files changed

+75
-56
lines changed

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@ using namespace llvm;
55

66
namespace lldb_dap::protocol {
77

8-
bool fromJSON(const llvm::json::Value &Params, AssemblyBreakpointData &ABD,
8+
bool fromJSON(const llvm::json::Value &Params, PersistenceData &PD,
99
llvm::json::Path P) {
1010
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);
11+
return O && O.mapOptional("module", PD.module) &&
12+
O.mapOptional("symbol_mangled_name", PD.symbol_mangled_name);
1413
}
1514

16-
llvm::json::Value toJSON(const AssemblyBreakpointData &ABD) {
15+
llvm::json::Value toJSON(const PersistenceData &PD) {
1716
json::Object result{
18-
{"module", ABD.module},
19-
{"symbol_mangled_name", ABD.symbol_mangled_name},
20-
{"offset", ABD.offset},
17+
{"module", PD.module},
18+
{"symbol_mangled_name", PD.symbol_mangled_name},
2119
};
2220

2321
return result;
@@ -26,13 +24,13 @@ llvm::json::Value toJSON(const AssemblyBreakpointData &ABD) {
2624
bool fromJSON(const llvm::json::Value &Params, SourceLLDBData &SLD,
2725
llvm::json::Path P) {
2826
json::ObjectMapper O(Params, P);
29-
return O && O.mapOptional("assembly_breakpoint", SLD.assembly_breakpoint);
27+
return O && O.mapOptional("persistence_data", SLD.persistence_data);
3028
}
3129

3230
llvm::json::Value toJSON(const SourceLLDBData &SLD) {
3331
json::Object result;
34-
if (SLD.assembly_breakpoint)
35-
result.insert({"assembly_breakpoint", SLD.assembly_breakpoint});
32+
if (SLD.persistence_data)
33+
result.insert({"persistence_data", SLD.persistence_data});
3634
return result;
3735
}
3836

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,27 @@
2323

2424
namespace lldb_dap::protocol {
2525

26-
/// Data used to help lldb-dap resolve assembly breakpoints across different
27-
/// sessions.
28-
struct AssemblyBreakpointData {
26+
/// Data used to help lldb-dap resolve breakpoints persistently across different sessions.
27+
/// This information is especially useful for assembly breakpoints, because `sourceReference`
28+
/// can change across sessions. For regular source breakpoints the path and line are the same
29+
/// For each session.
30+
struct PersistenceData {
2931
/// The source module path.
3032
std::string module;
3133

3234
/// The symbol unique name.
3335
std::string symbol_mangled_name;
34-
35-
/// The breakpoint offset from the symbol resolved address.
36-
lldb::addr_t offset;
3736
};
38-
bool fromJSON(const llvm::json::Value &, AssemblyBreakpointData &,
37+
bool fromJSON(const llvm::json::Value &, PersistenceData &,
3938
llvm::json::Path);
40-
llvm::json::Value toJSON(const AssemblyBreakpointData &);
39+
llvm::json::Value toJSON(const PersistenceData &);
4140

4241
/// Custom source data used by lldb-dap.
4342
/// This data should help lldb-dap identify sources correctly across different
4443
/// sessions.
4544
struct SourceLLDBData {
46-
/// Assembly breakpoint data.
47-
std::optional<AssemblyBreakpointData> assembly_breakpoint;
45+
/// Data that helps lldb resolve this source persistently across different sessions.
46+
std::optional<PersistenceData> persistence_data;
4847
};
4948
bool fromJSON(const llvm::json::Value &, SourceLLDBData &, llvm::json::Path);
5049
llvm::json::Value toJSON(const SourceLLDBData &);

lldb/tools/lldb-dap/SourceBreakpoint.cpp

Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -47,41 +47,17 @@ llvm::Error SourceBreakpoint::SetBreakpoint(const protocol::Source &source) {
4747

4848
if (IsAssemblySource(source)) {
4949
// Breakpoint set by assembly source.
50-
std::optional<lldb::addr_t> raw_addr =
51-
m_dap.GetSourceReferenceAddress(*source.sourceReference);
52-
if (!raw_addr)
53-
return llvm::createStringError(llvm::inconvertibleErrorCode(),
54-
"Invalid sourceReference.");
55-
56-
lldb::SBAddress source_address(*raw_addr, m_dap.target);
57-
if (!source_address.IsValid())
58-
return llvm::createStringError(llvm::inconvertibleErrorCode(),
59-
"Invalid sourceReference.");
60-
61-
lldb::SBSymbol symbol = source_address.GetSymbol();
62-
if (!symbol.IsValid()) {
63-
// FIXME: Support assembly breakpoints without a valid symbol.
64-
return llvm::createStringError(llvm::inconvertibleErrorCode(),
65-
"Breakpoints in assembly without a valid "
66-
"symbol are not supported yet.");
50+
if (source.adapterData && source.adapterData->persistence_data) {
51+
// Prefer use the adapter persitence data, because this could be a breakpoint
52+
// from a previous session where the `sourceReference` is not valid anymore.
53+
if (llvm::Error error = CreateAssemblyBreakpointWithPersistenceData(*source.adapterData->persistence_data))
54+
return error;
55+
} else {
56+
if (llvm::Error error = CreateAssemblyBreakpointWithSourceReference(*source.sourceReference))
57+
return error;
6758
}
68-
69-
lldb::SBInstructionList inst_list =
70-
m_dap.target.ReadInstructions(symbol.GetStartAddress(), m_line);
71-
if (inst_list.GetSize() < m_line)
72-
return llvm::createStringError(llvm::inconvertibleErrorCode(),
73-
"Invalid instruction list size.");
74-
75-
lldb::SBAddress address =
76-
inst_list.GetInstructionAtIndex(m_line - 1).GetAddress();
77-
78-
m_bp = m_dap.target.BreakpointCreateBySBAddress(address);
7959
} else {
80-
// Breakpoint set by a regular source file.
81-
const auto source_path = source.path.value_or("");
82-
lldb::SBFileSpecList module_list;
83-
m_bp = m_dap.target.BreakpointCreateByLocation(source_path.c_str(), m_line,
84-
m_column, 0, module_list);
60+
CreatePathBreakpoint(source);
8561
}
8662

8763
if (!m_log_message.empty())
@@ -98,6 +74,50 @@ void SourceBreakpoint::UpdateBreakpoint(const SourceBreakpoint &request_bp) {
9874
BreakpointBase::UpdateBreakpoint(request_bp);
9975
}
10076

77+
void SourceBreakpoint::CreatePathBreakpoint(const protocol::Source &source) {
78+
const auto source_path = source.path.value_or("");
79+
lldb::SBFileSpecList module_list;
80+
m_bp = m_dap.target.BreakpointCreateByLocation(source_path.c_str(), m_line,
81+
m_column, 0, module_list);
82+
}
83+
84+
llvm::Error SourceBreakpoint::CreateAssemblyBreakpointWithSourceReference(int64_t source_reference) {
85+
std::optional<lldb::addr_t> raw_addr =
86+
m_dap.GetSourceReferenceAddress(source_reference);
87+
if (!raw_addr)
88+
return llvm::createStringError(llvm::inconvertibleErrorCode(),
89+
"Invalid sourceReference.");
90+
91+
lldb::SBAddress source_address(*raw_addr, m_dap.target);
92+
if (!source_address.IsValid())
93+
return llvm::createStringError(llvm::inconvertibleErrorCode(),
94+
"Invalid sourceReference.");
95+
96+
lldb::SBSymbol symbol = source_address.GetSymbol();
97+
if (!symbol.IsValid()) {
98+
// FIXME: Support assembly breakpoints without a valid symbol.
99+
return llvm::createStringError(llvm::inconvertibleErrorCode(),
100+
"Breakpoints in assembly without a valid "
101+
"symbol are not supported yet.");
102+
}
103+
104+
lldb::SBInstructionList inst_list =
105+
m_dap.target.ReadInstructions(symbol.GetStartAddress(), m_line);
106+
if (inst_list.GetSize() < m_line)
107+
return llvm::createStringError(llvm::inconvertibleErrorCode(),
108+
"Invalid instruction list size.");
109+
110+
lldb::SBAddress address =
111+
inst_list.GetInstructionAtIndex(m_line - 1).GetAddress();
112+
113+
m_bp = m_dap.target.BreakpointCreateBySBAddress(address);
114+
return llvm::Error::success();
115+
}
116+
117+
llvm::Error SourceBreakpoint::CreateAssemblyBreakpointWithPersistenceData(const protocol::PersistenceData &persistence_data) {
118+
return llvm::Error::success();
119+
}
120+
101121
lldb::SBError SourceBreakpoint::AppendLogMessagePart(llvm::StringRef part,
102122
bool is_expr) {
103123
if (is_expr) {

lldb/tools/lldb-dap/SourceBreakpoint.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "Breakpoint.h"
1313
#include "DAPForward.h"
14+
#include "Protocol/DAPTypes.h"
1415
#include "Protocol/ProtocolTypes.h"
1516
#include "lldb/API/SBError.h"
1617
#include "llvm/ADT/StringRef.h"
@@ -50,8 +51,9 @@ class SourceBreakpoint : public Breakpoint {
5051
uint32_t GetColumn() const { return m_column; }
5152

5253
protected:
53-
llvm::Error SetAssemblyBreakpoint(const protocol::Source &source);
54-
llvm::Error SetPathBreakpoint(const protocol::Source &source);
54+
void CreatePathBreakpoint(const protocol::Source &source);
55+
llvm::Error CreateAssemblyBreakpointWithSourceReference(int64_t source_reference);
56+
llvm::Error CreateAssemblyBreakpointWithPersistenceData(const protocol::PersistenceData &persistence_data);
5557

5658
// logMessage part can be either a raw text or an expression.
5759
struct LogMessagePart {

0 commit comments

Comments
 (0)