How to trace a function in huge source directory?

cscope ctags

Suppose you have a huge source directory for example a kernel source or a library source like OpenCV and if you want to trace a function call,what do you do?

We do a case study:

Suppose there is a function warpPerspective() & you want the defination(one or multiple) for it

how do you trace the defination ?

Well, [grep -nr “warpPerspective”] is one way to do it but you get only multiple instances of the functions





Two tools come handy in this case



Using vim editor & these tools we can easily goto the function defination of any function and trace it or we can search for :

(cscope options)

Find this C symbol:

Find this global definition:

Find functions called by this function:

Find functions calling this function:

Find this text string:

Change this text string:

Find this egrep pattern:

Find this file:

Find files #including this file:

Find assignments to this symbol:



First Method:

Goto top level directory where you want to trace the function for eg kernel git directory.

1]cscope -R

to create a database ,an scope.out file will be created.

Now you will see a window like this with multiple options.










2]Enter warpPerspective in find global defination:

You will be presented with possible accurances of that file:










Same as this you can also find strings & symbols and get all accurances.

3]Now suppose you want to follow or trace this function:

press 1 for going into warp.cpp

(vim should be preinstalled)

4]Press escape

5] :cs add csope.out (full path)

6]:set tags=cscope.out (full path)

7]Now place your cursor over the function you want to trace

& hit ctrl -] (control and right square bracket key)

8]If there are multiple accurances you will see a list: