From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 6WS/MuSr/WlBsyIAWB0awg (envelope-from ) for ; Fri, 08 May 2026 05:24:52 -0400 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=AXQNZw7/; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id BD9651E093; Fri, 08 May 2026 05:24:52 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 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_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.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 139051E093 for ; Fri, 08 May 2026 05:24:52 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E796F4BA2E2E for ; Fri, 8 May 2026 09:24:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E796F4BA2E2E 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=AXQNZw7/ 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 52A1B4BA2E16 for ; Fri, 8 May 2026 09:24:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 52A1B4BA2E16 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 52A1B4BA2E16 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778232245; cv=none; b=UYXCFacin/aBNdJuaUR7yvXwwN5smqHYUA+zv0zzUCqJbZUOS7fbdJpQLLMM2Mhz4ygrmG/XypkssjfpAiJthufnI361brb2XX/8d9Xeyf97V1g6Ljm+7mSMZwtL1sky8gu2T89gacN6wtKg9vPFhnEYqB6U3wZ0zcMoh4HZO+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778232245; c=relaxed/simple; bh=vvYXz0Ze7HzroHR+gpfG/FiOFj1LFR2MfCrmuTXNB5c=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=NBQ6IyUJkEeN5XgHxHx/RfQLGgp2byfrkNnuNjzuzG96TEf9xHsOgstCS/bactn/s/yb+so8Omg1vJm94RHvTHb1q597TNCM4YA2KJNRsk+5OUmWP93MJzmcgve8N8/efX7PP1GF03/Hs+JqbU/leyPrmoXjqGcdOmgG7UiaKNI= ARC-Authentication-Results: i=1; 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=AXQNZw7/ DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 52A1B4BA2E16 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778232245; 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=9ArFl8L4QlJ81XvPVpauX7BvyriKWuCN+Yu1DwAeydQ=; b=AXQNZw7/vcWFYYbbHZPbSw0st5pyvfZs3jBX5oMrWAwR0To3flmsS9j0HNM+vM8IvZ9umF gHKU5+X9cb/atJJyUNMHX/mIH8fxs6z0QxvF4SMF8oWfCZHiW2XW6/D5oLHVIzFV4YvQjU s1yLT5RopeIr3V8B/JZDtxxeShOD4Nw= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-582-HfavBfwjMsCXLFMNWsClQA-1; Fri, 08 May 2026 05:24:03 -0400 X-MC-Unique: HfavBfwjMsCXLFMNWsClQA-1 X-Mimecast-MFC-AGG-ID: HfavBfwjMsCXLFMNWsClQA_1778232242 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-48a9592f666so10674395e9.1 for ; Fri, 08 May 2026 02:24:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778232241; x=1778837041; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=HEk2YSpgyaIDseE15vq6rHwhfMoRbrOMGgDv7lRED3U=; b=FGXI8druxZwK8WUdMD7dthIqEXxu8TTVFJmXob2GFnkVNrPgfDQXAyq4f8jSc14Sza tND0WrXRsvVd4paigG9X2AqYnbD1wyoBmdBRRJ7LdIqhspnL21yyBUb2RM0eJFEPRe+g DMaG1FC8FQeK8p/df0SHWp1L7yE8zdo4VUK4j3MRODm8fwMUNzQZ1HGilhq5USW+Kxa3 87bJO+pdiv2oowj26l8rwqAKvnCS2mSnXq4PxOoI6ypGy3q86KqLqdMpdEUQNFn5cL24 a8PIWkeRqFKQWnfTu1/K8+vrpnUAotl/PAxqqMqrNq+85WpsbMX7+xnOePdwkmACqleA 7KXw== X-Forwarded-Encrypted: i=1; AFNElJ9ZlRSlV34Wi5TwIZL7HDKnyva2hVYB8u1CGPvoPFRqfisG+VYkZ4+f4h+1QcK5PdlLL67LIg0Rjg9TzQ==@sourceware.org X-Gm-Message-State: AOJu0Yzm8QPq4VEo5L2u4f4sVKoEk+CCcRaNlNUh2XH3K5aYfJ7Uhs8p /udfFowhsFwLNdqL9sLu26gErya3vXElMn5d+1fhOWcIVsc3aNqah/0eLqtOCJGSTSZyZtBg0qX uz83hApJ7yOT9XsyK1QDb5HV7EN9EaM2PlB6tKm/yxhwoQ4R9Fx29xcnubNbCU0WByatDL/k= X-Gm-Gg: AeBDieto/zdM18oop6vSaDxkFeeNl2QFOIUPB0CQiLeeJTLQYlJlFkOW/5KogavUutE XQZcWoqYL4WHSGb1Umyi4rFgGp752ZkaZbvA5XTZYAIawFVBeg7Wfu1PxQurCNKgkR8Wq5a5Bad nAysVoO6xamsD42MzrxDYags9GJsY8CUqJNqCdu98UnRsnhB/4FGOGSC6PGWDtEX/U8qW1LZQ8y 7IOd6k17xx+X8yFmDZW6aFHiLJKanBWlSoYdXdoq1iNA8S0nDaRxmoXd9o/4k5hkJYQXI9qr8ps IeA+rbjLQnt9vtRnnUqCW+AoDnHLdwW9RkD83wTqqXO+6C+5q6zi0ubUl1ukcVme03ztOwfChvY Ao8K2A3ZbQtqFs9TOTAqjH3mBNJ0= X-Received: by 2002:a05:600c:5308:b0:48a:906a:9050 with SMTP id 5b1f17b1804b1-48e51e20759mr175351365e9.10.1778232241323; Fri, 08 May 2026 02:24:01 -0700 (PDT) X-Received: by 2002:a05:600c:5308:b0:48a:906a:9050 with SMTP id 5b1f17b1804b1-48e51e20759mr175350825e9.10.1778232240760; Fri, 08 May 2026 02:24:00 -0700 (PDT) Received: from localhost ([31.111.84.232]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e642d1b70sm16862535e9.2.2026.05.08.02.24.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 May 2026 02:24:00 -0700 (PDT) From: Andrew Burgess To: jakob.schaeffeler@tum.de, gdb-patches@sourceware.org Cc: Jakob =?utf-8?Q?Sch=C3=A4ffeler?= Subject: Re: [PATCH] gdb/tui: Fix unexpected reuse of color pairs In-Reply-To: <20260507080327.1690909-1-jakob.schaeffeler@tum.de> References: <20260507080327.1690909-1-jakob.schaeffeler@tum.de> Date: Fri, 08 May 2026 10:23:59 +0100 Message-ID: <87o6iqdzkg.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: osci9hSMxdnp9C1pc6Ay9rrl_mqgRqAS5EHKeZpLEBw_1778232242 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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 Thanks for working on this. This looks like it could be a good improvement. jakob.schaeffeler@tum.de writes: > From: Jakob Sch=C3=A4ffeler Commit message text should be line wrapped at around 72 characters, your commit message will need to be reformatted so that it is readable in 'git log' output. > > TUI translates ANSI styling sequences to curses color pairs. > Currently in this process uses COLOR_PAIR which only returns values from = 0 to 255 which results in unexpected reuse of color pairs. typo: "Currently, this process uses COLOR_PAIR, which only returns values .= .." > This patch avoids calling COLOR_PAIR(pair) to be able to render more than= 256 color pairs. For this the wattron call is replaced with wcolor_set. > This also results in last_color_pair no longer being needed since we set = the color directly with wcolor_set and do not need wattron/off pairs any lo= nger. > This results in SHRT_MAX different color pairs to be available. To get > all 65535 color pairs init_pair is replaced with init_extended_pair, > which returns an int instead of short. typo: "...which TAKES int instead of short.". They both return 'int'. > This patch was tested with make check-gdb TESTS=3D"gdb.tui/*.exp" It would be good if there was a new test added which checks the new extended colour range. Is there a reason why this cannot be done? I also wonder how widely available this extended colour API is? Is this supported on mingw? Or FreeBSD? Or Solaris (is this even used/supported these days)? I wonder if we should be adding configure checks for this API, or if it's OK to just put a hard requirement in place? At the very least it would be nice to document in the commit message if nowhere else, what version/package requirements this is now placing on us. Also, I suspect this patch is probably more than trivial, so we will probably need a copyright assignment in agreement before we could accept it. Information on this process can be found here: https://sourceware.org/gdb/wiki/ContributionChecklist#FSF_copyright_Assignm= ent If you have any questions, feel free to ask and we can help out. Thanks, Andrew > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D34134 > --- > gdb/tui/tui-io.c | 16 +++------------- > 1 file changed, 3 insertions(+), 13 deletions(-) > > diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c > index 642b88ead0c..5e239179b5e 100644 > --- a/gdb/tui/tui-io.c > +++ b/gdb/tui/tui-io.c > @@ -265,10 +265,6 @@ get_color (const ui_file_style::color &color, int *r= esult) > return true; > } > =20 > -/* The most recently emitted color pair. */ > - > -static int last_color_pair =3D -1; > - > /* The most recently applied style. */ > =20 > static ui_file_style last_style; > @@ -299,7 +295,7 @@ get_color_pair (int fg, int bg) > =09 back to the default if we've used too many. */ > if (next >=3D COLOR_PAIRS) > =09return 0; > - init_pair (next, fg, bg); > + init_extended_pair (next, fg, bg); > color_pair_map[c] =3D next; > return next; > } > @@ -320,9 +316,7 @@ tui_apply_style (WINDOW *w, ui_file_style style) > #endif > wattroff (w, A_UNDERLINE); > wattroff (w, A_REVERSE); > - if (last_color_pair !=3D -1) > - wattroff (w, COLOR_PAIR (last_color_pair)); > - wattron (w, COLOR_PAIR (0)); > + wcolor_set (w, 0, nullptr); > =20 > const ui_file_style::color &fg =3D style.get_foreground (); > const ui_file_style::color &bg =3D style.get_background (); > @@ -342,10 +336,7 @@ tui_apply_style (WINDOW *w, ui_file_style style) > =09 bgi =3D (ncurses_norm_attr >> 4) & 15; > #endif > =09 int pair =3D get_color_pair (fgi, bgi); > -=09 if (last_color_pair !=3D -1) > -=09 wattroff (w, COLOR_PAIR (last_color_pair)); > -=09 wattron (w, COLOR_PAIR (pair)); > -=09 last_color_pair =3D pair; > +=09 wcolor_set (w, 0, &pair); > =09} > } > =20 > @@ -907,7 +898,6 @@ tui_setup_io (int mode) > savetty (); > =20 > /* Clean up color information. */ > - last_color_pair =3D -1; > last_style =3D ui_file_style (); > color_map.clear (); > color_pair_map.clear (); > --=20 > 2.54.0