From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id sPLnFUCYHGh8GBoAWB0awg (envelope-from ) for ; Thu, 08 May 2025 07:40:48 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gnu.org header.i=@gnu.org header.a=rsa-sha256 header.s=fencepost-gnu-org header.b=TrZea52C; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 48B741E10E; Thu, 8 May 2025 07:40:48 -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 E009D1E092 for ; Thu, 8 May 2025 07:40:46 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6A4593858C2F for ; Thu, 8 May 2025 11:40:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6A4593858C2F Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gnu.org header.i=@gnu.org header.a=rsa-sha256 header.s=fencepost-gnu-org header.b=TrZea52C Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id 594B93858C62 for ; Thu, 8 May 2025 11:40:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 594B93858C62 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 594B93858C62 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:470:142:3::10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1746704417; cv=none; b=O3p9QLQUbkTm3O+kpcSSzLHxVgYsAmzJTpGdaMdDKCxi/JFNiqndgcDJibj+UFXpGMev3O+bWpIGjO+9k9OOeLPjlryPOMUlSiTyZR2sQ6uheVgZa5284yKRphV4SEThG7hFQKiE4A+v3b6Jp5IAZs94DT4ELl8ntLpUHlqBsrk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1746704417; c=relaxed/simple; bh=Z/Lb1d6Kpqc4hswnzH/mKjt0HfkHHeo0119R4u3xQIo=; h=DKIM-Signature:Date:Message-Id:From:To:Subject; b=IzEJd8fgeSB/gYP2M+CVlPXa+KoAcyj+rcthiRu0Qu8QXVeB1IhUO9NICKwptEEHbWa8CHkV3BVSMZR3yB8Z+lPZ9Ziv+G3J6hLXnhdm4NzICQY3TeqCiMUzq6ofyG4RGVcSfZojlbkdSMUWccCGXLPuCpHeWcGyUMmhMtUJpGE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 594B93858C62 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uCzbs-00065U-Co; Thu, 08 May 2025 07:40:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=RrozwebkQQUokFF64uLCPKilqWi2S38sWhp/xh5gi2M=; b=TrZea52C0+Ph apaxfnJjR/ox8j2xG1nYJ8ogILSDtrZJzaZQJhJTdGIcFjS9B6Lgm1qxMBD+aRq0eMt+qo3Y9/yla dkxqT46dZLw9qo/Z1fBO1mdqIfyE4eUhIB7L6GzI4kR3/cxluKgbN+8KmSPS5f8/UqSomuxXCn220 YSLsecs5zqk8BeTzJK5z2+zlAdm+wcuN3wIX/shyv5BRDSb4qHJl5Cnyo8r8dJqGSgp3z9e31ioPs NMwxFT8/eGtKMnl2n+HN6PwhnudCav8aSIqFZ9sA0FRNMYfKRErqAofGhrzs+hzCpGwUJam+1JXH9 25FowLIuv6CIecaleNjGxQ==; Date: Thu, 08 May 2025 14:40:10 +0300 Message-Id: <868qn7e3fp.fsf@gnu.org> From: Eli Zaretskii To: Craig Blackmore Cc: gdb-patches@sourceware.org In-Reply-To: <20250508101721.2000793-1-craig.blackmore@embecosm.com> (message from Craig Blackmore on Thu, 8 May 2025 11:17:21 +0100) Subject: Re: [RFC PATCH v2] gdb: Add python support for demangling register unwind values References: <20250410110426.3488955-1-craig.blackmore@embecosm.com> <20250508101721.2000793-1-craig.blackmore@embecosm.com> 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 > From: Craig Blackmore > Cc: Craig Blackmore , > Eli Zaretskii > Date: Thu, 8 May 2025 11:17:21 +0100 > > > Reviewed-By: Eli Zaretskii > --- > Changes since v1: > * Updated subheading in documentation as suggested by Eli. > * Rebased. > > gdb/NEWS | 11 +++ > gdb/doc/python.texi | 48 +++++++++++ > gdb/extension-priv.h | 8 ++ > gdb/extension.c | 35 ++++++++ > gdb/extension.h | 6 ++ > gdb/frame.c | 3 + > gdb/guile/guile.c | 2 + > gdb/python/lib/gdb/__init__.py | 17 ++++ > gdb/python/lib/gdb/unwinder.py | 34 ++++++++ > gdb/python/py-registers.c | 2 +- > gdb/python/py-unwind.c | 80 +++++++++++++++++ > gdb/python/py-value.c | 25 ++++++ > gdb/python/python-internal.h | 4 + > gdb/python/python.c | 4 +- > .../gdb.python/py-unwind-demangler.c | 80 +++++++++++++++++ > .../gdb.python/py-unwind-demangler.exp | 86 +++++++++++++++++++ > .../gdb.python/py-unwind-demangler.py | 44 ++++++++++ > gdb/testsuite/gdb.python/py-value.exp | 8 ++ > 18 files changed, 495 insertions(+), 2 deletions(-) > create mode 100644 gdb/testsuite/gdb.python/py-unwind-demangler.c > create mode 100644 gdb/testsuite/gdb.python/py-unwind-demangler.exp > create mode 100644 gdb/testsuite/gdb.python/py-unwind-demangler.py > > diff --git a/gdb/NEWS b/gdb/NEWS > index a82b7e3342c..7514ce4ddd9 100644 > --- a/gdb/NEWS > +++ b/gdb/NEWS > @@ -112,6 +112,17 @@ info sharedlibrary > > * Python API > > + ** Added gdb.UnwindRegisterValueDemangler. This is the base class for Unwind > + Register Value Demanglers which are called after obtaining a register value > + from an unwinder and allow that value to be demangled before being used by > + GDB. > + > + ** New read-only boolean attribute gdb.Value.is_lval_register which indicates > + if the value is from a register on the inferior. > + > + ** New read-only boolean attribute gdb.Value.is_lval_memory which indicates > + if the value is from inferior memory. > + > ** New class gdb.Color for dealing with colors. > > ** New constant gdb.PARAM_COLOR represents color type of a > diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi > index 7bb650347f7..7fd0ba4f83b 100644 > --- a/gdb/doc/python.texi > +++ b/gdb/doc/python.texi > @@ -938,6 +938,16 @@ fetched when the value is needed, or when the @code{fetch_lazy} > method is invoked. > @end defvar > > +@defvar Value.is_lval_register > +The value of this read-only boolean attribute is @code{True} if this > +@code{gdb.Value} is from a register on the inferior. > +@end defvar > + > +@defvar Value.is_lval_memory > +The value of this read-only boolean attribute is @code{True} if this > +@code{gdb.Value} is from inferior memory. > +@end defvar > + > @defvar Value.bytes > The value of this attribute is a @code{bytes} object containing the > bytes that make up this @code{Value}'s complete value in little endian > @@ -3160,6 +3170,44 @@ the matching unwinders are enabled. The @code{enabled} field of each > matching unwinder is set to @code{True}. > @end table > > +@subheading Unwind Register Value Demangler > + > +After getting a register value from an unwinder, @value{GDBN} will call > +out to extension language demanglers to allow them to modify the value. > +This is useful in case a register value needs demangling before > +@value{GDBN} uses it and avoids the need to write a new unwinder. > + > +Currently, only one demangler can be registered at any one time and it > +is registered globally. > + > +@subheading Skeleton Code for a Register Value Demangler > + > +Here is an example of how to structure a user created demangler: > + > +@smallexample > +from gdb.unwinder import UnwindRegisterValueDemangler > + > +class MyUnwindRegisterValueDemangler(UnwindRegisterValueDemangler): > + def __init__(self): > + # Register self as the one and only demangler > + super().__init__("MyUnwinder_Name") > + > + def __call__(self, frame_type, reg, value): > + """ > + Return new value if demangled, otherwise None. > + """ > + if frame_type != : > + return None > + > + if reg.name == : > + new_value = ... compute demangled value ... > + return new_value > + > + return None > + > +my_demangler = MyUnwindRegisterValueDemangler() > +@end smallexample > + > @node Xmethods In Python > @subsubsection Xmethods In Python > @cindex xmethods in Python Thanks, the documentation parts are okay. Reviewed-By: Eli Zaretskii