From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id D012E3858409 for ; Fri, 1 Mar 2024 00:12:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D012E3858409 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D012E3858409 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709251966; cv=none; b=LNZSQs18+r4kOUxUZ59ZUkG5eRJbofIiIWM2FemqQANZf+q9eDD2NN1wj0BE05uMxl8lTRvEVTtdzbAfZSWTaV2v1cNClGBXAlxQaLLCDL9BHADC8mjpkkUv5MRcvHXlGZWns4kbc1SSdCky/DIJJW/wVLx1Znbx3Dag7WH8f1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709251966; c=relaxed/simple; bh=Nz1Drdb08NFqku7t4n0aZYesVlCAmoi0PsR6ojPy2jY=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=hfxh8UqniYfBlEG/ElH+bT7TtHjz3EE2TROrFDC6YlM9KDoL5GyGVTqCvSHvhCMpV8gYvJkrE5aSKctOAIW0P3mSJQMJ3deKvKCZnbkSqAyyFGb17hK1x5T0Fdg33M50Iw8M/4UgMA1mmobyRjEKQiLYsdHaxaNvxT+TeXSjFkk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709251961; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rNXqfnjcWJE8+UVHarSjoNFBWw2nVzzFaGCo0cXTUss=; b=fsfWa62JRUtMQY92eXIIeGLh1cinS8lBBr7WoVCB6gZ7rsttxkrVIbVkZmbyuslkeWDR9u ctg815Vq0tu/SaP95q/7xZ7qzNDp01MRDDPcqneN8p0B+nl6i1aKKFoIsRYTdDIS6s4uIB PXt70d/Kbtj/yV5a4xh6E9YXRIS9Eno= Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-306-1JsJDglKNtaUEakVmMIOcA-1; Thu, 29 Feb 2024 19:12:38 -0500 X-MC-Unique: 1JsJDglKNtaUEakVmMIOcA-1 Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-299ba5ae65eso1217072a91.3 for ; Thu, 29 Feb 2024 16:12:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709251956; x=1709856756; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rNXqfnjcWJE8+UVHarSjoNFBWw2nVzzFaGCo0cXTUss=; b=PopvrjBCsAEOvA7L6ARSqcsDwKWdszA1r5pQvJregSe4jHSpnZEPiqpbTSg/474NW3 LusOSHYT4f1zKYVkHShRFeZ37DFwPj0Kt8mWvevED/rptHSAxA8meAUFP8BY7cergSNZ uF8sCEQjAZE0dyx96fs/cI/0yW0bQudvYRIBcbuQkvNGc/ioLGluBACfcosh5lX4rHZ7 t9uv3j6+b/rR0b4qkpgi7cHJWQFHa5e4GdM+VNmeCvbyUWqY6i91uem9X+P5uRK1M7ZC TttPAno/AuIk+JYf7a+5jGJrw5jZjpDy2RZXJy5KbEKa47cc4UJGW6RMLgodNNCY1lRF Td5g== X-Gm-Message-State: AOJu0YxeU5l+tdzVw8fDAGnr/n03vcSHmebTxc1/t8yUBZYtDCYWQcan SRUHikOSaKRCiJ0TXCqezhpG/Z7I0Cc5USzoYCXVRiJR+9hC29sXtjE1cCpgp09OldolKTbRwub ywujtXBDjKUJoWQI5cCYOr16jKnKDJGveBNWRYBDMED/5l0fHpiilNLVY8yn3L81valTIVw+ODo qkL4aeBWGmFKvpe3mScPNqKMbSFzAMNqcOQQf33mMn X-Received: by 2002:a17:90a:db54:b0:29b:f71:a58 with SMTP id u20-20020a17090adb5400b0029b0f710a58mr194511pjx.21.1709251956505; Thu, 29 Feb 2024 16:12:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IEBOOmA0zZAuZ3fbnSHYTBZBQk55tq4VEkRutLDjTG7VTHhfNzjUOaXF3yZZrdQldhjqUAO0edLrwNkhE53bBI= X-Received: by 2002:a17:90a:db54:b0:29b:f71:a58 with SMTP id u20-20020a17090adb5400b0029b0f710a58mr194478pjx.21.1709251955538; Thu, 29 Feb 2024 16:12:35 -0800 (PST) MIME-Version: 1.0 References: <20240203021515.705567-1-amerey@redhat.com> In-Reply-To: From: Aaron Merey Date: Thu, 29 Feb 2024 19:12:24 -0500 Message-ID: Subject: [PING*2][PATCH v4] gdb/debuginfod: Ctrl-C asks to cancel further downloads To: gdb-patches@sourceware.org Cc: Tom de Vries , Eli Zaretskii X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Fri, Feb 23, 2024 at 3:07=E2=80=AFAM Eli Zaretskii wrote: > > Sorry for missing this. The documentation parts of this patch are > okay. > > Reviewed-By: Eli Zaretskii Thanks Eli. Ping re. the non-documentation parts of the patch. Aaron On Thu, Feb 22, 2024 at 5:26=E2=80=AFPM Aaron Merey wro= te: > > Ping > > Thanks, > Aaron > > On Fri, Feb 2, 2024 at 9:15=E2=80=AFPM Aaron Merey wr= ote: > > > > v3: https://sourceware.org/pipermail/gdb-patches/2023-March/197679.html > > > > v4 includes changes needed to apply the patch to the current master bra= nch. > > > > Currently gdb only allows for debuginfod downloads to be cancelled one = at > > a time via Ctrl-C. This can be a burden if one wishes to cancel a larg= e > > series of downloads. Additionally there can also be ambiguity between = whether > > Ctrl-C during a download was intended to cancel a download or interrupt= the > > inferior. > > > > This patch addresses these issues by adding a new debuginfod setting an= d > > changing the behavior of Ctrl-C during a download. > > > > Add a new command "set debuginfod cancel one/all/ask", where: > > - "one" means Ctrl-C cancels one download, > > - "all" means Ctrl-C cancels all further downloads, and > > - "ask" means Ctrl-C asks whether to cancel all further downloads. A "= yes" > > implies "set debuginfod cancel all", and a "no" implies "set debuginf= od > > 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 debuginf= od > > cancel ask". Note that cancelling all further downloads implies "set > > debuginfod enabled off". > > > > A single Ctrl-C during downloading now sets the quit_flag and proceeds = with > > all downloads. If the inferior has the terminal, then a second Ctrl-C = during > > downloading triggers a query asking whether to cancel the download or > > interrupt the inferior. If the user wishes to cancel the download then > > the setting of 'set debuginfod cancel' determines whether one or all > > downloads are cancelled. In the case of "set debuginfod cancel ask", > > there will be another query at this point asking whether to cancel one > > or all downloads. > > > > If the inferior does not have the terminal, then a second Ctrl-C during > > downloading simply cancels the download according to the setting of > > "set debuginfod cancel". In this case there is no query asking whether > > to interrupt the inferior or cancel a download. > > > > Example session where inferior has terminal: > > > > (gdb) run > > [...] > > Downloading separate debug info for /lib64/libxyz.so > > [### ]^C= ^C > > Cancel the current download? > > If no, then Ctrl-C will be sent to the target process. ([y] or n) y > > Cancelling download of separate debug info for /lib64/libxyz.so... > > Cancel further downloading for this session? (y or [n]) n > > Downloading separate debug info for /lib64/libabcd.so > > > > Example session where inferior does not have terminal: > > > > (gdb) run > > [...] > > Downloading separate debug info for /lib64/libxyz.so > > [### ]^C= ^C > > Cancelling download of separate debug info for /lib64/libxyz.so... > > Cancel further downloading for this session? (y or [n]) y > > Debuginfod has been disabled. > > To re-enable use the 'set debuginfod enabled' command. > > > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D29582 > > Suggested-By: Martin Li=C5=A1ka > > Co-Authored-By: Tom de Vries > > --- > > gdb/debuginfod-support.c | 183 +++++++++++++++++++++++++++++++++++++-- > > gdb/doc/gdb.texinfo | 21 +++++ > > 2 files changed, 199 insertions(+), 5 deletions(-) > > > > diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c > > index 7d8ada39e96..97d4b2f2bac 100644 > > --- a/gdb/debuginfod-support.c > > +++ b/gdb/debuginfod-support.c > > @@ -38,6 +38,8 @@ static cmd_list_element *maint_show_debuginfod_cmdlis= t; > > static const char debuginfod_on[] =3D "on"; > > static const char debuginfod_off[] =3D "off"; > > static const char debuginfod_ask[] =3D "ask"; > > +static const char debuginfod_one[] =3D "one"; > > +static const char debuginfod_all[] =3D "all"; > > > > static const char *debuginfod_enabled_enum[] =3D > > { > > @@ -47,6 +49,20 @@ static const char *debuginfod_enabled_enum[] =3D > > nullptr > > }; > > > > +/* Valid values for set debuginfod cancel command. */ > > + > > +static const char *debuginfod_cancel_enum[] =3D > > +{ > > + debuginfod_one, > > + debuginfod_all, > > + debuginfod_ask, > > + nullptr > > +}; > > + > > +/* Value of debuginfod cancellation mode. */ > > + > > +static const char *debuginfod_cancel =3D debuginfod_ask; > > + > > static const char *debuginfod_enabled =3D > > #if defined(HAVE_LIBDEBUGINFOD) > > debuginfod_ask; > > @@ -109,9 +125,11 @@ debuginfod_section_query (const unsigned char *bui= ld_id, > > struct user_data > > { > > user_data (const char *desc, const char *fname) > > - : desc (desc), fname (fname) > > + : pass_quit_flag (false), inf_had_term (false), desc (desc), fname= (fname) > > { } > > > > + bool pass_quit_flag; > > + bool inf_had_term; > > const char * const desc; > > const char * const fname; > > ui_out::progress_update progress; > > @@ -156,10 +174,83 @@ progressfn (debuginfod_client *c, long cur, long = total) > > if (check_quit_flag ()) > > { > > ui_file *outstream =3D get_unbuffered (gdb_stdout); > > - gdb_printf (outstream, _("Cancelling download of %s %s...\n"), > > - data->desc, styled_fname.c_str ()); > > - return 1; > > - } > > + > > + /* If a single Ctrl-C occurs during downloading, let it propagat= e to the > > + target. If more than one Ctrl-C occurs, ask whether to cancel= the > > + current download or interrupt the target. If the download is > > + cancelled, the setting of debuginfod_cancel will determine whe= ther > > + the current download is cancelled or debuginfod is disabled. = */ > > + if (!data->pass_quit_flag) > > + data->pass_quit_flag =3D true; > > + else > > + { > > + int resp =3D 1; > > + bool extra_nl =3D false; > > + > > + if (data->inf_had_term) > > + { > > + /* If Ctrl-C occurs during the following prompts, catch t= he > > + exception to prevent unsafe early returns to gdb's mai= n > > + event loop. During these prompts, Ctrl-C is equivalen= t to > > + answering 'y'. */ > > + try > > + { > > + resp =3D yquery (_("Cancel the current download?\nIf = no, " > > + "then Ctrl-C will be sent to the tar= get " > > + "process. ")); > > + } > > + catch (const gdb_exception &) > > + { > > + /* If the query doesn't complete, then we need an add= itional > > + newline to get "Cancelling download of..." printed= on a > > + separate line. */ > > + extra_nl =3D true; > > + } > > + } > > + if (resp) > > + { > > + if (extra_nl) > > + { > > + gdb_printf (outstream, "\n"); > > + extra_nl =3D false; > > + } > > + > > + gdb_printf (outstream, _("Cancelling download of %s %s...= \n"), > > + data->desc, styled_fname.c_str (= )); > > + if (debuginfod_cancel =3D=3D debuginfod_ask) > > + { > > + try > > + { > > + resp =3D nquery > > + (_("Cancel further downloading for this session= ? ")); > > + } > > + catch (const gdb_exception &) > > + { > > + resp =3D 1; > > + extra_nl =3D true; > > + } > > + > > + if (resp) > > + debuginfod_cancel =3D debuginfod_all; > > + else > > + debuginfod_cancel =3D debuginfod_one; > > + } > > + if (debuginfod_cancel =3D=3D debuginfod_all) > > + { > > + if (extra_nl) > > + gdb_printf (outstream, "\n"); > > + > > + gdb_printf (outstream, > > + _("Debuginfod has been disabled.\nTo re-e= nable " > > + "use the 'set debuginfod enabled' comma= nd.\n")); > > + debuginfod_enabled =3D debuginfod_off; > > + } > > + > > + data->pass_quit_flag =3D false; > > + return 1; > > + } > > + } > > + } > > > > if (debuginfod_verbose =3D=3D 0) > > return 0; > > @@ -330,6 +421,10 @@ debuginfod_source_query (const unsigned char *buil= d_id, > > user_data data ("source file", srcpath); > > > > debuginfod_set_user_data (c, &data); > > + > > + if (!target_terminal::is_ours ()) > > + data.inf_had_term =3D true; > > + > > if (target_supports_terminal_ours ()) > > { > > term_state.emplace (); > > @@ -341,6 +436,11 @@ debuginfod_source_query (const unsigned char *buil= d_id, > > build_id_len, > > srcpath, > > &dname)); > > + if (data.pass_quit_flag) > > + set_quit_flag (); > > + if (data.inf_had_term && term_state.has_value ()) > > + target_terminal::inferior (); > > + > > debuginfod_set_user_data (c, nullptr); > > } > > > > @@ -376,6 +476,10 @@ debuginfod_debuginfo_query (const unsigned char *b= uild_id, > > user_data data ("separate debug info for", filename); > > > > debuginfod_set_user_data (c, &data); > > + > > + if (!target_terminal::is_ours ()) > > + data.inf_had_term =3D true; > > + > > if (target_supports_terminal_ours ()) > > { > > term_state.emplace (); > > @@ -384,6 +488,12 @@ debuginfod_debuginfo_query (const unsigned char *b= uild_id, > > > > fd =3D scoped_fd (debuginfod_find_debuginfo (c, build_id, build_id= _len, > > &dname)); > > + > > + if (data.pass_quit_flag) > > + set_quit_flag (); > > + if (data.inf_had_term && term_state.has_value ()) > > + target_terminal::inferior (); > > + > > debuginfod_set_user_data (c, nullptr); > > } > > > > @@ -419,6 +529,10 @@ debuginfod_exec_query (const unsigned char *build_= id, > > user_data data ("executable for", filename); > > > > debuginfod_set_user_data (c, &data); > > + > > + if (!target_terminal::is_ours ()) > > + data.inf_had_term =3D true; > > + > > if (target_supports_terminal_ours ()) > > { > > term_state.emplace (); > > @@ -427,6 +541,11 @@ debuginfod_exec_query (const unsigned char *build_= id, > > > > fd =3D scoped_fd (debuginfod_find_executable (c, build_id, build_i= d_len, > > &dname)); > > + if (data.pass_quit_flag) > > + set_quit_flag (); > > + if (data.inf_had_term && term_state.has_value ()) > > + target_terminal::inferior (); > > + > > debuginfod_set_user_data (c, nullptr); > > } > > > > @@ -467,6 +586,10 @@ debuginfod_section_query (const unsigned char *bui= ld_id, > > { > > user_data data (desc.c_str (), filename); > > debuginfod_set_user_data (c, &data); > > + > > + if (!target_terminal::is_ours ()) > > + data.inf_had_term =3D true; > > + > > if (target_supports_terminal_ours ()) > > { > > term_state.emplace (); > > @@ -475,6 +598,12 @@ debuginfod_section_query (const unsigned char *bui= ld_id, > > > > fd =3D scoped_fd (debuginfod_find_section (c, build_id, build_id_l= en, > > section_name, &dname)); > > + > > + if (data.pass_quit_flag) > > + set_quit_flag (); > > + if (data.inf_had_term && term_state.has_value ()) > > + target_terminal::inferior (); > > + > > debuginfod_set_user_data (c, nullptr); > > } > > > > @@ -523,6 +652,33 @@ show_debuginfod_enabled (ui_file *file, int from_t= ty, cmd_list_element *cmd, > > "\"%s\".\n"), debuginfod_enabled); > > } > > > > +/* Set callback for "set debuginfod cancel". */ > > + > > +static void > > +set_debuginfod_cancel (const char *value) > > +{ > > + debuginfod_cancel =3D 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 > > @@ -627,6 +783,23 @@ When set to \"ask\", prompt whether to enable or d= isable debuginfod." ), > > &set_debuginfod_prefix_list, > > &show_debuginfod_prefix_list); > > > > + add_setshow_enum_cmd ("cancel", class_run, debuginfod_cancel_enum, > > + _("Set Ctrl-C behaviour for debuginfod."), > > + _("Show Ctrl-C behaviour for debuginfod."), > > + _("\ > > +When set to \'one\', pressing Ctrl-C twice cancels a single \ > > +download.\nWhen set to \'all\', pressing Ctrl-C twice cancels all furt= her downloads.\n\ > > +When set to \'ask\', pressing Ctrl-C twice asks what to do.\nA single = Ctrl-C during \ > > +downloading is passed to the target process being debugged.\nA second = Ctrl-C \ > > +during downloading may raise a prompt asking whether to cancel the dow= nload or \ > > +send Ctrl-C to the target.\nIf the download is cancelled, then no Ctrl= -C is \ > > +sent to the target."), > > + 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 e98c15242bc..d6df28896b1 100644 > > --- a/gdb/doc/gdb.texinfo > > +++ b/gdb/doc/gdb.texinfo > > @@ -50259,6 +50259,27 @@ is set to @code{ask} for interactive sessions. > > Display whether @code{debuginfod enabled} is set to @code{on}, @code{o= ff} or > > @code{ask}. > > > > +@kindex set debuginfod cancel > > +@anchor{set debuginfod cancel} > > +@item set debuginfod cancel > > +@itemx set debuginfod cancel one > > +@cindex debuginfod @kbd{Ctrl-C} behaviour > > +Pressing @kbd{Ctrl-C} twice during downloading will cancel the current > > +download. > > + > > +@item set debuginfod cancel all > > +Pressing @kbd{Ctrl-C} twice during downloading will cancel this and al= l > > +further downloads. > > + > > +@item set debuginfod cancel ask > > +Pressing @kbd{Ctrl-C} twice during downloading will cancel the current > > +download and prompt whether to cancel all further downloads. By defau= lt, > > +@code{debuginfod cancel} is set to @code{ask} for interactive sessions= . > > + > > +@kindex show debuginfod cancel > > +@item show debuginfod cancel > > +Display the current setting of @code{debuginfod cancel}. > > + > > @kindex set debuginfod urls > > @cindex configure debuginfod URLs > > @item set debuginfod urls > > -- > > 2.43.0 > >