GDB: apply ast pretty printing to specialized structures (#17884)

The `ZendAstPrettyPrinter` had logic to handle the various structures that are
based on `zend_ast`, like `zend_ast_decl`, but the printer was only installed
when the value was a `zend_ast`, meaning that for the specialized structures
the details wouldn't be shown unless they were cast (in GDB) to `zend_ast`.
Instead, just register the printer for the specialized structures too.
This commit is contained in:
DanielEScherzer 2025-02-25 00:17:14 -08:00 committed by GitHub
parent cc116067b2
commit 0b42749621
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 2 deletions

View file

@ -826,7 +826,11 @@ asm(
".ascii \"pp_set.add_printer('zend_ast_kind', '^zend_ast_kind$', ZendAstKindPrettyPrinter)\\n\"\n"
".ascii \"\\n\"\n"
".ascii \"class ZendAstPrettyPrinter(gdb.printing.PrettyPrinter):\\n\"\n"
".ascii \" \\\"Print a zend_ast\\\"\\n\"\n"
".ascii \" \\\"\\\"\\\"\\n\"\n"
".ascii \" Print a zend_ast, or one of the specialized structures based on it:\\n\"\n"
".ascii \" zend_ast_decl, zend_ast_list, zend_ast_op_array, zend_ast_zval, or\\n\"\n"
".ascii \" zend_ast_znode\\n\"\n"
".ascii \" \\\"\\\"\\\"\\n\"\n"
".ascii \"\\n\"\n"
".ascii \" def __init__(self, val):\\n\"\n"
".ascii \" self.val = val\\n\"\n"
@ -899,6 +903,11 @@ asm(
".ascii \"\\n\"\n"
".ascii \"\\n\"\n"
".ascii \"pp_set.add_printer('zend_ast', '^_zend_ast$', ZendAstPrettyPrinter)\\n\"\n"
".ascii \"pp_set.add_printer('zend_ast_decl', '^_zend_ast_decl$', ZendAstPrettyPrinter)\\n\"\n"
".ascii \"pp_set.add_printer('zend_ast_list', '^_zend_ast_list$', ZendAstPrettyPrinter)\\n\"\n"
".ascii \"pp_set.add_printer('zend_ast_op_array', '^_zend_ast_op_array$', ZendAstPrettyPrinter)\\n\"\n"
".ascii \"pp_set.add_printer('zend_ast_zval', '^_zend_ast_zval$', ZendAstPrettyPrinter)\\n\"\n"
".ascii \"pp_set.add_printer('zend_ast_znode', '^_zend_ast_znode$', ZendAstPrettyPrinter)\\n\"\n"
".ascii \"\\n\"\n"
".ascii \"class ZvalPrettyPrinter(gdb.printing.PrettyPrinter):\\n\"\n"
".ascii \" \\\"Print a zval\\\"\\n\"\n"

View file

@ -156,7 +156,11 @@ class ZendAstKindPrettyPrinter(gdb.printing.PrettyPrinter):
pp_set.add_printer('zend_ast_kind', '^zend_ast_kind$', ZendAstKindPrettyPrinter)
class ZendAstPrettyPrinter(gdb.printing.PrettyPrinter):
"Print a zend_ast"
"""
Print a zend_ast, or one of the specialized structures based on it:
zend_ast_decl, zend_ast_list, zend_ast_op_array, zend_ast_zval, or
zend_ast_znode
"""
def __init__(self, val):
self.val = val
@ -229,6 +233,11 @@ class ZendAstPrettyPrinter(gdb.printing.PrettyPrinter):
pp_set.add_printer('zend_ast', '^_zend_ast$', ZendAstPrettyPrinter)
pp_set.add_printer('zend_ast_decl', '^_zend_ast_decl$', ZendAstPrettyPrinter)
pp_set.add_printer('zend_ast_list', '^_zend_ast_list$', ZendAstPrettyPrinter)
pp_set.add_printer('zend_ast_op_array', '^_zend_ast_op_array$', ZendAstPrettyPrinter)
pp_set.add_printer('zend_ast_zval', '^_zend_ast_zval$', ZendAstPrettyPrinter)
pp_set.add_printer('zend_ast_znode', '^_zend_ast_znode$', ZendAstPrettyPrinter)
class ZvalPrettyPrinter(gdb.printing.PrettyPrinter):
"Print a zval"