CSCOPE Installing Cscope Sudo Apt-Get Update Sudo Apt-Get
Total Page:16
File Type:pdf, Size:1020Kb
CSCOPE Installing cscope sudo apt-get update sudo apt-get install cscope This builds the cross-reference symbol table for the code base. Commands to operate cscope commands are built from the folder under which we have the need to navigate around. In our case, our current working directory should be weenix. 1. cscope build - search recursively in sub directories-> cscope -R Useful options for the command: 2. option -d if the cross-reference doesn't want to be updated. 3. option -p n will display the filename of the search word with upto n components in the path. [n-1 directories up in the path from current folder and the file name (n-1) + 1]. Default value is 1 [just displays the filename]. See screenshot below for -p3: 4. option -C -> ignore case in the search 5. option -V gives the version number of the cscope eg: cscope -RdCp3 will build the cscope cross reference recursively into sub-directories, with no update in cross reference, and the search path contains 3 components (including the filename like kernel/vm/brk.c) with search ignoring the case of the keyword. cscope window looks like below after being built. There will be 2 sub sections shown. The first section contains the results of the search we asked for. Second section contains the navigator options where we type in our search. Use 'tab key' to switch between the sub sections. Type in a key word in the appropriate section. press Enter. press tab. use up and down arrow keys. press enter to go that file. {optionally if you had already built ctags, refer below, u can go to definition of any other symbol you are looking for in the current page you are in}. Issue the vim command - :q or :q! to exit from that file and return to the cscope window. Use 'space key' to go to more set of results if not covered in the same page. Use 'up and down arrow keys' to go up and down. Press 'Enter key' after typing the search keyword in the options to retrieve results. Press 'ctrl + d' from cscope window to exit from cscope tool and return to the terminal prompt. CTAGS One can also use another tool to navigate to the definition of the symbol in the code: CTAGS. 1. Give the command ctags -R from the weenix folder to build it. place the cursor over any function or a variable or a struct object, and press ctrl + ], will take you to its corresponding definition. 'ctrl + t' will bring you back to the caller. ctags works like a stack. As u keep moving nestedly inside of the definitions of various symbols by pressing ctrl + ], pressing ctrl+t will bring you to the corresponding caller of the same in the order from recently invoked definition. that is, if u had used ctrl + ] 4 times, pressing ctrl + t will pop off the last definition you looked into and returns to the page from where you pressed the ctrl+] the fourth time. So, pressing ctrl + t will bring you to the first place where u pressed ctrl + ]. Example: //proc.c Void proc_create(int status) { … Sched_wakeup_on(&some_param); … } Keep the cursor on sched_wakeup_on() and press ctrl + ]. It will take you to the definition of sched_wakeup_on(); //sched.c Void sched_wakeup_on(<type> someparam) { … kthread_t *thr = ktqueue_dequeue(q); … } Keep the cursor on kthread_t and press ctrl + ]. It will take you to the definition of the structure kthread_t. //kthread.h typedef struct kthread { context_t kt_ctx; /* this thread's context */ char *kt_kstack; /* the kernel stack */ …. } From here, pressing ctrl + T will take you back to sched.c (the place from where we pressed ctrl + ] for kthread_t) Now from sched.c, pressing ctrl + T will take you to proc.c ----------------------------------XXXXXXXXXXXXXXXXXXXXXXX---------------------------------- .