From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id cEbNNYTlMWlhfBkAWB0awg (envelope-from ) for ; Thu, 04 Dec 2025 14:48:20 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Fm/fHEVJ; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id CDF921E0B3; Thu, 04 Dec 2025 14:48:20 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=no autolearn_force=no version=4.0.1 Received: from sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 34B311E08D for ; Thu, 04 Dec 2025 14:48:20 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A6DA94C31831 for ; Thu, 4 Dec 2025 19:48:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A6DA94C31831 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Fm/fHEVJ Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 9F1F04BC89A1 for ; Thu, 4 Dec 2025 19:47:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9F1F04BC89A1 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine 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 9F1F04BC89A1 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=1764877655; cv=none; b=xXlQFDP29KDe6HMb5YgTWaCryDTPk6Dgfb2jxsc6lFurfxvWbox9xfyQYrBlPy4uXtKhfNvKgR8h0xMytbbQ7gSe1wsN7Fa2VHikMMUmRHrGiitdULQ4aoAgCXbgggJXpl+td1hRs4aCpEYJcFxne9JATp6CVVZ9qL5A6HdebnE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1764877655; c=relaxed/simple; bh=KbJBbmpDZOOtPjzxLNl25/8WG+PmHluJMDhZrgB0ZvQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=X+uBuexLpB2b17qnSSXJXuAANCwNM5DTUGo3Qqi4vyXNahseE/+Vszs75gCQeliWi28LrLXWFLipvQyc/x5fCLseqLId//S7y9YE5ucwTbLrXCBtWsAOTtd6Hldzp31ngMc1nfwmf2inOX40OtF+gLMAvExjpoS2sOVOIOKw8Mk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9F1F04BC89A1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764877655; 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=UQShQqYewYGfFGGHsekEjKXh6Opvyz/x2drb5Ph9nss=; b=Fm/fHEVJgkLu7lU8rqpBKDgDxJbhhWoq34GJIecnUGP2X6Aphopxmn7xhpp4lplzTgD7xU qLSRO1gih2icalMtguQbCpTAradm1OoYTNfKVw9eSEwqWjSywoSmgcAcloxhVzJElgQ8q7 DU7FypaIIVM9NQj/9iwOTYRdKph+jVQ= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-686-PUlOxuZNM1yFq5Q-soNKiA-1; Thu, 04 Dec 2025 14:47:34 -0500 X-MC-Unique: PUlOxuZNM1yFq5Q-soNKiA-1 X-Mimecast-MFC-AGG-ID: PUlOxuZNM1yFq5Q-soNKiA_1764877653 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-42b487cda00so771367f8f.3 for ; Thu, 04 Dec 2025 11:47:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764877652; x=1765482452; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=UQShQqYewYGfFGGHsekEjKXh6Opvyz/x2drb5Ph9nss=; b=rpkrvxs9Bo3Wnbwk4jOZ7JpiEhimLni+q4+J8b4mYQQ+JHmHu5pfwBfidNs3ZLaKD7 CwOQumww/svVZ9iEnwNgnfOzmm9w6zv8MZsiQ7xtr04+SKx71in9X+7WPx/oM2emAFl9 360Z46Ei6sYRDAKCt4oOFpoQdzzD+irUbjd0A81+STY6cxmS6Xa4VZ7ARRYRRt8iJPG1 mUTQSmwuAYe4QzXmAGR3QdqbZmhAISsXD3t51S+rK8Ew7iihpKZ9JaHNJ/l83aHlhQaj s2u8By1TyC9YIH6UCaorit3OkOLC6wdljJd2x135bqwF8iSBHirw1bEn9BnJr6NgQatR Kh8g== X-Gm-Message-State: AOJu0YwAwdBgetvQp1saOyDiSU4dICpBkMZD6JxgZfivcbXDq0i+Pl1k Ot3+li19wezN/vt2cpfpg4aJwFF35hJ7WtOMlMTjuoTEDZHpIGJYz8qAsGpt6R+/HRMOaKoG3k2 r+F9f53iOA5qg4kMQbAdNvDM7Wf6lY+eW38bHPpIV75mDLAu4T7/SEm8mtB5D1sMK8UFhYkf/L8 54QJmShQQW/4UWX7Bjh19OeMU58f5MDfWvDWQ8Y/22j0bVNJo= X-Gm-Gg: ASbGncvh19pcHtpoX++ZxQH2Dp+sYrYEQ5vVcjWD07Qc90YNZrYs88StAeXyYNusvOY ZZq3eDMKzMOhRrDqR4kWtETaGTyRz/X9a6bs7aw8CkGoVwcfAg7T+Dklyz3sOB5q4764VRsmpca A+XQv+DEVm7vFxFyNugW4UKghFUY48disEBMEqWyXKMivsUcj4vnKlN+t7/C9RvQgX/poftG+vH PSlkmwpVygFFD0JC6vrE81J+gcBpD+DmwZQN/zynfsyBo2XHPMGmRtEZSN63W/H/XD/a82LZF0T hGauBpJDnYUdypNpsM0zWTZJUE/xrbB9yQhg66RWe+oAP6wq3kb14LOnQXYgRe4TGMQ7OR0csi1 QI+6h X-Received: by 2002:a05:6000:1acc:b0:429:bc68:6c95 with SMTP id ffacd0b85a97d-42f731c302amr7389740f8f.47.1764877652235; Thu, 04 Dec 2025 11:47:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IF6jHOQB0aMWpZb0uwSWmt+HEPRGlvwx5gvJsdDRQUEAGlJWxom4iHrihmvPviy4WuWhEqnVw== X-Received: by 2002:a05:6000:1acc:b0:429:bc68:6c95 with SMTP id ffacd0b85a97d-42f731c302amr7389717f8f.47.1764877651725; Thu, 04 Dec 2025 11:47:31 -0800 (PST) Received: from localhost ([31.111.84.207]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42f7cbe9070sm4746004f8f.7.2025.12.04.11.47.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Dec 2025 11:47:31 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Guinevere Larsen Subject: [PATCH 1/2] gdb: make get_chars_per_line return an unsigned value Date: Thu, 4 Dec 2025 19:47:24 +0000 Message-ID: <3114f2c93bed492dc8cb0aadcd426d68e94e7a33.1764877519.git.aburgess@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 4Ueksga02D1OUCH_yJHr4hyZYiwQRD8PhHXuPOWQwJc_1764877653 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org I noticed that get_chars_per_line currently returns an 'int', but the value it is returning, from utils.c, is an 'unsigned int'. In some cases this can cause weird behaviour as an unlimited width terminal will have UINT_MAX characters per line, which will appear as negative when returned from get_chars_per_line. This has been the case since get_chars_per_line was added in commit: commit 2f2287318b33ddf855a692fcc191f6b25caf4644 Date: Wed Dec 16 18:18:40 2020 +0100 [gdb/cli] Add a progress meter Lets make get_chars_per_line return an unsigned value, and update all the uses of this function to hold the result in an unsigned variable. I ran into this issue when looking at print_gdb_hints (from top.c) where a very large get_chars_per_line() value would appear negative, and so the startup hints would be printed without a box when really they should have been boxed. Someone else noticed this problem while I was building this patch, and pushed commit: commit 06e470d8fc0ae0e83fe0977fdf8c011998980891 Date: Sat Nov 29 15:48:55 2025 +0100 gdb: handle unlimited screen width case in print_gdb_hints this commit reverts that earlier commit in favour of fixing the type of 'width'. There are other bugs in this code relating to how 'width' is handled, but they are fixed in the next commit. Additionally, in cli-out.c I've had to add some additional code so that the progress bars are disabled when the screen width is unlimited. Previously, an unlimited screen width would appear as a negative value, which was less than MIN_CHARS_PER_LINE, so the progress bars would be disabled. Our existing debuginfod tests rely on this. To minimise disruption to the tests, for now, I've updated the code in cli-out.c so that we specifically disable progress bars when the screen width is unlimited, as it is during our tests. It would be better, in the future, if we had a separate setting to disable progress bars, and the testsuite could use this. There's no tests with this commit yet as print_gdb_hints has other bugs which will be fixed in the next commit. At this point I'll add some tests. Reviewed-By: Guinevere Larsen --- gdb/cli-out.c | 10 ++++++---- gdb/top.c | 10 +++++----- gdb/utils.c | 3 ++- gdb/utils.h | 5 +++-- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/gdb/cli-out.c b/gdb/cli-out.c index 27a82f607eb..137ff13ef5d 100644 --- a/gdb/cli-out.c +++ b/gdb/cli-out.c @@ -298,7 +298,7 @@ cli_ui_out::do_progress_notify (const std::string &msg, const char *unit, double howmuch, double total) { - int chars_per_line = get_chars_per_line (); + unsigned int chars_per_line = get_chars_per_line (); struct ui_file *stream = get_unbuffered (m_streams.back ()); cli_progress_info &info (m_progress_info.back ()); @@ -322,7 +322,8 @@ cli_ui_out::do_progress_notify (const std::string &msg, } if (info.state != progress_update::BAR - || chars_per_line < MIN_CHARS_PER_LINE) + || chars_per_line < MIN_CHARS_PER_LINE + || chars_per_line == UINT_MAX) return; if (total > 0 && howmuch >= 0 && howmuch <= 1.0) @@ -385,14 +386,15 @@ void cli_ui_out::clear_progress_notify () { struct ui_file *stream = get_unbuffered (m_streams.back ()); - int chars_per_line = get_chars_per_line (); + unsigned int chars_per_line = get_chars_per_line (); scoped_restore save_pagination = make_scoped_restore (&pagination_enabled, false); if (!stream->isatty () || !current_ui->input_interactive_p () - || chars_per_line < MIN_CHARS_PER_LINE) + || chars_per_line < MIN_CHARS_PER_LINE + || chars_per_line == UINT_MAX) return; if (chars_per_line > MAX_CHARS_PER_LINE) diff --git a/gdb/top.c b/gdb/top.c index 1214101ad18..1aefe74b394 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -1414,7 +1414,7 @@ box_one_message (ui_file *stream, std::string message, int width) void print_gdb_hints (struct ui_file *stream) { - int width = get_chars_per_line (); + unsigned int width = get_chars_per_line (); /* Arbitrarily setting maximum width to 80 characters, so that things are big and visible but not overwhelming. */ @@ -1439,10 +1439,10 @@ print_gdb_hints (struct ui_file *stream) styled_string (command_style.style (), "apropos ")); /* If there isn't enough space to display the longest URL in a boxed - style or if screen width is unlimited, use the simple styling of a - singular visual break. The longest URL is used because the other - messages may be broken into multiple lines, but URLs can't. */ - if (width - 3 <= (int) docs_url.length ()) + style, use the simple styling of a singular visual break. The longest + URL is used because the other messages may be broken into multiple + lines, but URLs can't. */ + if (width - 3 <= docs_url.length ()) { for (string_file &msg : styled_msg) gdb_printf (stream, "%s\n", msg.c_str ()); diff --git a/gdb/utils.c b/gdb/utils.c index ffe0d639e3a..d322843925b 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -1548,9 +1548,10 @@ gdb_flush (struct ui_file *stream) /* See utils.h. */ -int +unsigned int get_chars_per_line () { + gdb_assert (chars_per_line > 0); return chars_per_line; } diff --git a/gdb/utils.h b/gdb/utils.h index 0e28f9424e5..6316547653e 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -157,9 +157,10 @@ extern void wrap_here (int); extern void reinitialize_more_filter (void); -/* Return the number of characters in a line. */ +/* Return the number of characters in a line. Will never be zero, but can + be UINT_MAX, which indicates unlimited characters per line. */ -extern int get_chars_per_line (); +extern unsigned int get_chars_per_line (); extern bool pagination_enabled; -- 2.47.1