On Thu, 2026-07-02 at 09:57 +0100, Andrew Stubbs wrote:
> Ping.

Thanks for the patch, sorry about the delay in reviewing this.

Testing this is usually a bit of a pain.  You don't happen to have a
precanned way of doing this by any chance? :)

Given that I rarely touch the world of rtx, you're probably in a better
position to assess this patch than me.  Mostly looks good...
> 
> On 26/06/2026 16:07, Andrew Stubbs wrote:
> > Adds new features to the GDB Python script that prints GCC
> > internals.
> > 
> > - Improved output for rtx_def types.
> > - Also enable printing for rtx, const_rtx, rtx_insn, etc.
> > - Add icode details for rtx_insn.
> > - Add register details for REG nodes.
> > 
> > Examples:
> >    <rtx_def 0x12345678 (mem)>
> >    <rtx_def 0x12345678 (reg:DI 685 pseudo)>
> >    <rtx_def 0x12345678 (reg:DI 1 r1)>
> >    <rtx_def 0x12345678 (insn 160 movdi_symbol)>
> > 
> > gcc/ChangeLog:
> > 
> >     * gdbhooks.py (Rtx): Decode more things.
> >     (RtxPrinter): Improve output.
> >     (build_pretty_printer): Match more rtx types.
> > ---
> >   gcc/gdbhooks.py | 54 ++++++++++++++++++++++++++++++++++----------
> > -----
> >   1 file changed, 38 insertions(+), 16 deletions(-)
> > 
> > diff --git a/gcc/gdbhooks.py b/gcc/gdbhooks.py
> > index 616fc605f62..74f358d51f2 100644
> > --- a/gcc/gdbhooks.py
> > +++ b/gcc/gdbhooks.py
> > @@ -423,6 +423,9 @@ class Rtx:
> >       def GET_CODE(self):
> >           return self.gdbval['code']
> >   
> > +    def XINT(self, n):
> > +        return self.gdbval['u']['fld'][n]['rt_int']
> > +
> >   def GET_RTX_LENGTH(code):
> >       val_rtx_length = gdb.parse_and_eval('rtx_length')
> >       return intptr(val_rtx_length[code])
> > @@ -435,30 +438,45 @@ def GET_RTX_FORMAT(code):
> >       val_rtx_format = gdb.parse_and_eval('rtx_format')
> >       return val_rtx_format[code].string()
> >   
> > +def get_insn_name(icode):
> > +    return gdb.parse_and_eval('insn_data')[icode]['name'].string()
> > +
> > +def reg_name(regno):
> > +    val_reg_names = gdb.parse_and_eval('reg_names')
> > +    try:
> > +        return val_reg_names[regno].string()
> > +    except:
> > +        return "pseudo"
> > +
> > +def mode_name(mode):
> > +    return gdb.parse_and_eval('mode_name')[mode].string()
> > +
> >   class RtxPrinter:
> >       def __init__(self, gdbval):
> >           self.gdbval = gdbval
> >           self.rtx = Rtx(gdbval)
> >   
> >       def to_string (self):
> > -        """
> > -        For now, a cheap kludge: invoke the inferior's print
> > -        function to get a string to use the user, and return an
> > empty
> > -        string for gdb
> > -        """
> > -        # We use print_inline_rtx to avoid a trailing newline
> > -        gdb.execute('call print_inline_rtx (stderr, (const_rtx)
> > %s, 0)'
> > -                    % intptr(self.gdbval))
> > -        return ''

...in that you're replacing the terrible kludge I wrote for this back
in 2013...

> > -
> > -        # or by hand; based on gcc/print-rtl.c:print_rtx
> >           result = ('<rtx_def 0x%x'
> >                     % (intptr(self.gdbval)))
> >           code = self.rtx.GET_CODE()
> > -        result += ' (%s' % GET_RTX_NAME(code)
> > -        format_ = GET_RTX_FORMAT(code)
> > -        for i in range(GET_RTX_LENGTH(code)):
> > -            print(format_[i])
> > +        name = GET_RTX_NAME(code)
> > +        result += ' (%s' % name
> > +        if name == 'insn' or name == 'call_insn' or name ==
> > 'jump_insn':
> > +            result += ' %d' % self.gdbval['u2']['insn_uid']
> > +            icode = self.rtx.XINT(5)

(might want a trailing comment here: # INSN_CODE)

> > +            if icode != -1:
> > +                result += ' %s' % get_insn_name(icode)
> > +            else:
> > +                result += ' <unrecognized>'
> > +        elif name == 'reg':
> > +            regno = self.gdbval['u']['reg']['regno']
> > +            mode = mode_name(self.gdbval['mode'])
> > +            result += ':%s %d %s' % (mode, regno, reg_name(regno))
> > +        #else:
> > +        #format_ = GET_RTX_FORMAT(code)
> > +        #for i in range(GET_RTX_LENGTH(code)):
> > +        #    print(format_[i])

...though I see that you're commenting out my old implementation for
this case.  How well does it work?  Should we just remove it?  Is any
of it worth saving?  IIRC I tried it, had issues with it, and found the
kludge easier, but that was 13 years ago.

One other nit: please update the multiline string at the top of the
file, in particular the "RTL expressions use a kludge" part, which is
no longer true with your improvement.

OK with those nits addressed.

Hope this sounds sane; thanks again for the patch.
Dave

Reply via email to