Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Kevin Buettner <kevinb@redhat.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: Re: [PATCH] Add QUIT to inner loop in value_print_array_elements
Date: Fri, 25 Sep 2026 17:26:57 -0700	[thread overview]
Message-ID: <20260925172315.20eb519c@f44-mesa-1> (raw)
In-Reply-To: <20260922201202.2189948-1-tromey@adacore.com>

On Tue, 22 Sep 2026 14:12:02 -0600
Tom Tromey <tromey@adacore.com> wrote:

> When printing an array, some work is done to detect repeated elements.
> This work is not interruptible, and it is somewhat slow (see
> PR exp/32681).
> 
> This patch adds QUITs to the relevant spots.

My AI-enabled patch review workflow confirmed Gwen's finding.
It said:

    Finding 1 -- the dominant uninterruptible loop is in char-print.c,
    not the array code.

    I profiled the exact repro from the thread (perf record on a
    patched build, 8 MiB static char p[], "print p"). 99% of samples
    are:

      print_command_1 -> print_value -> value_print -> c_value_print
	-> c_value_print_array -> printstr -> generic_printstr
	-> count_next_character -> iterate -> gdb_iconv -> iconv
	(98.98%)

    value_print_array_elements never appears. The reason is
    gdb/c-valprint.c:259: a char array that passes
    c_textual_element_type is printed through
    current_language->printstr -- the string path -- which entirely
    bypasses the code this patch modifies.

    Two measurements confirm this on the patched build (maint time
    1, print elements 10, max-value-size unlimited). A char array of
    8 MiB, printed through generic_printstr and iconv, takes 43.3 s.
    An int array of the same 8 MiB, which goes through
    value_print_array_elements, takes 0.29 s.

    So Guinevere's "you may have missed a spot" is correct, and the
    missed spot is char-print.c:279. The outer loop there, at
    char-print.c:525, already has a QUIT at line 529, but it only
    runs once per distinct character -- for a uniform array the
    inner while (1) consumes all 8M characters inside a single outer
    iteration, which is why the existing QUIT never fires.

    The fix is small: event-top.h is already included at
    char-print.c:21, so adding a QUIT as the first statement of the
    while (1) body at line 279 would do it, either in this patch or
    in an immediate follow-up. The commit message might also be
    softened: "This patch adds QUITs to the relevant spots" reads as
    a complete fix for the PR 17613 symptom, which it is not.

AI model used was GLM 5.3 Flash.  It had 3 other findings too, but
they were minor.

Kevin


      parent reply	other threads:[~2026-09-26  0:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22 20:12 Tom Tromey
2026-09-24 20:36 ` Guinevere Larsen
2026-09-26  0:26 ` Kevin Buettner [this message]

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=20260925172315.20eb519c@f44-mesa-1 \
    --to=kevinb@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@adacore.com \
    /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