views:

1098

answers:

26

I sometimes need to modify OSS code or other peoples' code (usually C-based, but sometimes C++/Java) and find myself "grep"ing headers for types, function declarations etc. as I follow code flow and try to understand the system. Is there a good tool that exists to aid in code browsing. I'd love to be able to click on a type and be taken to the declaration or click on a function name and be taken to it's implementation. I'm on a linux box, so replies like "just use Visual Studio" won't necessarily work for me. Thanks!

+7  A: 

You can't get anything better than SourceInsight.

aku
totally agree :)
Prakash
+3  A: 

I've heard amazing things about OpenGrok. I know another team at my place of employ uses it and they find it very handly. From its web site:

OpenGrok is a fast and usable source code search and cross reference engine. It helps you search, cross-reference and navigate your source tree. It can understand various program file formats and version control histories like Mercurial, Git, SCCS, RCS, CVS, Subversion, Teamware, ClearCase, Perforce and Bazaar. In other words it lets you grok (profoundly understand) the open source, hence the name OpenGrok. It is written in Java.

Blair Conrad
+5  A: 

I use Vim with ctags and taglist plugins. You can move the cursor to a variable name and with a key combination it will take you to the declaration of the variable (and back). Taglist will also show an overview of all functions, classes etc. in a side bar.

cschol
+3  A: 

The Eclipse IDE is capable of working with C/C++ in addition to Java. There is a write-up on how to configure Eclipse for C/C++ development on IBM's Developer Works site.

edit: Why has this been voted down? It is a valid answer. Eclipse with the C/C++ addon will allow the question author to do what he is wanting to do. I am not the only one to have suggested, yet the others have not been voted down. So why has this one been voted down?

jsumners
+1  A: 

If you're looking for something simple and ubiquitous, try etags. It's not going to be as good as the heavyweight tools, but it's on pretty much everything and it works with emacs. Use ctags for vi.

tgamblin
+2  A: 

Vim and Ctags works for me.

Matt Gregory
A: 

IntelliJ is pretty good as a source browser under Linux. It's got really good support for jumping between source and function declarations. Haven't tried it with C/C++ code, but it works well with Ruby and Java.

hoyhoy
A: 

I've not used it directly, but I have used sites created with lxr and thought it very handy. It converts your project into line-numbered and cross-referenced HTML files, using links to cross-reference function and file names. There are some examples of projects source indexed with it here.

It doesn't appear that there is a version newer than 2006, but it may still work for what you want.

HitScan
A: 

I use Anjuta IDE. Not bad. Not sure how it compares to Eclipse IDE.

Dustin
+6  A: 

Doxygen can generate an set of web pages that include a source browser. Not quite as fancy as an IDE, but all it needs is a web browser.

cunkel
A: 

Any IDE will work fine. Netbeans and Eclipse are java based but have plugins for C/C++

+2  A: 

I do a bit in the kernel space, and keep coming back the scope.

For example:

$ cd /usr/src/redhat/BUILD/kernel-version

$ cscope -R -p4

   Find this C symbol:
   Find this function 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:

I usually "live" in c-scope when working on someone elses project. I use this to open files with "gvim" (my IDE), edit things, then quit "back" to c-scope, It helps me keep task focused.

I believe that cscope can be configured to work with vim and emacs, although I've seen people use other editors also.

Best of luck to you.

Wade Mealing
A: 

I use kscope, which uses cscope in the background, but provides function lists etc. as well. Seems to handle large projects like the linux kernel well too. The kscope homepage has a good concise description of what it does and doesn't do.

Luuk Paulussen
A: 

cscope has always been my favorite. There is also cbrowser, but I have not tried it. ctags is also used a lot.

+1  A: 

ctags is very useful. There are two steps involved. First run the program ctags on all your source and include directories. This creates a file named 'tags' in the local directory. ctags *.c *.h would do fine if all your source is in a single directory. When you work with source in multiple directories, it can be worth running ctags in multiple locations. Then, within vi, with your cursor on any function, defined type or variable use ctl-] to go to the definition of that entity. Use etags if you're using emacs.

Leonard
A: 

I support the use of doxygen.

This tool generated a javadoc like bunch of html pages, allowing to index all the code, to browse in it (where is this function used, and by which function...), like you can do in an IDE. It is very easy to make it work.

I had once to maintain 2000 files of C code of a 15 years old C project. It took me an hour to index the code with doxygen a provide the other developpers with the generated doc. (I know, this phrase sounds like an add, but it is true... It's really a nice tool)

A wonderful tool, which works on all C-like languages.

Laurent K
A: 

I use the Understand for C++. It's very handy tool to deal with large amounts of code. It also can calculate code statistics and draw call graph. Must have!

Igor Semenov
A: 

I've had great success using doxygen. For best results (particularly when creating documentation for c++) install graphviz and enable in your doxygen configuration file.

This will automatically generate dependency maps and class diagrams that are linked to the rest of the html documentation.

Andrew Edgecombe
A: 

Even if you are not a developer go for Source Insight

And if you are, its a MUST HAVE :)

Prakash
A: 

Doxygen is wonderful. I've had to get across several legacy code bases that I was never involved in before, and it's been fantastic for that (even though the code bases were not documented using Doxygen format).

Peter K.
A: 

cscope. (wanted to mod up other scope post, but i don't have karma yet).

  • global search and replace
  • find all places a function is called
  • find all places called by a function
  • find files including this file.

really simple usage: $ cscope -R

if you don't know vi, then change your EDITOR and VIEWER environmental variables to your preferred editor.

A: 

I find ID Utils quite handy. It is like an instant recursive grep. There are bunch of vim recipes to go with it.

sigjuice
A: 

Go for Doxygen and set EXTRACT_ALL to YES. It is simply powerful and easy. Once you love it, you can stick to it across all platforms and languages.

http://www.doxygen.org

A: 

I use and like the free software tool GNU global.

bortzmeyer
A: 

A language-sensitive source code search engine can be found at SD Source Code Search Engine. It can handle many languages at the same time. Searches can be performed for patterns in a specific langauge, or patterns across languages (such as "find identifiers involving TAX"). By being sensitive to langauge tokens, the number of false positives is reduced, saving time for the user. It understands C, C++, C#, COBOL, Java, ECMAScript, Java, XML, Verilog, VHDL, and a number of other languages.

Ira Baxter
A: 

I use Source-Navigator(TM) from here. It is quite impressive and helps a lot. It is written in Tcl/Tk, is available as an executable for windows and as source code ready to build on *nix.

Adrian