Skip to content
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

Feature Request: Auto Attach Filter setting #957

Closed
trymeouteh opened this issue Apr 7, 2024 · 2 comments
Closed

Feature Request: Auto Attach Filter setting #957

trymeouteh opened this issue Apr 7, 2024 · 2 comments

Comments

@trymeouteh
Copy link

The JavaScript Debug extension has a setting named "Auto Attach Filter". It allows you to choose from one of the three settings

  • disabled (Default)
  • onlyWithFlag
  • always

Having this setting in PHP Debug can allow a user to run a PHP script in the terminal, with custom arguements and have the debugger.

@trymeouteh
Copy link
Author

trymeouteh commented Apr 8, 2024

I found a way around this.

I created these three PHP VSCode debug launch configurations. The PHP: Console one will allow you to run the currently opened PHP script in the VSCode debug console. The PHP: Terminal one will allow you to run any PHP script on your device using the terminal, when you start debugging it will wait for you to run the script and then start debugging, allowing you to use arguments within the script.

    "launch": {
        "configurations": [
            {
                "name": "PHP: Console",
                "type": "php",
                "request": "launch",
                "program": "${file}",
                "cwd": "${fileDirname}"
            },
            {
                "name": "PHP: Terminal",
                "type": "php",
                "request": "launch"
            }
        ]
    },

And this is what I added to my php.ini on the system

xdebug.mode = debug
xdebug.start_with_request = yes

I am using xdebug v3

The only minor downside to using the PHP: Terminal is that the outputs will only be in the terminal and not in the debug console. You can still use the debug console to change variable values for example, but any echo calls will appear in the terminal and not in the debug console.

@zobo
Copy link
Contributor

zobo commented Apr 8, 2024

Hi @trymeouteh sorry for not getting back to you earlier.

I did not have much time to look at how JS-debug's "Auto Attach Filter" works, but from the documentation it seems like it sets some environment variables in the terminal that it opens.

PHP/Xdebug work in similar but not completely same way.

It's good to understand that VSCODE IDE listens for incoming debug connections and PHP/Xdebug initiates the debug connection. It does so when it is correctly configured. The XDEBUG_MODE has to contain the "debug" switch and there must either be a xdebug.start_with_request setting or a trigger env variable XDEBUG_SESSION. See https://xdebug.org/docs/step_debug#activate-debugger-cmd

So if Xdebug is loaded, but not configured, you probably could get it to connect to the IDE if you set environment variables XDEBUG_MODE=debug and XDEBUG_SESSIONS=1.

There are options how this could be implemented, but I do not really see a benefit over using launch.json to start a program.
Is there any reason you want to do it directly from the terminal?

Regarding the output. Yes, the stdout and strerr will be printed in the terminal, where the PHP script is executing. If you start the script via the launch.json program option the script will be executed by the php-debug extension and so it can capture the output and display it in the debug console.

There is also an option to redirect STDOUT of the script via a DBGP command, but this is not exposed in any way in the current php-debug extension. STDOUT redirection is not possible though...

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

No branches or pull requests

2 participants