aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2023-05-17 07:43:52 -0600
committerTom Tromey <tromey@adacore.com>2023-06-12 12:10:15 -0600
commit3c453cfb1945eb97f68b3aca4d84f4884c564d0c (patch)
treeee1e6de13eee71765cb6558edc33d4b35446ebe7 /gdb
parentad9cdfbcfdf9c7a679393d35adaf95e2b3cb6fd0 (diff)
downloadgdb-3c453cfb1945eb97f68b3aca4d84f4884c564d0c.zip
gdb-3c453cfb1945eb97f68b3aca4d84f4884c564d0c.tar.gz
gdb-3c453cfb1945eb97f68b3aca4d84f4884c564d0c.tar.bz2
Implement DAP breakpointLocations request
This implements the DAP breakpointLocations request.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/data-directory/Makefile.in1
-rw-r--r--gdb/python/lib/gdb/dap/__init__.py1
-rw-r--r--gdb/python/lib/gdb/dap/locations.py45
-rw-r--r--gdb/testsuite/gdb.dap/basic-dap.c2
-rw-r--r--gdb/testsuite/gdb.dap/basic-dap.exp15
5 files changed, 63 insertions, 1 deletions
diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in
index 9e34d4c..a3775a4 100644
--- a/gdb/data-directory/Makefile.in
+++ b/gdb/data-directory/Makefile.in
@@ -96,6 +96,7 @@ PYTHON_FILE_LIST = \
gdb/dap/__init__.py \
gdb/dap/io.py \
gdb/dap/launch.py \
+ gdb/dap/locations.py \
gdb/dap/memory.py \
gdb/dap/next.py \
gdb/dap/pause.py \
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 <http://www.gnu.org/licenses/>.
+
+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))
diff --git a/gdb/testsuite/gdb.dap/basic-dap.c b/gdb/testsuite/gdb.dap/basic-dap.c
index 2570b8b..5fb11fa 100644
--- a/gdb/testsuite/gdb.dap/basic-dap.c
+++ b/gdb/testsuite/gdb.dap/basic-dap.c
@@ -38,7 +38,7 @@ address_breakpoint_here ()
int
line_breakpoint_here ()
{
- do_not_stop_here ();
+ do_not_stop_here (); /* FIRST */
function_breakpoint_here ();
address_breakpoint_here ();
return 0; /* BREAK */
diff --git a/gdb/testsuite/gdb.dap/basic-dap.exp b/gdb/testsuite/gdb.dap/basic-dap.exp
index ca0d1be..df9afcf 100644
--- a/gdb/testsuite/gdb.dap/basic-dap.exp
+++ b/gdb/testsuite/gdb.dap/basic-dap.exp
@@ -71,6 +71,21 @@ if {!$ok} {
fail "check new breakpoint event"
}
+# Check that there are breakpoint locations on each line between FIRST
+# and BREAK.
+set first_line [gdb_get_line_number "FIRST"]
+set last_line [expr {$line - 1}]
+set obj [dap_check_request_and_response "breakpoint locations" \
+ breakpointLocations \
+ [format {o source [o path [%s]] line [i %d] endLine [i %d]} \
+ [list s $srcfile] $first_line $last_line]]
+# We know gdb returns the lines in sorted order.
+foreach entry [dict get [lindex $obj 0] body breakpoints] {
+ gdb_assert {[dict get $entry line] == $first_line} \
+ "line $first_line in result"
+ incr first_line
+}
+
set obj [dap_check_request_and_response "reset breakpoint by line number" \
setBreakpoints \
[format {o source [o path [%s]] breakpoints [a [o line [i %d]]]} \