Debugging Perl with Visual Studio Code
Asked Answered
K

4

12

I have just started with Perl today and installed ActivePerl 5.24.1 and everything went well. I was able to create my test program testPerl.pl with simple a print command and run it through console.

Now I wanted to use Visual Studio Code to run my Perl script, and so I opened the project folder [testPerl.pl location] with Visual Studio Code and tried to debug the code. I have installed the Perl-Debug extension in the editor and when I hit F5, Visual Studio Code asked me to Select Environment and I chose the Perl Debug option, which actually created the launch.json file for me with the below contents.

{
    "version": "0.0.2",
    "configurations": [
        {
            "type": "perl",
            "request": "launch",
            "exec": "perl",
            "name": "Perl-Debug",
            "root": "${workspaceRoot}/",
            "program": "${workspaceRoot}/${command.AskForProgramName}",
            "inc": [],
            "stopOnEntry": true
        }
    ]
}

I have kept default values as it, and when I hit F5 again, it asked me for a command with default value test.pl. It is because of ${command.AskForProgramName}, I assume. I entered my file name testPerl.pl in the command, but then nothing happens. It starts and ends without any print in console.

How can I actually configure this launch.json file or is there another way I need to do this?

Korikorie answered 19/1, 2017 at 5:55 Comment(4)
In this doc it says Please note that the attributes available in these launch configurations vary from debugger to debugger. You can use IntelliSense to find out which attributes exist for a specific debugger.Sleek
@Sleek Agreed, and it is as expected and creates its own auto-generated launch.json file and according to its auto generated file, it is as similar as what we execute in command line..Korikorie
Unfortunately I don't have access to a Windows box where I am allowed to install an ActivePerl so I cannot try. It certainly looks right. Is there some way to get what it's doing into the log panel of your VSCode?Sleek
I wish I could give you the details if it gets logged but unfortunately nothing logs in the Editor..Korikorie
H
3

I tried with a newer version of the plugin: Perl Debug version 0.2.0.

This works out of the box. The proposed configuration looks as follows:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "perl",
            "request": "launch",
            "name": "Perl-Debug local",
            "program": "${workspaceFolder}/${relativeFile}",
            "exec": "perl",
            "execArgs": [],
            "root": "${workspaceRoot}/",
            "inc": [],
            "args": [],
            "env": {},
            "stopOnEntry": true
        },
        {
            "type": "perl",
            "request": "launch",
            "name": "Perl-Debug remote",
            "program": "${workspaceFolder}/${relativeFile}",
            "root": "${workspaceRoot}/",
            "stopOnEntry": true,
            "port": 5000
        }
    ]
}

Do note I tried this out on a Mac, with Visual Studio Code version 1.24.0.

Haeres answered 7/6, 2018 at 19:16 Comment(2)
For what is the Per-Debug remote?Montgolfier
The link to Perl Debug Plugin is not valid anymore!Commeasure
J
1

I ran Visual Studio Code on a Mac and changed

"program": "${workspaceRoot}/${command.AskForProgramName}"

to

"program": "${file}"

to get the current file to debug.

Juncture answered 3/4, 2017 at 21:7 Comment(0)
F
0

"inc":['some/path'] doesn’t work for me but I successfully tried to specify paths in .vscode/settings.json:

{
  "perl.perlInc": ["."]
}

See https://marketplace.visualstudio.com/items?itemName=richterger.perl

Fillmore answered 18/8, 2023 at 13:38 Comment(0)
C
0

Please install perl debug adapter from the market place and launch.json should look something like below {

"version": "0.2.0",
"configurations": [
    {
        "type": "perl",
        "request": "launch",
        "name": "Perl-Debug",
        "program": "${workspaceFolder}/${relativeFile}",
        "stopOnEntry": true,
        "reloadModules": true
    }
]
Chesser answered 9/2 at 12:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.