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: Thu, 17 Aug 2023 07:20:04 +0000	[thread overview]
Message-ID: <bug-30771-4717-UmW0fpqDeo@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 #4 from Moshe Rubin <moshe.rubin at gmail dot com> ---
Hi Tom,

Your intriguing suggestion about using "pipe" (albeit in later versions of gdb)
got me thinking.

Checking two versions of gdb 8.2 my organization uses:

    GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1
    GNU gdb (GDB) 8.2.1

it turns out that they support an earlier version of "pipe":

    (gdb) help pipe
    Pipe gdb output via a shell command
      (gdb) pipe cmd1 cmd2
          is equivalent to
      $ cmd1 | cmd2

    Examples:
    pipe "p Vehicles::g_cliquer._members" "grep rectRaw"
    pipe "p g_invlut" "tail -10|sort -n"

(This differs from what I found in gdb 13.1:

    (gdb) help pipe
    pipe, |
    Send the output of a gdb command to a shell command.
    Usage: | [COMMAND] | SHELL_COMMAND
    Usage: | -d DELIM COMMAND DELIM SHELL_COMMAND
    Usage: pipe [COMMAND] | SHELL_COMMAND
    Usage: pipe -d DELIM COMMAND DELIM SHELL_COMMAND

    Executes COMMAND and sends its output to SHELL_COMMAND.

    The -d option indicates to use the string DELIM to separate COMMAND
    from SHELL_COMMAND, in alternative to |.  This is useful in
    case COMMAND contains a | character.

    With no COMMAND, repeat the last executed command
    and send its output to SHELL_COMMAND.)

I figured I'd give the older "pipe" a try, and found some intriguing but less
than satisfactory results.  Here is a session I had in 8.2.1 (the results in
8.1.1 are identical) with my comments based on the line numbers:

<session>
  1 (gdb) info thread 1 2 3
  2   Id   Target Id         Frame
  3 * 1    Thread 0x155538844700 (LWP 8876) __GI_raise (sig=sig@entry=6) at
../sysdeps/unix/sysv/linux/raise.c:51
  4   2    Thread 0x155538885700 (LWP 8875) 0x0000155552be3aa8 in hack_digit
(p=0x155538882480) at printf_fp.c:175
  5   3    Thread 0x155555354b00 (LWP 16327) 0x0000155554019ad3 in
futex_wait_cancelable (...) at ../sysdeps/unix/sysv/linux/futex-internal.h:88
  7
  8 (gdb) pipe "thread 2" "cat > /dev/null"
  9 [Switching to thread 2 (Thread 0x155538885700 (LWP 8875))]
 10 #0  0x0000155552be3aa8 in hack_digit (p=0x155538882480) at printf_fp.c:175
 11
 12 (gdb) pipe "thread 2" "cat > /dev/null"
 13
 14 (gdb) pipe "thread 3" "cat > /dev/null"
 15 [Switching to thread 3 (Thread 0x155555354b00 (LWP 16327))]
 16 #0  0x0000155554019ad3 in futex_wait_cancelable (...) at    
../sysdeps/unix/sysv/linux/futex-internal.h:88
 17
 18 (gdb) pipe "thread 3" "cat > /dev/null"
 19
 20 (gdb) pipe "thread 2" "cat > /dev/null"
 21 [Switching to thread 2 (Thread 0x155538885700 (LWP 8875))]
 22 #0  0x0000155552be3aa8 in hack_digit (p=0x155538882480) at printf_fp.c:175
 23
 24 (gdb) pipe "thread 2" "cat > /dev/null"
 25
 26 (gdb) thread 1
 27 [Switching to thread 1 (Thread 0x155538844700 (LWP 8876))]
 28 #0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
 29 51      ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
 30 (gdb) thread 1
 31 [Switching to thread 1 (Thread 0x155538844700 (LWP 8876))]
 32 #0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
 33 51      in ../sysdeps/unix/sysv/linux/raise.c
 34 (gdb) thread 1
 35 [Switching to thread 1 (Thread 0x155538844700 (LWP 8876))]
 36 #0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
 37 51      in ../sysdeps/unix/sysv/linux/raise.c
 38 (gdb)
 39
</session>

To simplify things, I only show the first three threads.  Here are the
findings:

+-------+---------+------------------+----------+--------------------------------------------+
| Lines | Mode    | Thread Selection | Visible? | Comment                      
             |
+-------+---------+------------------+----------+--------------------------------------------+
| 3     |         |                  |          | gdb session opens with thread
#1 selected  |
| 8-10  | pipe    | #1 -> #2         | yes      |                              
             |
| 12    | pipe    | #2 -> #2         | NO       | see lines 26-29 for VISIBLE
case (regular) |
| 14-16 | pipe    | #2 -> #3         | yes      |                              
             |
| 18    | pipe    | #3 -> #3         | NO       |                              
             |
| 20-22 | pipe    | #3 -> #2         | yes      |                              
             |
| 24    | pipe    | #2 -> #2         | NO       |                              
             |
| 26-29 | regular | #1 -> #1         | yes      |                              
             |
+-------+---------+------------------+----------+--------------------------------------------+

Using ">&" instead of ">" to pipe cat's output doesn't make a difference:

    (gdb) pipe "thread 3" "cat >& /dev/null"
    [Switching to thread 3 (Thread 0x155555354b00 (LWP 16327))]
    #0  0x0000155554019ad3 in futex_wait_cancelable (...) at
../sysdeps/unix/sysv/linux/futex-internal.h:88

When I left out the pipe character ">" I expected to see two identical outputs,
but it does not:

    (gdb) pipe "thread 3" "cat"
    [Switching to thread 3 (Thread 0x155555354b00 (LWP 16327))]
    #0  0x0000155554019ad3 in futex_wait_cancelable (...) at
../sysdeps/unix/sysv/linux/futex-internal.h:88
    88      in ../sysdeps/unix/sysv/linux/futex-internal.h
    (gdb)

-----------------------------------
Questions re gdb 8.2 "pipe" command:
-----------------------------------

(1) Why is it not silent when selecting between non-identical threads, but
silent with identical threads?
(2) Is there a way to get the 8.2 "pipe" to work correctly and silence the
output completely?

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

  parent reply	other threads:[~2023-08-17  7:20 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 [this message]
2023-08-17 13:00 ` tromey at sourceware dot org
2023-08-18 12:08 ` moshe.rubin at gmail dot com
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-UmW0fpqDeo@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).