Home >Backend Development >C++ >Day - Configuring NixOS to use the C debbuger in VSCode
I install all my packages in environment.systemPackages in /etc/nixos/configuration.nix.
So, in addition to gcc, to use debbuger you need:
environment.systemPackages = with pkgs; [ ... vscode-fhs gdb ]
Using vscode-fhs makes the work much easier, installing the vscode package (without fhs) causes some inconvenience. More information here.
In vscode, install this extension:
For greater reliability, I "forced" the creation of paths with:
environment.variables.PATH = "${lib.makeBinPath [ pkgs.gdb pkgs.gcc_multi // esse é o pacote que utilizo pro gcc ]}:$PATH";
Don't forget to restart your computer after sudo nixos-rebuild switch
Within the project, create a .vscode folder and add a launch.json and tasks.json file
tasks.json:
{ "tasks": [ { "type": "cppbuild", "label": "C/C++: gcc arquivo de build ativo", "command": "/nix/store/2ap4rlj55kw8q5ndycl0r8w312ggpf1c-gcc-wrapper-13.2.0/bin/gcc", "args": [ "-fdiagnostics-color=always", "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "Tarefa gerada pelo Depurador." } ], "version": "2.0.0" }
launch.json:
{ "version": "0.2.0", "configurations": [ { "name": "Debug arquivo ativo", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}", "args": [], "cwd": "${fileDirname}", "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "miDebuggerPath": "/nix/store/2ap4rlj55kw8q5nd2460r8w312ggpf1c-gdb-14.2/bin/gdb", "preLaunchTask": "C/C++: gcc arquivo de build ativo", "internalConsoleOptions": "openOnSessionStart" } ] }
For the command field in tasks.json, use the which gcc command to get the path.
Do the same for launch.json's miDebuggerPath with the command which gdb
Enter the file you want to debug and press F5:
Debug and be happy.
The above is the detailed content of Day - Configuring NixOS to use the C debbuger in VSCode. For more information, please follow other related articles on the PHP Chinese website!