richterger / Perl-LanguageServer

Language Server for Perl
Other
224 stars 53 forks source link

Allow attaching to a remote debugger #28

Open Nowaker opened 4 years ago

Nowaker commented 4 years ago

The approach in this extension is to have VS Code run perl -d on a file one wants to debug. This isn't an approach suitable for debugging big web applications that are started separately in a Docker container with -d parameter, and PERLDB_OPTS='RemotePort=127.0.0.1:9000' environment variable.

We need a way to instruct the extension to open a debug port (e.g. 9000) so that the web application can connect to it. The extension itself should not attempt to do perl -d [currentlyOpenedFileinVsCode].

bradmccormack commented 3 years ago

Would this require making changes such as

vscode.debug.registerDebugAdapterDescriptorFactory('perl', {
        createDebugAdapterDescriptor(session: vscode.DebugSession, executable: vscode.DebugAdapterServer) {

        }
    });

To handle the different type of debugging?

You have mentioned in the Debugger Settings for launch.json that only launch is an option due to limitations in Perl.

I believe that means that we can't attach the client to an existing debugger process but that doesn't stop making a change such as above so that we can start up a debugger process that sits there waiting for a web application to connect to it right?

I'm learning about developing VS Code extensions, in particular debugger extensions and would love to have this in place for Perl web projects.

Cheers!

richterger commented 3 years ago

It's not possible to attach to a running Perl programm. That is what I mean with limitation of Perl itself.

Of course it would be possible that a program is started with special debug options, that then connects to the debugger. Actually the LanguageServer already listens on a port for communication with the debugee. Maybe this can be used, to implement your use case.

This is not an use case for me at the moment and I have not the time to take care on it right now, but I am happy to support you, if you would like to work on this.

bradmccormack commented 3 years ago

It's not possible to attach to a running Perl programm. That is what I mean with limitation of Perl itself.

Of course it would be possible that a program is started with special debug options, that then connects to the debugger. Actually the LanguageServer already listens on a port for communication with the debugee. Maybe this can be used, to implement your use case.

This is not an use case for me at the moment and I have not the time to take care on it right now, but I am happy to support you, if you would like to work on this.

Thanks @richterger. Yeah I intend to start the web application with Perl debugging configured to point to the debugger server instance and not attach.

I appreciate your assistance.

Hopefully I'll get a PR up incorporating this.

nametable commented 3 years ago

@bradmccormack Any progress on this idea of making the web app connect to the debugger? I am also very interested in this as I work with web applications using perl, so I would be willing to help get it working also. Currently, I am resorting to saving the %ENV of the web application and then debugging the specific request later.

It would be really great to be able to debug each individual request as it comes in through Apache/nginx/whatever!

nametable commented 3 years ago

@bradmccormack Maybe it would be helpful for us to take a look at XDebug, it may be possible to do some direct porting of the PHP extension/adapter that uses XDebug (https://github.com/xdebug/vscode-php-debug).

@richterger Any thoughts on this? PHP uses xdebug as a .so library I believe but in Perl could we include some shell debug code before the real application to simulate what XDebug does for PHP?