Source code browsers
Abandoned SourceWeb
SourceWeb [13] is another example of a Clang-based technology. Again, you'd probably want to build it yourself. You'll need GCC, Clang, and Qt development headers, which should be readily available in your package manager.
Indexing a project with SourceWeb is a two-stage process. First, you create the JSON compilation database. For projects not using CMake, SourceWeb provides its own btrace
tool. It works reasonably well and relies on the same mechanisms as Bear. Choosing one over another is mainly a matter of taste. However, btrace
doesn't build compile_commands.json
directly: it generates a logfile you'll need to postprocess with the sw-btrace-to-compiledb
command. You might prefer Bear to skip this extra step.
Then, you run
sw-lang-indexer --index-project
in the project's build directory to generate an index file. The latter is a binary database that the SourceWeb GUI uses to do lookups, much like tags
or cscope.out
. This will take some time. For a large codebase, you might want to add --incremental
to retain per-file indexes and speed up future index rebuilds.
When you have an index, run sourceweb index
to launch SourceWeb navigator's Qt-based GUI. You see the project outline in the left pane; files are opened in the right (Figure 4). You can browse for files, global definitions, and symbols. To this end, SourceWeb supports regular expressions. Right-click on any symbol in the source code viewer and choose Cross-references. You'll learn how the symbol is used. This is a feature set you'd expect from a code browser, yet it's pretty basic. Moreover, the application misbehaved once and crashed during startup another time on an Ubuntu 16.04 LTS box.
SourceWeb feels interesting but somewhat incomplete, especially if you think about its GUI. And it's a pity because the project never saw official release and now seems to be unmaintained. It is about 15K source lines of code (SLOC) and BSD-licensed, so if you are looking for a pet project, please give it a chance.
Here you are. The four options I just covered aren't the only ones available in Linux. Yet, I think they are the most promising. Personally, I use Cscope and Woboq Code Browser most often, but your mileage may vary. To help you decide, I summarized the tools in Table 1, so you can compare them side by side. Shall you decide to join the Universal Ctags team, or pick up SourceWeb? Please let us know!
Table 1
Source Code Navigators
Name | Version (last release) | Active | License | Parser(s) | Interface | Language support | References [a] |
---|---|---|---|---|---|---|---|
Exuberant Ctags/Universal Ctags |
58 (7 Sep 2009)/? [b] |
No/Yes |
GPLv2 |
Custom, regex-based |
Command line [c] |
Various |
No/Yes |
Cscope |
15.8a (4 Apr 2015) |
Yes |
BSD |
Custom |
Curses [d] |
C/C++/Java [e] |
Yes |
Woboq Code Browser |
2.0.1 (10 Aug 2016) |
Yes |
Dual |
Clang |
Command line/Web |
C/C++ |
Yes |
SourceWeb |
? [b] |
No |
BSD 2-clause |
Clang |
Command line/Qt |
C/C++ |
Yes |
a. The tool not only jumps to definitions but also shows where (and how) they are used. |
|||||||
b. No official release at the time of writing. |
|||||||
c. Generator. Different front ends are available for browsing. |
|||||||
d. Third-party GUIs are available. |
|||||||
e. C++/Java support is limited. |
Infos
- "Code compilation" by Valentine Sinitsyn, Linux Voice, issue 22, January 2016, pg. 94, https://www.linuxvoice.com/download-linux-voice-issue-22/
- ctags(1) man page: https://linux.die.net/man/1/ctags
- Exuberant Ctags: http://ctags.sourceforge.net/
- Universal Ctags: http://ctags.io
- Cscope: http://cscope.sourceforge.net
- "System Calls," Linux Voice, issue 29, August 2016, pg. 20
- Ack: http://http://beyondgrep.com
- LV forums: http://forums.linuxvoice.com
- cscope(1) man page: https://linux.die.net/man/1/cscope
- Woboq: https://code.woboq.org
- Bear: https://github.com/rizsotto/Bear
- CC BY-NC-SA 3.0: https://creativecommons.org/licenses/by-nc-sa/3.0/
- SourceWeb: http://rprichard.github.io/sourceweb/
« Previous 1 2
Buy this article as PDF
(incl. VAT)