richterger / Perl-LanguageServer

Language Server for Perl
Other
220 stars 53 forks source link

Debugger support for breakpoints in Catalyst #126

Open s13ffen opened 2 years ago

s13ffen commented 2 years ago

I greatly appreciated the work on this project, as it helps me in my everyday coding.

I have some projects, which run a perl backend server using Catalyst, but I do not get breakpoints of the Perl-LanguageServer debugger to work properly.

I am able to debug the code using the standard debugger for my server like this: perl -d ./script/my_server.pland inserting breakpoints in the code using $DB::single=1;

I launch the debugger of the Perl-LanguageServer using this configuration: "program": "${workspaceFolder}/script/my_server.pl" This launches the Catalyst Server correctly, but breakpoints set using the Perl-LanguageServer debugger are shown as "Unverified Breakpoint" and do not make the debugger stop at this point. Breakpoints defined as before using $DB::single=1; have the Perl-LanguageServer debugger stop and work as expected.

I wonder whether this is where the Perl-LanguageServer fails my debugging approaches: The called perl script ./script/my_server.pl calls the Catalyst App using the ScriptRunner: Catalyst::ScriptRunner->run('MyServer', 'Server');

One additional remark: While running the debugger with perl -d the breakpoints are shown without the error, but do not make the perl -d debugger stop.

Maybe someone has an idea on how to get the Perl-LanguageServer debugger breakpoints work with Catalyst.

tangledhelix commented 2 years ago

I haven't managed to make the debugger breakpoints work either (meaning the red dot in the gutter), I get the same "Unverified Breakpoint" message. But I have a config that works with $DB::single=1; and does cause the VScode debugger to stop at that point. Variable watches, etc, are all working at that point too.

Here's my config (minus some things that are very specific to my app that you won't care about). I'm using Perlbrew, but there's no reason this won't work with any other Perl, as long as Perl::LanguageServer is installed in that Perl.

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "perl",
            "request": "launch",
            "name": "Perl Debug local-perlbrew :3001",
            "program": "${workspaceRoot}/script/myapp_server.pl",
            "exec": "/Users/dan/perl5/perlbrew/perls/perl-5.35.6/bin/perl -d",
            "args": ["-p", "3001"],
            "cwd": "${workspaceRoot}/",
            "env": {
                "DBIC_TRACE": 1,
                "CATALYST_DEBUG": 1,
                "PERL_UNBUFFERED": 1
            },
            "stopOnEntry": false,
            "reloadModules": true
        }
    ]
}

One note: it still works if stopOnEntry is true - I just have no use for that and I always click Continue, so I just turned it off.

ecos-ps commented 2 years ago

I haven't worked with Catalyst or any other CGI webserver by now. I guess it has something to do with forking inside of a webserver. The Perl Language Server doesnt support forking by now and it is quite complex. (see #102)

The author doesnt need this feature, but considers it very useful. (see https://github.com/richterger/Perl-LanguageServer/issues/102#issuecomment-932820607)

Contributions welcome.

richterger commented 2 years ago

@ecos-ps I don't think that has somethin to do with forking.

I don't use Catalyst, so I can only guess. Breakpoints can only be set, when the Code (Perl module) is loaded. Perl::LanguageServer listens to notifications form the debugger, when new modules are loaded and sets the breakpoints. I don't know how Catalyst loads it's code, but I would expect, that LanguageServer doesn't get notified.

You can try to break into the debugger, with $DB::single=1 and set a breakpoint at the next line. Does this work?

Second question: Does signle stepping works after the break with $DB::single ?