From patchwork Fri Oct 18 09:42:33 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: 99137 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 887473858429 for ; Fri, 18 Oct 2024 09:43:41 +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.129.124]) by sourceware.org (Postfix) with ESMTP id 8940E3858404 for ; Fri, 18 Oct 2024 09:43:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8940E3858404 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 8940E3858404 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729244595; cv=none; b=ZS+TqSkLzzGhL/PMZf1P/49Nw/OK9lPuwP24+r26ECwV6y26RwsmOozOEKM7JA/pvWcUWbzofalLOIOxRmPVUeZJrNrqYZDe2oXFtPof3UgB5ZVG77gFCot+pXYgpXpwils9vqdPPvlpl2kJv1roRoGfwMZj7X9ZGXda8OZwwAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729244595; c=relaxed/simple; bh=yrHkyGVGvzE2VPHZcjounQRzLv0OuRhgbLCanQ8PcoY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vRlRgfkEBrpbhi23jImeTZv0JGpbwZm+LLu8Z0s2AGoJGtpWNeMxtpkQbwmmsZvwUexb326rXIqe1KmuMhaOnW1DFeih2js1XQ/LoiJbxKUIz3uhk7Q6ygMJFlm8Xcci58WKuKOIkMHpyg8XTEK+LVlppCO9VCGmim/7cJNkrXI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729244592; 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=mi+/5e+grCJH8LU083iADPf1/dXuK/Z+5rfozcVtRLM=; b=EPDARRk8dj19OKkhsaIbJh7C46tVMY10GCPVg2zyoWOCYAmIo6rytst/VuLp1EfvmrOvwq ez/8BzU4o5/r0UdjNRWfNys6iLF4+J4xSKugsGEpnwH83r4J9MneSpM1NcMMJrzrY9zz+B VRNGKee3S1D98rFvekVCei5prgl3zLc= Received: from mx-prod-mc-05.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-381-4KvhqUxrOhSxy-PEduhS5g-1; Fri, 18 Oct 2024 05:43:11 -0400 X-MC-Unique: 4KvhqUxrOhSxy-PEduhS5g-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 69048195609F for ; Fri, 18 Oct 2024 09:43:10 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.242.17]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EDB981956086; Fri, 18 Oct 2024 09:43:08 +0000 (UTC) From: =?utf-8?q?Alexandra_H=C3=A1jkov=C3=A1?= To: gdb-patches@sourceware.org Cc: ahajkova@redhat.com Subject: [PATCH v3 1/2] gdbreplay: Use getopt_long to parse command line arguments Date: Fri, 18 Oct 2024 11:42:33 +0200 Message-ID: <20241018094307.2434631-1-ahajkova@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.6 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 --- v3: - remove the unneeded chunk of the code gdbserver/gdbreplay.cc | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/gdbserver/gdbreplay.cc b/gdbserver/gdbreplay.cc index c2359e4ab43..7ef52b82d0b 100644 --- a/gdbserver/gdbreplay.cc +++ b/gdbserver/gdbreplay.cc @@ -57,6 +57,8 @@ #include "gdbsupport/netstuff.h" #include "gdbsupport/rsp-low.h" +#include "getopt.h" + #ifndef HAVE_SOCKLEN_T typedef int socklen_t; #endif @@ -425,30 +427,39 @@ gdbreplay_usage (FILE *stream) captured_main (int argc, char *argv[]) { FILE *fp; - int ch; - - if (argc >= 2 && strcmp (argv[1], "--version") == 0) + int ch, optc; + enum opts { OPT_VERSION = 1, OPT_HELP }; + static struct option longopts[] = { - gdbreplay_version (); - exit (0); - } - if (argc >= 2 && strcmp (argv[1], "--help") == 0) + {"version", no_argument, nullptr, OPT_VERSION}, + {"help", no_argument, nullptr, OPT_HELP}, + {nullptr, no_argument, nullptr, 0} + }; + + while ((optc = getopt_long (argc, argv, "", longopts, nullptr)) != -1) { - gdbreplay_usage (stdout); - exit (0); + switch (optc) + { + case OPT_VERSION: + gdbreplay_version (); + exit (0); + case OPT_HELP: + gdbreplay_usage (stdout); + exit (0); + } } - if (argc < 3) + if (optind + 2 != argc) { gdbreplay_usage (stderr); exit (1); } - fp = fopen (argv[1], "r"); + fp = fopen (argv[optind], "r"); if (fp == NULL) { - perror_with_name (argv[1]); + perror_with_name (argv[optind]); } - remote_open (argv[2]); + remote_open (argv[optind + 1]); while ((ch = logchar (fp)) != EOF) { switch (ch)