Slashdot Mirror


Source Code Browsing Tools?

Marco Sanvido asks: "I often look at source code (especially C, but this question is valid for other languages as well) and I have a really hard time in understanding how it works. Documentation is often missing or quite outdated, and the only way to see how the program works is to try to understand the source code. Which tools do you prefer to use for browsing and studying source code? So far I have used LXR for Linux, Eclipse for java, and CScope, but I'm not sure that these tools are the best solution." It's tempting to flood this question with answers for your IDE, but the key thing here is _browsing_, not _development_. What decent, lightweight programs would work well as source code viewers?

40 of 165 comments (clear)

  1. A couple of options by plover · · Score: 5, Informative
    If you're looking for really lightweight, run the code through a prettyprinter first. Pick the style you can most easily read. For example, I personally don't like K&R style, but that's entirely up to you.

    If you're looking more for documentation of existing code, doxygen is great. It produces click-to-follow hierarchies, graphical pictures of trees, and can will intelligently display some of the comments it encounters. It can produce output in html, LaTeX, rtf, PS, PDF, and even man pages. And I know from experience that it can handle some pretty massive projects.

    --
    John
    1. Re:A couple of options by diverscuba023 · · Score: 2, Interesting

      The only problem with doxygen is the amount of time it takes to generate the documentation for an entire project. I had one project it would take almost 48 hours to produce the documentation for and it could not generate the graphs for two of the hiearchies since they were too big. The source code was only about 500K lines.

  2. The only option by Frogbert · · Score: 3, Funny

    Real programmers use "type".

    1. Re:The only option by Alfred,+Lord+Tennyso · · Score: 5, Funny

      Actually, real programmers use cat.

    2. Re:The only option by popeyethesailor · · Score: 4, Funny

      Um no. They may grep, sed, awk, diff, tr, tail,head or more; but they never cat.

    3. Re:The only option by Catastrophator · · Score: 3, Funny

      Bah! Real programmers program with the switches on the front panel! Damn whippersnappers... And get of my lawn!

    4. Re:The only option by shenanigans · · Score: 2, Funny

      Bah. Real programmers use hexdump.

    5. Re:The only option by Richard+Steiner · · Score: 2, Funny

      Real programmers don't work on toy platforms (like UNIX) at all. :-) We use tools like ED, DOWNDATER, IACULL, and LISTER to generate CCFs in a proper format which our compilers understand (not that "diff" crap), use SGSs written in SymStream to control our product compiles, read dumps in octal (hex is for long-haired bean-sprout-eating UNIX freaks and peecee weenies, and interactive debuggers are for slopeheads who lack the mental capacity to write real programs), and don't use formal change management. Real programmers can keep track of potential merge errors and fix them manually if one occurs at GEN time, and we drink Mountain Dew, not that hot smelly crap made from beans.

      --
      Mainframe/UNIX Bit Twiddler and long time Windows/Linux Hobbyist.
      The Theorem Theorem: If If, Then Then.
    6. Re:The only option by Bastian · · Score: 3, Funny

      And get of my lawn!

      Real programmers know that forgetting even a single byte in any stream of data can turn it into gibberish or worse.

    7. Re:The only option by Autonomous+Cow · · Score: 2, Funny

      Indeed. But a real UNIX hacker can unplug the monitor, cat the source files to /dev/dsp and listen for bugs in the system. And he knows from the tune whether its compiler errors or silly warnings designed for people who think lint-clean does not imply a wool suit.

      --
      The Autonomous Cow. Moo.
  3. OpenGrok by Lucractius · · Score: 4, Informative

    the opensolaris code browser is built off a bunch of open source stuff.

    OpenGrok
    its incredibly easy to use, and makes things very easy to read. and is now packaged for your enjoyment.
    and available at http://www.opensolaris.org/os/project/opengrok/

    --
    XML - A clever joke would be here if /. didn't mangle tag brackets.
    1. Re:OpenGrok by Anonymous Coward · · Score: 2, Interesting

      That looks very interesting but the requirement page lists a servlet container, such as Glassfish or Tomcat, just to use it. Is there a way to use it without installing Tomcat or Glassfish or is it primarily a web app? I have no interest in any of the online functionality it offers and requiring a servlet container seems to be overkill for my needs. Running Tomcat or Glassfish in the background simply for this application definitely removes it from being a "lightweight" option.

  4. Nothing Can Beat a Good Editor by justanyone · · Score: 2, Insightful


    Nothing Can Beat a Good Editor

    As much as we might like to use some special purpose tool for this purpose, most of the time that I'm looking at code I'm not entirely sure if I'm going to be editing it or just peeking. Thus, it's silly to be in one program when I need another. And, the added "system weight" of running a "heavy" editor vs. /bin/less or vi or emacs is silly, when I don't want to remember all their key combinations for moving around the file - top, bottom, page up pagedown, etc.

    Syntax highlighting is THERE in an editor, and I don't have to restart if I change my mind about changing the file.

    http://ultraedit/com/ is a GREAT editor for Windows, or Jedit or Eclipse for Win or unix.

    1. Re:Nothing Can Beat a Good Editor by plover · · Score: 4, Informative
      For windows, I've completely replaced "notepad.exe" with "notepad2.exe" And when I say completely, I mean I crawled through my system registry editing every occurrance of "notepad.exe" to "notepad2.exe". Shell opens, file associations, defaults of every sort use it. I love it. And unless someone using the computer is particularly observant, they don't even notice it's not the original notepad.

      It has a very simple interface that looks like the original notepad, it does syntax coloring for two dozen different languages and file formats, shows bracket matching, adds line numbers, word wrap features, support for UNIX- and mac-style line terminations, regexps, and is in general what notepad itself should have been back in the 1990s. Plus, it's freeware. What more could you want?

      --
      John
    2. Re:Nothing Can Beat a Good Editor by b17bmbr · · Score: 2, Informative

      or, you could have copied the executable to C:\windows and renamed it notepad.exe. it sucks that windows doesn't use symlinks though. would make it a whole lot easier. but then again, isn't that the point of windows, making what need to do impossible, everything you don't want to do easy.

      --
      My problem? I was perfectly gruntled, until some numbnuts came by and dissed me.
    3. Re:Nothing Can Beat a Good Editor by dolmen.fr · · Score: 2, Informative

      Notepad.exe is both in %WINDIR% and %WINDIR%\System32 and as the other poster pointer, it is a hard task to replace them in XP due to system file protection.

    4. Re:Nothing Can Beat a Good Editor by Jerf · · Score: 2, Informative

      emacs used to be a heavy editor. But "heavy" is a relative term. In an era where people will open Eclipse to edit a file, is emacs really heavy anymore? Probably not. Most of the features people will complain about like news reader, etc., are loadable modules anyhow and who cares what modules the program might load?

      On my personal system, emacs in text mode loads before I'm ready to edit the file, which is all I can ask for, and it's still the fastest XWindows editor I can open. It may be "heavier" than other editors based on GTK or QT, but it seems GTK and QT aren't necessarily "light" themselves, so my emacs will be up way before even lightweight things like GEdit.

      I think calling emacs "heavy" now is just inertia from the era of 1MB machines. If emacs is heavy, than so is damn near every app I run and that's not a very useful definition if it never distinguishes between anything.

  5. Krugle by WeAzElMaN · · Score: 2, Informative

    If I'm looking at third-party code (instead of my own), I like to use Krugle. It's still in beta and I was lucky enough to get a beta invite, but it's an extremely powerful tool for searching through repositories and documentation.

  6. LXR by ashridah · · Score: 2, Informative

    I've always considered stuff like LXR (linux cross reference) to be good for this kind of thing.

    LXR's claim to fame is that it started out being a cross-referenced browser for the linux kernel source code, but since it was released, the newer versions has moved towards becoming more of a general source browser. (might need to use cvs, don't know if a proper release was made)

    It does neat tricks like processing source code, building function/variable/header/etc line references for usage, definition, declaration etc, and cramming them into a db for retreival. It can also handle interfacing with CVS to pull source code directly from a CVS server, which is interesting. Also handles full text searching too, if you get glimpse or whatever.

    Of course, the interface to LXR is a web browser, which makes it less than ideal if you consider that it isn't integrated into an IDE, but for the purpose of tracing/searching large amounts of code, it's still pretty useful.

    ash

  7. codeviz by meowsqueak · · Score: 4, Informative

    You can make some useful call graphs with codeviz + graphviz. I sometimes find this useful for tracing the heirarchy of abstraction through a set of C source files.

    http://www.csn.ul.ie/~mel/projects/codeviz/

  8. One excellent option... by dracken · · Score: 2, Informative

    ..is Redhat Sourcenavigator . You can look at class hierarchy, static call graphs, jump to function declarations/definitions/callsites. Try it out.

  9. JEdit by ChaseTec · · Score: 2, Interesting

    I needed an easy to use C source code browser because I'm porting an old bbs game to Java. JEdit fit the bill perfectly. Out of the box it's not much more then a text editor with syntax highlighting(130+ languages). It has a feature call HyperSearch that can be used for search through single files or multiple files and have a little box of hyperlinked results. It has lots of plugins to extend it's funtionality but nothing extra to get in the way when you first install it. Check it out at jedit.org. The only thing some people might take issue with is that it requires Java.

    --
    My Hello World is 512 bytes. But it's also a valid Fat12 boot sector, Fat12 file reader, and Pmode routine.
  10. gdb by Bastian · · Score: 4, Interesting

    I'm actually a fan of using a debugger to step through code I'm trying to understand. I can let it keep track of the call stack for me and it saves me from having to manually surf around multiple source files to figure out where the next function I need to look at is.

    It's not a good way to figure out how every nook and cranny of the code works, but it's great for an initial scan-through to see the overall structure of a module. And if you are at liberty to throw in an embeddable scripting language (I use F-Script) you can poke and prod at anything you want with ease.

    1. Re:gdb by marcosdumay · · Score: 2, Interesting

      Use GDB inside of Emacs (M-x gdb) That way, you have an entire buffer to navigate through the code, while the debugger output is displayed on another buffer. And, yes, the code buffer is always actualized to the running instruction when the debugger beaks.

  11. SciTe by stony3k · · Score: 2, Informative

    I prefer to use SciTe - it's really lightweight - supports code folding, syntax highlighting and it's open source.

    --
    Freedom is not worth having if it does not include the freedom to make mistakes. - Mahatma Gandhi
  12. Source Insight by Anonymous Coward · · Score: 2, Interesting
  13. Not really a browser, but helpful by Klowner · · Score: 2, Informative

    I've found Doxygen to be pretty handy, it'll output to a bunch of HTML files and even create nifty relationship graphs for OO languages like C++

    http://www.stack.nl/~dimitri/doxygen/

  14. FishEye by pajama · · Score: 2, Interesting

    If you develop in Java you could try FishEye:
    http://www.cenqua.com/fisheye/

  15. A query language for browsing by mmacdona86 · · Score: 2, Interesting

    To plug a personal project of mine--
    Browse-by-Query is a database for code with a query language specifically designed for finding things in code.
    I was dissatisfied with fixed-function browsers, so I developed this.
    Use expressions more powerful than regular expressions to search through and understand your codebase.
    Works only with Java now (there's a standalone version and Eclipse plugin) but I hope I (or someone else) will extend it to others.

  16. Understand for C++ by barries · · Score: 2, Interesting

    We use Understand for C++ (link is to the index of all "Understand for..." family members) when reviewing and designing formal unit tests for our clients' code. It's extremely useful for manual static analysis: understanding structure and inter-relatedness, so to speak.

    However, to understand dynamic behavior you should look at various tracing options, even the lowly printf(), or try stepping through in a debugger. The larger, more complex and the more object-oriented the code, the more important understanding the dynamics are.

    Anyway, Understand for C++ is much more interactive than any of the free comment extraction or cross reference tools and the database has a Perl API, though we've not had a chance to use it. It's worth the price if your doing this as part of your job.

    - Barrie
  17. Emacs by sdfad1 · · Score: 2, Interesting

    I know you said no IDE's, but if you merge well with Emacs, it can do the work too. Emacs is not exactly a heavy weight, depending on how you install it (it's often built into your distro anyway). It uses this thing (I don't really know it that well to be honest) called tags - ctags or etags.

    Basically you run etags (check your man pages) from the command line that will parse through your source files and create a lookup table in a file (name TAGS by default I think). While browsing the source file, you just have to position the cursor at the right symbol, and press M-. (that's usually Alt-DOT) and it'll take you to the function definition. (vim has a similar thing)

    I haven't used it too much, since I'm a Lisper, and the Slime development environment (Emacs addon mode) for Lisp has a similar thing (and it doesn't need to create any tables beforehand) that also provides a "stack-like" functionality. That means you can jump to the function definition, then pop back to where you were. This can be handy for quick detours just to lookup small functions for example.

    The advantage here is that you have the all the files locally, so it's faster than browsing through a web interface (html-ized source files, like the Sourceforge CVS frontend - I still use that a lot, and it is SLOW), and you can also edit the source (just a bonus).

  18. Understand from Scitools by Flu · · Score: 2, Informative
    I regulary use Understand C/C++ from SCITools (is available for Java and other languages) to browse source code (in my case, embedded sources that is supposed to be compiled using the Keil compiler). It's "right-click, for information" attetude makes browsing around a breeze. The reason is that it builds an internal database when loading the project (which takes a second or a few, depending on the size of the sources), and once built, the interface is astonishingly fast!

    One of the things I like most, is that it also colours all parts of the code that is #ifdef'ed out. Another thing is that the information windows for any token displays all kind of information: calls, callees, references, uses (including sets/get/modifies), used locals, used globals, exposed globals etc - all of which in a tree view, so it is very easy to decide what's important and what's not.

    It is possible to use it as an editor as well, which I do, but as such it isn't perfect.

    Also, importing a completely new project requires almost no intervension - it will simply prompt for where any missing #includes are located and add them to the searchpath, so just setting it up for a quick test is done in no-time.

  19. Re:How dare you... by Per+Wigren · · Score: 2, Funny

    Hey, we weren't supposed to talk about IDEs!

    --
    My other account has a 3-digit UID.
  20. SourceNavigator by schlenk · · Score: 2, Informative

    You could also take a look at SourceNavigator at http://sourcenav.sourceforge.net/index.html.

  21. Tools I have used, GNU Global & NCC by ZorroXXX · · Score: 2, Informative
    Lxr is good for browsing "static" code like the different linux releases. But as a tool for browsing arbitrary source code it is too cumbersome to set up and use.

    I have sometimes used GNU Global which makes indexed html pages of the code. Somewhat similar to lxr but there is no setup, just run two commands, gtags and htags. One nice thing about global is that it can be used on any incomplete subset of a software system. Want to just look at the files in the drivers/net/wireless directory in the linux kernel tree? Fine, just run gtags and htags from that directory (and no other setup is necessary).

    I have also used NCC which "compiles" each file and makes a index file with information like "function AAA calls functions BBB, CCC and DDD, reads variables EEE, writes variables FFF and GGG". The format is not exactly like that but you get the idea. NCC includes a text mode gopher-like variable usage/function call browser and there is a script to make graphical call graphs (via dot from graphviz). At work I have also used information from ncc files in combination with with information from the map file to find maximum stack usage.

    This study (which I just found while writing this) seems to have an interesting analysis of this topic.

    --
    When you are sure of something, you probably are wrong (search for "Unskilled and Unaware of It").
  22. Brilliant source code browser by heretic108 · · Score: 2

    Leo - http://leo.sourceforge.net/

    A GUI literate programming editor - can import sources in many languages, and break them down into classes/methods/functions.
    You then have ability to create all manner of 'views' of the code.

    --
    -- In the beginning was the WORD, and the WORD was UNSIGNED, and the main(){} was without form and void...
  23. Universal advise by ceeam · · Score: 2, Funny

    Just rewrite it. Reading others' code is for wimps.

  24. Not *browsing* but *understanding* by PurplePhase · · Score: 3, Interesting

    Unfortunately the story poster was a bit vague. They could mean that they or the person assigned don't read code, yet they need to know how a program works, or what it does. There are many times when you don't want to or cannot run/debug a program to analyze it.

    There have been many links posted which I'm going to have to explore - not the editor links (jEdit and Emacs rulz!) but the conceptualization links. Unfortunately most if not all IDEs are still code-file based. The most prominent other tool for project conceptualization is UML which has been gaining IDE integration. Yet there are still a couple problems with that:

    1. The UML usually generates accurate structures for classes, but doesn't or cannot generate execution diagrams (what, 4 types in UML?) or state diagrams.

    2. These static diagrams represent only the level of the code instead of being an interactive object with drill-downs or abstract-up commands!

    To understand a new set of code or codebase, I need something that analyzes the code and reports back to me on its tactics and strategies - what patterns are used, what weaknesses are in the code, ... Current tools give you unuseful amounts like cyclomatic complexity, or other ratings like test coverage or Fowler's class interdepence/brittleness/(whatever) measure. However those things are useful to me only: if you know nothing about code, have any resources to plug testing holes, or are actively managing a codebase, respectively. None of them say what the code *does* or how it does it. So we need something that covers concerns orthogonal to what already exists.

    Which makes me more curious about the comment asking if anyone uses the tools researchers are working on for visualizing a project. I haven't kept up on academics - where do I start looking? And is there anything there with demos, products available, or in post-beta releases?

    8-PP

  25. Source Navigator by avdi · · Score: 2, Informative

    Source Navigator is the perhaps the most amazingly useful freebie I've ever downloaded. It's absolutely indispensible for making sense of large C/C++ codebases (and it has some support for other languages too). The cross-referencing ability is particularly useful; it's great to be able to call up a graphical call-tree of any function.

    --

    --
    CPAN rules. - Guido van Rossum
  26. My choice by idontgno · · Score: 2, Insightful
    Which tools do you prefer to use for browsing and studying source code?

    14-inch greenbar, preferably printing on a color-capable impact printer.

    Wide continuous paper, plus a large work surface, means I can stretch a module out and mark it up with highlighters and scribble notes. A straightedge and some detective work means I can verify "indentation" levels (code nesting).

    Of course, run a source code beautifier over it first.

    Why, yes, I am old; how did you guess?

    --
    Welcome to the Panopticon. Used to be a prison, now it's your home.