amezin / vscode-linux-kernel Goto Github PK
View Code? Open in Web Editor NEWVisual Studio Code project/compile_commands.json generator for Linux kernel sources and out-of-tree modules
License: The Unlicense
Visual Studio Code project/compile_commands.json generator for Linux kernel sources and out-of-tree modules
License: The Unlicense
as below issue, vscode language server couldn't parse string definition.
For instance, during Android Linux kernel development, the builds are usually done by a make bootimage
is the global repo-workspace. (repo is an Android-specific tool for managing multiple git repositories) This builds the kernel with proper flags and configuration. This affects the paths. For instance:
repo workspace: /path/to/lineage-src
kernel repository and the VS Code workspace: /path/to/lineage-src/kernel/fxtec/msm8998
build artifacts: /path/to/lineage-src/out/target/product/pro1/obj/KERNEL_OBJ/usr/.initramfs_data.cpio.gz.cmd
However, the python script expects the cmd
files to be present in the current working directory tree. One can change directory
to point to some build artifact directory, but then the relative paths are incorrect. Trying to correct them manually causes some include path errors.
Out of tree builds are nothing new for the Linux kernel and are not Android-specific: https://lwn.net/Articles/90818/
Note: I tried playing around with includePath
but it after arriving at:
"includePath": [
"${workspaceFolder}/include",
"${workspaceFolder}/arch/arm64/include",
"/path/to/lineage/out/target/product/pro1/obj/KERNEL_OBJ/arch/arm64/include/",
"/path/to/lineage/out/target/product/pro1/obj/KERNEL_OBJ/arch/arm64/include/generated",
"/path/to/lineage/out/target/product/pro1/obj/KERNEL_OBJ/include/",
"/path/to/lineage/out/soong/ndk/sysroot/usr/include"
]
I ended up having errors like function type is not allowed for bool
inside a definition of a struct
, so something is completely wrong here
To reproduce, follow https://wiki.lineageos.org/devices/pro1/build, instead of the Start the build step, execute make bootimage
in the root of the LineageOS tree. You can probably use some different device, the outcome should be the same.
Here's my compile commands, both vanilla and with paths adjusted.
compile_commands.json.zip
compile_commands_patched.json.zip
EDIT: the following contents of c_cpp_properties.json
worked for me:
{
"configurations": [
{
"name": "Linux",
"cStandard": "c11",
"intelliSenseMode": "gcc-x64",
"compileCommands": "${workspaceFolder}/compile_commands.json",
"defines": ["__KERNEL__"],
"includePath": [
"${workspaceFolder}/include",
"${workspaceFolder}/arch/arm64/include",
"/marcin/proj/lineage/out/target/product/pro1/obj/KERNEL_OBJ/arch/arm64/include/",
"/marcin/proj/lineage/out/target/product/pro1/obj/KERNEL_OBJ/arch/arm64/include/generated",
"/marcin/proj/lineage/out/target/product/pro1/obj/KERNEL_OBJ/include/",
"/marcin/proj/lineage/out/soong/ndk/sysroot/usr/include"
]
}
],
"version": 4
}
Generate a .json file for every .cmd.* file, then join them. So the Python script will only handle one .cmd.* at a time, and a Makefile will run the script for all files.
parse_cmd_file with ./kernel/.kmod.o.cmd results:
command match result:
{'kernel/kmod.o': 'gcc -Wp,-MD,kernel/.kmod.o.d -nostdinc -isystem /usr/lib/gcc-lib/i486-linux/3.3.5/include -D__KERNEL__ -Iinclude -Wall -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -ffreestanding -O2 -fomit-frame-pointer -pipe -msoft-float -mpreferred-stack-boundary=2 -march=i686 -Iinclude/asm-i386/mach-default -DKBUILD_BASENAME=kmod -DKBUILD_MODNAME=kmod -c -o kernel/kmod.o kernel/kmod.c'}
source match result:
{}
When code linux-3.17.28
, VS code loads all the kernel files (30000+).This will cause VS Code analysis to be slow, and there are many files in it that I don't care about, I only care about those files that are needed for compilation (6000+).
I think it is possible to create a folder outside the kernel (for example, linux-3.17.28-build-need) with soft links to the files needed for compilation. and then code linux-3.17.28-build-need
. This will greatly shorten the time of vscode analysis
Generating a compile_commands.json file for kernel module development per the README throws an error ValueError: Chunksize must be 1+, not 0
.
git checkout v5.11.13-arch1
make O=$BUILDDIR defconfig
(I'm on x86_64)cd $BUILDDIR && make -j8
git clone https://github.com/jpear1/hello-module.git
make -C $BUILDDIR M=$PWD modules
. Optionally make clean
after.git clone [email protected]:amezin/vscode-linux-kernel.git .vscode
python .vscode/generate_compdb.py -O $BUILDDIR $PWD
Building *.o.cmd file list...
Parsing *.o.cmd files...
Traceback (most recent call last):------------------] 0.0%
File "/home/jack/scratch/hello/.vscode/generate_compdb.py", line 88, in <module>
main()
File "/home/jack/scratch/hello/.vscode/generate_compdb.py", line 84, in main
gen_compile_commands(**vars(cmd_parser.parse_args()))
File "/home/jack/scratch/hello/.vscode/generate_compdb.py", line 64, in gen_compile_commands
for compdb_chunk in pool.imap_unordered(functools.partial(parse_cmd_file, out_dir), cmd_files, chunksize=int(math.sqrt(len(cmd_files)))):
File "/usr/lib/python3.9/multiprocessing/pool.py", line 437, in imap_unordered
raise ValueError(
ValueError: Chunksize must be 1+, not 0
Python version: 3.9.3
GNU Make version: 4.3
GCC version: 10.2.0
OK, I've generated compile_commands.json, but what's next? How to use it? I expect it should be another way to build module/kernel from VS Code rather than running 'make' in terminal, shouldn't it? No clue.
Also there is a statement in README:
"Unfortunately, tasks.json will not work out of the box in this configuration"
And how to make it work manually? What is workaround?
Please, add more instructions to README.
I have clone it on remote server ,but not working
I am just curious: I just realized that you implemented generate_compdb.py
on your own.
So far I was using gen_compile_commands.py from upstream
Is there is anything missing in the upstream solution for your use-case?
This would give a cool devcontainer
Hi amezin,
Your vscode project for the linux kernel has been helpful to me. Thanks!
Could you please clarify what license this tool is distributed under, if you have the time?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.