GDB (xrefs)
Loading...
Searching...
No Matches
locations.py
Go to the documentation of this file.
1# Copyright 2023 Free Software Foundation, Inc.
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16import gdb
17
18# This is deprecated in 3.9, but required in older versions.
19from typing import Optional
20
21from .server import capability, request
22from .sources import decode_source
23from .startup import in_gdb_thread
24
25
26@in_gdb_thread
27def _find_lines(source, start_line, end_line):
28 filename = decode_source(source)
29 lines = set()
30 for entry in gdb.execute_mi("-symbol-list-lines", filename)["lines"]:
31 line = entry["line"]
32 if line >= start_line and line <= end_line:
33 lines.add(line)
34 return {"breakpoints": [{"line": x} for x in sorted(lines)]}
35
36
37# Note that the spec says that the arguments to this are optional.
38# However, calling this without arguments is nonsensical. This is
39# discussed in:
40# https://github.com/microsoft/debug-adapter-protocol/issues/266
41# This points out that fixing this would be an incompatibility but
42# goes on to propose "if arguments property is missing, debug adapters
43# should return an error".
44@request("breakpointLocations")
45@capability("supportsBreakpointLocationsRequest")
46def breakpoint_locations(*, source, line: int, endLine: Optional[int] = None, **extra):
47 if endLine is None:
48 endLine = line
49 return _find_lines(source, line, endLine)