Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Craig Blackmore <craig.blackmore@embecosm.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFC PATCH v2] gdb: Add python support for demangling register unwind values
Date: Thu, 08 May 2025 14:40:10 +0300	[thread overview]
Message-ID: <868qn7e3fp.fsf@gnu.org> (raw)
In-Reply-To: <20250508101721.2000793-1-craig.blackmore@embecosm.com> (message from Craig Blackmore on Thu, 8 May 2025 11:17:21 +0100)

> From: Craig Blackmore <craig.blackmore@embecosm.com>
> Cc: Craig Blackmore <craig.blackmore@embecosm.com>,
> 	Eli Zaretskii <eliz@gnu.org>
> Date: Thu,  8 May 2025 11:17:21 +0100
> 
> 
> Reviewed-By: Eli Zaretskii <eliz@gnu.org>
> ---
> 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 != <frame we need to handle>:
> +          return None
> +
> +        if reg.name == <reg that needs demangling>:
> +          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 <eliz@gnu.org>

  reply	other threads:[~2025-05-08 11:40 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-10 11:04 [RFC PATCH] " Craig Blackmore
2025-04-10 12:31 ` Eli Zaretskii
2025-05-08 10:17 ` [RFC PATCH v2] " Craig Blackmore
2025-05-08 11:40   ` Eli Zaretskii [this message]
2025-05-12 13:15   ` Andrew Burgess
2026-04-30 15:19     ` Craig Blackmore
2026-04-30 15:31     ` [PATCH v3] " Craig Blackmore
2026-04-30 16:05       ` Eli Zaretskii
2026-05-20 13:16       ` [PATCH v4 0/1] " Craig Blackmore
2026-05-20 13:16         ` [PATCH v4 1/1] " Craig Blackmore
2026-05-20 15:44           ` Eli Zaretskii
2026-05-21  9:47           ` Andrew Burgess
2026-05-27 10:49             ` Craig Blackmore
2026-06-08 12:04         ` [PATCH v5 0/1] " Craig Blackmore
2026-06-08 12:04           ` [PATCH v5 1/1] gdb: Add python support for transforming " Craig Blackmore
2026-06-08 12:13             ` Eli Zaretskii
2026-07-15  9:56           ` [PING][PATCH v5 0/1] gdb: Add python support for demangling " Craig Blackmore
2026-07-29 15:01           ` [PATCH " Craig Blackmore

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=868qn7e3fp.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=craig.blackmore@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox