Skip to content

Add GDB pretty-printer for zend_ast #13520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 2024

Conversation

arnaud-lb
Copy link
Member

This builds on top of #13463 to add GDB pretty-printers for zend_ast. Since ASTs contain zval, I've also included a minimal zval pretty printer.

Similarly to #13463, with these printers I'm trying to not hide the internals of the pretty printed types as this would be inconvenient when debugging. I just use to_string() to print a small string representation of the type when possible, and children() to help GDB walk the struct.

As zend_ast are deep structures, these settings are useful:

(gdb) set print pretty on
(gdb) set print max-depth 2

The first one enables indentation.

(gdb) p ast
$1 = (zend_ast *) 0x7ffff7a87180

(gdb) p /r *ast
$2 = {
  kind = 67,
  attr = 0,
  lineno = 1,
  child = {0x1}
}

(gdb) p *ast
$3 = ((zend_ast_decl*)0x7ffff7a87180) = {
  kind = ZEND_AST_FUNC_DECL,
  attr = 0,
  start_lineno = 1,
  end_lineno = 1,
  flags = 0,
  doc_comment = 0x0,
  name = "some_function_name",
  child[0] = ((zend_ast_list*)0x7ffff7a870c0) = {
    kind = ZEND_AST_PARAM_LIST,
    attr = 0,
    lineno = 1,
    children = 2,
    child[0] = ((zend_ast*)0x7ffff7a87090) = {...},
    child[1] = ((zend_ast*)0x7ffff7a87120) = {...}
  },
  child[1] = 0x0,
  child[2] = ((zend_ast_list*)0x7ffff7a87150) = {
    kind = ZEND_AST_STMT_LIST,
    attr = 0,
    lineno = 1,
    children = 0
  },
  child[3] = 0x0,
  child[4] = 0x0
}

@arnaud-lb arnaud-lb changed the title Add GDB pretty-printers for zend_ast Add GDB pretty-printer for zend_ast Feb 26, 2024
@arnaud-lb
Copy link
Member Author

I'm going to merge this in a few days unless there are objections

@arnaud-lb arnaud-lb force-pushed the gdb-pretty-printer-ast branch from 1741e33 to 407669e Compare April 12, 2024 11:09
@arnaud-lb arnaud-lb marked this pull request as ready for review April 12, 2024 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant