7

I'm working with a large codebase and often find it to be tedious and hard to understand class relationships. I found the following wiki that describes various tools for working with OOP in C++, but they're either outdated or do not work! What Emacs tools are available for working with large OO codebases?

Here is what I have found:

  • Object Oriented Browser
    • Hasn't been updated since 2002! Defunct
  • Ebrowse
    • I can't even find a download link for the parser...my target would either be Windows or Mac OS X Thanks @tu-do for pointing out it's in the emacs bin directory
  • Emacs Code Browser
    • Only seems to support Etags, but not Global tags or cscope
6

I'm writing a guide for Ebrowse and will release it in this week.Ebrowse is a fast parser used to process C++ source files to produce a database that contains the class hierarchy that is later processed by Emacs to produce a class tree representation. It is somewhat like GNU Global, but is built-into Emacs and produce a class tree, so it will take longer to process in large source tree.

To use Ebrowse:

find . -name '*.cpp' -or -name '*.h' | ebrowse

Add more extension if you want. If your project only has hundreds of files, then =Ebrowse= works really well. After executing the command, a file named BROWSE is generated; this is the database that contains the class hierarchy. Simply open this file and Emacs automatically recognizes the file and process it. After done processing the database, Emacs displays an index of all classes in the database in a tree format: if a class is derived from a class, it is nested inside the parent class. This buffer is called a Tree buffer. Emacs provides three ways to interact with Ebrowse:

  • Tree buffer: a buffer that displays the tree.
  • Member buffer: a buffer that displays members of each class. You can toggle between declarations and definitions of a class and jump to the location of each in the corresponding source file.
  • Source buffer: your code buffer. You can interact Ebrowse database like finding and viewing (open for read-only) declaration and definition, open a =Member= buffer of a class that contains the tag at point...

If you have a large project (i.e. more than 10000 cpp files), but all classes are in .h files, then don't add .cpp or else it would take very long to generate BROWSE file. You will lose the ability to switch to definition though; but this can be done by using ctags or GNU Global. The most important thing is to view class hierarchy in Tree buffer, and this is the advantage of Ebrowse.

WIP guide is here.

Update: Alternatively, you can use doxygen to generate all kinds of graphs (caller/callee graphs, dependency graphs, class hierarchy graphs...) but it also takes a long time to generate all, even for small source tree like ipxe. This is not that doxygen is slow, in fact it's quite optimized, but to compute dependency for whole code base is not a trivial task.

Bonus: If you work with C and want to see call graph, use GNU Cflow. See my Reddit annswer.

  • This might sound silly, but where can I find the "ebrowse" executable? Is it not available for Windows or Mac OS X? – cheezy Nov 5 '14 at 4:23
  • @cheezy It is installed along with Emacs. So, if you install Emacs, it should be under the bin directory that contains Emacs. So, if you can run emacs in the command line, you should be able to run ebrowse. – Tu Do Nov 5 '14 at 4:24
  • @cheezy btw, did completion work for you? – Tu Do Nov 5 '14 at 4:30
  • +1 purely for Org syntax. Oh, and I guess the answer is good, too :) – Sean Allred Nov 5 '14 at 4:37
  • @SeanAllred woot didn't notice that. Fixed :) – Tu Do Nov 5 '14 at 4:39
2

You can have a nice helm interface to interactively use cscope:

http://wikemacs.org/wiki/Python#Indexing_sources:_ctags.2C_cscope.2C_pycscope

https://github.com/sergey-pashaev/helm-cscope

We then have functions like M-x helm-cscope-find-global-definition available. The navigation is quicker.

  • But, what he wanted is an overview of class hierarchy, not navigation and this is unique to Ebrowse, since the only viable navigation tool he had for his project is etags “Making tag completion table” Freezes/Blocks — how to disable – Tu Do Nov 5 '14 at 10:43
  • mmh, IMO (s)he doesn't only look for an overview of class hierarchy (despite the title), but for "tools [are] available for working with large OO codebases". cscope helps for that (better than etags) and is the very last word of his question :) – Ehvince Nov 5 '14 at 14:21
  • Well in his previous thread he already stated that only etags is usable with project, despite trying other solutions like GNU Global (which is definitely better than ctags). But for a class hierarchy, Eborwse or external tool like Doxygen is a viable option. And the very first sentence is "I'm working with a large codebase and often find it to be tedious and hard to understand class relationships" :) – Tu Do Nov 5 '14 at 14:33
  • Oh, looks like you're refering to another thread (that I wasn't aware of). cscope does help with class relationships because we can "find who calls this class" and stuff like that. ok, I am not perfectly in the subject, but still have my place :) – Ehvince Nov 5 '14 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.