Ping.

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 ''
-
-        # 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)
+            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])
          result += ')>'
          return result
@@ -661,7 +679,11 @@ def build_pretty_printer():
      pp.add_printer_for_types(['edge', 'edge_def *'],
                               'edge',
                               CfgEdgePrinter)
-    pp.add_printer_for_types(['rtx_def *'], 'rtx_def', RtxPrinter)
+    pp.add_printer_for_types(['rtx_def *', 'rtx', 'const_rtx', 'rtx_insn *',
+                              'const rtx_insn *', 'rtx_jump_insn *',
+                              'const rtx_jump_insn *', 'rtx_call_insn *',
+                              'const rtx_call_insn *'],
+                             'rtx_def', RtxPrinter)
      pp.add_printer_for_types(['opt_pass *'], 'opt_pass', PassPrinter)
pp.add_printer_for_regex(r'vec<(\S+), (\S+), (\S+)> \*',

Reply via email to