Sunday, April 1, 2012

Applying filter to results in cscope

I had always wanted cscope to be a little more intelligent and let me specify the range of search results, which may be very handy when you are browsing a large project and want to look into a particular file instead of whole project. Of course one way is to put the results in a file and use your shell scripting skills (but do you really want to do that ??).

Googling didn't give any useful results, so I decided to spend my Sunday to do some useful work, and added support in cscope to apply filters to search. Here is what it can do currently.

a) Apply filename filter to your "Find C symbols"
b) You can tell cscope to not include the patterns from a particular file.
c) It supports logical OR (I didn't try other regex)

Snapshots below.

=> Search of i_nlink in linux codebase 500 instances like below



 => But I'm really interested in the places where its accessed in vfs_code. (Notice the message "(Filtered with : vfs)" at top.



 
=> Soon I realize, I was only interested in looking at header files (look at filter string at the top of screen)



=> Or not so, actually in only 'C' files.

 

=> I want all references from directory and lock files.



Download the source code from here and compile it as below.

a) ./configure
b) make
c) src/cscope -R

Njoy !!

2 comments:

Sankar P said...

I am just trying to write a simple file system (to understand fs basics) and was very thrilled to find that you too have attempted the same few years back. I came to your blog because the filesystem that I was creating was mounting fine but not accepting cd command. Somehow Google led me to your blog. I could not find the answer to my problem in your blog, but got something else which I was feeling few minutes back. While I was doing the development, I was getting so frustrated by cscope listing 1000 results for searching something like "inode_operations" and I was thinking, I should patch cscope to show results only from a particular path, without going to subdirs (but your approach of using name-prefixes is better). I have not tried your patch yet, but curios as to why you have not sent this upstream.

Reading your fs effort and this cscope work, made me to feel that I am travelling in the right path in my fs development as our experiences seemed to be similar afaics from your blogposts. Thanks for the cscope patch. I will try to use it once I have made some good progress in my fs development/learning (dont want any distractions now and so not trying the cscope patch now).

Unknown said...

I did try to send it upstream, but it got rejected because cscope already has the ability to redirect the output to any shell command. So you can redirect the output to grep and get the same results.