From patchwork Thu Sep 29 08:25:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 58136 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4553B3858424 for ; Thu, 29 Sep 2022 08:26:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4553B3858424 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664439962; bh=DeouU68BPWGg2zfwyMbwkl2xomLzS5sirm4lhT69SDc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=qgX+XI4jWeGj5P6NA01zCVOzCBo7HcHa56BBXKOSBdg+NQ9qmHLLI76zR8TbqcAtD uaUi+IAocAwUdksNGA1hEkaHwYqHzkJg76in0SJ5XvD68H4W1414IA1NAHXUgpqGKi c21KrXIZzhLCMDikNa1LsXc4rH/14fku29h3awbo= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 02CE53858418 for ; Thu, 29 Sep 2022 08:25:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 02CE53858418 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id ED8E71F45B; Thu, 29 Sep 2022 08:25:36 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D30CA13A71; Thu, 29 Sep 2022 08:25:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id VJY/MoBWNWPlGAAAMHmgww (envelope-from ); Thu, 29 Sep 2022 08:25:36 +0000 Date: Thu, 29 Sep 2022 10:25:35 +0200 To: gdb-patches@sourceware.org Subject: [PATCH][gdb/debuginfod] Ask to cancel further downloads Message-ID: <20220929082534.GA22465@delia.home> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Hi, Say you're debugging an executable and debug info is being downloaded for shared libraries, and you want to cancel all downloading, there's no option but to keep ^C-ing: ... $ 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... Downloading separate debug info for system-supplied DSO at 0x7ffff7fc6000... ^CCancelling download of separate debug info for system-supplied DSO at 0x7ffff7fc6000... Downloading 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". Temporary breakpoint 1, main () at /home/vries/hello.c:6 6 printf ("hello\n"); (gdb) ... While this is doable for the 3 shared libraries in this example session, it becomes burdensome if there are many. Add a new command "set debuginfod cancel one/all/ask", where: - "one" means ^C cancels one download, - "all" means ^C cancels all further downloads, and - "ask" means ^C asks whether to cancel all further downloads. A "yes" implies "set debuginfod cancel all", and a "no" implies "set debuginfod cancel one", so the question is only asked once. Note that the behaviour as it was before this patch is equivalent to "set debuginfod cancel one". Instead, the new default is "set debuginfod cancel ask". Note that cancelling all further downloads implies "set debuginfod enabled off". An example session looks like: ... $ 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. To re-enable use the 'set debuginfod enabled on' command. [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) ... Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29582 Suggested-By: Martin Liška Co-Authored-By: Aaron Merey Any comments? Thanks, - Tom [gdb/debuginfod] Ask to cancel further downloads --- gdb/debuginfod-support.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ gdb/doc/gdb.texinfo | 20 ++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c index 5f04a2b38ca..a1180016600 100644 --- a/gdb/debuginfod-support.c +++ b/gdb/debuginfod-support.c @@ -33,6 +33,8 @@ static cmd_list_element *show_debuginfod_prefix_list; static const char debuginfod_on[] = "on"; static const char debuginfod_off[] = "off"; static const char debuginfod_ask[] = "ask"; +static const char debuginfod_one[] = "one"; +static const char debuginfod_all[] = "all"; static const char *debuginfod_enabled_enum[] = { @@ -42,6 +44,20 @@ static const char *debuginfod_enabled_enum[] = nullptr }; +/* Valid values for set debuginfod cancel command. */ + +static const char *debuginfod_cancel_enum[] = +{ + debuginfod_one, + debuginfod_all, + debuginfod_ask, + nullptr +}; + +/* Value of debuginfod cancellation mode. */ + +static const char *debuginfod_cancel = debuginfod_ask; + static const char *debuginfod_enabled = #if defined(HAVE_LIBDEBUGINFOD) debuginfod_ask; @@ -119,6 +135,20 @@ 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)); + 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.\nTo re-enable use the" + " 'set debuginfod enabled on' command.\n")); + debuginfod_enabled = debuginfod_off; + } return 1; } @@ -393,6 +423,33 @@ show_debuginfod_enabled (ui_file *file, int from_tty, cmd_list_element *cmd, "\"%s\".\n"), debuginfod_enabled); } +/* Set callback for "set debuginfod cancel". */ + +static void +set_debuginfod_cancel (const char *value) +{ + debuginfod_cancel = value; +} + +/* Get callback for "set debuginfod cancel". */ + +static const char * +get_debuginfod_cancel () +{ + return debuginfod_cancel; +} + +/* Show callback for "set debuginfod cancel". */ + +static void +show_debuginfod_cancel (ui_file *file, int from_tty, cmd_list_element *cmd, + const char *value) +{ + gdb_printf (file, + _("Debuginfod cancellation mode is currently set to " + "\"%s\".\n"), debuginfod_cancel); +} + /* Set callback for "set debuginfod urls". */ static void @@ -473,6 +530,21 @@ source files."), &set_debuginfod_prefix_list, &show_debuginfod_prefix_list); + add_setshow_enum_cmd ("cancel", class_run, debuginfod_cancel_enum, + _("Set cancellation mode for debuginfod."), + _("Show cancellation mode for debuginfod."), + _("\ +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\ +When set to all, ^C cancels all further downloads.\n\ +When set to ask, ^C asks what to do."), + set_debuginfod_cancel, + get_debuginfod_cancel, + show_debuginfod_cancel, + &set_debuginfod_prefix_list, + &show_debuginfod_prefix_list); + /* set/show debuginfod urls */ add_setshow_string_noescape_cmd ("urls", class_run, _("\ Set the list of debuginfod server URLs."), _("\ diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 238a49b027d..718f42fbc02 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -48035,6 +48035,26 @@ is set to @code{ask} for interactive sessions. Display whether @code{debuginfod enabled} is set to @code{on}, @code{off} or @code{ask}. +@kindex set debuginfod cancel +@anchor{set debuginfod cancel} +@item set debuginfod cancel +@itemx set debuginfod cancel one +@cindex debuginfod cancellation mode +Pressing @code{^C} will cancel one download. + +@item set debuginfod cancel all +Pressing @code{^C} will cancel all further downloads. + +@item set debuginfod cancel ask +Pressing @code{^C} will prompt the user to cancel all further downloads before +attempting to perform the next query. By default, @code{debuginfod cancel} +is set to @code{ask} for interactive sessions. + +@kindex show debuginfod cancel +@item show debuginfod cancel +Display whether @code{debuginfod cancel} is set to @code{one}, @code{all} or +@code{ask}. + @kindex set debuginfod urls @cindex configure debuginfod URLs @item set debuginfod urls