diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 5704d0a..5e21b37 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -1,15 +1,38 @@ { "configurations": [ - { - "name": "Linux", - "includePath": [ - "${workspaceFolder}/**", - "${env:C_INCLUDE_PATH}" - ], - "defines": [], - "cStandard": "c11", - "intelliSenseMode": "linux-gcc-x64" - } + { + "name": "Linux", + // BEGIN: Obtained from compile_commands.json generated with bear command + // Defined with -I args + "includePath": [ + "${workspaceFolder}/**", + "${env:LINUX_MODULES_FOLDER}/source/arch/x86/include", + "${env:LINUX_MODULES_FOLDER}/source/include", + "${env:LINUX_MODULES_FOLDER}/source/arch/x86/include/uapi", + "${env:LINUX_MODULES_FOLDER}/source/include/uapi", + "${env:LINUX_MODULES_FOLDER}/build/arch/x86/include/generated", + "${env:LINUX_MODULES_FOLDER}/build/include" + ], + // Defined with -include + "forcedInclude": [ + "${env:LINUX_MODULES_FOLDER}/source/include/linux/compiler-version.h", + "${env:LINUX_MODULES_FOLDER}/source/include/linux/kconfig.h", + "${env:LINUX_MODULES_FOLDER}/source/include/linux/compiler_types.h" + ], + // Defined with -D + "defines": [ + "__KERNEL__", + "DCC_USING_FENTRY", + "MODULE", + "KBUILD_BASENAME=\"test_module\"", + "KBUILD_MODNAME=\"test_module\"", + "__KBUILD_MODNAME=kmod_test_module" + ], + // END + "cStandard": "c11", + "cppStandard": "c++14", + "intelliSenseMode": "linux-gcc-x64" + } ], "version": 4 - } \ No newline at end of file +} \ No newline at end of file diff --git a/README.md b/README.md index 25192a7..38f65b2 100644 --- a/README.md +++ b/README.md @@ -43,4 +43,16 @@ sudo rmmod [module_name].ko ## Usefull links - https://www.kernel.org/doc/html/latest/ -- https://elixir.bootlin.com/linux/v6.13/source/ \ No newline at end of file +- https://elixir.bootlin.com/linux/v6.13/source/ + +## Notes + +1. Find required headers files + +``` +nix shell nixpkgs#bear +cd 01_basic_module/ +bear --append --output ../.vscode/compile_commands.json -- make -C $LINUX_MODULES_FOLDER/build M=$PWD modules +``` + +Search -I args and -D args \ No newline at end of file diff --git a/flake.nix b/flake.nix index 697b9af..8a6fc4e 100644 --- a/flake.nix +++ b/flake.nix @@ -21,7 +21,6 @@ packages = [ linux.moduleBuildDependencies ]; LINUX_MODULES_FOLDER = "${linux.dev}/lib/modules/${linux.modDirVersion}"; - C_INCLUDE_PATH = "${linux.dev}/lib/modules/${linux.modDirVersion}/source/include"; shellHook = '' echo "Current Linux Kernel used : ${linux.version}"