Bug 29582 - Usability improvement: CTRL+C when debugindod client is downloading a file
Summary: Usability improvement: CTRL+C when debugindod client is downloading a file
Status: NEW
Alias: None
Product: gdb
Classification: Unclassified
Component: cli (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 29581 (view as bug list)
Depends on:
Blocks:
 
Reported: 2022-09-18 08:20 UTC by Martin Liska
Modified: 2024-02-22 22:28 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
tentative patch (1.74 KB, patch)
2022-09-28 15:09 UTC, Tom de Vries
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Liska 2022-09-18 08:20:39 UTC
Let's imagine you're debugging a binary with many shared libs and you're in the middle of downloading debuginfo of the shared libs, you press CTRL+C.

At that point, the running downloading is terminated and gdb continues downloading the next debug info. I would expect to be asked if I want to terminate all future downloading or not. Having that one can easily exit a debugging session instead of waiting for the cancelation of all the downloading stuff.

Example:

[                                                                                                                                                                                           ]^CCancelling download of separate debug info for /lib64/libzypp.so.1722...
Downloading 13.35 MB separate debug info for /lib64/libstdc++.so.6                                                                                                                           
[###                                                                                                                                                                                        ]^CCancelling download of separate debug info for /lib64/libstdc++.so.6...
Downloading 0.37 MB separate debug info for /lib64/libgcc_s.so.1                                                                                                                             
[#############################################################                                                                                                                              ]^CCancelling download of separate debug info for /lib64/libgcc_s.so.1...
Downloading 5.93 MB separate debug info for /lib64/libc.so.6                                                                                                                                 
[##                                                                                                                                                                                         ]^CCancelling download of separate debug info for /lib64/libc.so.6...
[Thread debugging using libthread_db enabled]                                                                                                                                                
Using host libthread_db library "/lib64/libthread_db.so.1".
^CCancelling download of separate debug info for /lib64/librpm.so.9...
^CCancelling download of separate debug info for /lib64/libz.so.1...
^CCancelling download of separate debug info for /lib64/libboost_thread.so.1.80.0...
^C^CCancelling download of separate debug info for /lib64/libglib-2.0.so.0...
^CCancelling download of separate debug info for /lib64/libcrypto.so.1.1...
^CCancelling download of separate debug info for /lib64/libsigc-2.0.so.0...
^CCancelling download of separate debug info for /lib64/libzstd.so.1...
^CCancelling download of separate debug info for /lib64/libzck.so.1...
^CCancelling download of separate debug info for /lib64/libtinfo.so.6...
^CCancelling download of separate debug info for /lib64/libfa.so.1...
^CCancelling download of separate debug info for /lib64/liblzma.so.5...
^CCancelling download of separate debug info for /lib64/libm.so.6...
^CCancelling download of separate debug info for /lib64/librpmio.so.9...
^CCancelling download of separate debug info for /lib64/libpopt.so.0...
^CCancelling download of separate debug info for /lib64/libcap.so.2...
^CCancelling download of separate debug info for /lib64/libacl.so.1...
^CCancelling download of separate debug info for /lib64/libassuan.so.0...
^CCancelling download of separate debug info for /lib64/libgpg-error.so.0...
^CCancelling download of separate debug info for /lib64/libnghttp2.so.14...
^CCancelling download of separate debug info for /lib64/libidn2.so.0...
^CCancelling download of separate debug info for /lib64/libssh.so.4...
^CCancelling download of separate debug info for /lib64/libpsl.so.5...
^CCancelling download of separate debug info for /lib64/libssl.so.1.1...
^CCancelling download of separate debug info for /lib64/libgssapi_krb5.so.2...
^CCancelling download of separate debug info for /lib64/libldap.so.2...
^CCancelling download of separate debug info for /lib64/liblber.so.2...
^CCancelling download of separate debug info for /lib64/libbrotlidec.so.1...
^CCancelling download of separate debug info for /lib64/libpcre.so.1...
^CCancelling download of separate debug info for /lib64/libgcrypt.so.20...
^CCancelling download of separate debug info for /lib64/libbz2.so.1...
^CCancelling download of separate debug info for /lib64/liblua5.4.so.5...
^CCancelling download of separate debug info for /lib64/libunistring.so.2...
^CCancelling download of separate debug info for /lib64/libkrb5.so.3...
^CCancelling download of separate debug info for /lib64/libk5crypto.so.3...
^CCancelling download of separate debug info for /lib64/libcom_err.so.2...
^CCancelling download of separate debug info for /lib64/libkrb5support.so.0...
^CCancelling download of separate debug info for /lib64/libsasl2.so.3...
^CCancelling download of separate debug info for /lib64/libbrotlicommon.so.1...
^CCancelling download of separate debug info for /lib64/libkeyutils.so.1...
^CCancelling download of separate debug info for /lib64/libresolv.so.2...
^CCancelling download of separate debug info for /lib64/libselinux.so.1...
^CCancelling download of separate debug info for /lib64/libpcre2-8.so.0...
[New Thread 0x7ffff60c76c0 (LWP 22188)]
^C
Thread 1 "Zypp-main" received signal SIGINT, Interrupt.
0x00007ffff7307c1e in fstatat64 () from /lib64/libc.so.6
Missing separate debuginfos, use: zypper install zypper-debuginfo-1.14.56-1.1.x86_64
(gdb) Quit(gdb) Quit
Comment 1 Tom de Vries 2022-09-18 08:34:34 UTC
*** Bug 29581 has been marked as a duplicate of this bug. ***
Comment 2 Tom de Vries 2022-09-20 11:28:40 UTC
This seems to work:
...
diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c
index 5f04a2b38ca..69dad2b9b86 100644
--- a/gdb/debuginfod-support.c
+++ b/gdb/debuginfod-support.c
@@ -119,6 +119,12 @@ progressfn (debuginfod_client *c, long cur, long total)
       gdb_printf ("Cancelling download of %s %ps...\n",
                  data->desc,
                  styled_string (file_name_style.style (), data->fname));
+      int resp = nquery (_("Cancel further downloading for this session? "));

+      if (resp)
+       {
+         gdb_printf (_("Debuginfod has been disabled.\n"));
+         debuginfod_enabled = debuginfod_off;
+       }
       return 1;
     }
 
...
Comment 3 Tom de Vries 2022-09-20 13:59:25 UTC
Example session:
...
$ gcc ~/hello.c -g
$ rm -Rf ~/.cache/debuginfod_client/
$ gdb -q -iex "set debuginfod enabled on" a.out -ex start
Reading symbols from a.out...
Temporary breakpoint 1 at 0x40113a: file /home/vries/hello.c, line 6.
Starting program: /data/vries/gdb_versions/devel/a.out 
Downloading separate debug info for /lib64/ld-linux-x86-64.so.2...
^CCancelling download of separate debug info for /lib64/ld-linux-x86-64.so.2...
Cancel further downloading for this session? (y or [n]) y
Debuginfod has been disabled.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Temporary breakpoint 1, main () at /home/vries/hello.c:6
6         printf ("hello\n");
(gdb) info shared
From                To                  Syms Read   Shared Object Library
0x00007ffff7fc90a0  0x00007ffff7ff0025  Yes (*)     /lib64/ld-linux-x86-64.so.2
0x00007ffff7dd6700  0x00007ffff7f3bd8d  Yes (*)     /lib64/libc.so.6
(*): Shared library is missing debugging information.
(gdb) 
...
Comment 4 Martin Liska 2022-09-20 15:36:27 UTC
I like it Tom, thanks for it.
Comment 5 Aaron Merey 2022-09-22 00:16:15 UTC
(In reply to Tom de Vries from comment #2)
> diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c
> index 5f04a2b38ca..69dad2b9b86 100644
> --- a/gdb/debuginfod-support.c
> +++ b/gdb/debuginfod-support.c
> @@ -119,6 +119,12 @@ progressfn (debuginfod_client *c, long cur, long total)
>        gdb_printf ("Cancelling download of %s %ps...\n",
>                   data->desc,
>                   styled_string (file_name_style.style (), data->fname));
> +      int resp = nquery (_("Cancel further downloading for this session?
> "));
> 
> +      if (resp)
> +       {
> +         gdb_printf (_("Debuginfod has been disabled.\n"));
> +         debuginfod_enabled = debuginfod_off;
> +       }
>        return 1;
>      }

As long as debuginfod remains enabled gdb will query the user every time they cancel a download. I think it would be preferable for gdb to remember when the user answered "n" so that individual downloads can be cancelled without having to answer the query each time.

Maybe we should also add a gdb command such as 'set debuginfod cancel-all on/off' so that the behavior of ctrl-c during downloads can be set without having to answer the query every session. 'on' could mean ctrl-c disables debuginfod while 'off' only cancels the current download.
Comment 6 Tom de Vries 2022-09-28 15:09:19 UTC
(In reply to Aaron Merey from comment #5)
> (In reply to Tom de Vries from comment #2)
> > diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c
> > index 5f04a2b38ca..69dad2b9b86 100644
> > --- a/gdb/debuginfod-support.c
> > +++ b/gdb/debuginfod-support.c
> > @@ -119,6 +119,12 @@ progressfn (debuginfod_client *c, long cur, long total)
> >        gdb_printf ("Cancelling download of %s %ps...\n",
> >                   data->desc,
> >                   styled_string (file_name_style.style (), data->fname));
> > +      int resp = nquery (_("Cancel further downloading for this session?
> > "));
> > 
> > +      if (resp)
> > +       {
> > +         gdb_printf (_("Debuginfod has been disabled.\n"));
> > +         debuginfod_enabled = debuginfod_off;
> > +       }
> >        return 1;
> >      }
> 
> As long as debuginfod remains enabled gdb will query the user every time
> they cancel a download. I think it would be preferable for gdb to remember
> when the user answered "n" so that individual downloads can be cancelled
> without having to answer the query each time.
> 
> Maybe we should also add a gdb command such as 'set debuginfod cancel-all
> on/off' so that the behavior of ctrl-c during downloads can be set without
> having to answer the query every session. 'on' could mean ctrl-c disables
> debuginfod while 'off' only cancels the current download.

Good points.

I've come up with "set debuginfod cancel one/all/ask" to address these.
Comment 7 Tom de Vries 2022-09-28 15:09:43 UTC
Created attachment 14367 [details]
tentative patch
Comment 8 Aaron Merey 2022-09-29 02:23:21 UTC
(In reply to Tom de Vries from comment #7)
> Created attachment 14367 [details]
> tentative patch

Thanks for the patch, I think this works nicely. I just have a couple suggestions regarding some of the wording. 

> +      if (debuginfod_cancel == debuginfod_ask)
> +	{
> +	  int resp = nquery (_("Cancel further downloading for this session? "));
> +	  if (resp)
> +	    debuginfod_cancel = debuginfod_all;
> +	  else
> +	    debuginfod_cancel = debuginfod_one;
> +	}
> +      if (debuginfod_cancel == debuginfod_all)
> +	{
> +	  gdb_printf (_("Debuginfod has been disabled.\n"));

Here it could be useful to include instructions for how to re-enable debuginfod. Something like: 
"Debuginfod has been disabled. To re-enable use the 'set debuginfod enabled on' command."

> +  add_setshow_enum_cmd ("cancel", class_run, debuginfod_cancel_enum,
> +			_("Set cancellation mode for debuginfod."),
> +			_("Show cancellation mode for debuginfod."),
> +			_("\
> +When set to one, ^C cancels a single download.\n\
> +When set to all, ^C cancels all further downloads.\n\
> +When set to ask, ^C asks what to do."),

To be extra clear about what the cancellation mode is I'd add the following line:

The cancellation mode controls the behavior of ^C while a file is downloading from debuginfod.\n\
When set to one, ^C cancels a single download.\n\
...
Comment 10 Hannes Domani 2024-01-10 17:09:36 UTC
(In reply to Tom de Vries from comment #9)
> https://sourceware.org/pipermail/gdb-patches/2022-September/192188.html

I wonder why this patch was never pushed.
Comment 11 Aaron Merey 2024-02-22 22:28:09 UTC
(In reply to Hannes Domani from comment #10)
> (In reply to Tom de Vries from comment #9)
> > https://sourceware.org/pipermail/gdb-patches/2022-September/192188.html
> 
> I wonder why this patch was never pushed.

I've updated this patch and reposted it to gdb-patches

https://sourceware.org/pipermail/gdb-patches/2024-February/206331.html