From 3c453cfb1945eb97f68b3aca4d84f4884c564d0c Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 17 May 2023 07:43:52 -0600 Subject: Implement DAP breakpointLocations request This implements the DAP breakpointLocations request. --- gdb/python/lib/gdb/dap/__init__.py | 1 + gdb/python/lib/gdb/dap/locations.py | 45 +++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 gdb/python/lib/gdb/dap/locations.py (limited to 'gdb/python') diff --git a/gdb/python/lib/gdb/dap/__init__.py b/gdb/python/lib/gdb/dap/__init__.py index f07228e..f3dd3ff 100644 --- a/gdb/python/lib/gdb/dap/__init__.py +++ b/gdb/python/lib/gdb/dap/__init__.py @@ -25,6 +25,7 @@ from . import bt from . import disassemble from . import evaluate from . import launch +from . import locations from . import memory from . import next from . import pause diff --git a/gdb/python/lib/gdb/dap/locations.py b/gdb/python/lib/gdb/dap/locations.py new file mode 100644 index 0000000..6c59157 --- /dev/null +++ b/gdb/python/lib/gdb/dap/locations.py @@ -0,0 +1,45 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import gdb + +# This is deprecated in 3.9, but required in older versions. +from typing import Optional + +from .server import request +from .startup import in_gdb_thread, send_gdb_with_response + + +@in_gdb_thread +def _find_lines(filename, start_line, end_line): + lines = set() + for entry in gdb.execute_mi("-symbol-list-lines", filename)["lines"]: + line = entry["line"] + if line >= start_line and line <= end_line: + lines.add(line) + return {"breakpoints": [{"line": x} for x in sorted(lines)]} + + +@request("breakpointLocations") +def breakpoint_locations(*, source, line: int, endLine: Optional[int] = None, **extra): + if endLine is None: + endLine = line + if "path" in source: + filename = source["path"] + elif "name" in source: + filename = source["name"] + else: + raise Exception("") + return send_gdb_with_response(lambda: _find_lines(filename, line, endLine)) -- cgit v1.1