|
8 | 8 |
|
9 | 9 | #include "Breakpoint.h"
|
10 | 10 | #include "DAP.h"
|
| 11 | +#include "Protocol/DAPTypes.h" |
11 | 12 | #include "ProtocolUtils.h"
|
12 | 13 | #include "lldb/API/SBAddress.h"
|
13 | 14 | #include "lldb/API/SBBreakpointLocation.h"
|
| 15 | +#include "lldb/API/SBFileSpec.h" |
14 | 16 | #include "lldb/API/SBLineEntry.h"
|
| 17 | +#include "lldb/API/SBModule.h" |
15 | 18 | #include "lldb/API/SBMutex.h"
|
16 | 19 | #include "llvm/ADT/StringExtras.h"
|
17 | 20 | #include <cstddef>
|
|
21 | 24 |
|
22 | 25 | using namespace lldb_dap;
|
23 | 26 |
|
| 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 | + |
24 | 43 | void Breakpoint::SetCondition() { m_bp.SetCondition(m_condition.c_str()); }
|
25 | 44 |
|
26 | 45 | void Breakpoint::SetHitCondition() {
|
@@ -73,15 +92,22 @@ protocol::Breakpoint Breakpoint::ToProtocolBreakpoint() {
|
73 | 92 | const auto column = line_entry.GetColumn();
|
74 | 93 | if (column != LLDB_INVALID_COLUMN_NUMBER)
|
75 | 94 | breakpoint.column = column;
|
76 |
| - } else { |
| 95 | + } else if (source) { |
77 | 96 | // Assembly breakpoint.
|
78 | 97 | auto symbol = bp_addr.GetSymbol();
|
79 | 98 | 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); |
85 | 111 | }
|
86 | 112 | }
|
87 | 113 |
|
|
0 commit comments