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 {
1919llvm::Expected<protocol::BreakpointLocationsResponseBody>
2020BreakpointLocationsRequestHandler::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
0 commit comments