How to enable mixed mode debugging in Visual Studio Code? - linux

I have a C#.NET Core Web application that uses some C++ code for certain operations.
This web application is running on Cent OS 8. (I am a Windows Developer and working on Linux for first time and so with VSCode)
I only have the option to debug using VSCode in CentOS. I am familiar with VS2019 Mixed mode debugging but I am not able to find that option in VSCode. Does it not support it?
Launch.Json doesn't allow "profiles" to add to it, which was allowed in VisualStudio2019 which enabled the mixed mode debugging.
One work around I tried was making a Launch.json setting for gdb:
"configurations": [
{
"name": "(gdb) Attach",
"type": "cppdbg",
"request": "attach",
"program": "${workspaceFolder}/CSharpCodeBinary/ManagedCode.dll",
"processId": "${command:pickProcess}",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
Once I run the ManagedCode.dll on a terminal, I attach to "dotnet" application hoping to get a breakpoint hit in the unmanaged cpp file (that generates UnmanagedCode.so).
The "ManagedCode.dll" is the C# NetCore assembly which loads the native "UnmanagedCode.so" for accessing unmanaged code.
I have built "UnmanagedCode.so" using g++ -Og switch to generate symbols.
Still I am getting no luck to hit the breakpoint.
I just want to somehow hit the breakpoint inside UnmanagedCode.so code. Any way is acceptable.

Related

Visual Studio Code debugger attaches but does not stop node js process

I have a Node js application (running on Windows) which occasionally "hangs" - it gives no sign of progress. From Visual Studio Code, I attach the debugger by selecting the process ID. Evidence of successful attachment is given both from within VSC and standard out (console):
"Debugger listening on ws://x.y.z.1:9229/242f50ce-a43c-48dc-9926-23520ed10ed3
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached."
However, the process continues to run and clicking on the "pause" symbol in the debugger control bar un-ghosts momentarily but does not change to the "continue" symbol (other control symbols on the bar remain ghosted).
Launch configuration:
{
"launch": {
"configurations": [
{
"name": "Attach by Process ID",
"processId": "${command:PickProcess}",
"request": "attach",
//"skipFiles": [
// "<node_internals>/**"
//],
"type": "node"
},
{
"name": "Launch Program",
"program": "${workspaceFolder}/index.js",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"type": "node", "args": ["set", "31100-1", "subsets" ]
}
]
},
"workbench.colorTheme": "Default High Contrast"
}
On occasion when I attach and then detach ("Stop Debugging") the process seems to continue and behave normally (no longer hung), but I am not able to discover where and/or why it is hanging.
I should add that while this Node js program runs from both a windows power shell and a Cygwin tcsh, it is when running from the Cygwin that I am seeing this behavior (insufficient testing from power shell to say whether or not this ever occurs)
I can understand that the source might not be visible from VSC or that the callstack would be abbreviated/incomplete, but I would expect the process to stop. Perhaps it has and I am misinterpreting the VSC presentation.
Any discussion or suggestions are welcomed. I am both a Node js and VSC novice.

VSCode NodeJs: Debugger not stopping at breakpoint (WSL2/Ubuntu18)

Using WSL2/Ubuntu18 I've not been able to make the VSCode NodeJs Debugger to stop on the breakpoints of any NodeJs app. When I start the debugger, it runs (I can see the output on the integrated terminal) but breakpoints are simply ignored.
The simple.js file, with a breakpoint on line 3:
The launch.json is set to:
{
"version": "0.2.0",
"configurations": [
{
"name": "NodeJs: Launch Program",
"program": "${file}",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"type": "pwa-node",
"console": "integratedTerminal"
}
]
}
When I press F5 or click on the "Start Debugging" button on VS Code, the app runs and following appears on the integrated Terminal:
/usr/bin/env 'NODE_OPTIONS=--require /home/myuser/.vscode-server/bin/ea3859d4ba2f3e577a159bc91e3074c5d85c0523/extensions/ms-vscode.js-debug/src/bootloader.bundle.js --inspect-publish-uid=http' 'VSCODE_INSPECTOR_OPTIONS={"inspectorIpc":"/tmp/node-cdp.19338-1.sock","deferredMode":false,"waitForDebugger":"","execPath":"/home/myuser/.nvm/versions/node/v14.15.1/bin/node","onlyEntrypoint":false,"autoAttachMode":"always","fileCallback":"/tmp/node-debug-callback-ff32d873905abafa"}' /home/myuser/.nvm/versions/node/v14.15.1/bin/node ./simple.js
Debugger attached.
0
1
2
3
4
Waiting for the debugger to disconnect...
I've already upgraded from Node10 to Node14, but the problem persists.
On another computer using WSL1, and using the same launch.json the debugger stops at the given breakpoints. Do I need to set something additionally on WSL2? For the record, this is what appears on the integrated terminal on the WSL1 computer before it stops at line 3:
/usr/bin/env 'NODE_OPTIONS=--require /home/myuser/.vscode-server/bin/ea3859d4ba2f3e577a159bc91e3074c5d85c0523/extensions/ms-vscode.js-debug/src/bootloader.bundle.js --inspect-publish-uid=http' 'VSCODE_INSPECTOR_OPTIONS={"inspectorIpc":"/tmp/node-cdp.787-3.sock","deferredMode":false,"waitForDebugger":"","execPath":"/home/myuser/.nvm/versions/node/v14.15.1/bin/node","onlyEntrypoint":false,"autoAttachMode":"always","fileCallback":"/tmp/node-debug-callback-b901b6d6e3e9799b"}' /home/myuser/.nvm/versions/node/v14.15.1/bin/node ./simple.js
Debugger attached.
<Breakpoint hit and stop...>
Additional info, debugging Python3 files work correctly on both machines.
Both computers have the same VS Code Version installed.
Update:
You can follow the issue on GitHub: https://github.com/microsoft/vscode/issues/113283
The problem is that the NodeJs App is being run from a symlinked address - so the debugger can not handle it.
Answer from one of the developers of VSCode/NodeJS on github:
It looks like you have your script symlinked into /bin/nhosko/simple.js, but its actual location is /mnt/c/Users//bin-nhosko/simple.js. In this case you need to specify some flags so that Node will report the linked location that vscode sees and told the debugger about: https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_can-i-debug-if-im-using-symlinks. I want to make the debugger smart enough to fix this automatically in microsoft/vscode-js-debug#776.
https://github.com/microsoft/vscode/issues/113283#issuecomment-750371948

In vscode using node.js, ctrl+F5 always asks for “select environment”. This didn't happen a few weeks ago

Whenever I press F5 or Ctrl+F5, vscode asks me to "select Environment". I have to choose Node.js every time. Somebody has given this solution:
Run > Add Configuration > select Environment. It works for that particular folder.
However, when I change folders the problem persists. How can I set up configurations globally?
The worst part is that this problem started appearing since 4-5 weeks. Before that vscode was automatically debugging & running my files on node.js
I found a workaround.
Installed this free extension code runner.
https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner
I had to set a custom shortcut key for enabling it to run since Ctrl+Alt+N didn't work for me.
The type key is missing in /.vscode\launch.json (Access it from the top left gear icon or open it in vscode), please see #Andy's answer:
{
"version": "0.2.0",
"configurations": [
{
"type": "node", // to avoid the environment Select
"request": "launch",
"name": "Debug File",
"program": "${file}"
}
]
}
If the type key is not there, Vscode asks you about the type.
There is actually an official solution for this and there is no need to install other extensions, as Visual Studio Code comes with support of Node.Js
The configuration file for running and debugging is in .vscode\launch.json, which can be found in the Run panel.↓
Then you can change the configuration file to the desired effect. If you want to run or debug the current file directly, the configuration is like this
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug File",
"program": "${file}"
}
]
}
it is also possible to run the index.js file in the current working directory.
"program": "${workspaceFolder}/src/index.js"
More information:
https://go.microsoft.com/fwlink/?linkid=830387
Debugging current file in VS Code

Unable to debug C on VS Code using gdb on Windows Subsystem for Linux

I am using VS Code to debug 'C' code using Windows Subsystem for linux.
I basically want to compile the 'C' code using a linux based compiler for a Operating System's course.
I have set the default terminal to 'WSL' on Visual Studio Code.
On clicking the debug button I am getting the below error
'Unable to start debugging. The value of miDebuggerPath is invalid'
I verified that 'gdb' is installed in the Windows Subsystem for Linux and its executable (ELF File) is present in '/usr/bin/gdb' location
This is m launch.json
{
// 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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/temp",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
//"preLaunchTask": "Compile C Ubuntu"
}
]
}
Any direction will be helpful :)
The issue you are running into is the missing remoting call using bash.exe that is needed to call the debugger on the WSL site. You will need to add a section called "pipeTransport": and configure it. For more information, there is a how-to document located here.
You can find additional information on our extension's GitHub site at https://github.com/microsoft/vscode-cpptools.

How can I debug a Node.js application running with PM2 in VSCode?

Visual Studio code has some awesome debug functionality built in that makes it easy to debug applications with node. However, my application is configured to use PM2. How can I set up Visual Studio Code to debug with PM2?
You can add a launch configuration in VSCode, in the file named launch.json, that attaches to the process you want like this:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach to Process",
"processId": "${command:PickProcess}"
},
{...}
]
}
Press ctrl+shift+D to show the debug section in Visual Studio Code, pick "Attach to Process" and then press "play". VSCode will automatically show you the options available on you local machine. Besides the process ids of the running node processes VSCode shows the full path of your node app so it is easy to pick the right process to attach.

Resources