perlvisual-studio-codevscode-debuggervscode-remote

VSCode debugger runs Perl scripts in an (almost) empty environment


I'm running VSCode on OpenSuse Leap 15.6, connecting to a remote SSH instance running on Ubuntu 22.04. Client and server are both updated.

I've been using the Perl - Language Server and Debugger for Perl extension for years without any problems.

Since a few weeks the scripts that I attempt to debug in order to fix minor (unrelated) problems die when run into the debugger.

I figured this is due to some missing environment variables, specifically some environment variables I defined in /etc/environment; turns out, only these environment variables are available to my scripts when they run in the debugger:

$VAR1 = 'PLSDI_REMOTE=127.0.0.1:13605';
$VAR1 = 'PERL5DB=BEGIN { $| = 1 ; require Perl::LanguageServer::DebuggerInterface }';
$VAR1 = 'PLSDI_SESSION=95bf6688-2283-4f55-b02e-ca37ae4d6027';
$VAR1 = 'PLSDI_OPTIONS=reload_modules';

Basically everything is missing. Most notably, PATH, whose absence is preventing a few commands that are run in backticks (that are meant to undergo shell interpretation) from being resolved to actual executables.

Perl scripts run in VSCode's terminal / outside of VSCode (for example when connected to the server via SSH) run perfectly and have access to the full environment. The environment is empty only when the scripts are run in VSCode's debugger.

My launch.json configurations never explicitly set any environment variable, yet everything has been working fine up until now.

Did something change? I may have inadvertedly changed something that led to this, but if that's the case, for the life of me I can't figure out what it is.

What could be the reason for the suddenly empty environment?

Right now I'm explicitly setting the environment in each and every launch.json configuration I need to run, which is getting annoying pretty fast.


% code --version
1.92.0
b1c0a14de1414fcdaa400695b4db1c0799bc3124
x64

Remote - SSH version: v0.113.1

Perl - Language Server and Debugger for Perl version: v2.6.2


Steps to reproduce:

  1. Install VSCode
  2. Install the Remote - SSH extension
  3. Connect to a remote SSH instance
  4. Install the Perl - Language Server and Debugger for Perl extension;
  5. Add a configuration to debug a script (such as this one) to launch.json:
{
    "type": "perl",
    "request": "launch",
    "name": "test.pl",
    "program": "/home/user/playground/test.pl",
    "reloadModules": true,
    "stopOnEntry": true,
}
  1. Create the script:
#!/usr/bin/env perl

use strict;
use warnings;

use open qw(:std :utf8);

use Data::Dumper;

while (my ($k, $v) = each(%ENV)) {
    print Dumper $k . '=' . $v;
}
  1. Run the configuration in the debugger and check the output console. This shows up:
$VAR1 = 'PLSDI_REMOTE=127.0.0.1:13605';
$VAR1 = 'PERL5DB=BEGIN { $| = 1 ; require Perl::LanguageServer::DebuggerInterface }';
$VAR1 = 'PLSDI_SESSION=95bf6688-2283-4f55-b02e-ca37ae4d6027';
$VAR1 = 'PLSDI_OPTIONS=reload_modules';

Solution

  • Updating the Perl::LanguageServer module fixed the issue:

    cpan Perl::LanguageServer
    

    I'll speculate this was due to the extension suddenly updating to a version that didn't cope well with the (older) installed version of Perl::LanguageServer. Which also is kinda hard to explain since I had auto-update turn on on the extension and the last version is several months old (hence I should've long experienced the issue), so I don't know.

    Anyways the takeaway is, if you're using the extension, always make sure both the extension and Perl::LanguageServer are up to date.