From patchwork Tue Mar 14 13:05:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 66366 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 67E93385843D for ; Tue, 14 Mar 2023 13:06:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 67E93385843D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678799166; bh=LRLs07T2HJ5c3a6LaZLb6o2UPBl8ODDNgGVONwC1HXc=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=IjfBBRY2pBT2VZppwgeiEP02Bf+RhCUbtgANqNJpUY25XT6sIdp80KGE/TsGBz2Xv RgK1380851DIbs7hOupTL5neooQ4XYBFUYVFNBtAVqloIfQGdR0wGZEgRl5iQ/UD9m t2dOLfFOMyF6AKxcc3UBx7oAvjQyRGyMdy7Cv2UM= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id CC8053858C5E for ; Tue, 14 Mar 2023 13:05:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CC8053858C5E Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D35381F894; Tue, 14 Mar 2023 13:05:34 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id BDEA113A79; Tue, 14 Mar 2023 13:05:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id GJdkLR5xEGQibAAAMHmgww (envelope-from ); Tue, 14 Mar 2023 13:05:34 +0000 To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFC 1/3] [gdb/dap] Add logging of ignored lines Date: Tue, 14 Mar 2023 14:05:33 +0100 Message-Id: <20230314130535.6369-2-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230314130535.6369-1-tdevries@suse.de> References: <20230314130535.6369-1-tdevries@suse.de> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This input sequence is accepted by DAP: ... {"seq": 4, "type": "request", "command": "configurationDone"}Content-Length: 84 ... This input sequence has the same effect: ... {"seq": 4, "type": "request", "command": "configurationDone"}ignorethis Content-Length: 84 ... but the 'ignorethis' part is silently ignored. Log the ignored bit, such that we have: ... READ: <<<{"seq": 4, "type": "request", "command": "configurationDone"}>>> WROTE: <<<{"request_seq": 4, "type": "response", "command": "configurationDone" , "success": true}>>> +++ run IGNORED: <<>> ... --- gdb/python/lib/gdb/dap/io.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gdb/python/lib/gdb/dap/io.py b/gdb/python/lib/gdb/dap/io.py index 74cc82301d7..28f4d93ba46 100644 --- a/gdb/python/lib/gdb/dap/io.py +++ b/gdb/python/lib/gdb/dap/io.py @@ -14,8 +14,9 @@ # along with this program. If not, see . import json +import sys -from .startup import start_thread, send_gdb +from .startup import start_thread, send_gdb, log def read_json(stream): @@ -31,6 +32,8 @@ def read_json(stream): if line.startswith(b"Content-Length:"): line = line[15:].strip() content_length = int(line) + continue + log("IGNORED: <<<%s>>>" % line) data = bytes() while len(data) < content_length: new_data = stream.read(content_length - len(data)) From patchwork Tue Mar 14 13:05:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 66365 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 35C8E38582BC for ; Tue, 14 Mar 2023 13:05:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 35C8E38582BC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678799158; bh=yxZAzzp77GfbO4/HrSkurbyKxgrbGYvuVSRLgl2o9n4=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=nUYbu7rub4P/2jYe0zy8Cw/MLpOkraxYzDMzRUiB7e91jDnltB4iyXxfIVLCdKeQC xKIJFHqUBpwPrRuV40cd+UoHJ92YraJ4n3ISnmiiuLlqgm4gWX6X8cB7Nf7SX2hihd NqRi+6Dder0m150njArdkxf7FJxMdOW7OiDi7F2Y= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id E6C393858D39 for ; Tue, 14 Mar 2023 13:05:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E6C393858D39 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id EDA67219C6; Tue, 14 Mar 2023 13:05:34 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D7D5313A1B; Tue, 14 Mar 2023 13:05:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id sNe8Mx5xEGQibAAAMHmgww (envelope-from ); Tue, 14 Mar 2023 13:05:34 +0000 To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFC 2/3] [gdb/dap] Allow Content-Length on separate line Date: Tue, 14 Mar 2023 14:05:34 +0100 Message-Id: <20230314130535.6369-3-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230314130535.6369-1-tdevries@suse.de> References: <20230314130535.6369-1-tdevries@suse.de> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Currently this DAP input is accepted: ... Content-Length: 54 {"seq": 1, ...}Content-Length: 163 {"seq": 2, ...}Content-Length: 136 ... Also allow: ... Content-Length: 54 {"seq": 1, ...} Content-Length: 163 {"seq": 2, ...} Content-Length: 136 ... which makes command files a bit easier to read. --- gdb/python/lib/gdb/dap/io.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gdb/python/lib/gdb/dap/io.py b/gdb/python/lib/gdb/dap/io.py index 28f4d93ba46..fd9953a7aaa 100644 --- a/gdb/python/lib/gdb/dap/io.py +++ b/gdb/python/lib/gdb/dap/io.py @@ -28,7 +28,10 @@ def read_json(stream): line = stream.readline() line = line.strip() if line == b"": - break + if content_length != None: + break + else: + continue if line.startswith(b"Content-Length:"): line = line[15:].strip() content_length = int(line) From patchwork Tue Mar 14 13:05:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 66367 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0DF813857BB2 for ; Tue, 14 Mar 2023 13:06:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0DF813857BB2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678799186; bh=wszmdbmo8JJX4jzJnOqejbIfZqA88FC9E+5SWOg7ROQ=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=ZKKcyulo7HQMjZWtdXjEDIFtMDBJTyzzAWFE1rpN3jq49u+hsnPCRug3v4DSwfVn1 F0wJVpOjLmx2zj9Xjndo32yCBqYrLGhf3Yzav0z/WnoDTC7pfPgFt6YM/JKORHZvVK qV4Hs12nBvAPnn8OC1TtrK1r+lD87B5vbhqSUsqw= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 17C1C3858C83 for ; Tue, 14 Mar 2023 13:05:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 17C1C3858C83 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 137C021A8B; Tue, 14 Mar 2023 13:05:35 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id F22E013A1B; Tue, 14 Mar 2023 13:05:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gNIsOh5xEGQibAAAMHmgww (envelope-from ); Tue, 14 Mar 2023 13:05:34 +0000 To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFC 3/3] [gdb/dap] Allow WAIT_FOR_EVENTS input Date: Tue, 14 Mar 2023 14:05:35 +0100 Message-Id: <20230314130535.6369-4-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230314130535.6369-1-tdevries@suse.de> References: <20230314130535.6369-1-tdevries@suse.de> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Modify the dap input format to allow a WAIT_FOR_EVENTS line: ... Content-Length: 54 WAIT_FOR_EVENTS: 1 {"seq": 1, "type": "request", "command": "initialize"} Content-Length: 163 ... that ensures that we wait for a specific amount of events before continuing to process input. --- gdb/python/lib/gdb/dap/io.py | 7 ++++++- gdb/python/lib/gdb/dap/server.py | 12 +++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/gdb/python/lib/gdb/dap/io.py b/gdb/python/lib/gdb/dap/io.py index fd9953a7aaa..27d89e7a175 100644 --- a/gdb/python/lib/gdb/dap/io.py +++ b/gdb/python/lib/gdb/dap/io.py @@ -22,6 +22,7 @@ from .startup import start_thread, send_gdb, log def read_json(stream): """Read a JSON-RPC message from STREAM. The decoded object is returned.""" + wait_for_events = 0 # First read and parse the header. content_length = None while True: @@ -36,13 +37,17 @@ def read_json(stream): line = line[15:].strip() content_length = int(line) continue + if line.startswith(b"WAIT_FOR_EVENTS:") and content_length != None: + line = line[16:].strip() + wait_for_events = int(line) + break log("IGNORED: <<<%s>>>" % line) data = bytes() while len(data) < content_length: new_data = stream.read(content_length - len(data)) data += new_data result = json.loads(data) - return result + return (result, wait_for_events) def start_json_writer(stream, queue): diff --git a/gdb/python/lib/gdb/dap/server.py b/gdb/python/lib/gdb/dap/server.py index 92b4eee1c5e..88b41684602 100644 --- a/gdb/python/lib/gdb/dap/server.py +++ b/gdb/python/lib/gdb/dap/server.py @@ -16,6 +16,7 @@ import json import queue import sys +import time from .io import start_json_writer, read_json from .startup import ( @@ -45,6 +46,7 @@ class Server: self.out_stream = out_stream self.child_stream = child_stream self.delayed_events = [] + self.send_event_cnt = 0 # 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. @@ -110,7 +112,9 @@ class Server: start_thread("output reader", self._read_inferior_output) start_json_writer(self.out_stream, self.write_queue) while not self.done: - cmd = read_json(self.in_stream) + res = read_json(self.in_stream) + cmd = res[0] + wait_for_events = res[1] log("READ: <<<" + json.dumps(cmd) + ">>>") result = self._handle_command(cmd) self._send_json(result) @@ -118,6 +122,11 @@ class Server: self.delayed_events = [] for event, body in events: self.send_event(event, body) + while True: + if wait_for_events <= self.send_event_cnt: + self.send_event_cnt -= wait_for_events + break + time.sleep(1) # Got the terminate request. This is handled by the # JSON-writing thread, so that we can ensure that all # responses are flushed to the client before exiting. @@ -143,6 +152,7 @@ class Server: if body is not None: obj["body"] = body self._send_json(obj) + self.send_event_cnt += 1 def shutdown(self): """Request that the server shut down."""