xdebug / vscode-php-debug

PHP Debug Adapter for Visual Studio Code 🐞⛔
MIT License
781 stars 178 forks source link

Cant expand/inspect objects in Watch but can in Variables #804

Closed nickchomey closed 2 years ago

nickchomey commented 2 years ago

I'm creating a new issue here to follow-on from a comment I made on this closed issue: https://github.com/xdebug/vscode-php-debug/issues/52

I can drill-down into objects in the Variables pane, but not in Watch. I can't expand $bp->data and trying to watch that directly just returns null.

image

PHP version: 7.4.29 Xdebug version: 3.1.4 VS Code extension version: 1.25.0

Your launch.json:

"version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "maxConnections": 1
        },
}

Xdebug php.ini config: <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">

DBGp Settings |   -- | -- Max Children | 32 Max Data | 1024 Max Depth | 1 Show Hidden Properties | No Extended Properties | No Notifications | No Resolved Breakpoints | No Breakpoint Details | No   |   PHP |   Build Configuration |   Version (Run Time) | 7.4.29 Version (Compile Time) | 7.4.3 Debug Build | no Thread Safety | disabled   |   Directive | Local Value xdebug.mode | debug, develop xdebug.start_with_request | trigger xdebug.start_upon_error | default xdebug.use_compression | 1 xdebug.file_link_format | no value xdebug.filename_format | no value xdebug.log | no value xdebug.log_level | 7 xdebug.var_display_max_children | -1 xdebug.var_display_max_data | -1 xdebug.var_display_max_depth | -1 xdebug.max_nesting_level | 256 xdebug.cli_color | 0 xdebug.force_display_errors | Off xdebug.force_error_reporting | 0 xdebug.halt_level | 0 xdebug.max_stack_frames | -1 xdebug.show_error_trace | Off xdebug.show_exception_trace | Off xdebug.show_local_vars | Off xdebug.dump.COOKIE | no value xdebug.dump.ENV | no value xdebug.dump.FILES | no value xdebug.dump.GET | no value xdebug.dump.POST | no value xdebug.dump.REQUEST | no value xdebug.dump.SERVER | no value xdebug.dump.SESSION | no value xdebug.dump_globals | On xdebug.dump_once | On xdebug.dump_undefined | Off xdebug.profiler_append | Off xdebug.cloud_id | no value xdebug.client_host | localhost xdebug.client_port | 9003 xdebug.discover_client_host | Off xdebug.client_discovery_header | no value xdebug.idekey | no value xdebug.connect_timeout_ms | 200 xdebug.scream | Off xdebug.gc_stats_output_name | gcstats.%p xdebug.trace_output_name | trace.%c xdebug.trace_format | 0 xdebug.trace_options | 0 xdebug.collect_assignments | Off xdebug.collect_return | Off

Xdebug logfile (from setting xdebug.log in php.ini): I cant create one - level 7 doesnt show anything relevant and level 10 creates an 8GB file.

VS Code extension logfile (from setting "log": true in launch.json): phpdebuglog.txt

Code snippet to reproduce:

In my case need to install buddypress, but I suspect it happens for any object.

zobo commented 2 years ago

Thanks for the report. I'll look at it asap

nickchomey commented 2 years ago

I just discovered the xdebug settings parameters for launch.json. When I set max depth to a higher number, I can then expand $bp. However, I still can't see $bp->data in the Watch panel. I tried making max_data extremely high (thinking perhaps it had run out of space) but that didn't help

"xdebugSettings": {
    "max_depth": 2,
    "max_children": 1000,
    "max_data": 10000000
},

I'm glad to have found this because it also solves my issue with the children being limited. I'll explore the other settings as well. But the $bp->data issue seems worth investigating. Though, your documentation says this about max_depth(there should be no need to change this as depth is retrieved incrementally, large value can cause IDE to hang).. Does that mean it should automatically be setting its depth? If so, that's worth looking into as well

Thanks!

zobo commented 2 years ago

Hi!

Regarding drill down. The Watch pane currently uses eval to retrieve the variable value. The sad side effect here is that drill down isn't available directly. Increasing max_depth is one way around this, another is something I have implemented in the Inspect window (Debug Console). I will probably extend the Watch implementation too.

Regarding the $bp->data issue, I looked at the dump and here is what I see:

When the variable is inspected this is a small part of the response:

<property name="data" facet="private" type="array" children="1" numchildren="67">

I see here that this is a private field and so evaluating $bp->data should indeed return null.

A way around this would be to change the internal logic of Watch, so that it would try to use propery_get insted of eval. I am already doing this for Hover and it's already causing issues in some edge cases. See https://github.com/xdebug/vscode-php-debug/issues/742#issue-1134357885

Indeed you can write anything in the Watch pane, so the logic would need to be really smart on when to use property_get and when eval.

I will have a look at it.

I, sadly, don't have a solution for you at the moment - aside from changing the property to public...

nickchomey commented 2 years ago

Thanks very much for looking into this so quickly! That all makes sense. I think my problem is largely solved just from changing the max_depth setting - I can very easily just watch $bp and then drill down into $bp->data from there. So, don't put any more effort into this unless you think that it might be relevant to broader changes that you already have in mind.

Thanks again!