[v2,4/5,dap,&,linetable] : Add breakpointLocations request

Message ID 20240117210518.1784638-3-simon.farre.cx@gmail.com
State New
Headers
Series [v2,1/5,dap,&,linetable] : Add column to linetable entry |

Commit Message

Simon Farre Jan. 17, 2024, 9:05 p.m. UTC
  This adds the breakpointLocations request.

Testing might strictly not be possible for this feature. Users are going
to have wildly varying compilers and compiler versions that outputs
wildly different debug symbol information. So unless we can restrain the
tests to some specific toolchain that I can handroll the tests for, this
will not be useful (and handrolling for a specific compiler defeats the
purpose - as one can just use the eyes then to verify).

v2:
Fixed type check issue

Forgot the obligatory **args at the end of breakpoint_locations
---
 gdb/python/lib/gdb/dap/breakpoint.py | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
  

Patch

diff --git a/gdb/python/lib/gdb/dap/breakpoint.py b/gdb/python/lib/gdb/dap/breakpoint.py
index 9cbd7ae0c47..70c93b0a03d 100644
--- a/gdb/python/lib/gdb/dap/breakpoint.py
+++ b/gdb/python/lib/gdb/dap/breakpoint.py
@@ -437,3 +437,30 @@  def set_exception_breakpoints(
     return {
         "breakpoints": _set_exception_catchpoints(options),
     }
+
+
+@in_gdb_thread
+def _get_logical_bp_locations(name: str, line: int):
+    linetable = gdb.lookup_linetable(name)
+    if linetable is not None:
+        return [
+            {"line": lte.line, "column": lte.column} for lte in linetable.line(line)
+        ]
+    else:
+        return []
+
+
+@request("breakpointLocations")
+@capability("supportsBreakpointLocationsRequest")
+def breakpoint_locations(
+    *,
+    # This is a Source but we don't type-check it.
+    source,
+    line: int,
+    column: Optional[int],
+    endLine: Optional[int],
+    endColumn: Optional[int],
+    **args,
+):
+    # for now we don't support column, endLine, endColumn. We just return per line
+    return {"breakpoints": _get_logical_bp_locations(source["path"], line)}