1. 程式人生 > >建立、編輯linux核心工程

建立、編輯linux核心工程

用過source insight、vim(未使用外掛)建立編寫linux核心工程,一直想找個更合適的工具。畢竟,source insight是商業軟體,而vim如果不使用外掛還是不怎麼方便。瞭解到vim和emacs都可以用外掛構建出原始碼工程,嘗試過emacs沒能成功,也許是我用vim已經習慣了,最近用vim嘗試了一下,就沒有問題。

vim的linux核心工程主要參考了《Linux核心開發環境管理和搭建(Git&Vim)》。Ubuntu系統下。

(1)從https://www.kernel.org/下載最新穩定版本linux-4.16.4.tar.xz,執行tar -xvf linux-4.16.4.tar.xz解壓。

(2)在https://download.csdn.net/download/notbaron/9907972 下載所需要的外掛。

(3)執行cd後,在當前使用者主目錄建立資料夾.vim/autoload/,.vim/syntax/,.vim/doc/,.vim/plugin/。

(4)將plug.vim複製到.vim/autoload/ ; 

taglist的doc資料夾內容複製到.vim/doc/,plugin資料夾內容複製到.vim/plugin/ ;

winmanager的doc資料夾內容複製到.vim/doc/,plugin資料夾內容複製到.vim/plugin/ ;

minibufexpl.vim複製到.vim/plugin/ ;


a.vim複製到.vim/plugin/ ;

grep.vim複製到.vim/plugin/ ;

visualmark.vim複製到.vim/plugin/ 。

(5)對於supertab.vmb

vim supertab.vmb

:so %

(6)ctags 在Ubuntu上自帶。

核心原始碼linux-4.16.4中執行make tags,會生成tags

(7)tar -xzvf cscope-15.8b.tar.gz 解壓cscope, sudo make & make install編譯安裝

在原始碼根目錄linux-4.16.4中執行如下:

$ cscope -Rbq

會生成三個檔案, cscope.in.out, cscope.out, cscope.po.out

(8)執行cd後,在當前使用者主目錄建立檔案.vimrc,內容如下:

" Specify a directory for plugins
" - For Neovim: ~/.local/share/nvim/plugged
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.vim/plugged')

" Make sure you use single quotes
" 注意要使用單引號

" Shorthand notation; fetches https://github.com/junegunn/vim-easy-align
" 如果外掛在 GitHub 的地址是 https://github.com/junegunn/vim-easy-align
" 可以縮寫成下面這樣
Plug 'junegunn/seoul256.vim'
Plug 'junegunn/vim-easy-align'

" Any valid git URL is allowed
" 或者直接給定外掛 git 地址
Plug 'https://github.com/junegunn/vim-github-dashboard.git'

" Multiple Plug commands can be written in a single line using | separators
" 多個 `Plug` 命令可以寫在一行,用 `|` 符號分割
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'

" On-demand loading
Plug 'scrooloose/nerdtree', { 'on':  'NERDTreeToggle' }
Plug 'tpope/vim-fireplace', { 'for': 'clojure' }

" Using a non-master branch
Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }

" Using a tagged release; wildcard allowed (requires git 1.9.2 or above)
Plug 'fatih/vim-go', { 'tag': '*' }

" Plugin options
Plug 'nsf/gocode', { 'tag': 'v.20150303', 'rtp': 'vim' }

" Plugin outside ~/.vim/plugged with post-update hook
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }

" Unmanaged plugin (manually installed and updated)
Plug '~/my-prototype-plugin'

" Initialize plugin system
call plug#end()

syntax enable

syntax on

colorscheme desert

set tags=/home/yong/linux-4.16.4/tags

let Tlist_Show_One_File=1

let Tlist_Exit_OnlyWindow=1

let g:winManagerWindowLayout='FileExplorer|TagList'

nmap wm :WMToggle

set cscopequickfix=s-,c-,d-,i-,t-,e-

cs add /home/yong/linux-4.16.4/cscope.out /home/yong/linux-4.16.4

let g:miniBufExplMapCTabSwitchBufs = 1

let g:miniBufExplMapWindowNavVim = 1

filetype plugin indent on

set completeopt=longest,menu

let g:SuperTabRetainCompletionType=2

let g:SuperTabDefaultCompletionType="<C-X><C-O>"
 
(9) Vim-plug (plug.vim)是一個 mini 的外掛管理器

開啟vim後執行:PlugInstall來安裝外掛,:PlugUpdate來更新外掛,執行 :PlugClean來移除未使用的外掛,:PlugUpgrade來更新vim-plug本身。PlugStatus:檢視外掛狀態。

(10)進入原始碼linux-4.16.4目錄,執行vim,在vim中執行wm,或者:WMToggle。https://blog.csdn.net/sxw1002/article/details/54866124

常用操作

ctrl + w + h  游標focus左側樹形目錄

ctrl + w + l  游標focus右側檔案顯示視窗

ctrl + w + w  游標自動在左右側視窗切換

ctrl + w + r  移動當前視窗的佈局位置

O  遞迴開啟選中結點下的所有目錄

x  合攏選中結點的父目錄

X  遞迴合攏選中結點下的所有目錄

P  跳到根結點

p  跳到父結點

K  跳到當前目錄下同級的第一個結點

J  跳到當前目錄下同級的最後一個結點

k 跳到當前目錄下同級的前一個結點

j  跳到當前目錄下同級的後一個結點


試用了一下,覺得不好用,想查詢include/linux/mm.h檔案中的typedef struct page,最後vim卡住不動了。