DEV Community

Cover image for Dia 23 - Configurando o NixOS para utilizar o debbuger de C no VSCode
Matheus Gomes
Matheus Gomes

Posted on

Dia 23 - Configurando o NixOS para utilizar o debbuger de C no VSCode

Eu instalo meus pacotes todos em environment.systemPackages no /etc/nixos/configuration.nix.

Então, além do gcc, para utilizar o debbuger é necessário:

environment.systemPackages = with pkgs; [
...
vscode-fhs
gdb
]
Enter fullscreen mode Exit fullscreen mode

Utilizar o vscode-fhs facilita muito o trabalho, instalar o pacote vscode (sem o fhs) gera alguns transtornos. Mais informações aqui.

No vscode, instale essa extensão:

extensão vscode c/c++

Para maior confiabilidade, "forcei" a criação de paths com:

environment.variables.PATH = "${lib.makeBinPath [
pkgs.gdb
pkgs.gcc_multi // esse é o pacote que utilizo pro gcc
]}:$PATH";
Enter fullscreen mode Exit fullscreen mode

Não esqueça de reiniciar o computador após o sudo nixos-rebuild switch

Dentro do projeto, crie uma pasta .vscode e adicione um arquivo launch.json e tasks.json

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"
}
Enter fullscreen mode Exit fullscreen mode

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"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Para o campo command do tasks.json utilize o comando which gcc para pegar o caminho.
Faça o mesmo para miDebuggerPath do launch.json com o comando which gdb

Entre no arquivo que deseja depurar e aperte F5:
imagem do depurador funcionando

Depure e seja feliz.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more