From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id EREPDHQ4M2ksYBsAWB0awg (envelope-from ) for ; Fri, 05 Dec 2025 14:54:28 -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=byhTySt8; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 2E4F61E0B3; Fri, 05 Dec 2025 14:54:28 -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 34F1C1E0AB for ; Fri, 05 Dec 2025 14:54:27 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B72E64D10851 for ; Fri, 5 Dec 2025 19:54:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B72E64D10851 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=byhTySt8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id A1E534BC894E for ; Fri, 5 Dec 2025 19:53:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A1E534BC894E 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 A1E534BC894E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1764964406; cv=none; b=VQ7FW8jWAcGXV2dnf5B96s666mkPz8+O4EHtinv6Y/V0L3ppe8IN72ylWcQBbYRhveGWoNYs3GfGhsNsc+0iT8gYdneCCbNFemc67pRz7BH6owLsOnAfa1GbbNCKtxmLeJ7J/2w/TY2tmuXPyFje2YEkvQqyhzjqrbq0ACkrOCY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1764964406; c=relaxed/simple; bh=TvtnqvwkBtRpF9n8SaexXNd8gCDm1tRWv72Ko8zWd2k=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=gzZ7hNuhUHoPhCGRJoDVNZAEOCV60Zm+xjipMcVy1lMQ1XVxaHomir+tAFsua8VPk+xgm3aCXslYhOAlhSXfOVVIrDnlKf0Ano9mHpQmkid02Z/cxJjoJ2h1Ltx7wKRvs3wLUa5jLcY4/zWKfDjeG7MjKjPPj6TrLaouFiNpXio= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A1E534BC894E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1764964406; 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=lQeeELgqUHB87kNMOyNVcwg0Wm5zC1ft76rl6LqZxzk=; b=byhTySt89IiBB1WnxqTH/1WY8edepi3S69jN2EItljyACsPaxxt+10Hey3z2oKUmcNwgzY CPUfjeCeZcysWt4v4qRHYS9KsvdClvFDWnCZDLlS4npasgSSzgN3F8CfqCAPQxhj1vOT9B R4a84F0lSSPCs+LmsqqOnIySH6LLsaM= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-193-B6S6AYUVNlOziJNHc6RSTg-1; Fri, 05 Dec 2025 14:53:25 -0500 X-MC-Unique: B6S6AYUVNlOziJNHc6RSTg-1 X-Mimecast-MFC-AGG-ID: B6S6AYUVNlOziJNHc6RSTg_1764964404 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-42b366a76ffso1411455f8f.1 for ; Fri, 05 Dec 2025 11:53:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764964403; x=1765569203; 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=lQeeELgqUHB87kNMOyNVcwg0Wm5zC1ft76rl6LqZxzk=; b=Rfmeh3a9brLTFEGSiIQcIjnlIFH4nuYNZHQSxm0AX34hV6Kkn07N8/bf+f33dhJ5Pk AbE2U1bhHGqcTu/hMbdfc6RqjcGvP0s3vx3sSOqiqGsBmyaMKraGuD1klRTGmreTLY8J BeO/2K2KudEvCicOl2LeCKpjXrl4rWrQwvuCZ6yQ91zD5x0+af3rTEEfrsXj4YlWJjU+ YtJPGAsIHyXe+gOGVH87mJYH7miUnYKovH6w2PJeXUDWgQaR7iA3LCIkf7KAqB9HTaWc TWYFnAWhAE1Q6TnY8E9eKc91Q59CjReBvCYNiss+USm/9d/5aWcUnSYecRglCHsZIXml nARQ== X-Gm-Message-State: AOJu0YwbfUP/hBJRTgxabgTiRjOGCu6R1m6be/skOnxP1UvY4jf3mj7K jvc8G4PRA8It9QUk/DfQtu8MyXHyV18hRvgy2EEDQ+Z/n5VcjPOe3riJEABirfT49FM6cI2vqrg bm1tiX3ocZxotoy5G7vleHIXu65wf+uAZSp0nLN4w1nfxFNQNYCHCxqpLtBPzX2Zc4faJTErWv1 TyTr4PSahfmx98dAKUq9nx+HT//0x0KIMgajQoWX5lhwGAvu4= X-Gm-Gg: ASbGncv80qsUe/L23pJdKJHEw4mue9mHPgYL70Y+VOs1hG6zWx62z9Bv6uGyd0D9oYA B9geWaI0HVti2p4ZYH1b/Dsx2jGxZGKLBaVRlSH9IMGDDMYeiJ3mV5Ht9qEJxaav2DUUGaeNmMl zvBqNaiT+Gx6dZa7hkn5TY82jS/rRQsxgThKzhTrKsyE+qzlfK21apEkHUjghCk0BqEYRhizZss Oklm2MZUMj/je5pk0kKn++ULuN/3iPs8RHIfCEyyNdsJDK3TgLTgPpycEljcJCuHUP50wYsKQAJ XXIAkBoTHVlMCBNsf7CoV6vpvC/jWqwOGUDGpRXPle+GZvT88g6R90vd0o4ToCh/wOJ08wm7nLX dHzJA X-Received: by 2002:a05:6000:40c8:b0:429:b525:6dc2 with SMTP id ffacd0b85a97d-42f89f1419dmr356189f8f.17.1764964402793; Fri, 05 Dec 2025 11:53:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IEPuJAJbvFrWKJq45P82Q4P7ZmoG6stxTP2PeSJH4cAfQr0pGH3ZxUXOi3Hrfs025GXJaE9GA== X-Received: by 2002:a05:6000:40c8:b0:429:b525:6dc2 with SMTP id ffacd0b85a97d-42f89f1419dmr356168f8f.17.1764964402240; Fri, 05 Dec 2025 11:53:22 -0800 (PST) Received: from localhost ([31.111.84.207]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42f7cbff352sm10534757f8f.17.2025.12.05.11.53.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Dec 2025 11:53:21 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Guinevere Larsen Subject: [PATCHv3 1/3] gdb: make get_chars_per_line return an unsigned value Date: Fri, 5 Dec 2025 19:53:15 +0000 Message-ID: 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: sbLUAKfqlZMp4PIDeINBeeDr9c17PPFZcYQOFPty4gQ_1764964404 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 works around the signed / unsigned confusion entirely within print_gdb_hints by adding a case to 'int' in one place. The change I present here reverts parts of 06e470d8fc0a in favour of fixing the type of WIDTH within print_gdb_hints. It is worth nothing that there are other bugs in print_gdb_hints relating to how WIDTH is handled, but these are fixed in the next commit. By updating the return type of get_chars_per_line, I ran into some issues in cli-out.c relating to how progress bars are handled. The existing code includes code like: if (!stream->isatty () || !current_ui->input_interactive_p () || chars_per_line < MIN_CHARS_PER_LINE) return; The early return here triggers when progress bars should not be printed. Notice that when the terminal width is unlimited, CHARS_PER_LINE will appear negative, and so the early return will trigger. It turns out that our testsuite depends on this; the debuginfod tests don't expect to see a progress bar, and they don't because within the tests we set the width to unlimited. By "fixing" the type of CHARS_PER_LINE to 'unsigned int', an unlimited width terminal no longer triggers the early return, and GDB starts trying to print a progress bar in our debuginfod tests, which cause the tests to fail. I think the real fix is to add a new flag to allow progress bars to be disabled, the tests can then use this. I will add just such a flag at the end of this series. For now though, I propose adding a bodge. If CHARS_PER_LINE is UINT_MAX, then we should act as if progress bars are disabled. The above code now becomes: if (!stream->isatty () || !current_ui->input_interactive_p () || chars_per_line < MIN_CHARS_PER_LINE || chars_per_line == UINT_MAX) return; This change is in cli_ui_out::clear_progress_notify. There is a similar change in cli_ui_out::do_progress_notify. With these two changes, the debuginfod tests are working again. This bodge will be removed by the last patch in this series. 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 | 19 ++++++++++--------- gdb/top.c | 10 +++++----- gdb/utils.c | 3 ++- gdb/utils.h | 5 +++-- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/gdb/cli-out.c b/gdb/cli-out.c index 27a82f607eb..5aa13a64271 100644 --- a/gdb/cli-out.c +++ b/gdb/cli-out.c @@ -298,18 +298,16 @@ 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 ()); - if (chars_per_line > MAX_CHARS_PER_LINE) - chars_per_line = MAX_CHARS_PER_LINE; - if (info.state == progress_update::START) { 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) { gdb_printf (stream, "%s\n", msg.c_str ()); info.state = progress_update::BAR; @@ -321,10 +319,12 @@ cli_ui_out::do_progress_notify (const std::string &msg, } } - if (info.state != progress_update::BAR - || chars_per_line < MIN_CHARS_PER_LINE) + if (info.state != progress_update::BAR) return; + if (chars_per_line > MAX_CHARS_PER_LINE) + chars_per_line = MAX_CHARS_PER_LINE; + if (total > 0 && howmuch >= 0 && howmuch <= 1.0) { std::string progress = string_printf (" %3.f%% (%.2f %s)", @@ -385,14 +385,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