Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Keith Seitz <keiths@redhat.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH v2] Add gstack script
Date: Fri, 13 Dec 2024 11:57:46 -0800	[thread overview]
Message-ID: <6f928801-dbde-4559-86ef-8aa28baa164f@redhat.com> (raw)
In-Reply-To: <87seqre59x.fsf@tromey.com>

On 12/13/24 11:45 AM, Tom Tromey wrote:
>>>>>> "Keith" == Keith Seitz <keiths@redhat.com> 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


  reply	other threads:[~2024-12-13 20:03 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-25 18:18 [PATCH] " Keith Seitz
2024-12-11 16:51 ` Andrew Burgess
2024-12-11 16:58   ` Keith Seitz
2024-12-12 21:07 ` [PATCH v2] " Keith Seitz
2024-12-13  7:36   ` Eli Zaretskii
2024-12-13 18:21     ` Keith Seitz
2024-12-13 19:04       ` Eli Zaretskii
2024-12-13 19:45   ` Tom Tromey
2024-12-13 19:57     ` Keith Seitz [this message]
2024-12-18 18:05 ` [PATCH v3] " Keith Seitz
2024-12-18 19:22   ` Eli Zaretskii
2024-12-18 21:47     ` Keith Seitz
2024-12-20 16:15   ` Tom Tromey
2024-12-20 18:18     ` Keith Seitz
2024-12-20 18:26       ` Tom Tromey
2024-12-20 20:47         ` Keith Seitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6f928801-dbde-4559-86ef-8aa28baa164f@redhat.com \
    --to=keiths@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox