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

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

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm fail Testing failed

Commit Message

Simon Farre Jan. 16, 2024, 7:13 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).
---
 gdb/python/lib/gdb/dap/breakpoint.py | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
  

Patch

diff --git a/gdb/python/lib/gdb/dap/breakpoint.py b/gdb/python/lib/gdb/dap/breakpoint.py
index 9cbd7ae0c47..fe3c209051d 100644
--- a/gdb/python/lib/gdb/dap/breakpoint.py
+++ b/gdb/python/lib/gdb/dap/breakpoint.py
@@ -437,3 +437,29 @@  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],
+):
+    # for now we don't support column, endLine, endColumn. We just return per line
+    return {"breakpoints": _get_logical_bp_locations(source["path"], line)}