Skip to content

Commit 0b42749

Browse files
GDB: apply ast pretty printing to specialized structures (php#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.
1 parent cc11606 commit 0b42749

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

main/debug_gdb_scripts.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,11 @@ asm(
826826
".ascii \"pp_set.add_printer('zend_ast_kind', '^zend_ast_kind$', ZendAstKindPrettyPrinter)\\n\"\n"
827827
".ascii \"\\n\"\n"
828828
".ascii \"class ZendAstPrettyPrinter(gdb.printing.PrettyPrinter):\\n\"\n"
829-
".ascii \" \\\"Print a zend_ast\\\"\\n\"\n"
829+
".ascii \" \\\"\\\"\\\"\\n\"\n"
830+
".ascii \" Print a zend_ast, or one of the specialized structures based on it:\\n\"\n"
831+
".ascii \" zend_ast_decl, zend_ast_list, zend_ast_op_array, zend_ast_zval, or\\n\"\n"
832+
".ascii \" zend_ast_znode\\n\"\n"
833+
".ascii \" \\\"\\\"\\\"\\n\"\n"
830834
".ascii \"\\n\"\n"
831835
".ascii \" def __init__(self, val):\\n\"\n"
832836
".ascii \" self.val = val\\n\"\n"
@@ -899,6 +903,11 @@ asm(
899903
".ascii \"\\n\"\n"
900904
".ascii \"\\n\"\n"
901905
".ascii \"pp_set.add_printer('zend_ast', '^_zend_ast$', ZendAstPrettyPrinter)\\n\"\n"
906+
".ascii \"pp_set.add_printer('zend_ast_decl', '^_zend_ast_decl$', ZendAstPrettyPrinter)\\n\"\n"
907+
".ascii \"pp_set.add_printer('zend_ast_list', '^_zend_ast_list$', ZendAstPrettyPrinter)\\n\"\n"
908+
".ascii \"pp_set.add_printer('zend_ast_op_array', '^_zend_ast_op_array$', ZendAstPrettyPrinter)\\n\"\n"
909+
".ascii \"pp_set.add_printer('zend_ast_zval', '^_zend_ast_zval$', ZendAstPrettyPrinter)\\n\"\n"
910+
".ascii \"pp_set.add_printer('zend_ast_znode', '^_zend_ast_znode$', ZendAstPrettyPrinter)\\n\"\n"
902911
".ascii \"\\n\"\n"
903912
".ascii \"class ZvalPrettyPrinter(gdb.printing.PrettyPrinter):\\n\"\n"
904913
".ascii \" \\\"Print a zval\\\"\\n\"\n"

scripts/gdb/php_gdb.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ def to_string(self):
156156
pp_set.add_printer('zend_ast_kind', '^zend_ast_kind$', ZendAstKindPrettyPrinter)
157157

158158
class ZendAstPrettyPrinter(gdb.printing.PrettyPrinter):
159-
"Print a zend_ast"
159+
"""
160+
Print a zend_ast, or one of the specialized structures based on it:
161+
zend_ast_decl, zend_ast_list, zend_ast_op_array, zend_ast_zval, or
162+
zend_ast_znode
163+
"""
160164

161165
def __init__(self, val):
162166
self.val = val
@@ -229,6 +233,11 @@ def num_children(self):
229233

230234

231235
pp_set.add_printer('zend_ast', '^_zend_ast$', ZendAstPrettyPrinter)
236+
pp_set.add_printer('zend_ast_decl', '^_zend_ast_decl$', ZendAstPrettyPrinter)
237+
pp_set.add_printer('zend_ast_list', '^_zend_ast_list$', ZendAstPrettyPrinter)
238+
pp_set.add_printer('zend_ast_op_array', '^_zend_ast_op_array$', ZendAstPrettyPrinter)
239+
pp_set.add_printer('zend_ast_zval', '^_zend_ast_zval$', ZendAstPrettyPrinter)
240+
pp_set.add_printer('zend_ast_znode', '^_zend_ast_znode$', ZendAstPrettyPrinter)
232241

233242
class ZvalPrettyPrinter(gdb.printing.PrettyPrinter):
234243
"Print a zval"

0 commit comments

Comments
 (0)