Searching for particular functions, keywords, header files, etc etc over big source code directory is difficult task for any one. But in Linux everything is easier if you know some tricks. Since it is an open source, you will get many hands to save you for anything.

ctags and cscope are alternative options for linux cross reference (LXR) source code browser or indexer. These two works fine for anyone who doesn’t has internet access and challenges in perfomation with LXR. Let me give some sort of hints for using these effectively. But whatever I say here is not the complete detail of these. If you dig deep you will get more and more sort of useful informations about this.

ctags

1) Installation is so simple

$ sudo apt-get install exuberant-ctags

exuberant-ctags -> is the variant of ctags works as similar, it is mainly distributed along with vim at olden days.

2) To create tag(database) file or index file of source code

$ cd linux.x.xx.x/
$ ctags -R

whereas ‘R’ represents recursively.

3) You will get a file named tags inside the source directory

4) Content of tags shown inside vim editor

contentoftag

How to browse for a particular function,

5) Open any file using vim

f1

6) To find where printk has been defined press CTRL + ] by placing cursor over printk, it will drop you into that target file

f2

7) You can continue to navigate pressing CTRL + ] repeatedly

f3

8) Moral : ctags puts each entry into its stack when it reaches top it reports

On pressing one more time CTRL + ]

F4

9) To go one step back press CTRL + T

f3

10) When it reaches bottom of stack, again it reports

f5

Useful….!

11) What will happen on the absence of tags file inside the source directory…?

Pressing CTRL + ]

f7

I hope you may understand ctags, it is always a better practice to create tags file inside the source directory for Kernel Hackers to work.

cscope

1) Installation is so simple

$ sudo apt-get install cscope

2) To create tag(database) file or index file of source code

$ cd linux.x.xx.x/
$ cscope -R

whereas ‘R’ represents recursively.

3) You will get a binary file named cscope.out inside the source directory

4) Then, you will get a self explanatory interactive window to use, here I will share some examples, again I will repeat the words that on digging deep you will find more stuff

c2

5) To find different places where printk has been used

c3

on hitting enter

pho

Pressing corresponding number you may get into that file.

6) Another, to find global declaration of printk, type printk at option Find this global definition: 

pho1

7)  cscope is very well supported in vim, typing “:cs”

dd

cc

8) To exit press CTRL + D

Spend some time with cscope.

Enjoy….!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s