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

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

Checks

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

Commit Message

Simon Farre Jan. 22, 2024, 1:31 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

v3:

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31271
---
 gdb/python/lib/gdb/dap/breakpoint.py | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
  

Comments

Tom Tromey Feb. 7, 2024, 7:44 p.m. UTC | #1
>>>>> "Simon" == Simon Farre <simon.farre.cx@gmail.com> writes:

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

It may be possible to write a custom test case using the "DWARF
assembler".

Simon> +@request("breakpointLocations")
Simon> +@capability("supportsBreakpointLocationsRequest")

This already exists in locations.py.

I'll send a patch to make sure that double-registration is impossible.

Tom
  

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)}