From patchwork Fri Oct 4 18:57:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandra Petlanova Hajkova X-Patchwork-Id: 98411 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 95233385EC04 for ; Fri, 4 Oct 2024 18:58:05 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 115E9385E003 for ; Fri, 4 Oct 2024 18:57:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 115E9385E003 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 115E9385E003 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728068259; cv=none; b=F8e/k6VLy5AqTh/QZ2lsctOVpHnW0Vt0Y1Ckl+EqPtVlOEJgZ06dR6aGhKBAPzooTbVwH349lFl0loDG/t6m0IH0lOJlqZRreQw0b+I66RN8gNzHLh4/WtbiTAgm3AI2k1DN9H2pP7QTTWwQg/+oyRHjnJiPuNKZbZqnmDDu7Kg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728068259; c=relaxed/simple; bh=N9I6kTr1mzAhQIFxQaRga9CoojZzdL0faPH0y4FU344=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Hll8WR0+5lhYkZGWOGOffD1pLz7BVMci64Vv89flG6E3kYDPxCrO4xfIDH5eSzDgZXzs9Cujfj6r4hDHaXPXMQSWPGG559xg5lGXD7DWJtAqJj1gvn4HIeltNTuPNJbsBpSrw1DWP3jQD7xrPIJZrTTjm529Wqibp5o2FZs0c1s= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728068257; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BVB0LmSUzGiHAsudLWo8nUUMCiKLe/BY76/FIZYwhKg=; b=V+6U0C/0ELelklTiGN9xv9vV/yL4MTz8IbYfvAmDJn3OF8lzH8PHB/wmckBS2yb7oQfdVb +T0nKMVipQgHdwQqSU7B60TfpwPjlRYdpgCfzrHdfPD+QnReXfZ8EO6SEY7wC6MA2Fbp6W 0KtlQE/XfdxbNe8annzYjWG/BcSJgx0= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-602-FMri4eG8P1WaBBy99f0pyw-1; Fri, 04 Oct 2024 14:57:36 -0400 X-MC-Unique: FMri4eG8P1WaBBy99f0pyw-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E8F7E1955E84 for ; Fri, 4 Oct 2024 18:57:34 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.242.3]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D82123000198; Fri, 4 Oct 2024 18:57:33 +0000 (UTC) From: =?utf-8?q?Alexandra_H=C3=A1jkov=C3=A1?= To: gdb-patches@sourceware.org Cc: ahajkova@redhat.com Subject: [PATCH] gdbreplay: Add --debug-logging option Date: Fri, 4 Oct 2024 20:57:32 +0200 Message-ID: <20241004185732.153001-1-ahajkova@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org As gdbreplay communicates with GDB, it outputs all the remote protocol communication it reads from the remotelogfile to stderr. This patch disables this behavior by default but adds the new --debug-logging option which turns printing the packets to stderr on again. The motivation for this change is to make it possible to use gdbreplay with TCL tests. Printing the whole remotelog file out seems to overflow the expect cache wich causes gdbreplay to not to get the packet its expects and results in going out of sync with GDB. Other motivation is making communication between GDB and gdbreplay faster as printing bigger remotelogfile takes considerable amount of time. --- gdbserver/README | 11 ++--- gdbserver/gdbreplay.cc | 100 +++++++++++++++++++++++++++++------------ 2 files changed, 78 insertions(+), 33 deletions(-) diff --git a/gdbserver/README b/gdbserver/README index 5b47510c3e3..e7e99ec7988 100644 --- a/gdbserver/README +++ b/gdbserver/README @@ -125,8 +125,9 @@ Then start GDB (preferably in a different screen or window) and use the Repeat the same sequence of user commands to GDB that you gave in the original debug session. GDB should not be able to tell that it is talking -to GDBreplay rather than a real target, all other things being equal. Note -that GDBreplay echos the command lines to stderr, as well as the contents of -the packets it sends and receives. The last command echoed by GDBreplay is -the next command that needs to be typed to GDB to continue the session in -sync with the original session. +to GDBreplay rather than a real target, all other things being equal. + +As GDBreplay communicates with GDB, it outputs only the commands +it expects from GDB. The --debug-logging option turns printing the +remotelogfile to stderr on. GDBreplay then echos the command lines +to stderr, as well as the contents of the packets it sends and receives. diff --git a/gdbserver/gdbreplay.cc b/gdbserver/gdbreplay.cc index c2359e4ab43..cc8dc22c0fb 100644 --- a/gdbserver/gdbreplay.cc +++ b/gdbserver/gdbreplay.cc @@ -66,6 +66,7 @@ typedef int socklen_t; static int remote_desc_in; static int remote_desc_out; +bool debug_logging = 0; static void sync_error (FILE *fp, const char *desc, int expect, int got) @@ -259,13 +260,13 @@ remote_open (const char *name) } static int -logchar (FILE *fp) +logchar (FILE *fp, bool print) { int ch; int ch2; ch = fgetc (fp); - if (ch != '\r') + if (ch != '\r' && (print || debug_logging)) { fputc (ch, stderr); fflush (stderr); @@ -282,16 +283,22 @@ logchar (FILE *fp) ungetc (ch, fp); ch = '\r'; } - fputc (ch == EOL ? '\n' : '\r', stderr); - fflush (stderr); + if (print || debug_logging) + { + fputc (ch == EOL ? '\n' : '\r', stderr); + fflush (stderr); + } break; case '\n': ch = EOL; break; case '\\': ch = fgetc (fp); - fputc (ch, stderr); - fflush (stderr); + if (print || debug_logging) + { + fputc (ch, stderr); + fflush (stderr); + } switch (ch) { case '\\': @@ -316,14 +323,28 @@ logchar (FILE *fp) break; case 'x': ch2 = fgetc (fp); - fputc (ch2, stderr); - fflush (stderr); + if (print || debug_logging) + { + fputc (ch2, stderr); + fflush (stderr); + } ch = fromhex (ch2) << 4; ch2 = fgetc (fp); - fputc (ch2, stderr); - fflush (stderr); + if (print || debug_logging) + { + fputc (ch2, stderr); + fflush (stderr); + } ch |= fromhex (ch2); break; + case 'c': + fputc (ch, stderr); + fflush (stderr); + break; + case 'E': + fputc (ch, stderr); + fflush (stderr); + break; default: /* Treat any other char as just itself */ break; @@ -354,14 +375,14 @@ expect (FILE *fp) int fromlog; int fromgdb; - if ((fromlog = logchar (fp)) != ' ') + if ((fromlog = logchar (fp, false)) != ' ') { sync_error (fp, "Sync error during gdb read of leading blank", ' ', fromlog); } do { - fromlog = logchar (fp); + fromlog = logchar (fp, false); if (fromlog == EOL) break; fromgdb = gdbchar (remote_desc_in); @@ -386,12 +407,12 @@ play (FILE *fp) int fromlog; char ch; - if ((fromlog = logchar (fp)) != ' ') + if ((fromlog = logchar (fp, false)) != ' ') { sync_error (fp, "Sync error skipping blank during write to gdb", ' ', fromlog); } - while ((fromlog = logchar (fp)) != EOL) + while ((fromlog = logchar (fp, false)) != EOL) { ch = fromlog; if (write (remote_desc_out, &ch, 1) != 1) @@ -426,16 +447,27 @@ captured_main (int argc, char *argv[]) { FILE *fp; int ch; + char **next_arg = &argv[1]; - if (argc >= 2 && strcmp (argv[1], "--version") == 0) + while (*next_arg != NULL && **next_arg == '-') { - gdbreplay_version (); - exit (0); - } - if (argc >= 2 && strcmp (argv[1], "--help") == 0) - { - gdbreplay_usage (stdout); - exit (0); + if (argc >= 3 && strcmp (*next_arg, "--version") == 0) + { + gdbreplay_version (); + exit (0); + } + + else if (argc >= 3 && strcmp (*next_arg, "--help") == 0) + { + gdbreplay_usage (stdout); + exit (0); + } + else if (argc == 4 && strcmp (*next_arg, "--debug-logging") == 0) + debug_logging = 1; + else if (argc == 4) + fprintf (stderr, "Invalid option %s\n", *next_arg); + + next_arg++; } if (argc < 3) @@ -443,13 +475,14 @@ captured_main (int argc, char *argv[]) gdbreplay_usage (stderr); exit (1); } - fp = fopen (argv[1], "r"); + fp = fopen (*next_arg, "r"); if (fp == NULL) { - perror_with_name (argv[1]); + perror_with_name (*next_arg); } - remote_open (argv[2]); - while ((ch = logchar (fp)) != EOF) + next_arg++; + remote_open (*next_arg); + while ((ch = logchar (fp, false)) != EOF) { switch (ch) { @@ -462,10 +495,21 @@ captured_main (int argc, char *argv[]) play (fp); break; case 'c': - /* Command executed by gdb */ - while ((ch = logchar (fp)) != EOL); + /* We want to always print the command executed by GDB. */ + if (!debug_logging) + { + fprintf (stderr, "\n"); + fprintf (stderr, "Command expected from GDB:\n"); + } + while ((ch = logchar (fp, true)) != EOL); + break; + case 'E': + if (!debug_logging) + fprintf (stderr, "E"); + while ((ch = logchar (fp, true)) != EOL); break; } + } remote_close (); exit (0);