public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "moshe.rubin at gmail dot com" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug cli/30771] GDB needs a silent thread-selecting command akin to "select-frame"
Date: Fri, 18 Aug 2023 12:08:30 +0000	[thread overview]
Message-ID: <bug-30771-4717-erhdxPlZJa@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-30771-4717@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=30771

--- Comment #6 from Moshe Rubin <moshe.rubin at gmail dot com> ---
You were right - a local "pipe" custom command was getting automatically
loaded.  Sorry about that <g>.

Examining its code, and that of other solutions for passing internal command
output to an external program (https://stackoverflow.com/a/50359976), they all
suffer from the same drawback that they use gdb.execute(cmd, to_string=True)
and then pipe the output to the external tool. gdb.execute("thread 2",
to_string=True) returns the output as a string, but also displays it to the
screen.  The fact that gdb.execute(<cmd>, to_string=True) does not always
suppress screen output is a bug and should be fixed.created and fixed.

However, thanks to your comment about InferiorThread.switch(), I believe we
have a solution, even for gdb 8.2!

In my case, when gdb opens my core, I want to iterate over all threads in it
(i.e., the current inferior) without any screen output.

To determine the number of threads in the current inferior:

    (gdb) python print(len(gdb.selected_inferior().threads()))
    17

From the gdb command prompt, select each thread one at a time by specifying the
target thread object and calling the switch() function:

    (gdb) python gdb.selected_inferior().threads()[0].switch()
    (gdb) thread
    [Current thread is 17 (LWP 631)]
    (gdb) python gdb.selected_inferior().threads()[1].switch()
    (gdb) thread
    [Current thread is 16 (LWP 630)]
    (gdb) python gdb.selected_inferior().threads()[2].switch()
    (gdb) thread
    [Current thread is 15 (LWP 629)]
    . . .
    (gdb) python gdb.selected_inferior().threads()[16].switch()
    (gdb) thread
    [Current thread is 1 (LWP 598)]
    (gdb)

The main thing to note is the ability to switch/select a different thread with
*no* screen output.

Kudos and thanks to you, Tom, for suggesting this power user method.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

  parent reply	other threads:[~2023-08-18 12:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-16 15:41 [Bug gdb/30771] New: GDB need " moshe.rubin at gmail dot com
2023-08-16 17:37 ` [Bug cli/30771] " tromey at sourceware dot org
2023-08-16 17:58 ` [Bug cli/30771] GDB needs " moshe.rubin at gmail dot com
2023-08-16 18:15 ` moshe.rubin at gmail dot com
2023-08-16 22:27 ` tromey at sourceware dot org
2023-08-17  7:20 ` moshe.rubin at gmail dot com
2023-08-17 13:00 ` tromey at sourceware dot org
2023-08-18 12:08 ` moshe.rubin at gmail dot com [this message]
2024-05-08 18:47 ` tromey at sourceware dot org

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=bug-30771-4717-erhdxPlZJa@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).