aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2023-11-07 09:16:48 -0700
committerTom Tromey <tromey@adacore.com>2023-11-21 07:09:08 -0700
commit587a1031aa10ec3e6cd8faa7cd1bbe9a5edc3736 (patch)
treef2d45e84a3009bae6f88a9a63d13d0486439e591
parentd80aef339f6c7c30da28f79056725eedd64f84d7 (diff)
downloadgdb-587a1031aa10ec3e6cd8faa7cd1bbe9a5edc3736.zip
gdb-587a1031aa10ec3e6cd8faa7cd1bbe9a5edc3736.tar.gz
gdb-587a1031aa10ec3e6cd8faa7cd1bbe9a5edc3736.tar.bz2
Refactor DAP queue handling
A couple of spots in the DAP code use the same workaround for the absence of queue.SimpleQueue before Python 3.6. This patch consolidates these into a single spot.
-rw-r--r--gdb/python/lib/gdb/dap/server.py8
-rw-r--r--gdb/python/lib/gdb/dap/startup.py13
2 files changed, 11 insertions, 10 deletions
diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py
index 031bf49..ead911d 100644
--- a/gdb/python/lib/gdb/dap/server.py
+++ b/gdb/python/lib/gdb/dap/server.py
@@ -16,12 +16,11 @@
import functools
import inspect
import json
-import queue
-import sys
from .io import start_json_writer, read_json
from .startup import (
exec_and_log,
+ DAPQueue,
in_dap_thread,
in_gdb_thread,
send_gdb,
@@ -54,10 +53,7 @@ class Server:
# This queue accepts JSON objects that are then sent to the
# DAP client. Writing is done in a separate thread to avoid
# blocking the read loop.
- if sys.version_info[0] == 3 and sys.version_info[1] <= 6:
- self.write_queue = queue.Queue()
- else:
- self.write_queue = queue.SimpleQueue()
+ self.write_queue = DAPQueue()
self.done = False
global _server
_server = self
diff --git a/gdb/python/lib/gdb/dap/startup.py b/gdb/python/lib/gdb/dap/startup.py
index eba0721..a16b51f 100644
--- a/gdb/python/lib/gdb/dap/startup.py
+++ b/gdb/python/lib/gdb/dap/startup.py
@@ -23,6 +23,14 @@ import traceback
import sys
+# Adapt to different Queue types. This is exported for use in other
+# modules as well.
+if sys.version_info[0] == 3 and sys.version_info[1] <= 6:
+ DAPQueue = queue.Queue
+else:
+ DAPQueue = queue.SimpleQueue
+
+
# The GDB thread, aka the main thread.
_gdb_thread = threading.current_thread()
@@ -158,10 +166,7 @@ def send_gdb_with_response(fn):
"""
if isinstance(fn, str):
fn = Invoker(fn)
- if sys.version_info[0] == 3 and sys.version_info[1] <= 6:
- result_q = queue.Queue()
- else:
- result_q = queue.SimpleQueue()
+ result_q = DAPQueue()
def message():
try: