@@ -47,41 +47,17 @@ llvm::Error SourceBreakpoint::SetBreakpoint(const protocol::Source &source) {
47
47
48
48
if (IsAssemblySource (source)) {
49
49
// 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;
67
58
}
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);
79
59
} 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);
85
61
}
86
62
87
63
if (!m_log_message.empty ())
@@ -98,6 +74,50 @@ void SourceBreakpoint::UpdateBreakpoint(const SourceBreakpoint &request_bp) {
98
74
BreakpointBase::UpdateBreakpoint (request_bp);
99
75
}
100
76
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
+
101
121
lldb::SBError SourceBreakpoint::AppendLogMessagePart (llvm::StringRef part,
102
122
bool is_expr) {
103
123
if (is_expr) {
0 commit comments