Skip to content

Commit e3934cb

Browse files
committed
add persistence data to response
1 parent 7242cd8 commit e3934cb

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

lldb/tools/lldb-dap/Breakpoint.cpp

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88

99
#include "Breakpoint.h"
1010
#include "DAP.h"
11+
#include "Protocol/DAPTypes.h"
1112
#include "ProtocolUtils.h"
1213
#include "lldb/API/SBAddress.h"
1314
#include "lldb/API/SBBreakpointLocation.h"
15+
#include "lldb/API/SBFileSpec.h"
1416
#include "lldb/API/SBLineEntry.h"
17+
#include "lldb/API/SBModule.h"
1518
#include "lldb/API/SBMutex.h"
1619
#include "llvm/ADT/StringExtras.h"
1720
#include <cstddef>
@@ -21,6 +24,22 @@
2124

2225
using namespace lldb_dap;
2326

27+
static std::optional<protocol::PersistenceData>
28+
GetPersistenceDataForAddress(lldb::SBAddress &addr) {
29+
protocol::PersistenceData persistence_data;
30+
lldb::SBModule module = addr.GetModule();
31+
if (!module.IsValid())
32+
return std::nullopt;
33+
34+
lldb::SBFileSpec file_spec = module.GetFileSpec();
35+
if (!file_spec.IsValid())
36+
return std::nullopt;
37+
38+
persistence_data.module = file_spec.GetFilename();
39+
persistence_data.file_addr = addr.GetFileAddress();
40+
return persistence_data;
41+
}
42+
2443
void Breakpoint::SetCondition() { m_bp.SetCondition(m_condition.c_str()); }
2544

2645
void Breakpoint::SetHitCondition() {
@@ -73,15 +92,22 @@ protocol::Breakpoint Breakpoint::ToProtocolBreakpoint() {
7392
const auto column = line_entry.GetColumn();
7493
if (column != LLDB_INVALID_COLUMN_NUMBER)
7594
breakpoint.column = column;
76-
} else {
95+
} else if (source) {
7796
// Assembly breakpoint.
7897
auto symbol = bp_addr.GetSymbol();
7998
if (symbol.IsValid()) {
80-
breakpoint.line =
81-
m_bp.GetTarget()
82-
.ReadInstructions(symbol.GetStartAddress(), bp_addr, nullptr)
83-
.GetSize() +
84-
1;
99+
lldb::SBAddress start_address = symbol.GetStartAddress();
100+
breakpoint.line = m_bp.GetTarget()
101+
.ReadInstructions(start_address, bp_addr, nullptr)
102+
.GetSize() +
103+
1;
104+
105+
// Add persistent data so that the breakpoint can be resolved
106+
// in future sessions.
107+
std::optional<protocol::PersistenceData> persistence_data =
108+
GetPersistenceDataForAddress(start_address);
109+
if (persistence_data)
110+
source->adapterData->persistence_data = std::move(persistence_data);
85111
}
86112
}
87113

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "lldb/API/SBStream.h"
3232
#include "lldb/Utility/IOObject.h"
3333
#include "lldb/Utility/Status.h"
34+
#include "lldb/Utility/TraceIntelPTGDBRemotePackets.h"
3435
#include "lldb/lldb-defines.h"
3536
#include "lldb/lldb-enumerations.h"
3637
#include "lldb/lldb-types.h"
@@ -1406,11 +1407,16 @@ void DAP::EventThread() {
14061407
// avoids sending paths that should be source mapped. Note that
14071408
// CreateBreakpoint doesn't apply source mapping and certain
14081409
// implementation ignore the source part of this event anyway.
1409-
llvm::json::Value source_bp = bp.ToProtocolBreakpoint();
1410-
source_bp.getAsObject()->erase("source");
1410+
protocol::Breakpoint protocol_bp = bp.ToProtocolBreakpoint();
1411+
llvm::json::Value protocol_bp_value = toJSON(protocol_bp);
1412+
1413+
// "source" is not needed here, unless we add adapter data to be
1414+
// saved by the client.
1415+
if (protocol_bp.source && !protocol_bp.source->adapterData)
1416+
protocol_bp_value.getAsObject()->erase("source");
14111417

14121418
llvm::json::Object body;
1413-
body.try_emplace("breakpoint", source_bp);
1419+
body.try_emplace("breakpoint", protocol_bp);
14141420
body.try_emplace("reason", "changed");
14151421

14161422
llvm::json::Object bp_event = CreateEventObject("breakpoint");

0 commit comments

Comments
 (0)