Skip to content

GDB: format output for class entries and class constants #15955

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
Oct 9, 2024

Conversation

DanielEScherzer
Copy link
Member

@DanielEScherzer DanielEScherzer commented Sep 19, 2024

For zend_string pointers in class entries, show the string contents (if not NULL).

For class constants, the ce (class entry pointer) field is shown with the name of the class, and the doc_comment field is shown with the string ontents if possible.

@iluuu1994
Copy link
Member

For class entries, for null pointers replace 0x0 with NULL for clarity.

Is this really necessary? NULL is literally just # define NULL ((void*)0) in C.

For class constants, the ce (class entry pointer) field is shown with the name of the class, the doc_comment field is shown with the string contents if possible, and NULL if not

Displaying the name directly does seem useful, but isn't it possible to solve this more generically by creating a pretty-printer that supports zend_string?

/cc @arnaud-lb

@arnaud-lb
Copy link
Member

For class entries, for null pointers replace 0x0 with NULL for clarity.

Is this really necessary? NULL is literally just # define NULL ((void*)0) in C.

I also think that 0x0 is fine, as it's usual in gdb

For class constants, the ce (class entry pointer) field is shown with the name of the class, the doc_comment field is shown with the string contents if possible, and NULL if not

Displaying the name directly does seem useful, but isn't it possible to solve this more generically by creating a pretty-printer that supports zend_string?

There is a zend_string pretty-printer, but not a zend_string* one:

(gdb) p ce.name
$1 = (zend_string *) 0x125e900
(gdb) p *ce.name
$2 = "ReflectionClass" = {gc = {refcount = 617, u = {type_info = 502}}, h = 12675994317140297638, len = 15, val = "ReflectionClass"}

We could have a zend_string* pretty-printer, but it should not hide the pointer type and address, as these are useful information. I would suggest to print something like this (type, address, string, but not the struct contents) :

(zend_string *) 0x125e900 "ReflectionClass"

@iluuu1994
Copy link
Member

Some infos are still useful, i.e. whether the string is interned, persistent, etc. Maybe also print that?

@arnaud-lb
Copy link
Member

That would clutter the output, especially in print pretty off mode as everything is on the same line. These information can be easily printed by dereferencing the pointer.

If we have

(gdb) p *ce
$3 = {
  type = 1 '\001',
  name = (zend_string*) 0x125e8f0 "ReflectionClass"
  ...
}

We can easily inspect the name with

(gdb) p *(zend_string*) 0x125e8f0

or

(gdb) p *ce.name

For `zend_string` pointers in class entries, show the string contents (if not
`NULL`).

For class constants, the `ce` (class entry pointer) field is shown with the
name of the class, and the `doc_comment` field is shown with the string
contents if possible.
@DanielEScherzer
Copy link
Member Author

We could have a zend_string* pretty-printer, but it should not hide the pointer type and address, as these are useful information. I would suggest to print something like this (type, address, string, but not the struct contents) :

I spent a while trying to get a pointer printer to work and couldn't get GDB to apply it when looking at pointers, but if you know how to do this I agree that it would be nice to have

I also think that 0x0 is fine, as it's usual in gdb

Removed the extra NULL handling

@arnaud-lb
Copy link
Member

I spent a while trying to get a pointer printer to work and couldn't get GDB to apply it when looking at pointers, but if you know how to do this I agree that it would be nice to have

My bad, tried it too and I don't think there is a way to pretty print pointers after all

@arnaud-lb arnaud-lb merged commit e34eebb into php:master Oct 9, 2024
10 checks passed
@arnaud-lb
Copy link
Member

Thank you @DanielEScherzer!

@DanielEScherzer DanielEScherzer deleted the gdb branch October 9, 2024 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants