Search code examples
visual-studio-codeintellisensekernel-module

Why is VSCode's Intellisense unable to parse #if defined(__GNUC__)?


I use Atom, CLion for kernel module development and I'd like to give VSCode a try.

Intellisense can't find some types and macros such as all the uint*_t, u*, dev_t, DECLARE_BITMAP().

After a quick look at the types.h, it seems all these types/macros are defined after #if defined(__GNUC__).

  • Is it a known issue?
  • How to solve that? The kernel headers are full of those #if defined().

Here is my c_cpp_properties.json:

{
    "configurations": [
        {
            "defines": [
                "__GNUC__",
                "__KERNEL__",
                "_GNU_SOURCE",
                "MODULE",
            ],
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/src/kernels/3.10.0-1127.8.2.el7.x86_64/include/**",
                "/usr/src/kernels/3.10.0-1127.8.2.el7.x86_64/arch/x86/include/**"
            ],
            "compilerPath": "/opt/rh/devtoolset-7/root/usr/bin/gcc",
            "cStandard": "gnu11",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

Solution

  • Linux kernel has many header files with the same names, but located in the different directories. And exact path to these files really matters.

    For that reason it is better to not "glob" (using terminating /**) include directories for the Linux kernel but write the exact ones:

    "includePath": [
        # You could glob include directories for your module
        "${workspaceFolder}/**",
        # .. but do not glob Linux kernel ones
        "/usr/src/kernels/3.10.0-1127.8.2.el7.x86_64/include",
        # Do not glob arch-specific include directories for Linux kernel too
        "/usr/src/kernels/3.10.0-1127.8.2.el7.x86_64/arch/x86/include"
    ],