6

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
Malabarba
  • 22,878
  • 6
  • 78
  • 163
cheezy
  • 287
  • 2
  • 7

2 Answers2

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.

albert
  • 109
  • 2
Tu Do
  • 6,772
  • 20
  • 39
  • This might sound silly, but where can I find the "ebrowse" executable? Is it not available for Windows or Mac OS X? – cheezy Nov 05 '14 at 04: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 05 '14 at 04:24
  • @cheezy btw, did completion work for you? – Tu Do Nov 05 '14 at 04:30
  • +1 purely for Org syntax. Oh, and I guess the answer is good, too :) – Sean Allred Nov 05 '14 at 04:37
  • @SeanAllred woot didn't notice that. Fixed :) – Tu Do Nov 05 '14 at 04:39
  • In 26.3 and under Windows the BROWSE was shown literally as text. Had to make sure to use ebrowse.exe from the Emacs bin-folder (Cygwin installed its own, incompatible version as /usr/bin/ebrowse). Then I had to put this code into my dot-emacs: `(require 'ebrowse) (add-to-list 'auto-mode-alist '("BROWSE$" . ebrowse-tree-mode))`. Finally it worked! This is a great tool and accompanies Etags very well. To optimize the presentation for wide-screens consider `follow-delete-other-windows-and-split`. You'll figure it out. – Andreas Spindler May 05 '20 at 11:27
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.

Ehvince
  • 1,091
  • 10
  • 14
  • 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](http://emacs.stackexchange.com/questions/2919/making-tag-completion-table-freezes-blocks-how-to-disable/2936?noredirect=1#comment4250_2936) – Tu Do Nov 05 '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 05 '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 05 '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 05 '14 at 14:53