vscode插件:
vscode配置:
{ "editor.padding.top": 30, "editor.fontLigatures": false, "editor.lineHeight": 30, "editor.fontSize": 16, "editor.fontFamily": "'JetBrains Mono', Hack, 'PingFang SC Regular'", "editor.cursorBlinking": "expand", "editor.minimap.showSlider": "always", "editor.minimap.enabled": true, "editor.renderWhitespace": "selection", "editor.cursorSmoothCaretAnimation": true, "editor.wordWrap": "on", "editor.detectIndentation": true, "editor.insertSpaces": false, "editor.rulers": [ { "column": 80, "color": "#ffffff10" }, ], "editor.tokenColorCustomizations": { "[Monokai]": { "textMateRules": [ { "scope": "entity.name.type", "settings": { "foreground": "#FBDE4B", "fontStyle": "" } }, { "scope": "variable.other.global", "settings": { "foreground": "#ee57c8", "fontStyle": "" } }, { "scope": "entity.name.label", "settings": { "foreground": "#f1575c", "fontStyle": "" } }, { "scope": "variable.other.property", "settings": { "foreground": "#f1575c", "fontStyle": "" } }, { "scope": "variable.other.enummember", "settings": { "foreground": "#A6E22E", "fontStyle": "" } }, { "name": "Class/Constructor modifier", "scope": [ "storage.type" ], "settings": { "fontStyle": "" } }, { "scope": "variable.parameter", "settings": { "fontStyle": "" } } ] } }, "search.showLineNumbers": true, "files.autoGuessEncoding": true, "files.associations": { "*.h": "c", "*.c": "c", "Kconfig": "kconfig" }, "files.exclude": { "**/.o": true }, "C_Cpp.updateChannel": "Insiders", "C_Cpp.inactiveRegionForegroundColor": "#ffffff", "C_Cpp.default.intelliSenseMode": "clang-x64", "C_Cpp.intelliSenseCacheSize": 20480, "C_Cpp.exclusionPolicy": "checkFilesAndFolders", "bracket-pair-colorizer-2.showBracketsInGutter": true, "bracket-pair-colorizer-2.showBracketsInRuler": false, "bracket-pair-colorizer-2.showHorizontalScopeLine": false, "bracket-pair-colorizer-2.highlightActiveScope": true, "bracket-pair-colorizer-2.activeScopeCSS": [ "backgroundColor : {color}", "borderStyle : solid", "borderWidth : 0px", "opacity : 0.6" ], "workbench.colorCustomizations": { "[Monokai]": { "tab.inactiveBackground": "#272822", "tab.activeBorderTop": "#f1575c", "tab.border": "#272822", "editor.selectionHighlightBackground": "#f3e13b00", "editor.selectionBackground": "#ff990070", "editorCursor.foreground": "#f1575c", "statusBar.background": "#272822", "sideBar.background": "#272822", "titleBar.activeBackground": "#272822", "editorGroupHeader.tabsBackground": "#272822", "editorWidget.background": "#272822", "peekView.border": "#f1575c", "peekViewResult.background": "#272822", "peekViewTitle.background": "#272822", "editorHoverWidget.border": "#272822", "editorHoverWidget.background": "#30312a", "menu.background": "#272822" } }, "workbench.activityBar.visible": true, "workbench.startupEditor": "newUntitledFile", "workbench.sideBar.location": "left", "workbench.colorTheme": "Monokai", "[markdown]": { "editor.wordWrap": "bounded" }, "[python]": { "editor.tabSize": 4, "editor.insertSpaces": true }, "explorer.confirmDelete": false, "git.enableSmartCommit": true, "git.confirmSync": false, "window.zoomLevel": 0, "breadcrumbs.enabled": true, "telemetry.enableTelemetry": false, "terminal.integrated.rendererType": "dom", "tabnine.experimentalAutoImports": true, "editor.largeFileOptimizations": false, "http.proxySupport": "off", "workbench.editor.enablePreview": false, }编译linux内核代码,使用参数O指定编译文件存放路径: O=out/
生成compile_commands.json:最新内核版本 scripts/gen_compile_commands.py -d out/
vscode 打开内核代码所在的文件夹。然后手动创建文件夹.vscode。创建文件c_cpp_properties.json和settings.json
c_cpp_properties.json文件内容配置如下,mac和win可能配置有些不太一样。
{ "configurations": [ { "name": "Linux", "includePath": [ "${workspaceFolder}/**" ], "defines": [ "__KERNEL__" ], "compilerPath": "/usr/bin/gcc", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "clang-x64", "compileCommands": "${workspaceFolder}/out/compile_commands.json" } ], "version": 4 }当vscode将文件解析完成后,vscode的右下角会出现一个圆柱体的图标
