xdebug / vscode-php-debug

PHP Debug Adapter for Visual Studio Code 🐞⛔
MIT License
768 stars 175 forks source link

Ignore requests to specific endpoints entirely #909

Closed iandunn closed 1 year ago

iandunn commented 1 year ago

I'd like to completely ignore any request that comes in to a specific file/URL. I've tried using skipFiles and ignore, but it seems like those will still handle the request, but they will skip the file when stepping through the codebase.


PHP version: 8.0.28 Xdebug version: 3.2.0 VS Code extension version: 1.32.1

launch.json:

{
    "name": "Listen for Xdebug",
    "type": "php",
    "request": "launch",
    "port": 9003,

    "skipFiles": [
        "admin-ajax.php",
        "**/admin-ajax.php",
        "${workspaceFolder}/public_html/mu/wp-admin/admin-ajax.php"
      ],

      "ignore": [
        "admin-ajax.php",
        "**/admin-ajax.php",
        "${workspaceFolder}/public_html/mu/wp-admin/admin-ajax.php"
      ],

      "maxConnections": 1
}

Xdebug php.ini config:

[xdebug]
zend_extension=/opt/homebrew/Cellar/php@8.0/8.0.28/pecl/20200930/xdebug.so

xdebug.mode = debug,develop
xdebug.idekey = iandunn
xdebug.client_host = 127.0.0.1
xdebug.cli_color = 1
xdebug.var_display_max_data = 1024
xdebug.var_display_max_depth = 6
zobo commented 1 year ago

Hi! skipFiles is for skipping over files when you do a step-in operation. Commonly referred to as "Just My Code", where you typically don't want to step into framework or vendor code.

ignore is very similar but just ignores exceptions/errors inside those files. "I don't care about exceptions inside vendor.".

Now for your request. If I understand, you would like to debug only certain "entrypoints" or better ignore some entrypoints? There is currently no configuration for this but what you could do is add some PHP code that can help you here. Although there is no what to disconnect from debugger in code there is a xdebug_connect_to_client function that can trigger a connection to debugger from code.

How you could use this is that you don't initiate a debug session from the browser (do not set the XDEBUG_SESSION cookie) but rather add a call xdebug_connect_to_client(); in such code location that will only trigger on the desired entrypoint.

Let me know if this is clear. And be sure not to commit and deploy to production :)

Maybe you could also abuse the XDEBUG_SESSION_STOP GET parameter, but I have not tried such monstrosity...

Best!

iandunn commented 1 year ago

Thanks, that's helpful info. It doesn't seem too convenient, though. I switched over from PHPStorm and it was easy to do this there, so I was looking for something similar.

IMO it'd be a good feature to add, but I totally understand if there isn't a lot of demand for it.

zobo commented 1 year ago

I see. Should not be that hard to implement. Will leave this open and see if I can get to it.

iandunn commented 1 year ago

Sounds good, thanks!

iandunn commented 1 year ago

This is working for me, thanks!