Run and Debug problems in Visual Studio Code using haxe - visual-studio-code

I'm currently coding in Haxe with Heaps using Visual Studio Code. The latter has recently updated to version 1.56 which is now giving my a strange problem I can't manage to fix. Before the update, I was able to click Run and Debug using Hashlink in order to open the window of my game. After the update, when I Run and Debug it no longer opens the window, despite the compile.hxml and launch.json being exactly the same as before:
compile.hxml:
-cp src
-lib heaps
-lib hlsdl
-hl main.hl
-main Main
.json
"version": "0.2.0",
"configurations": [
{
"name": "HashLink (launch)",
"request": "launch",
"type": "hl",
"cwd": "${workspaceFolder}",
"preLaunchTask": {
"type": "haxe",
"args": "active configuration"
}
},
{
"name": "HashLink (attach)",
"request": "attach",
"port": 6112,
"type": "hl",
"cwd": "${workspaceFolder}",
"preLaunchTask": {
"type": "haxe",
"args": "active configuration"
}
}
]
Is anyone experiencing a similar problem?

Update: hashlink-debugger 1.1.2 was released, which should fix the problem.
It's a known issue:
HL debugger no longer works in latest vscode #97
You can downgrade to the previous VSCode release or subscribe to the issue and wait for the hashlink-debugger update.

Related

VS Code: "Unable to read file" after directory change

After moving my project to another folder, the VS Code debugger tries to open the files in their old path when an exception is thrown, resulting in a "Unable to read file" error in VS Code. How to fix this?
This is my launch.json file:
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/Project.Host/bin/Debug/netcoreapp3.1/Project.Host.dll",
"args": [],
"cwd": "${workspaceFolder}/src/Project.Host",
"stopAtEntry": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "^\\s*Now listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
}
I've noticed that there are some old breakpoints in my debugger so I removed them, without breakpoints the debugger worked just fine, but whenever I tried to add a new breakpoint it referred to an old cpp file location.
Ended up reinstalling vscode -_- it helped but I don't think everyone can just reinstall vscode when there's a problem. For some reason, some internal vscode settings didn't refresh when I moved the folder with the code to a new location.

How to disable "just my code" setting in VSCode debugger?

When starting my project in the debugger (C# .NET Core), it states it's debugging "just my code".
I want to also debug the libraries, and can't see a setting to disable this anywhere in VSCode.
Is it possible to disable?
Just adding "justMyCode": false to launch.json doesn't work. You need to add a separate config in launch.json like below. FYI each {} represents a config.
"configurations": [
{
.... # existing config
},
{
"name": "Debug Unit Test",
"type": "python",
"request": "test",
"justMyCode": false,
}
]
As pointed out in here
For this you need to change the launch.json file. Inside the launch.json file you have to set "justMyCode" to false.
As described here. (I was pointed to that link through this post on the Visual Studio Code site.)
VSCode 1.60 was complaining about the "request": "test" method suggested by others.
But I did have to add a new section below my existing configuration to get "justMyCode": false to work.
Here is what worked for me:
{
// 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": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"args": [
"blah",
"whatever"
]
},
{
"name": "Python: Debug Unit Tests",
"type": "python",
"request": "launch",
"purpose": ["debug-test"],
"console": "integratedTerminal",
"justMyCode": false,
}
]
}
The purpose addition appears to be important.
I found the correct approach documented here: https://code.visualstudio.com/docs/python/testing#_debug-tests
If you're specifically debugging Python unit tests, adding "justMyCode": "false" to your normal config won't do, you'll need to add another in your launch.json with "request": "test":
{
"name": "Debug Unit Test",
"type": "python",
"request": "test",
"justMyCode": false,
},
Source: Github Microsoft/vscode-python Issue #7131
I added the "justMyCode": false" setting to launch.json and it still didn't stop at breakpoints in external library code. What was even more confusing: It did work for once and then suddenly it didn't anymore.
Then I found out: If you are in the "Run and Debug (SHIFT+CMD+D)"-tab and select your configuration there and click the green triangle / "Start Debugging (F5)" it works! However, if I click "Debug Python File" in the upper right corner it does not stop in external library code!
As of 2022, VS Code no longer seems to have an “Open launch.json” shortcut in its command palette, but it still prompts you to edit launch.json to set "justMyCode" to false. The solution that worked for me was:
create a directory called .vscode in the root of the repository
create a file called launch.json in the .vscode directory
put this text in the file:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Unit Test",
"type": "python",
"request": "test",
"justMyCode": false,
}
]
}
There will be an error message under the word "test" saying that "test" is not a valid value, and that "attach" would be valid. However, it doesn't work for me if I change "test" to "attach". If the "version" field isn't there, it doesn't work and VS Code raises an error saying launch.json is missing a field.
In the documenentation of Visual Studio Code they have a section "Skipping uninteresting code".
VS Code Node.js debugging has a feature to avoid source code that you don't want to step through (AKA 'Just My Code').
This feature can be enabled with the skipFiles attribute in your launch configuration. skipFiles is an array of glob patterns for script paths to skip.
In your launch.json file you have to add (or any other file you want to skip):
"skipFiles": [
"${workspaceFolder}/node_modules/**/*.js",
"${workspaceFolder}/lib/**/*.js"
]
If you are using vscode on mac, press shift+command+p, search for Open'launch.json', open an editor you want, and add the following JSON object to the file :
{
"name": "Python: Debug Unit Tests",
"type": "python",
"request": "launch",
"purpose": ["debug-test"],
"console": "integratedTerminal",
"justMyCode": false,
}
Reopen your vscode and now you can put breakpoints on lines that are imported or you have not written.
I added in the configurations part as below:
"configurations": [
{
"name": "Python: Curent File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false,
}
],
It took me a while to understand where the file needs to be and what exactly needs to be inside it. So here's what I've got for others to enjoy:
The launch.json file is not in the root of your project, it needs to be in .vscode/launch.json instead. And for new VSCode versions, once you open that file from that location, you can get warnings on issues in the file, and also automatically add sections to it.
For me, at the end the contents of the file is this:
{
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false
},
]
}
This allows me to enter (F11) other libs when I run a custom code in debug mode for Python.
None of the fiddling with launch.json worked for me.
I had to tick the "Allow setting breakpoints in any files" box in the Settings:
Recently, even I faced this issue where the VS code was not taking the latest launch.json (one with 'justMycode: false'). So, I had to perform the following steps.
Instead of running a debugger from the Top right group menu of the editor, I ran it from below status bar as shown in the below picture
Click here to see the screenshot of the status bar
Once clicked on this option a pop-up appears asking which launch.json you want to run your debugging with, as shown below.
Click here to see the screenshot of the pop-up menu
You can click on launch.json here to edit the configuration file and now the debugger opens with the selected launch.json and 'justtMycode:false' setting will be applied.
I merged the previous answers and the below setting works for me (vscode 1.75.0).
"launch": {
"configurations": [
{
"name": "Debug Unit Test",
"type": "python",
"request": "launch",
"purpose": "debug-test",
"justMyCode": false,
"program": "${file}",
}
],
},

Visual Studio Code - Node debugger breakpoints not being hit

I am trying to use VSCode to debug a node app I am running.
I launch the app in a separate terminal and then use the attach to process configuration to hook into it.
The attaching works correctly and I get a side panel that says 'loaded scripts' with the files in my project. If I click on one of those and set breakpoints there it will work correctly.
If I set a breakpoint on a file I open through the VSCode editor the breakpoint is greyed out and when I hover over it will say 'Breakpoint set but not yet bound'.
How can I make it so that the breakpoints I set on the code are bound?
Try this configuration in your launch file:
{
"name": "Attach to Process",
"type": "node",
"protocol": "inspector",
"request": "attach",
"stopOnEntry": false,
"port": 5858,
"localRoot": "${workspaceRoot}",
"remoteRoot": "/somepath/myprojectroot",
"sourceMaps": true
}
Make sure the remoteRoot is correct path, otherwise it won't know where to look for the source files.
On the VSCode settings search for 'debug javascript use preview', and then disable it. It should now bound all breakpoints.
I had a similar problem, I fixed it by appending /src to the "webRoot" path.
Here is an Example to Demonstrate What I Did:
Originally my "webRoot" property read:
"webRoot": "${workspaceFolder}"
Now my webRoot path reads:
"webRoot": "${workspaceFolder}/src",
Here is my ./.vscode/launch.json reads:
{
// 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": "chrome",
"request": "launch",
"name": "Launch Chrome",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}/src",
"trace": true
}
]
}
I had this issue with VSCode 1.52.1, the fix that worked for me was:
Disable debug.javascript.usePreview via Code > Preferences > Settings
Add "localRoot": "${workspaceFolder}/" to launch.json
Add "remoteRoot": "${workspaceFolder}/" to launch.json
The plain truth is that VSCode 1.20 does not allow you to hit breakpoints.
I tried 1.21 too, it also does not let you do it.
I went back to 1.18 and it works just as expected, no problem.
I faced the same issue...
After i try a lot of launch config combinations, i found the correctly.
{
"type": "node",
"request": "attach",
"name": "Attach Program",
"protocol": "inspector",
"restart": true,
"skipFiles": [
"<node_internals>/**"
],
"localRoot": "${workspaceFolder}",
"remoteRoot": "/",
}
Ps: I'm launch node script with nodemon using the --inspect parameter (that allow debugger to attach node).
I faced this issue as recently as yesterday after upgrading to VSCode 1.52.1. Debugger which was previously working fine suddenly started showing "Unbound Breakpoint". This was happening for all the breakpoints I was trying to set regardless of the place/file/line in code. I then had to add the "localRoot" property and make it point to my source code folder for it to start working again. Hope this helps. My launch.json configuration now looks like this
{
"name": "Attach by Process ID",
"processId": "${command:PickProcess}",
"request": "attach",
"skipFiles": [
"<node_internals>/**"
],
"localRoot": "${workspaceFolder}/Source",
"type": "pwa-node"
}
For me, just adding "localRoot": "${workspaceFolder}" to my default launch.json Configuration did the trick.
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/bin/www",
"localRoot": "${workspaceFolder}"
}
I'm late to the party but wanted to share what was causing my "Unbound Breakpoint" errors.
I have file A and B. File A called into File B (and was required at the top of File A). File A's breakpoints were working perfectly. File B's sometimes let me hit them but I wasn't getting the full debugging experience if it worked at all.
I finally realized the require statement at the top of File A had different casing than the actual folder structure. It was requireing /path/to/file, where it should have been /Path/To/File.
I fixed the path casing and the breakpoints in File B starting working again.
The very first thing you should check is the entry point - the first line of code that gets executed. If that one can bound a breakpoint, then you know your other breakpoints are unbound because something between the time your other breakpoints are met is pre-empted by an error introduced. Your code is not reachable in that case and the IDE can detect that your module is not loaded at all.
If all this doesnt work - consider starting your vsCode in the correct folder
(the root directory, e.g. C:\Users\user\programming\RandomApp).
This is also why some people need to specify "/src" to their workspace variable (just a wild guess) and others dont.
Start it in the correct Folder and you dont need the /src parts in the launch.json file.
for me this launch.json works with vscode version 1.59.1
{
// 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": "pwa-chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8100",
"webRoot": "${workspaceFolder}"
}
]
}
I have a TypeScript project, which suddenly didn't hit breakpoints anymore. In my case I had to move the project folder out of my iCloud Drive folder. There were other indicators that this path wasn’t ok, like missing git gutter indicators, as well. Here is my debug launch config. Breakpoints placed in app.ts are being hit.
{
"type": "node",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/src/app.ts",
"sourceMaps": true,
"protocol": "inspector",
"cwd": "${workspaceFolder}",
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
]
}
I'm using this configuration for debugging a TypeScript project:
{
"name": "Debug API",
"request": "attach",
"skipFiles": [
"<node_internals>/**"
],
"type": "pwa-node",
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/**/*.js",
"!**/node_modules/**"
]
},
outFiles did the trick and bound my breakpoints (VS Code 1.51.1).
I am running Docker Compose with the VSCode debugger and in my case, some of the breakpoints I set show unbounded and some show as bounded, even after trying the solutions above.
It seems the unbounded ones are outside of functions (on require or variable initialization statements for example).
I can only assume this is because the debugger attach runs after the docker containers have started (and hence these breakpoints are unreachable).
#alkasai has the correct answer.
But, it also matters which source code folder was added to your workspace. My repository structure is as such: C:\git\parent_folder\child_folder\src
My breakpoints were not working, so long as 'parent_folder' was the folder added to my workspace and my 'webRoot' entry looked like this:
"webRoot": "${workspaceRoot}",
But, if I added '/child_folder' to 'webRoot' (e.g. "webRoot": "${workspaceRoot}/child_folder"), the breakpoints worked.
However, if I removed 'parent_folder' from my VS Code workspace, and instead added 'child_folder' to the workspace (thus changing the underlying value of the '${workspaceRoot}' variable value), the original entry (without the '/child_folder' subfolder reference) caused the breakpoints to be activated.
For me the problem was that I forgot to set "sourceMap": true in my tsconfig.json file.
To hit breakpoints you need to compile in debug mode.
So when compiling the code using your tasks.json have debug flags enabled in your command attribute. C++ example :
{
"version": "2.0.0",
"tasks": [
{
"label": "Compile Test",
"type": "shell",
"command": "g++ -g test.cpp",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": true
},
"group": "build",
}
]
}
I am talking about the -g flag in the "command": "g++ -g test.cpp",

Can not change debug environment automatically on visual studio code with config

For example, my root workstation directory is /home/chain/Project. And I have two separate projects which is python and website. My launch.json goes:
{
"version": "0.2.0",
"configurations":
[
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config:python.pythonPath}",
"program": "${workspaceRoot}/python_project_source/test.py",
"cwd": "${workspaceRoot}/python_project_source",
"env": {},
"envFile": "${workspaceRoot}/.env",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
},
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "${workspaceRoot}/website/test.html",
"webRoot": "${workspaceRoot}/website"
}
]
}
As expected when I select test.py and press 'F5' it can switch to python debug environment, and when I select test.html the Chrome will be opened.
The fact is, VS code only remember the environment I debugged last time rather than change it automatically. So the only thing I do now is adding some comments to one environment (/* */) when I need to compile the other.:(
Is there something wrong in my launch.json?
Automatically switching the debug environment based on the file (or file-type) is not a current feature of Visual Studio Code, I believe.
You'll have to manually switch the launch configuration depending on the type of debugging task you want to perform.
And, of course, you could consider writing a feature request: https://github.com/Microsoft/vscode

Debugging Perl with Visual Studio Code

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?
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.
I ran Visual Studio Code on a Mac and changed
"program": "${workspaceRoot}/${command.AskForProgramName}"
to
"program": "${file}"
to get the current file to debug.