SilentBob

Why using SilentBob for generating tags?

SilentBob uses syntax analysis to parse source files, which makes it faster than a utility like Exuberant Ctags, which uses regular expressions to locate the appropriate line in a file. In a test run on the sources for the Linux kernel (version 2.6.19) Exuberant Ctags generated the tags table in 90 seconds, while SilentBob did its job in 10 seconds (on a 2.6MHz Celeron). SilentBob also supports multithreading optimizations.

Another difference is the format of tags tables: In tables created by Exuberant Ctags, regular expressions are used to locate the appropriate line in a file. This means that if you edit the file, and the position of some definition is changed, you don't need to rebuild the tags table. This is good for Exuberant Ctags because it means you don't need to regenerate the table often, but it also means that if you are viewing huge files, jumping to a tag definition will be much slower than if line numbers were used. That's why SilentBob uses line number in its tags tables; however, that means you have to update the tags table after every major edit.

SilentBob is another new tool for analyzing source code. It currently supports C/C++, Perl, and Python, but its plugin framework (which is not documented at the moment) enables users to add support for new languages and other features easily.

You can get source tarball and deb packages from the downloads section of the software's site. After installation, invoke SilentBob three times in the directory with source code:

  bob --make-ctags
  bob --cfiles
  bob -L cfiles --call-tags

This will generate three files: tags, the common tags table; cfiles, a list of C/C++ files; and call_tags, the call tags table. The call tags table contains tags for function calls, so if you want to find all the calls of some function, you can point Vim to use the call tags table (:set tags=./call_tags) and use the same commands as for searching tags (:tag function-name and :tnext and :tprevious to cycle through results). These index files can be used by SilentBob to build call trees and backward call trees.

For Perl and Python, only tags tables and file lists are supported:

  bob <--perl | --python> --make-ctags
  bob <--perl | --python> --files
The second command will generate a perl_files or python_files file.

Once you have a tags table, SilentBob can show you a call tree:

  bob [--depth N] function

--depth option allows you to limit the depth of the tree. If the only thing you need to know is which functions are called by function, specify --depth 0. Otherwise, you will be shown which functions are called by functions called by functions (...) called by function.

Note that you can use this option with the tags table generated by SilentBob for Python and Perl files. Tables generated by Exuberant Ctags are not supported.

The call tags table is used to generate a backward call tree:

  bob [--depth N] -u function

This will show functions which call functions (...) which call function. In this case specify --depth 1 to see only functions which call function

SilentBob can also use the created cfiles file to search for text within C/C++ code. It checks operators; strings and comments are ignored.

  bob list of files --cgrep pieces of text, separated by comma

You can specify -L ./cfiles to use generated file list. Pieces of text should be from one operator, so if you are looking for testing of T variable, use:

  bob -L ./cfiles --cgrep if,T

SilentBob also includes a tags utility that lets you to view the tag definitions in a C/C++ file in a console. Invoke tags tag1 tag2 ... tagN to strip the fragments of code you are interested in from code -- function definitions, global variable declarations, etc. -- and you will see the fragments of code you need.