From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id WK43EhCTXGca/RUAWB0awg (envelope-from ) for ; Fri, 13 Dec 2024 15:03:28 -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=LKeOr59E; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 474EA1E097; Fri, 13 Dec 2024 15:03:28 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.1 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,RCVD_IN_SBL_CSS autolearn=unavailable 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 E0A7E1E091 for ; Fri, 13 Dec 2024 15:03:27 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7FFF23858D35 for ; Fri, 13 Dec 2024 20:03:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7FFF23858D35 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=LKeOr59E 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 A959C3858D21 for ; Fri, 13 Dec 2024 20:02:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A959C3858D21 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 A959C3858D21 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=1734120174; cv=none; b=sAxiP740/EeBeF1CtrRYCs2U0MPlyU4FVIYD7RNkaxq+bSqWMFxVIURggyvVztzJaMtPMtqLptTj9MJlVc3shkfi/6D2N6zLzTkj+oguEaO/bv8L1lFd9pkRcFuTx2D+mrtNYVHf4XdD1N2ADlOJ2WK7jORAHipYvpLuYGL8P8I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1734120174; c=relaxed/simple; bh=SQB5xjCA7zOrhYtTYpK6XJzjUA6ZpFq5ggf0mwQfjV4=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=ko38VDqRFyuw8h25rTpfrXyRvAGUEyVk8aI7IhN4p3jNdr1rb2WV/FwUAUeRLZkxDqsM2uh+uxurZH3Ferv1HUafFySVNey+vyOrkpWJHRqJpL28JkPP4lv092HEdlf94E3zVgGKIa5zptO5y8yeGlHPkC2sH+XjFCcdhkraDHQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A959C3858D21 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734120174; 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=5tSYlUqEjCxNqr09BniosXWXR0MxpLd2FrAJ2UwgN1E=; b=LKeOr59EBJpQJuAEuLDz3lZvX2b4038kSRmGahZ8SF7IP9thQw03Y5geo6q3hz5DnTzT0c dwc3owxBVTYNL9jX3cXaoq9A70D8BIYZVXpruL470r+e0Hz49V0pq7V22GNRCzos4PXXZP nAQaXLGaLN2czTHfsVM1Z1aaMoxST8o= Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-412-eBtsKB6uPTe0yBDdP912fA-1; Fri, 13 Dec 2024 15:02:53 -0500 X-MC-Unique: eBtsKB6uPTe0yBDdP912fA-1 X-Mimecast-MFC-AGG-ID: eBtsKB6uPTe0yBDdP912fA Received: by mail-oi1-f198.google.com with SMTP id 5614622812f47-3eb33ef5448so1516304b6e.1 for ; Fri, 13 Dec 2024 12:02:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734120172; x=1734724972; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5tSYlUqEjCxNqr09BniosXWXR0MxpLd2FrAJ2UwgN1E=; b=OAsytq5UOrpb1SsFnCsx5Bo045jRjm7l1A7XbJKSMDFKvXt4qU0afgeEJjI8mG3lxh HJ89N56ebi1OjB8094ZmX1Qg12ay45Q4F5cZuHsbbjIYh2E1Am2b5TtbcOYCGyqyYvdm 3ujleUfZFiO3RBUR7KlB4vCIcsNKluN4Ynbu5KvzAGDdZPnvqfnS5PzMoDI5oekn0ZNm 7zb4+hVmRrfhL7ZLN05RnP1pYAop0ZyC+KzX2S2/zkqcAdCNo8VpdtiyrmzBRY9QBpmb vPx5N3/O0d5H/m9c2kFYrexecJZ1KN7hMnaWfjVLK+pO7im4QLLmD5sKgSMEkfT/aclc EBuQ== X-Gm-Message-State: AOJu0YxQn4WdVagApjht55LvCt5kCsebNa7L2vRJfurqEIwDfYJbdHeL 3c1tw7XVuAjVKtMtZRlpXjAWD85/QyLMHUeQ9wEbmfGYB83y+5kz9oyoVvart3vm6d9VfzGjXq7 89UE6MIMR3y3lHG+4eiyTa2EPmudcLoZtvxTutW5d9ODbCASkHhlOn0JVNj1pjrVIUMs= X-Gm-Gg: ASbGnctCHc92AW4qRaX3XExZgUDO1pJJkSyJkOkFT8dH/r2r72THqO9hCr++oI1Mpaw Va3H3tJpJ+n1taGXBTbNc4bcuPfuxr2UGL85yLJx845RpG5WV0enEiHPNFqgtM3Y7Ewk4CwMuJ+ jX1j+iu1vL9jT0OTY95a6IwT+yLARAJmpxtnFpyzejZW3ugvq2t6YXssGGS3rMRpBTQP3ZlC3kI u7wD49ix0+KmxphB1lesEMMiKHe7hw1rblv1J0gqIlZlhyOA7AQcs0tNM3K2w== X-Received: by 2002:a05:6808:4445:b0:3e7:644e:3cab with SMTP id 5614622812f47-3eba6815b4fmr2313322b6e.7.1734120172357; Fri, 13 Dec 2024 12:02:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IEbr17/wT37mtfjLrOt+nuJeRm83sqBiuSRptj18acDlkDnpnnhJCIxApwvgr71grWunGO4fw== X-Received: by 2002:a17:902:ebcc:b0:215:9894:5670 with SMTP id d9443c01a7336-218929a26c6mr62744775ad.16.1734119868649; Fri, 13 Dec 2024 11:57:48 -0800 (PST) Received: from [150.1.200.127] ([172.56.107.48]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-218a1db78adsm1509375ad.16.2024.12.13.11.57.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 13 Dec 2024 11:57:48 -0800 (PST) Message-ID: <6f928801-dbde-4559-86ef-8aa28baa164f@redhat.com> Date: Fri, 13 Dec 2024 11:57:46 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] Add gstack script To: Tom Tromey Cc: gdb-patches@sourceware.org References: <08a19a3debe4a1e3c6072a807e79566277a7c0dc.1734022384.git.keiths@redhat.com> <87seqre59x.fsf@tromey.com> From: Keith Seitz In-Reply-To: <87seqre59x.fsf@tromey.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Bo9KJUWsGwoCXSnFwlp83pLT6QJwLpaJ2qDfmtNRbI0_1734120172 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 On 12/13/24 11:45 AM, Tom Tromey wrote: >>>>>> "Keith" == Keith Seitz writes: > > Keith> The script includes suggestions from gdb/32325 to include > Keith> versioning and help. [If this approach to gdb/32325 is acceptable, > Keith> I could propagate the solution to gcore/gdb-add-index.] > > This would be super. I will get that on my TODO list, then. > > Keith> +function print_try_help() { > Keith> + echo "Try '$0 --help' for more information." > > This should probably print to stderr. > > Keith> +function print_help() { > Keith> + print_usage > > Here, print_usage should print to stdout. So maybe this later spot: > > Keith> +# The sole remaining argument should be the PID of the process > Keith> +# whose backtrace is desired. > Keith> +if [ $# -ne 1 ]; then > Keith> + print_usage > > ... should redirect to stderr. Yeah, I will audit/adjust this. > > Keith> +define attach-bt > Keith> +attach \$arg0 > Keith> +echo "ATTACHED" > Keith> +thread apply all bt > Keith> +end > Keith> +attach-bt $PID > > I'm curious to understand why this is wrapped in a 'define'. By wrapping in a command like this, we can abort doing the backtrace if there was a problem attaching to a PID. Otherwise, if the attach fails, using a series of "-ex" options won't abort, and the terminal will be "spammed" with not-too-helpful error messages. Example: $ gdb -batch -ex "attach 1234" -ex "bt" ptrace: No such process. No stack. Admittedly, using "thread apply all bt full" does mitigate some of this, but IIRC, I ran into other use cases where we would see a additional, unhelpful error messages like demonstrated above. Motivation: Fedora's original version of gstack checked /proc/$PID and output an error message if that didn't exist. This, of course, only works on systems that support procfs. This is an attempt to include more than just those systems. Furthermore, (again with Fedora's original implementation) if gdb could not attach to a valid PID (e.g., 1), Fedora's gstack simply exited silently. This should fix that use case, too. It's almost certainly not going to work everywhere, but it works pretty well for Linux, and I figure that's a start. Keith