aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2023-07-27 14:27:05 -0600
committerTom Tromey <tromey@adacore.com>2023-08-01 13:14:47 -0600
commit13bd1a9175962980a3b0f1c0598698858c72fc04 (patch)
treefc16ba7ac0ddfdbb9cace50ce688824249ab0021 /gdb/python
parent4b6521cf69f45050f857edeb592bc46ea198041d (diff)
downloadgdb-13bd1a9175962980a3b0f1c0598698858c72fc04.zip
gdb-13bd1a9175962980a3b0f1c0598698858c72fc04.tar.gz
gdb-13bd1a9175962980a3b0f1c0598698858c72fc04.tar.bz2
Implement DAP "source" request
This implements the DAP "source" request. I renamed the "loadedSources" function from "sources" to "loaded_sources" to avoid any confusion. I also moved the loadedSources test to the new sources.exp. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30691
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/lib/gdb/dap/sources.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/gdb/python/lib/gdb/dap/sources.py b/gdb/python/lib/gdb/dap/sources.py
index 8063528..7fa1ae4 100644
--- a/gdb/python/lib/gdb/dap/sources.py
+++ b/gdb/python/lib/gdb/dap/sources.py
@@ -82,5 +82,27 @@ def _sources():
@request("loadedSources")
@capability("supportsLoadedSourcesRequest")
-def sources(**extra):
+def loaded_sources(**extra):
return send_gdb_with_response(_sources)
+
+
+# This helper is needed because we must only access the globals here
+# from the gdb thread.
+@in_gdb_thread
+def _get_source(source):
+ filename = decode_source(source)
+ with open(filename) as f:
+ content = f.read()
+ return {
+ "content": content,
+ }
+
+
+@request("source")
+def source(*, source=None, sourceReference: int, **extra):
+ # The 'sourceReference' parameter is required by the spec, but is
+ # for backward compatibility, which I take to mean that the
+ # 'source' is preferred.
+ if source is None:
+ source = {"sourceReference": sourceReference}
+ return send_gdb_with_response(lambda: _get_source(source))