From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id WMyQDCsLXGgDnx4AWB0awg (envelope-from ) for ; Wed, 25 Jun 2025 10:43:55 -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=bzW6yzxU; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 1C4BA1E11E; Wed, 25 Jun 2025 10:43:55 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-10.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_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED, RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (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 4848C1E0C2 for ; Wed, 25 Jun 2025 10:43:54 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BF9A13856DEE for ; Wed, 25 Jun 2025 14:43:53 +0000 (GMT) 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 4B3CC385701A for ; Wed, 25 Jun 2025 14:43:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4B3CC385701A 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 4B3CC385701A 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=1750862602; cv=none; b=HFEMv3ORsTLZMJB+YDu2QE9xzZksk+uK3K8i36+uxmWjSIhiln/AlYdKdHDZ09r2XmCpEc0kR7MHBTtkQJGkX72mK6drhKcFucapl9iga3Y7q7Mr+G3VjKjqiJ2MPi95RHimTIBgoU0o4wjsnYtdDyVOmazB2+kQCbFKOf4dgB8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1750862602; c=relaxed/simple; bh=wzByRtcwBj6454tAOkGLv9fUluqUysrqLj/3hlXZ6N8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=wF1ZNZVCbjiABtFnHLhSzs0TdKopCdcCtrJtuxyu6TwgaK/n/hN3nZXYds7463RSX0GLaAB8X+6lrpXW68sjRHx2hjzHwIp7m1tIuHhYx0vCThcBQBRlvNj4OW3ROqF4eQwZ8c6mE0HDZbdGdg4icOLwDLgF0hOQr856p94DBFU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4B3CC385701A 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=bzW6yzxU DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1750862583; 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=bw3RW/5dUgB20Hc5tLq0Xy73NHqhcf4ntCTzo90hwts=; b=bzW6yzxUvley1pwqI+4edWg8nL5GpJfaD/zjWkl3VoGu30kMGntw/VgyD/EaHwyXBsGE3w ka2WGhMgkGmgwyGhAlrgZkmhu/gHzoK749ryETPdKlALPxiQF2q3rS/ZtYFuLniVtIZavn V3lKInUsV7FSwCfBUJGtH7AC6jf2AK0= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-25-fhlsYJ1JO7ChFczU4eri2A-1; Wed, 25 Jun 2025 10:43:02 -0400 X-MC-Unique: fhlsYJ1JO7ChFczU4eri2A-1 X-Mimecast-MFC-AGG-ID: fhlsYJ1JO7ChFczU4eri2A_1750862581 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3a4f7ebfd00so947427f8f.2 for ; Wed, 25 Jun 2025 07:43:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750862581; x=1751467381; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bw3RW/5dUgB20Hc5tLq0Xy73NHqhcf4ntCTzo90hwts=; b=nmkALRcEwmKYV/vXwmyujqFw0pM4kdjCn/AE6dFMlxF9C8fbCde60XPPdfj+u9ar6r OMLd0iFBJiEO0clY8tZHMuBujCx6zCb1TQP/ezJkaBjOVF641aUViwqy62xNz1SmdRi5 5MWzuMCoI+PvRxOXmHPEKtYxTE9vUA8aUP1TLUqjGlnF/MNMwtmnMl36liGy21c91sm5 ztv0stLeZfSHrzxqsmTk1JGOmCD+Tv/xzuEB1xxw4MM4wEqRtXKlkWYewZvEKCl8MA0/ hGTMFNY0z0zAfrfHXxU8OoLoiCCX04sdzXt1hb2VuNSQAkKriZ+2yafBHu1XEuEzqAGp 9s8w== X-Gm-Message-State: AOJu0YycZtsdKGh0dpVL+RdE69F9OAUYkanwwgiiHHXuyEru5BybLwl9 fMlb6IeBDaiH9Q2WupI/ADG8mIUyVIvsVcq/yJokTw7qzNGPbzCCpTDBA8HlBUu9KtvaPqicmZn 8RKamFR5ytYNhGOhM1RB5qk1JFLBP+/GxqN0ubUWoS1ZJ/RcJhd6cM3otHO7KbfV8lISGIRlsQn C4WSRxy8+mjJsjaYQsYGwfwRUkF+3uNsAwTUHT6mBF1vYyyT8= X-Gm-Gg: ASbGnctm4gX6yyG8NvkkTPMpX/zMT1Q3gGHff0CANJeeI8hRQp+qZ5oDDluJy/a5Gu2 bbwLDXjNIzk+eu+3OUELYnthqepL/YuZTypdBDrM64J3ltfjPSuDAMO0uDVVLxKYG1TaWOEM/ul 9p9ykwAMiNVsOEkrd40CO/dvvcRj+ueVx/kSKI/+GN3DGciJ7faXYZpfpECCvwvbtwvgPNHbiMa tDim+86RfJk9YkDZGhc+rNQBpcSHHi+zKJFLFwZsIvyzR4jm/X4b1RM0XLnvkMcqPES8FyAYgnh 0vu7XIiu/Fc176TG+rO37z2HANLDGmIBdZgYGvRMrqUi0+0= X-Received: by 2002:a5d:5e8e:0:b0:3a5:52cc:346e with SMTP id ffacd0b85a97d-3a6ed61917emr2605525f8f.6.1750862580855; Wed, 25 Jun 2025 07:43:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGtkQzqV40KpLoLL2gCg7yW21bj/1mWqauDhqUs2EpyeE3oU3ECajnJ4jweAPuYxDREmgDPmg== X-Received: by 2002:a5d:5e8e:0:b0:3a5:52cc:346e with SMTP id ffacd0b85a97d-3a6ed61917emr2605498f8f.6.1750862580294; Wed, 25 Jun 2025 07:43:00 -0700 (PDT) Received: from localhost (75.226.159.143.dyn.plus.net. [143.159.226.75]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-453823b75cdsm21512325e9.32.2025.06.25.07.42.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 07:42:59 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv5 0/4] Python Style API Date: Wed, 25 Jun 2025 15:42:53 +0100 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: uMYATWYoG-6rc7t48S3uFVjzswu0zkrw3bJRZ8JjXiE_1750862581 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 After the gdb.Color support was added to the Python API I wondered if this would be enough to easily add styling to custom Python commands. But I don't think it is, there's still lots that would need to be handled in user code, for example, the intensity setting. And having styles that track named styles (e.g. if I want to apply the 'filename' style to some text from Python). So this series builds on top of the gdb.Color API to provide a new gdb.Style API which, I hope, makes it easy to start writing Python commands that can use GDB's styles. Here's an example of a simple custome command that uses styles: import os class user_home_cmd(gdb.Command): def __init__(self): super().__init__("user-home", gdb.COMMAND_USER) self._style = gdb.Style('filename') def invoke(self, args, from_tty): print("The filename is %s." % (self._style.apply(os.environ['HOME']))) user_home_cmd() The new 'user-home' command prints the current users home directory using 'filename' style. Changing the 'filename' style and re-running the command will track the style changes. In v2: - Fixed an issue with the py-style-parameter-set.exp test; GDB was not started in a terminal with styling support in one case, so tests would fail depending on how the testsuite was being run. In v3: - Another test issue. This time, the error message given when parsing an argument of the wrong type changes with Python version. Relax the regexp to accept any 'TypeError' message. In v4: - Two new patches. First patch extends pager_file so that gdb.Color, and gdb.Style when it's added can work well with GDB's pager. Last patch extends the gdb.write() Python function to also support styling. - I've renamed some of the classes in python/py-style.c, nothing major, I replaced 'stylepy' with 'style' in some names. I think the new names are clearer, and better match the rest of GDB's Python API code. - Unfortunately, the new pager_file changes mean that this patch series now depends on this other patch: https://inbox.sourceware.org/gdb-patches/444008aeae2bb3c68cf868fa317374b3d7973860.1750197766.git.aburgess@redhat.com Without that patch there will be some failures in gdb.python/py-color-pagination.exp. I'm not proposing to merge this until that other patch, or something like it, is merged. But this series could be reviewed independently. In v5: - The pager_file styling fixes mentioned for v4 have now been merged to master. I've rebased this series on top of them, and all the tests are now passing. - I've tweaked the wording for a couple of the commit messages just to make things clearer. - No real code changes. Thanks, Andrew --- Andrew Burgess (4): gdb: allow gdb.Color to work correctly with pagination gdb/python: add gdb.Style class gdb/python: new class gdb.StyleParameterSet gdb/python: extend gdb.write to support styled output gdb/Makefile.in | 1 + gdb/NEWS | 14 + gdb/doc/python.texi | 262 +++++- gdb/python/lib/gdb/__init__.py | 209 +++++ gdb/python/py-style.c | 824 ++++++++++++++++++ gdb/python/python-internal.h | 15 + gdb/python/python.c | 46 +- .../gdb.python/py-color-pagination.exp | 166 ++++ .../gdb.python/py-color-pagination.py | 82 ++ .../gdb.python/py-style-parameter-set.exp | 366 ++++++++ gdb/testsuite/gdb.python/py-style.exp | 371 ++++++++ gdb/ui-style.h | 6 + gdb/utils.c | 21 +- 13 files changed, 2366 insertions(+), 17 deletions(-) create mode 100644 gdb/python/py-style.c create mode 100644 gdb/testsuite/gdb.python/py-color-pagination.exp create mode 100644 gdb/testsuite/gdb.python/py-color-pagination.py create mode 100644 gdb/testsuite/gdb.python/py-style-parameter-set.exp create mode 100644 gdb/testsuite/gdb.python/py-style.exp base-commit: 125881849ad75f05d6c35fdb02a290cb740a75d4 -- 2.47.1