richterger / Perl-LanguageServer

Language Server for Perl
Other
224 stars 53 forks source link

perl crash when starting Perl::LanguageServer::run #24

Closed 0-wiz-0 closed 3 years ago

0-wiz-0 commented 4 years ago

Hi!

I've just packaged Perl-LanguageServer for pkgsrc and wanted to try it out with emacs/lsp-mode. That didn't work:

Bareword found where operator expected at - line 0, near "--port"
(Missing operator before port?)
Number found where operator expected at - line 0, near "port 32443"
(Do you need to predeclare port?)
Bareword found where operator expected at - line 0, near "--version"
(Missing operator before version?)
Number found where operator expected at - line 0, near "version 2.1.0"
(Do you need to predeclare version?)

so I looked over the bug reports and found this example usage:

perl -MPerl::LanguageServer -e Perl::LanguageServer::run

when I try this, I get a perl core dump:

(gdb) bt                                                               
#0  0x00007a499eb001e0 in ?? ()
#1  0x00007a499c408b8d in save_perl (my_perl=my_perl@entry=0x7a49a1888000, c=c@entry=0x7a499eb42700) at State.xs:954
#2  0x00007a499c40d880 in transfer (my_perl=my_perl@entry=0x7a49a1888000, prev=0x7a499eb42700, next=0x7a499eb42900, force_cctx=force_cctx@entry=0) at State.xs:1744               
#3  0x00007a499c40dfad in pp_slf (my_perl=0x7a49a1888000) at State.xs:2783
#4  0x00007a49a130b066 in Perl_runops_standard (my_perl=0x7a49a1888000) at run.c:42
#5  0x00007a49a127bccd in S_run_body (oldscope=<optimized out>, my_perl=<optimized out>) at perl.c:2716
#6  perl_run (my_perl=0x7a49a1888000) at perl.c:2639
#7  0x000000000040141e in main (argc=<optimized out>, argv=<optimized out>, env=<optimized out>) at perlmain.c:127
(gdb) quit                                                                                                                                     ````

An example from another bug report does work:

perl -e 'use Data::Dumper; use Perl::LanguageServer::Parser; my $source; { open my $fh, "<", $ARGV[0]; local $/; $source=<$fh>; } my $vars = Perl::LanguageServer::Parser::parse_perl_source(undef, "x", $source); print Dumper($vars);' path/to/some/perl/file.pm

gives me a long dump.

Any ideas how to debug this?

0-wiz-0 commented 4 years ago

I found the command line lsp-mode uses:

perl -MPerl::LanguageServer -e Perl::LanguageServer::run -- --port 32443 --version 2.1.0

That produces a core dump like above.

I hadn't mentioned bfore: I use Compiler-Lexer-0.23. I see no relevant diffs to the copy included in the Perl-LanguageServer distribution on cpan.

richterger commented 4 years ago

Which OS and which Perl Version you are using?

You can try out this small script to parse a file:

use ExtUtils::testlib ;
use lib ('lib') ;

use Perl::LanguageServer::Parser ;
use Data::Dump qw{dump} ;

my $filename = $ARGV[0];

open(my $fh, "<", $filename) or die("Cannot open $filename: $!");
my $script = do { local $/; <$fh> };

my ($vars, $tokens) = Perl::LanguageServer::Parser -> parse_perl_source ($filename, $script) ;

 print dump ($tokens), "\n" ;
 print dump ($vars), "\n" ;
0-wiz-0 commented 4 years ago

I'm running on NetBSD/amd64/9.99.67. Perl is, in general, running very well on NetBSD. The perl version is 5.30.3. The script you pasted seems to work fine, it produces output without a core dump.

richterger commented 4 years ago

I guess this is an issue with Coro or AnyEvent. Since I am not using NetBSD I have no idea what's wrong. The command line your using should never core dump, but just wait for input. You can run it with --debug i.e.

perl -MPerl::LanguageServer -e Perl::LanguageServer::run --debug

Maybe this give a hint were it crashs. Anyway, maybe you can find some known issues for Coro or AnyEvent on NetBSD.

0-wiz-0 commented 4 years ago

Thanks for the suggestion. AnyEvent seems to work fine, but Coro does not run its self tests successfully: https://rt.cpan.org/Public/Bug/Display.html?id=133270 I hope that fixing that will fix the issue here.

0-wiz-0 commented 3 years ago

The problem was in libpthread via Coro. The pkgsrc package has a bugfix. https://github.com/NetBSD/pkgsrc/blob/trunk/devel/p5-Coro/patches/patch-Coro_libcoro_coro.c