Search code examples
c++cdebuggingvisual-studio-codevscode-debugger

How to use Intel C/C++ Classic Compiler in VSCode debugger?


I'm setting up a C environment on a Mac to implement some numerical codes for my phd. I'm using the Intel C/C++ Classic compiler instead of the default clang.

So far, I manage to generate some debugging information evoking a command like icc -std=c17 -o code -g code.c

When I call the Run and Debug option in VSCode it show 2 options to me: C++(GDB/LLDB) and C++ (Windows). When I click the first one it shows 2 more options: C/C++: clang build and debug active file or C/C++: gcc build and debug active file. It does not show anything related to the Intel Classic Compiler. How do I use this compiler to debug with Intel C/C++ Classic compiler inside the VSCode environment?

Thanks in advance!


Solution

  • I think you are mixing compiling and debugging up, according to the documentation, choosing C/C++: gcc build and debug active file from the list of detected compilers on your system is just helping you to generate some configuration like this:

    {
      "version": "2.0.0",
      "tasks": [
        {
          "type": "shell",
          "label": "C/C++: g++ build active file",
          "command": "/usr/bin/g++",
          "args": ["-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}"],
          "options": {
            "cwd": "/usr/bin"
          },
          "problemMatcher": ["$gcc"],
          "group": {
            "kind": "build",
            "isDefault": true
          },
          "detail": "Task generated by Debugger."
        }
      ]
    }
    

    If you want to debug in VSCode, what you need to do is simply adding this configuration to your 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}/code",
                "args": [],
                "stopAtEntry": false,
                "cwd": "${fileDirname}",
                "environment": [],
                "externalConsole": false,
                "MIMode": "gdb",
                "setupCommands": [
                    {
                        "description": "Enable pretty-printing for gdb",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    },
                    {
                        "description": "Set Disassembly Flavor to Intel",
                        "text": "-gdb-set disassembly-flavor intel",
                        "ignoreFailures": true
                    }
                ]
            }
        ]
    }