Skip to content

Commit dbb2f9b

Browse files
committed
fix resolving of assembly source breakpoints
1 parent ee49203 commit dbb2f9b

File tree

7 files changed

+63
-32
lines changed

7 files changed

+63
-32
lines changed

lldb/tools/lldb-dap/Breakpoint.cpp

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
#include "Breakpoint.h"
1010
#include "DAP.h"
1111
#include "JSONUtils.h"
12+
#include "LLDBUtils.h"
1213
#include "lldb/API/SBAddress.h"
1314
#include "lldb/API/SBBreakpointLocation.h"
1415
#include "lldb/API/SBLineEntry.h"
1516
#include "lldb/API/SBMutex.h"
17+
#include "lldb/lldb-enumerations.h"
1618
#include "llvm/ADT/StringExtras.h"
1719
#include <cstddef>
1820
#include <cstdint>
@@ -63,14 +65,43 @@ protocol::Breakpoint Breakpoint::ToProtocolBreakpoint() {
6365
std::string formatted_addr =
6466
"0x" + llvm::utohexstr(bp_addr.GetLoadAddress(m_bp.GetTarget()));
6567
breakpoint.instructionReference = formatted_addr;
68+
69+
lldb::StopDisassemblyType stop_disassembly_display =
70+
GetStopDisassemblyDisplay(m_dap.debugger);
6671
auto line_entry = bp_addr.GetLineEntry();
67-
const auto line = line_entry.GetLine();
68-
if (line != UINT32_MAX)
69-
breakpoint.line = line;
70-
const auto column = line_entry.GetColumn();
71-
if (column != 0)
72-
breakpoint.column = column;
73-
breakpoint.source = CreateSource(line_entry);
72+
if (!ShouldDisplayAssemblySource(line_entry, stop_disassembly_display)) {
73+
const auto line = line_entry.GetLine();
74+
if (line != UINT32_MAX)
75+
breakpoint.line = line;
76+
const auto column = line_entry.GetColumn();
77+
if (column != 0)
78+
breakpoint.column = column;
79+
breakpoint.source = CreateSource(line_entry);
80+
} else {
81+
// Breakpoint made by assembly
82+
auto symbol_context = bp_addr.GetSymbolContext(
83+
lldb::eSymbolContextSymbol | lldb::eSymbolContextModule);
84+
if (symbol_context.IsValid()) {
85+
auto symbol = symbol_context.GetSymbol();
86+
breakpoint.line =
87+
m_bp.GetTarget()
88+
.ReadInstructions(symbol.GetStartAddress(), bp_addr, nullptr)
89+
.GetSize() +
90+
1;
91+
protocol::Source source;
92+
source.name = symbol.GetName();
93+
94+
auto module = symbol_context.GetModule();
95+
if (module.IsValid()) {
96+
std::string path = module.GetFileSpec().GetDirectory();
97+
path += "/";
98+
path += module.GetFileSpec().GetFilename();
99+
source.path = std::move(path);
100+
}
101+
102+
breakpoint.source = std::move(source);
103+
}
104+
}
74105
}
75106

76107
return breakpoint;

lldb/tools/lldb-dap/DAP.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ struct DAP {
169169
Variables variables;
170170
lldb::SBBroadcaster broadcaster;
171171
llvm::StringMap<SourceBreakpointMap> source_breakpoints;
172-
llvm::DenseMap<int64_t, SourceBreakpointMap> assembly_breakpoints;
172+
llvm::DenseMap<int64_t, llvm::DenseMap<uint32_t, SourceBreakpoint>>
173+
assembly_breakpoints;
173174
FunctionBreakpointMap function_breakpoints;
174175
InstructionBreakpointMap instruction_breakpoints;
175176
std::optional<std::vector<ExceptionBreakpoint>> exception_breakpoints;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ void BreakpointLocationsRequestHandler::AddAssemblyBreakpointLocations(
122122

123123
// start_line is relative to the symbol's start address
124124
lldb::SBInstructionList insts = symbol.GetInstructions(dap.target);
125-
for (uint32_t i = start_line - 1; i < insts.GetSize() && i < (end_line - 1);
125+
for (uint32_t i = start_line - 1; i < insts.GetSize() && i <= (end_line - 1);
126126
++i) {
127-
locations.emplace_back(i, 0);
127+
locations.emplace_back(i, 1);
128128
}
129129
}
130130

lldb/tools/lldb-dap/Handler/RequestHandler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,11 @@ class SetBreakpointsRequestHandler
391391
Run(const protocol::SetBreakpointsArguments &args) const override;
392392

393393
std::vector<protocol::Breakpoint> SetSourceBreakpoints(
394-
const std::string &path,
394+
const protocol::Source &source,
395395
const std::optional<std::vector<protocol::SourceBreakpoint>> &breakpoints)
396396
const;
397397
std::vector<protocol::Breakpoint> SetAssemblyBreakpoints(
398-
int64_t sourceReference,
398+
const protocol::Source &source,
399399
const std::optional<std::vector<protocol::SourceBreakpoint>> &breakpoints)
400400
const;
401401
};

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

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,20 @@ SetBreakpointsRequestHandler::Run(
2828
const auto &source = args.source;
2929
std::vector<protocol::Breakpoint> response_breakpoints;
3030
if (source.sourceReference)
31-
response_breakpoints = SetAssemblyBreakpoints(
32-
source.sourceReference.value(), args.breakpoints);
31+
response_breakpoints = SetAssemblyBreakpoints(source, args.breakpoints);
3332
else if (source.path)
34-
response_breakpoints =
35-
SetSourceBreakpoints(source.path.value(), args.breakpoints);
33+
response_breakpoints = SetSourceBreakpoints(source, args.breakpoints);
3634

3735
return protocol::SetBreakpointsResponseBody{std::move(response_breakpoints)};
3836
}
3937

4038
std::vector<protocol::Breakpoint>
4139
SetBreakpointsRequestHandler::SetSourceBreakpoints(
42-
const std::string &path,
40+
const protocol::Source &source,
4341
const std::optional<std::vector<protocol::SourceBreakpoint>> &breakpoints)
4442
const {
4543
std::vector<protocol::Breakpoint> response_breakpoints;
44+
std::string path = source.path.value_or("");
4645

4746
// Decode the source breakpoint infos for this "setBreakpoints" request
4847
SourceBreakpointMap request_bps;
@@ -96,10 +95,11 @@ SetBreakpointsRequestHandler::SetSourceBreakpoints(
9695

9796
std::vector<protocol::Breakpoint>
9897
SetBreakpointsRequestHandler::SetAssemblyBreakpoints(
99-
int64_t sourceReference,
98+
const protocol::Source &source,
10099
const std::optional<std::vector<protocol::SourceBreakpoint>> &breakpoints)
101100
const {
102101
std::vector<protocol::Breakpoint> response_breakpoints;
102+
int64_t sourceReference = source.sourceReference.value_or(0);
103103

104104
lldb::SBProcess process = dap.target.GetProcess();
105105
lldb::SBThread thread =
@@ -114,30 +114,26 @@ SetBreakpointsRequestHandler::SetAssemblyBreakpoints(
114114
return response_breakpoints; // Not yet supporting breakpoints in assembly
115115
// without a valid symbol
116116

117-
SourceBreakpointMap request_bps;
117+
llvm::DenseMap<uint32_t, SourceBreakpoint> request_bps;
118118
if (breakpoints) {
119119
for (const auto &bp : *breakpoints) {
120120
SourceBreakpoint src_bp(dap, bp);
121-
std::pair<uint32_t, uint32_t> bp_pos(src_bp.GetLine(), 0);
122-
request_bps.try_emplace(bp_pos, src_bp);
121+
request_bps.try_emplace(src_bp.GetLine(), src_bp);
123122
const auto [iv, inserted] =
124-
dap.assembly_breakpoints[sourceReference].try_emplace(bp_pos, src_bp);
123+
dap.assembly_breakpoints[sourceReference].try_emplace(
124+
src_bp.GetLine(), src_bp);
125125
// We check if this breakpoint already exists to update it
126126
if (inserted)
127127
iv->getSecond().SetBreakpoint(symbol);
128128
else
129129
iv->getSecond().UpdateBreakpoint(src_bp);
130130

131131
protocol::Breakpoint response_bp = iv->getSecond().ToProtocolBreakpoint();
132-
protocol::Source source;
133-
source.sourceReference = sourceReference;
134-
source.name = symbol.GetName();
135-
response_bp.source = std::move(source);
136-
132+
response_bp.source = source;
137133
if (!response_bp.line)
138134
response_bp.line = src_bp.GetLine();
139-
if (!response_bp.column)
140-
response_bp.column = src_bp.GetColumn();
135+
if (bp.column)
136+
response_bp.column = *bp.column;
141137
response_breakpoints.push_back(response_bp);
142138
}
143139
}

lldb/tools/lldb-dap/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lldb/tools/lldb-dap/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "lldb-dap",
33
"displayName": "LLDB DAP",
4-
"version": "0.2.13",
4+
"version": "0.2.14",
55
"publisher": "llvm-vs-code-extensions",
66
"homepage": "https://lldb.llvm.org",
77
"description": "Debugging with LLDB in Visual Studio Code",
@@ -265,6 +265,9 @@
265265
]
266266
},
267267
"breakpoints": [
268+
{
269+
"language": "lldb.disassembly"
270+
},
268271
{
269272
"language": "ada"
270273
},

0 commit comments

Comments
 (0)