From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id QHnvKeTXyWdFKQcAWB0awg (envelope-from ) for ; Thu, 06 Mar 2025 12:14:12 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=A06nj7ph; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id A652A1E105; Thu, 6 Mar 2025 12:14:12 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.0 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 1FD961E08E for ; Thu, 6 Mar 2025 12:14:12 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C21AE3858417 for ; Thu, 6 Mar 2025 17:14:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C21AE3858417 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=A06nj7ph 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 C0835385840C for ; Thu, 6 Mar 2025 17:10:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C0835385840C 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 C0835385840C 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=1741281041; cv=none; b=BTToDA8BcO46ymSzcuWIt/5ffxmlNmbvc80s3jaJdTImR/CbRAyuY5THc+a3gATXk6XNs8r1Twn3QDpRLxz95BI3qGxulreh5xN4u8ROOkbSwJTlspp03FYaH6I7SS8JttdYqQTnAE2mgcHSNXW9hpf+7OPuaHZidPEPAQmGKBo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741281041; c=relaxed/simple; bh=ZVU+es+S6fPYZIFyfP0SJgeNTx9ARAmO8c5x/QeZQQY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=NQ+0wkL7fqYeTx6l0YFBnHziDcsatCajjTPJ4Z/5Jy65qYEuC1nDpET/vrF1f8N9GRfKRd7MCrd0fw7QvtiZM3Nj6nI8Ubd4z73qaaH24lwn+A7Vmnh3gPB2dopCJ7b6NZkepwy60f9N16AKEb59vNMdCU5UpetNJQHaxdPjpP0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C0835385840C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741281041; 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: in-reply-to:in-reply-to:references:references; bh=NBIlVAOFwujV0JTyX53Se9AGSDRp+hZlsxFYuXCgemo=; b=A06nj7phVCRDC0HGQ5ztMxvU57lfg+Rq45j0qGI5EpT5ELAnUGwVDcr0R+5i3zqg/fcxnd MVYnDXVRMZiseqlVPtLaErB1cscXw5DPDxsnCDL9Fgvbjfsjvon2sfGmmSHvyPfeBtqGbw T/Aqb/nAzGTyMjOLiT0eXu4GGvBMlOE= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-144-rD2DRuPyMA-RgJbGkgmpcQ-1; Thu, 06 Mar 2025 12:10:35 -0500 X-MC-Unique: rD2DRuPyMA-RgJbGkgmpcQ-1 X-Mimecast-MFC-AGG-ID: rD2DRuPyMA-RgJbGkgmpcQ_1741281034 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-5e5d8a28de7so864118a12.2 for ; Thu, 06 Mar 2025 09:10:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741281033; x=1741885833; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NBIlVAOFwujV0JTyX53Se9AGSDRp+hZlsxFYuXCgemo=; b=Px1Ys73GSQk7Alxb8qygh0DegrZwObyy4ZkxvhC3Tb5NJ/u0txSu2HHtAzYTo60QuD BxLOtZsq0qWCwqOErxvqxDCRhQPb9Gy6r80dqCkLZlC1Xx5bj65iOn3W+7T3obOAMOs2 oSsRnzGZgbLt/Csy3C1PIE4CQ+qW//bj8N+uRjLKT8+g5Bex8tftEgK4EdCF8XD74Qdr xK7ViGFPHkjbOAcF5TTi+iJ5g1XdDbzAinsnsAcx8rzWAxmT7/oOHqnYJ+cNwuO3eXrC 0IAtjYkFEpboSuSSxmQ8AaFXFSgKq5K/RZiQQtwFmytwK5dS5uk95/TELzw3L/5G8dNL m6QA== X-Gm-Message-State: AOJu0Yx47p6By+eY7g0ExYRZFRgp3r4tni4Yjy4Dt41hkdW1V88p0JVN pbCywHdBCCw76HM/2mcWu3LP1oxBqH7pNF2owJO41TvfuJXz9vl6a0iF+HNdVLMhA0jBYW9I4zp SCIEuI6jdJafzgp3QAvOLfV2eJ3C+UHgVRCxgNx427QrX/yeUm/SyXLWrIXDn/YMsdBUuU1uubj BEPe+gEPoKrqbMeD1dE9OAQpJ3OiF493+prq76PJTurpA= X-Gm-Gg: ASbGncujhVv+iLSloo1uaViIKFlLMjnOOnY/GKafQrpW4rBy221izH77rlRo4WbRgr+ 2GkkbN5KEFhgiQpsZ2GFIkEhh+UJWJ9GQNHbQH5aPMZ0sydf5ksFNzTOZlmnTkh2hxG2xBNQQ4k RDAx3KK2BjW8AJjch94kVQLWMlNmrDP4Xca8eMtelNG1oxHiqOfW4h8M071FLpkI0d2AgyytVQs XPZXxz0TojYWfbwy76QSkmuc41esl4vEqaxiv2z1sNsrnso9qKnk/8P7N+AMPZqZxNJcbGIygwk EZdcUPfQ+5ofGaXtFYhL6HwyGhDo/aI6gLc= X-Received: by 2002:a05:6402:254a:b0:5e0:b542:fb32 with SMTP id 4fb4d7f45d1cf-5e59f3edf53mr8528057a12.19.1741281033185; Thu, 06 Mar 2025 09:10:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IGprO+UNtmnRtUPEQj7DkIox/kb358EruIXjnsKqltxFCACf5DOJQHabEYGbXBGgyvp9Tn9Gw== X-Received: by 2002:a05:6402:254a:b0:5e0:b542:fb32 with SMTP id 4fb4d7f45d1cf-5e59f3edf53mr8528018a12.19.1741281032737; Thu, 06 Mar 2025 09:10:32 -0800 (PST) Received: from localhost (52.72.115.87.dyn.plus.net. [87.115.72.52]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5e5c745d5cfsm1204086a12.19.2025.03.06.09.10.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Mar 2025 09:10:32 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 2/3] gcore: add -h|--help options, and improve help/usage message output Date: Thu, 6 Mar 2025 17:10:23 +0000 Message-ID: <6276f9ffdcfab6aadd5cc46c646197923a6c1043.1741280898.git.aburgess@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: OtAQj4tzPMEN3p55T1I4FYZ7IrlT9txtzOlML3avUxU_1741281034 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true 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~public-inbox=simark.ca@sourceware.org Like the previous commit, this copies a lot from: commit fb2ded33c1e519659743047ed7817166545b6d91 Date: Fri Dec 20 12:46:11 2024 -0800 Add gstack script And adds -h | --help options to the gcore script, and smartens up the help and usage output messages. The usage text is now split over several lines (as it was getting a bit long), and an input error suggests using `--help` instead of printing the full usage string. These changes bring gcore and gstack closer in behaviour. --- gdb/NEWS | 3 ++- gdb/doc/gdb.texinfo | 6 +++++- gdb/gcore-1.in | 50 ++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index d4453914755..5d9d9fb3063 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -27,7 +27,8 @@ * Linux checkpoint code has been updated to work with multiple inferiors. * The gcore script now has a -v or --version option, which prints the - version number, and then exits. + version number, and then exits. As well as a -h or --help option, + which prints each options and a brief description. * New commands diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 1ab87dd37f9..a1ae45c5121 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -51386,7 +51386,7 @@ gcore man @format @c man begin SYNOPSIS gcore -gcore [-v | --version] [-a] [-o @var{prefix}] [-d @var{directory}] +gcore [-v | --version] [-h | --help] [-a] [-o @var{prefix}] [-d @var{directory}] @var{pid1} [@var{pid2}...@var{pidN}] @c man end @end format @@ -51420,6 +51420,10 @@ gcore man Use @var{directory} as the data directory when invoking @value{GDBN} for running the gcore command. This argument is optional. +@item --help +@itemx -h +List all options, with brief explanations. + @item --version @itemx -v Print version information and then exit. diff --git a/gdb/gcore-1.in b/gdb/gcore-1.in index ce2f7321148..129e3697fb7 100644 --- a/gdb/gcore-1.in +++ b/gdb/gcore-1.in @@ -32,11 +32,38 @@ dump_all_cmds=() data_directory_opt=() +function print_usage() { + prefix="Usage: $0" + paddin=$(printf '%*s' ${#prefix}) + + echo "$prefix [-h|--help] [-v|--version]" + echo "$paddin [-a] [-o prefix] [-d data-directory]" + echo "$paddin pid1 [pid2...pidN]" +} + +function print_try_help() { + echo "Try '$0 --help' for more information." +} + +function print_help() { + print_usage + echo + echo "Create a core file of a running program using GDB." + echo + echo " -h, --help Print this message then exit." + echo " -v, --version Print version information then exit." + echo " -a Dump all memory mappings." + echo " -o prefix Use 'prefix.pid' as the core file name." + echo " The default prefix is 'core'." + echo " -d dir Pass '--data-directory dir' as an argument" + echo " to GDB." +} + function print_version() { echo "GNU gcore (${PKGVERSION}) ${VERSION}" } -while getopts :vao:d:-: OPT; do +while getopts vhao:d:-: OPT; do if [ "$OPT" = "-" ]; then OPT="${OPTARG%%=*}" OPTARG="${OPTARG#'$OPT'}" @@ -58,13 +85,26 @@ while getopts :vao:d:-: OPT; do d) data_directory_opt=("--data-directory" "$OPTARG") ;; + h | help) + print_help + exit 0 + ;; v | version) print_version exit 0 ;; + \?) + # getopts has already output an error message. + print_try_help 1>&2 + exit 2 + ;; *) - echo "usage: @GCORE_TRANSFORM_NAME@ [-v | --version] [-a] [-o prefix] [-d data-directory] pid1 [pid2...pidN]" - exit 2 + # Unknown single character options are handled by the \? + # case above. This is formatted to match the error + # getopts gives for an unknown single character option. + echo "$0: illegal option -- $OPT" 1>&2 + print_try_help 1>&2 + exit 2 ;; esac done @@ -73,8 +113,8 @@ shift $((OPTIND-1)) if [ "$#" -eq "0" ] then - echo "usage: @GCORE_TRANSFORM_NAME@ [-a] [-o prefix] [-d data-directory] pid1 [pid2...pidN]" - exit 2 + print_usage 1>&2 + exit 1 fi # Attempt to fetch the absolute path to the gcore script that was -- 2.47.1