From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 2/3] Handle Source in DAP breakpointLocations
Date: Fri, 28 Jul 2023 11:09:16 -0600 [thread overview]
Message-ID: <20230728-dap-source-refs-v1-2-1bcc5cdffd44@adacore.com> (raw)
In-Reply-To: <20230728-dap-source-refs-v1-0-1bcc5cdffd44@adacore.com>
This changes the DAP breakpointLocations request to accept a Source
and to decode it properly.
---
gdb/python/lib/gdb/dap/locations.py | 12 ++++--------
gdb/python/lib/gdb/dap/sources.py | 16 ++++++++++++++++
2 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/gdb/python/lib/gdb/dap/locations.py b/gdb/python/lib/gdb/dap/locations.py
index 594f1bad45b..a299e8da959 100644
--- a/gdb/python/lib/gdb/dap/locations.py
+++ b/gdb/python/lib/gdb/dap/locations.py
@@ -19,11 +19,13 @@ import gdb
from typing import Optional
from .server import capability, request
+from .sources import decode_source
from .startup import in_gdb_thread, send_gdb_with_response
@in_gdb_thread
-def _find_lines(filename, start_line, end_line):
+def _find_lines(source, start_line, end_line):
+ filename = decode_source(source)
lines = set()
for entry in gdb.execute_mi("-symbol-list-lines", filename)["lines"]:
line = entry["line"]
@@ -44,10 +46,4 @@ def _find_lines(filename, start_line, end_line):
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))
+ return send_gdb_with_response(lambda: _find_lines(source, line, endLine))
diff --git a/gdb/python/lib/gdb/dap/sources.py b/gdb/python/lib/gdb/dap/sources.py
index 50b5909ed1d..806352836db 100644
--- a/gdb/python/lib/gdb/dap/sources.py
+++ b/gdb/python/lib/gdb/dap/sources.py
@@ -54,6 +54,22 @@ def make_source(fullname, filename):
return result
+@in_gdb_thread
+def decode_source(source):
+ """Decode a Source object.
+
+ Finds and returns the filename of a given Source object."""
+ if "path" in source:
+ return source["path"]
+ if "sourceReference" not in source:
+ raise Exception("either 'path' or 'sourceReference' must appear in Source")
+ ref = source["sourceReference"]
+ global _id_map
+ if ref not in _id_map:
+ raise Exception("no sourceReference " + str(ref))
+ return _id_map[ref]["path"]
+
+
@in_gdb_thread
def _sources():
result = []
--
2.40.1
next prev parent reply other threads:[~2023-07-28 17:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-28 17:09 [PATCH 0/3] Implement DAP "source" request Tom Tromey
2023-07-28 17:09 ` [PATCH 1/3] Introduce sourceReference handling in DAP Tom Tromey
2023-07-28 17:09 ` Tom Tromey [this message]
2023-07-28 17:09 ` [PATCH 3/3] Implement DAP "source" request Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230728-dap-source-refs-v1-2-1bcc5cdffd44@adacore.com \
--to=tromey@adacore.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).