Source Code Browsing

A co-worker recommended GNU Global for browsing source code a few days ago. It was pretty easy to set up. Install it and then go to the root of your source tree and type gtags. Then you can run global on the command line and try it out. Try things like:

global funcName
global -x funcName
global -rx funcName
global -sx varName

That should give you the idea that it can find a function definition and all its references, or a variable name and all its references pretty quickly. Very handy.

There is an emacs interface as well. Load gtags.el (comes with global), open a file, and do M-x gtags-mode. c-h m will show you the commands gtags-mode provides for doing the same thing we just did on the command line.

I'm not sure if I'm going to switch to using global/gtags. I already use a combination of cscope and Exuberant ctags, both of which have their strengths, and both of which have emacs interfaces, naturally. They all seem to have troubles parsing out tags/symbols in my C++ code in various places, but for the most part they work well. My quick testing showed that GNU Globals did a little worse than what I'm already using using. You can see some issues it has here.

Overall, if you aren't already using a tool like this to help you browse your code (maybe you're using good ol' find and grep), I highly recommend picking up one (or more) of these tools. They are a lifesaver.

Comments

Anonymous said…
Note that git-grep makes find+grep-like usage insanely fast. It doesn't understand the code's structure, but it really blasts. (Then there's GNU idutils for snarfing some symbols. None of these really help for us Fortran guys, though.)
Bryan said…
That reminds me, I should have mentioned that global/gtags can use idutils. I didn't try it though.
Anonymous said…
Hi Bryan, it's Katie (Ily's cousin). I have a friend who recently posted a blog about his computer. It is all giberish to me but I thought maybe you could help him. He's looking for a motherboard or something like that. I gave him your blog, too. Talk to you soon (like two weeks!),
Katie.
http://qnacunningham.blogspot.com/
Anonymous said…
Just another note, this is what Nate is looking for: dual processor Xeon board with PCI-Express

I only know one of those words! He he he
Anonymous said…
Good words.

Popular posts from this blog

SystemVerilog Fork Disable "Gotchas"

'git revert' Is Not Equivalent To 'svn revert'

Put /etc Under Revision Control (with git)