Can't get Pretty Printers to work for debugging Nim code in Codium (VSCode) with GDB (nim-gdb.py) - gdb

I tried to debug my Nim code in VSCodium with Native Debug extension and GDB. But I can't get the Pretty Printers to work properly.
Here is my launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug x64 Linux",
"type": "gdb",
"gdbpath": "nim-gdb",
"request": "launch",
"target": "${workspaceRoot}/bin/debug/${fileBasenameNoExtension}",
"cwd": "${workspaceRoot}",
"valuesFormatting": "prettyPrinters",
"arguments": "",
"debugger_args": []
}
]
}
The nim-gdb.py is located under /usr/tools/ and will be loaded.
Here is the debugger output of the debugging session in VSCodium. It seem's that the nim-gdb.py is loaded successfully. But neither in the variables panel nor in the debugging console the values are formatted right. The str-variable is still missing and depending on where I set a breakpoint the values are often marked as <optimized out>
Debugger output
The Program was compiled with the following parameters:
nim c --outdir:"bin/debug" --debugger:native --opt:none test.nim
Compiler Version:
Nim Compiler Version 1.6.6 [Linux: amd64]
Compiled at 2022-05-22
Copyright (c) 2006-2021 by Andreas Rumpf
I know the gdb package needs to be compiled with python enabled. In my package manager is python as a dependency listed.
Is there something more I should care about?
References:
https://internet-of-tomohiro.netlify.app/nim/gdb.en.html
https://github.com/jasonprogrammer/nim-debug-example

Related

The configuration option popup for debugging a c++ project in Visual Studio Code does not appear

so I want to debug my .cpp program file but when I click on the Run and Debug button and proceed to select my debugging environment (C++ (GDB/LLDB)), the popup to select the configuration option does not even appear at all and the debugging just doesn't start.
This is before I click the environment popup:
and this is after:
Any help I can get for this problem is greatly appreciated as I can't seem to find any solutions at all on the internet, thank you very much!
p.s I've already tried uninstalling VS Code completely off my laptop and resetted all the settings and it didn't work.
Are you sure you installed the C/C++ Studio Code extension? If you don't get the popup, try writing the json files manually.
Create a .vscode folder in your working directory. In there create a file launch.json in which you declare how you run the debugger
{
"configurations": [
{
"name": "Debug",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}\\test.exe",
"stopAtEntry": true,
"cwd": "${workspaceRoot}",
"preLaunchTask": "Build Debug",
"miDebuggerPath": "c:\\mingw64\\bin\\gdb.exe"
}
]
}
This runs the gdb debugger that came with MinGW. You need to provide the path to your debugger at miDebuggerPath.
This debugs an executable test.exe that needs to be created in debug mode. For this you have the preLaunchTask option. In .vscode create a file tasks.json in which you describe the debug task as
{
"tasks": [
{
"type": "cppbuild",
"label": "Build Debug",
"command": "g++",
"args": [
"${workspaceRoot}\\test.cpp",
"-g",
"-o",
"${workspaceRoot}\\test.exe"
],
}
],
"version": "2.0.0"
}
This uses the gcc or g++ compiler that also comes with MinGW to compile a single source file test.cpp into the test.exe binary. You can select the debug launch configuration in the lower left corner of Studio Code and click Run.

Visual Studio Code with CMake Tools: launch.json not generated correctly?

I am trying to configure VSCode for debugging my code. My project is configured by CMake. I use the CMake Tools extensions. Configuring and building as well as quick debugging works so far.
But since I want to configure the launch specifications I let VSCode generate the launch.json file according to:
"Visual Studio Code generates a launch.json with almost all of the required information." https://code.visualstudio.com/docs/cpp/launch-json-reference
I do this by having my main.cpp tab open and then clicking on "create a launch.json file". (See picture.)
I am working in a Ubuntu 18.04 environment. Which is why I select C++ (GDB/LLDB) from the command pop up.
Then a launch.json is created and opened. But it looks extremely empty. See here:
{
// 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": []
}
I expected something more like the example from the VS json reference page:
{
"name": "C++ Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.out",
"args": ["arg1", "arg2"],
"environment": [{ "name": "config", "value": "Debug" }],
"cwd": "${workspaceFolder}"
}
Am I missing something? Since I have only a very brief idea of my possibilities with the launch.json and what is required to fill in to make it work correctly, I hoped that VS Code would help me out here.

VSCode LLDB on MacOS error when starting debugging session

I'm trying to configure VSCode for compiling/debugging C++ programs on MacOS. I am using the following launch.json file:
When I try and start a debugging session, I get the following error:
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
ERROR: Unable to start debugging. Unexpected LLDB output from command "-exec-run". process
exited with status -1 (attach failed ((os/kern) invalid argument))
The program '/path/to/Development/C++/helloworld/main' has exited with code 42
(0x0000002a).
It is worth mentioning that I am using an M1 Macbook, so x86_64 is not the correct architecture. I'm assuming that this is the reason for the error.
I can't seem to find any reference to this error anywhere online, does anyone know how I can solve this?
Edit: Adding "targetArchitecture": "ARM64" removed the warning, but does not fix the error.
I had the same problem and I found that VScode does not support a debugger for ARM64 binaries yet. Here is the issue link.
However, it works if you use another extension. Install CodeLLDB and set "type": "lldb" on launch.json like below.
{
// 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": "clang++ - Build and debug active file",
"type": "lldb",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"cwd": "${workspaceFolder}",
"preLaunchTask": "clang++ build active file"
}
]
}
You can check quick start guide of vscode-lldb repository.
Note that preLaunchTask's value should be the same as the label's value in your task.json.
Make Executable with command:
gcc file_name.c -g
launch.json
"targetArchitecture": "x86_64",
Using cargo's config instead of "program" resolved it for me (using Rust and LLDB).
{
"name": "(OSX) Launch",
"type": "lldb",
"request": "launch",
"cargo": {
"args": ["build", "--manifest-path", "${fileDirname}/../Cargo.toml"]
}
}

How to Launch and Debug WSL C++ Binary from Within Visual Studio

I want to be able to launch and debug a WSL Linux binary from within Visual Studio.
EDIT:
Please note that I want to build within WSL, i.e. gcc -g test.cpp -o test and only use Visual Studio to launch and debug the binary. Ideally I would like something like: devenv.exe /debugexe <binary> for a Linux binary. This would probably equate to something like DebugAdapterHost.Launch /LaunchJson:c:\wsl\vs\launch.json inside the command-window.
Taking the approach from this article, the following is a launch.json that acheives this for .NET:
{
"version": "0.2.0",
"adapter": "c:\\tools\\plink.exe",
"adapterArgs": "-ssh -pw <password> chrisnas#DBGDQPZ1 -batch -T ~/vsdbg/vsdbg --interpreter=vscode",
"configurations": [
{
"name": ".NET Core Launch",
"type": "coreclr",
"cwd": "/mnt/d/wsl/TestConsole/TestConsole/bin/Debug/netcoreapp2.1/publish",
"program": "TestConsole.dll",
"request": "launch"
}
]
}
I have seen articles that use GDBServer, however this a lot more cumbersome than the approach outlined above.
How could this be modified to work with C++?

Error while debugging using gdb debugger on VS Code using Windows 10 and MINGW complier

I was following the documentation on https://code.visualstudio.com/docs/cpp/config-mingw to set up my C++ development environment on VS code.
I succesfully created my build task and ran my build task, but when i tried to set up my debugger (GDB debugger), i got the following output on the terminal.
C:\Users\Ayon\c++\helloworld> cmd /C "c:\Users\Ayon\.vscode\extensions\ms-vscode.cpptools-0.28.1\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-shlwrnf5.x12 --stdout=Microsoft-MIEngine-Out-vg12hskh.c52 --stderr=Microsoft-MIEngine-Error-nrcvh0zz.0u0 --pid=Microsoft-MIEngine-Pid-m1nmxyvs.qk2 --dbgExe=C:\MinGW\bin\gdb.exe --interpreter=mi "
'cmd' is not recognized as an internal or external command,
operable program or batch file.
Im curious as to how the "cmd /" came about in the output. Please help me fix this error.
Thanks in advance.
For reference, here is my 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": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++.exe build active file"
}
]
}
Did you add mingw64/bin to your system path? Here's how to do so:
Control panel -> Edit path -> Environment variables -> Path -> New
You can also find more guidance on
vscode official website.
I believe the problem is with the MinGW installation. I also faced this problem for a long time, solved it by doing the following:
Completely removing the current MinGW Video tutorial
Installing MinGW-w64 from the site mentioned in vscode documentation. installation video tutorial
After this, I followed the configuration mentioned in this video. The video is for c code, but you can make the required changes to c++ code. Now I'm able to debug in vscode.
By this way, you will also be able to use the latest versions of gdb and g++ available.