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.

Figure 4: SourceWeb is a functional yet pretty basic source-code browser that just needs some love. And a new maintainer.

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

  1. "Code compilation" by Valentine Sinitsyn, Linux Voice, issue 22, January 2016, pg. 94, https://www.linuxvoice.com/download-linux-voice-issue-22/
  2. ctags(1) man page: https://linux.die.net/man/1/ctags
  3. Exuberant Ctags: http://ctags.sourceforge.net/
  4. Universal Ctags: http://ctags.io
  5. Cscope: http://cscope.sourceforge.net
  6. "System Calls," Linux Voice, issue 29, August 2016, pg. 20
  7. Ack: http://http://beyondgrep.com
  8. LV forums: http://forums.linuxvoice.com
  9. cscope(1) man page: https://linux.die.net/man/1/cscope
  10. Woboq: https://code.woboq.org
  11. Bear: https://github.com/rizsotto/Bear
  12. CC BY-NC-SA 3.0: https://creativecommons.org/licenses/by-nc-sa/3.0/
  13. SourceWeb: http://rprichard.github.io/sourceweb/

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Perl: Tricks with Vim

    The Vim editor has any number of tricks for helping you avoid unnecessary typing. In this month’s article, we look at some effort-saving Vim techniques for Perl hackers.

  • Tech Tools
  • Kernel News

    In kernel news: Rust in Linux; and Compiler and Kernel Frenemies.

  • QR Code Generators

    With the right tools, you can create your own QR code squares with information you want to share, for example, on a business card, in a letter, or on your website.

  • Start from Scratch

    Coreboot lets you build your own custom firmware while learning more about Linux.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News