From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id PgMoCQ7R0mjseg8AWB0awg (envelope-from ) for ; Tue, 23 Sep 2025 12:55:42 -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=R13TBsiE; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id EDF881E0BA; Tue, 23 Sep 2025 12:55:41 -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 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 31A461E04C for ; Tue, 23 Sep 2025 12:55:40 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 99922385841D for ; Tue, 23 Sep 2025 16:55:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 99922385841D 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=R13TBsiE 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 5F99C3858D26 for ; Tue, 23 Sep 2025 16:54:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5F99C3858D26 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 5F99C3858D26 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=1758646477; cv=none; b=Mni0MPseHLgRhE8eEm7XqAL63WAhaYYdMLpfAXGCf89sciBSwxCCJ5KMfdlflk2im/77Q4TjQUYgT8ZAK3WW77GySf9WhQBwMrxMR1ujctf/EeIRcOoR0YhrlJywu0krPxJdDyEOPmR1BSUT1dJf5k9HOcV5awbZ4/C6lggzf9Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1758646477; c=relaxed/simple; bh=8e8KDvwPKNT7nOGCX19u5XC9MOjzatA3b12W5fUbMqc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=SddP/60DQkD6l2+4h34/hSrXhqpUNZtWdNOBdR0TC165F//8h0XgHOeXo6V+UH5NPns3LM2XRoG64glTpyH0yHzr2U+Myq1x96ICciAt4MobPp8FAeqIsLm1zFl+H165r7NeFmSNsZGN2aoL5/zO2Lz4cUJNYAFoUOeTecFngHI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F99C3858D26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758646477; 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=KN7HPAK4JrAR06+1NYq6tv2Nway1s6RudDLK35TwY6A=; b=R13TBsiEkMQPs2fP9sQxoXrccDnE0cutjvRzdaXqEkuHMplJej9sQ0xM452kddGp6lbscx 61+UEEFj3vFlWlTNfPLmyhaZhWYWSW6lxUu+7oSNFAWq47EQf67W85m77hYjgqI/YVMBfc 8e52zDIdQcIuZIk9DeFJGLZmeIiwj0Q= 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-663-ToG6PtiON-SeLKSUzbIp4g-1; Tue, 23 Sep 2025 12:54:36 -0400 X-MC-Unique: ToG6PtiON-SeLKSUzbIp4g-1 X-Mimecast-MFC-AGG-ID: ToG6PtiON-SeLKSUzbIp4g_1758646475 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3ef21d77d2eso4781076f8f.1 for ; Tue, 23 Sep 2025 09:54:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758646474; x=1759251274; 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=KN7HPAK4JrAR06+1NYq6tv2Nway1s6RudDLK35TwY6A=; b=NqkRGsdMLiSYdHAfzI7cngvUEpUlEk3tCacyGt97t8Vr3vZPN1TiAtJUS92zb7avaC NoEpL4oSRd5n+IU/zvKRCooRPsTIxvMv8VWydiVK/7xZYD+qjeCrLvThZGk3YZ6EyD9u COD3cjvM111EpuC50CW8yUgSik0OwmlrA1f8TZjbV4IKki5mjaNB23FmRz6Uoubm+FQs nTrpLyffcqDnfmVsAbG9HUIljkcKJLEnz+Icjt/OhWczltDoiKgXfkMFTHW3VXwtZztj fDvNmCrDUNnNqpMpAK6Dy0ndKYUsTOuZkAt//bb4Xi4KTLw+TtPcClafUCkG37mhHsXV Ejzg== X-Gm-Message-State: AOJu0Yzg5Fa6b/hAby3mcw1+lOuJS6PkEfc/omifNJ3fAFceyvAIecmj o6oEePL45k0uf4INqrlulFRqsBPDhbOLxzsDBhYifoZXkpFn29Y9GYldUKdo4X74flevSkzn8qE rWF9XXL+JqVrqmQlgg+YBWwyYY1azx6ULWfO9xFNHaKinja82JJdi1sI4i99N2d5TBx+3wLQ1xJ +n9O1qW46KpaokmiQRjhnbKzQsPnNH9b9sJwhYzBlctYMON7A= X-Gm-Gg: ASbGncsExjK0uIL5qrzL+KZ6EFXQofFRnOYAP3pnUMNDZsqU/ZLDEHTeutyIq3Tw7sY ixkzZNZ1GhhdJ0Z91Vy7lDAza/wEGUmK+T8L6Eegl2pVnBVgDHB5nRoq+NkjPmDktob/mLw6OVX xZk2vITpBC1JGUW7jC+Ii4FLoWRDfzpPNmbiyJWKjR+ZLevHejUGXzh8prg9xPSmArt0lr486P7 xI7kGbB8ukW8gWIW6NQfJZqf9oidL/+2ceE5JqJLAOc2Ev34r9ETKEbG3nCimyXkCtHkFyZqDAq g5aMShNFLur9hpQWoYGS3t+tFye8+yEXfc8= X-Received: by 2002:a05:6000:2c10:b0:3ec:df2b:14c8 with SMTP id ffacd0b85a97d-405c59e1820mr3276559f8f.20.1758646474290; Tue, 23 Sep 2025 09:54:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGvkuph6fvIqUWsMtBYOESoTke2+t9GGH5Q9N6fyZzZKEgwJqYkivxuFOvunCiBBg4mswGtNw== X-Received: by 2002:a05:6000:2c10:b0:3ec:df2b:14c8 with SMTP id ffacd0b85a97d-405c59e1820mr3276542f8f.20.1758646473843; Tue, 23 Sep 2025 09:54:33 -0700 (PDT) Received: from localhost ([31.111.84.207]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3fe9dbf13f3sm8692184f8f.50.2025.09.23.09.54.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Sep 2025 09:54:33 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv9 0/3] new gdb.Style API Date: Tue, 23 Sep 2025 17:54:28 +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: d4emyAmSRKqJu7S_D7th2PoRXPqllJ8RUD9H5WpUrCA_1758646475 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. In v6: - Rebased as there were some style related changes merged to master recently. No conflicts, and everything still works fine, so there are no real changes here. In v7: - Rebased as there were more style related changes to master which caused some merged conflicts, and test failures. Both turned out to be trivial to fix. In v8: - I merged the gdb.Color + pagination fix, this leaves the 3 patches related to the gdb.Style API. - I've updated the tests in patch 3 to take commit e17e65798e4 into account. - No updates needed to the actual GDB changes. In v9: - Patch 1 updated inline with Tom's comments. In stylepy_apply, added comment to explain use of O!, switched to use python_string_to_host_string, and use "+" to link std::strings together. In stylepy_set_intensity I added an early return if the stylepy_style_from_name fails. - Patch 2 is unchanged. - In patch 3, I removed some of the error checking from gdbpy_style_object_to_ui_file_style, and replaced it with an assert. This allows the error checking, along with a better error message, to remain in gdbpy_write. - Rebased to HEAD and retested. Thanks, Andrew --- Andrew Burgess (3): 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 | 822 ++++++++++++++++++ gdb/python/python-internal.h | 14 + gdb/python/python.c | 30 +- .../gdb.python/py-color-pagination.exp | 61 +- .../gdb.python/py-color-pagination.py | 36 + .../gdb.python/py-style-parameter-set.exp | 366 ++++++++ gdb/testsuite/gdb.python/py-style.exp | 371 ++++++++ gdb/ui-style.h | 6 + 12 files changed, 2184 insertions(+), 8 deletions(-) create mode 100644 gdb/python/py-style.c create mode 100644 gdb/testsuite/gdb.python/py-style-parameter-set.exp create mode 100644 gdb/testsuite/gdb.python/py-style.exp base-commit: 3dfb60bdd5c6affab91a23172352a027ac05768b -- 2.47.1