Showing posts with label source code. Show all posts
Showing posts with label source code. Show all posts

Wednesday, July 7, 2010

Drupal source code and [g]vim/cscope

When you start looking at modules developed for Drupal - you kinda get lost amidst all the references to different system functions - user_external_load, db_query, etc. It becomes really maddening!

Fortunately a cscope-enable gvim binary will ease out the source code browsing angst to a large extent. Amongst all the other things, here is what I have in my .vimrc

if has("cscope")

   function! CScope_Refresh()
cs kill 0
 !find $PWD -name \*.php > files && cscope -b -i files
!find $PWD -name \*.js >> files && cscope -b -i files
!find $PWD -name \*.module >> files && cscope -b -i files
!find $PWD -name \*.info >> files && cscope -b -i files
!find $PWD -name \*.install >> files && cscope -b -i files
!find $PWD -name \*.inc >> files && cscope -b -i files
cs add .
!rm -f files
endfunction
comm! -nargs=0 R call CScope_Refresh()
endif

After you have sourced your .vimrc again, you can navigate into your Drupal install directory, fire up gvim and just hit :R and you will be able to search for symbols, look for references to functions, look for files etc. using the standard cscope commands:

e.g.:

:cs find g user_menu

The above will lead us to the definition of the user_menu function in user.module. 

Hope, this post will relieve some of your source code browsing pangs :)

Thursday, June 12, 2008

Coordinated debugging

I code in C mostly. I err and hence I debug too once in a while :). Have been using plain gdb for user-land program debugging for quite a while and it serves all my needs. Fast, from the command line, all the required bells and whistles (including readline) and I don't need no more.

And I even wonder how people use bulky IDEs like eclipse just to debug their programs! But lately, I wanted to browse the source code automatically while debugging. The alt-tab combinations to switch from gdb back to my source files in vim was getting a bit too tardy for me. And I had actually started considering thinking about an IDE (yuck...). But no more, presenting gdbtui!

Its gdb itself, but with the added convenience of co-ordinated source code browsing from within the terminal window itself! I was definitely happy to discover this gdb add-on today! Here is a screenshot that someone posted on flickr for you guys too. Definitely worth a try!