Skip to content

Commit ae32486

Browse files
committed
support assembly in BreakpointLocationsRequestHandler
1 parent a4eb0db commit ae32486

File tree

7 files changed

+76
-22
lines changed

7 files changed

+76
-22
lines changed

lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setBreakpoints.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import os
1313

1414

15-
@skip("Temporarily disable the breakpoint tests")
1615
class TestDAP_setBreakpoints(lldbdap_testcase.DAPTestCaseBase):
1716
def setUp(self):
1817
lldbdap_testcase.DAPTestCaseBase.setUp(self)

lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setExceptionBreakpoints.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import lldbdap_testcase
1111

1212

13-
@skip("Temporarily disable the breakpoint tests")
1413
class TestDAP_setExceptionBreakpoints(lldbdap_testcase.DAPTestCaseBase):
1514
@skipIfWindows
1615
def test_functionality(self):

lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_setFunctionBreakpoints.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import lldbdap_testcase
1111

1212

13-
@skip("Temporarily disable the breakpoint tests")
1413
class TestDAP_setFunctionBreakpoints(lldbdap_testcase.DAPTestCaseBase):
1514
@skipIfWindows
1615
def test_set_and_clear(self):

lldb/tools/lldb-dap/DAP.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ struct DAP {
219219
llvm::StringSet<> modules;
220220
/// @}
221221

222+
/// Number of lines of assembly code to show when no debug info is available.
223+
uint32_t number_of_assembly_lines_for_nodebug = 32;
224+
222225
/// Creates a new DAP sessions.
223226
///
224227
/// \param[in] log

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

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "DAP.h"
10-
#include "JSONUtils.h"
10+
#include "LLDBUtils.h"
1111
#include "RequestHandler.h"
1212
#include <vector>
1313

@@ -19,19 +19,50 @@ namespace lldb_dap {
1919
llvm::Expected<protocol::BreakpointLocationsResponseBody>
2020
BreakpointLocationsRequestHandler::Run(
2121
const protocol::BreakpointLocationsArguments &args) const {
22-
std::string path = args.source.path.value_or("");
2322
uint32_t start_line = args.line;
2423
uint32_t start_column = args.column.value_or(LLDB_INVALID_COLUMN_NUMBER);
2524
uint32_t end_line = args.endLine.value_or(start_line);
2625
uint32_t end_column =
2726
args.endColumn.value_or(std::numeric_limits<uint32_t>::max());
2827

28+
// Find all relevant lines & columns
29+
llvm::SmallVector<std::pair<uint32_t, uint32_t>, 8> locations;
30+
if (args.source.sourceReference) {
31+
AddAssemblyBreakpointLocations(locations, *args.source.sourceReference,
32+
start_line, end_line);
33+
} else {
34+
std::string path = args.source.path.value_or("");
35+
AddSourceBreakpointLocations(locations, std::move(path), start_line,
36+
start_column, end_line, end_column);
37+
}
38+
39+
// The line entries are sorted by addresses, but we must return the list
40+
// ordered by line / column position.
41+
std::sort(locations.begin(), locations.end());
42+
locations.erase(llvm::unique(locations), locations.end());
43+
44+
std::vector<protocol::BreakpointLocation> breakpoint_locations;
45+
for (auto &l : locations) {
46+
protocol::BreakpointLocation lc;
47+
lc.line = l.first;
48+
lc.column = l.second;
49+
breakpoint_locations.push_back(std::move(lc));
50+
}
51+
52+
return protocol::BreakpointLocationsResponseBody{
53+
/*breakpoints=*/std::move(breakpoint_locations)};
54+
}
55+
56+
template <unsigned N>
57+
void BreakpointLocationsRequestHandler::AddSourceBreakpointLocations(
58+
llvm::SmallVector<std::pair<uint32_t, uint32_t>, N> &locations,
59+
std::string path, uint32_t start_line, uint32_t start_column,
60+
uint32_t end_line, uint32_t end_column) const {
61+
2962
lldb::SBFileSpec file_spec(path.c_str(), true);
3063
lldb::SBSymbolContextList compile_units =
3164
dap.target.FindCompileUnits(file_spec);
3265

33-
// Find all relevant lines & columns
34-
llvm::SmallVector<std::pair<uint32_t, uint32_t>, 8> locations;
3566
for (uint32_t c_idx = 0, c_limit = compile_units.GetSize(); c_idx < c_limit;
3667
++c_idx) {
3768
const lldb::SBCompileUnit &compile_unit =
@@ -71,22 +102,34 @@ BreakpointLocationsRequestHandler::Run(
71102
locations.emplace_back(line, column);
72103
}
73104
}
105+
}
74106

75-
// The line entries are sorted by addresses, but we must return the list
76-
// ordered by line / column position.
77-
std::sort(locations.begin(), locations.end());
78-
locations.erase(llvm::unique(locations), locations.end());
107+
template <unsigned N>
108+
void BreakpointLocationsRequestHandler::AddAssemblyBreakpointLocations(
109+
llvm::SmallVector<std::pair<uint32_t, uint32_t>, N> &locations,
110+
int64_t sourceReference, uint32_t start_line, uint32_t end_line) const {
111+
lldb::SBProcess process = dap.target.GetProcess();
112+
lldb::SBThread thread =
113+
process.GetThreadByIndexID(GetLLDBThreadIndexID(sourceReference));
114+
lldb::SBFrame frame = thread.GetFrameAtIndex(GetLLDBFrameID(sourceReference));
79115

80-
std::vector<protocol::BreakpointLocation> breakpoint_locations;
81-
for (auto &l : locations) {
82-
protocol::BreakpointLocation lc;
83-
lc.line = l.first;
84-
lc.column = l.second;
85-
breakpoint_locations.push_back(std::move(lc));
86-
}
116+
if (!frame.IsValid())
117+
return;
87118

88-
return protocol::BreakpointLocationsResponseBody{
89-
/*breakpoints=*/std::move(breakpoint_locations)};
119+
lldb::SBSymbol symbol = frame.GetSymbol();
120+
if (symbol.IsValid()) {
121+
lldb::SBInstructionList insts = symbol.GetInstructions(dap.target);
122+
for (uint32_t i = start_line - 1; i < insts.GetSize() && i < (end_line - 1);
123+
++i) {
124+
locations.emplace_back(i, 0);
125+
}
126+
} else {
127+
for (uint32_t i = start_line - 1;
128+
i < dap.number_of_assembly_lines_for_nodebug && i < (end_line - 1);
129+
++i) {
130+
locations.emplace_back(i, 0);
131+
}
132+
}
90133
}
91134

92135
} // namespace lldb_dap

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "Protocol/ProtocolRequests.h"
1717
#include "Protocol/ProtocolTypes.h"
1818
#include "llvm/ADT/DenseSet.h"
19+
#include "llvm/ADT/SmallVector.h"
1920
#include "llvm/ADT/StringRef.h"
2021
#include "llvm/Support/Error.h"
2122
#include "llvm/Support/JSON.h"
@@ -217,6 +218,16 @@ class BreakpointLocationsRequestHandler
217218
}
218219
llvm::Expected<protocol::BreakpointLocationsResponseBody>
219220
Run(const protocol::BreakpointLocationsArguments &args) const override;
221+
222+
template <unsigned N>
223+
void AddSourceBreakpointLocations(
224+
llvm::SmallVector<std::pair<uint32_t, uint32_t>, N> &locations,
225+
std::string path, uint32_t start_line, uint32_t start_column,
226+
uint32_t end_line, uint32_t end_column) const;
227+
template <unsigned N>
228+
void AddAssemblyBreakpointLocations(
229+
llvm::SmallVector<std::pair<uint32_t, uint32_t>, N> &locations,
230+
int64_t sourceReference, uint32_t start_line, uint32_t end_line) const;
220231
};
221232

222233
class CompletionsRequestHandler : public LegacyRequestHandler {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ SourceRequestHandler::Run(const protocol::SourceArguments &args) const {
5252
insts.GetDescription(stream, exe_ctx);
5353
} else {
5454
// No valid symbol, just return the disassembly.
55-
lldb::SBInstructionList insts =
56-
dap.target.ReadInstructions(frame.GetPCAddress(), 32);
55+
lldb::SBInstructionList insts = dap.target.ReadInstructions(
56+
frame.GetPCAddress(), dap.number_of_assembly_lines_for_nodebug);
5757
insts.GetDescription(stream, exe_ctx);
5858
}
5959

0 commit comments

Comments
 (0)