The DAP specifies the following for the SetBreakpoints request:
The breakpoints returned are in the same order as the elements of the 'breakpoints' arguments
This was not followed, as lldb-vscode was returning the breakpoints in a different order, because they were first stored into a map, and then traversed. Of course, maps normally don't preserve ordering.
See this log I captured:
--> {"command":"setBreakpoints", "arguments":{ "source":{ "name":"main.cpp", "path":"/Users/wallace/fbsource/xplat/sand/test-projects/buck-cpp/main.cpp" }, "lines":[6,10,11], "breakpoints":[{"line":6},{"line":10},{"line":11}], "sourceModified":false }, "type":"request", "seq":3 } <-- {"body":{ "breakpoints":[ {"id":1, "line":11,"source":{"name":"main.cpp","path":"xplat/sand/test-projects/buck-cpp/main.cpp"},"verified":true}, {"id":2,"line":6,"source":{"name":"main.cpp","path":"xplat/sand/test-projects/buck-cpp/main.cpp"},"verified":true}, {"id":3,"line":10,"source":{"name":"main.cpp","path":"xplat/sand/test-projects/buck-cpp/main.cpp"},"verified":true}]}, "command":"setBreakpoints", "request_seq":3, "seq":0, "success":true, "type":"response" }
As you can see, the order was not respected. This was causing the IDE not to be able to disable/enable breakpoints by clicking on them in the breakpoint view in the lower corner of the Debug tab.
This diff fixes the ordering problem. The traversal + querying was done very fast in O(nlogn) time. I'm keeping the same complexity.
I also updated a couple of tests to account for the ordering.
For example, after setting and unsetting breakpoints, some ended up being duplicated and the IDE stopped working properly