Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×

Source Code Browsing Tools? 165

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?
This discussion has been archived. No new comments can be posted.

Source Code Browsing Tools?

Comments Filter:
  • A couple of options (Score:5, Informative)

    by plover ( 150551 ) * on Wednesday June 07, 2006 @11:37PM (#15492204) Homepage Journal
    If you're looking for really lightweight, run the code through a prettyprinter [wikipedia.org] 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 [stack.nl] 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.

    • 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.
    • Any editor with good syntax highlighting would probably give you most of what you want. Nedit [nedit.org] has long been my favorite. Simple, light, and with (last time I counted) 28 grammars.
    • doxygen chokes on the complex macros used in the legacy C modules of my C++ application. Does anybody know of any tool similar to doxygen, but better at parsing C?
  • by Frogbert ( 589961 ) <frogbert@gmail . c om> on Wednesday June 07, 2006 @11:42PM (#15492234)
    Real programmers use "type".
  • OpenGrok (Score:5, Informative)

    by Lucractius ( 649116 ) <Lucractius@NoSpAm.gmail.com> on Wednesday June 07, 2006 @11:43PM (#15492237) Journal
    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/ [opensolaris.org]
    • Re:OpenGrok (Score:2, Interesting)

      by Anonymous Coward
      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.
      • while the above post was anonymous and probably not seen by many. it asked if there was a way to run this on a more local/lite deployment. i dont know myself, ive already got a tomcat box lying round for testing so it wasnt hard for me. But if you dont have a servlet container available. theres a few non tomcat options

        http://servlets.com/engines/#embeddable [servlets.com] has a list of quite a few. and from the list

        http://jetty.mortbay.com/jetty/index.html [mortbay.com] seems to be the best candidate. (though it quotes no resource figu
      • It's a web app. If you're not using any currently, then this isn't for you. Personally, installing & configuring Apache and Tomcat (and PostgreSQL) is just part of my default install ritual, but I realize lots of people don't want to leave a dozen or so extra processes lying about (exp. when one of them is a JVM sucking down 70-100K of memory).
        • (exp. when one of them is a JVM sucking down 70-100K of memory).
          This is why I don't use Java! My computer's only got 640K of memory!
  • by justanyone ( 308934 ) on Wednesday June 07, 2006 @11:46PM (#15492259) Homepage Journal

    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/ [ultraedit] is a GREAT editor for Windows, or Jedit or Eclipse for Win or unix.
    • by plover ( 150551 ) * on Thursday June 08, 2006 @12:11AM (#15492373) Homepage Journal
      For windows, I've completely replaced "notepad.exe" with "notepad2.exe" [flos-freeware.ch] 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?

    • Okay, I almost started laughing when you said " a "heavy editor" vs ... emacs". I view emacs as quite a heavy editor, especially vs something like vi/vim. It has features for mail and news for crying out loud. Hell, I used to use Emacs, but have switched to vim. I switched partly because it was much lighter, even the gui. You really start to see it if you run it remotely using X.
      • 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 othe
      • Pardon me if I'm being ignorant here, but I thought the only reason vim doesn't normally have all these features is that not as many people write scripts for it. I know vim is just as extensible, so criticizing emacs for having such a large library of plug-ins (or even for including more of them out of the box) strikes me as being rather silly.

        Now, if you're wanting to be a badass who uses an old version of vi that doesn't include decent scripting support, that's different. But me, I'm a programmer and I
    • I love UltraEdit as well when I have to windoze my way through code.

      Treepad is not that bad as an alternative though. It is missing the nice compact search and replace dialog but otherwise is very feature rich.

      JsD
  • Krugle (Score:3, Informative)

    by WeAzElMaN ( 667859 ) on Wednesday June 07, 2006 @11:47PM (#15492264)
    If I'm looking at third-party code (instead of my own), I like to use Krugle [krugle.com]. 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.
  • LXR (Score:2, Informative)

    by ashridah ( 72567 )
    I've always considered stuff like LXR (linux cross reference) [linux.no] 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, declarati
    • LXR, how unique! Just like the submitter put right there in his question!
       
      • Of course, but he asked if there was anything better. You may as well assume my post is a vote in favour of LXR.
        It certainly helped me a lot while i was wading through the kernel source, and it does support non-kernel sourcecode in more than just C nowadays.

        ash
  • codeviz (Score:5, Informative)

    by meowsqueak ( 599208 ) on Wednesday June 07, 2006 @11:52PM (#15492292)
    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/ [csn.ul.ie]
  • Yeah I know we're not supposed to discuss IDE's. But its class browser (which can handle multiple languages) can greatly simplify trouncing through a code base.
  • by dracken ( 453199 ) on Wednesday June 07, 2006 @11:56PM (#15492308) Homepage
    ..is Redhat Sourcenavigator [sourceforge.net]. You can look at class hierarchy, static call graphs, jump to function declarations/definitions/callsites. Try it out.
  • JEdit (Score:3, Interesting)

    by ChaseTec ( 447725 ) <chase@osdev.org> on Wednesday June 07, 2006 @11:57PM (#15492318) Homepage
    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 [jedit.org]. The only thing some people might take issue with is that it requires Java.
  • gdb (Score:5, Interesting)

    by Bastian ( 66383 ) on Wednesday June 07, 2006 @11:59PM (#15492329)
    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.
    • by Hast ( 24833 )
      Do you know of any way of putting traces from a debugger back into the source browser?

      For me the holy grail would be to have a system similar to Doxygen which would allow me to "load" a trace from a debug session and use that to step around in the code.
      • I really don't. It's never occurred to me. I use XCode's gdb interface, which doubles as an editor. I just make my notes in the actual source as I'm stepping through with the debugger.

        Which reminds me; I don't know if other development environments do this, but XCode's "patch" feature is also really killer for figuring out what's going on. If you want to force the execution to go down a certain path, you can always break just before the conditional, comment it out, click patch, and continue without havin
    • Re:gdb (Score:3, Interesting)

      by marcosdumay ( 620877 )

      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.

  • SciTe (Score:2, Informative)

    by stony3k ( 709718 )
    I prefer to use SciTe - it's really lightweight - supports code folding, syntax highlighting and it's open source.
  • Source Insight (Score:2, Interesting)

    by Anonymous Coward
    http://www.sourceinsight.com/ [sourceinsight.com]
  • by Klowner ( 145731 ) on Thursday June 08, 2006 @12:12AM (#15492376) Homepage
    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/ [stack.nl]
  • You mentioned scope... what exactly doesn't it do that you'd like? Other than the time to build to source database (minutes for large projects, amortized heavily if you're only reading), it seems perfect to me.
    • cscope [sf.net]! Mod parent up! :)
    • I use cscope from within VIM... I'm pretty sure it's compiled by default in the available binaries... but I'm not sure.

      Anyway it works really well and I like VIM for the rest of my devleopment anyway so no extra tools are really needed.
  • FishEye (Score:2, Interesting)

    by pajama ( 48556 )
    If you develop in Java you could try FishEye:
    http://www.cenqua.com/fisheye/ [cenqua.com]
  • by mmacdona86 ( 524915 ) on Thursday June 08, 2006 @12:47AM (#15492522)
    To plug a personal project of mine--
    Browse-by-Query [sourceforge.net] 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.
  • Understand for C++ (Score:3, Interesting)

    by barries ( 15577 ) on Thursday June 08, 2006 @12:56AM (#15492551) Homepage

    We use Understand for C++ [scitools.com] (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
    • I use Understand for Fortran quite regularly and I really like it. The GUI has lots of little anoying quirks ... but those anoyances are more than made up for by the real meat of the program which realy does help you understand your code. Plus their support is _very_ responsive, every bug report or feature request I have submitted has been dealt with in 2 weeks or less. Also, they put out a new build every monday.
    • I emailed them about OS X support, and they replied that they have an OS X version in beta, but won't be ready to release until late this year.

      Just FYI for anybody else looking into it.
  • Emacs (Score:2, Interesting)

    by sdfad1 ( 880883 )

    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 ju

    • I second the recommendation for etags for Emacs users. It's a good way to dig down through code and then pop back up.
    • Don't forget some of the other features of EMACS too.

      First and foremost, syntax highlighting. I don't know a single program that highlights syntax as well as Emacs. Get your colour scheme right and code won't be the same without it. You can visually "see" the code structure at a glance without even having to read the words. Emacs indenting is also superior, and really helps when making out the overall structure. There's even a code folding option now, so you can finally collapse sections. Very useful at tim
      • Try the Emacs Code Browser (http://ecb.sourceforge.net/) and Doxymacs (http://doxymacs.sourceforge.net/).
      • Though I like Emacs and currently use it, I find the standard syntax highlighting of Vim superior.

        Maybe it is because I mostly use Perl.

        Two things stand out.

        emacs only highlights variables in Perl when they are declared, and does not to highlighting on @ and % variables. In Vim all variables are highlighted anywhere.

        The other thing is POD documentation. In Emacs one has to reload the file for POD sections to be highlighted, when in Vim they are highlighted from the moment you start a '=pod' section.

        • And emacs misses folding.

          Once there was an elisp folding package, but last time I searched, it was nowhere to be found.

        • Have you discovered cperl-mode yet? It's like perl-mode but done right.
        • Though I like Emacs and currently use it, I find the standard syntax highlighting of Vim superior. [...] emacs only highlights variables in Perl when they are declared, and does not to highlighting on @ and % variables. In Vim all variables are highlighted anywhere.

          You may be right about vim's syntax highlighting being better overall, but you are wrong about perl. My emacs highlights @foo and %foo well enough; they get colored and, IIRC, underlined.

          • Yeah, if he's using cperl-mode, he's using it wrong. It does a great job figuring out tricky things like $@foo[bar]->{baz}, etc., as well as the usual %hash, @array, $scalar (and $hash{foo}, $array[0], $#array, etc.)
    • I'm amazed that no one has mentioned the Emacs Code Browser. This includes a whole bunch of code analysis tools, including semantic parsing for intellisense-like completion, directory views, etc. It hooks up with Speedbar to make browsing easier and can mark up and index the code to identify functions/methods. It can be found at ECB at sourceforget.net [sourceforge.net]. It's built on top of the Collection of Emacs Development Environment Tools [sf.net].

      Also worth mentioning (and related) is the Java Development Environment for Ema

  • think beyond ed [gnu.org]
  • ...if your code is in a CVS or Subversion repository. It uses enscript [blogs.com] for syntax highlighting which works pretty well for a variety of languages (for example, Ruby [rubyforge.org]).

    I agree with some of the other folks here, though - a good IDE makes an excellent code browser. IntelliJ IDEA is awesome if you're working with Java code...
  • by Flu ( 16236 )
    I regulary use Understand C/C++ from SCITools [scitools.com] (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 t

  • Try PSpad. It's free. www.PSpad.com
  • This depends on what you want to do.

    If you are looking for this in relation to debugging a known bug, ctags + vim (or etags + emacs) is the way to go. This also applies in case you just want to learn the code.

    If you are looking for this to audit the security of a program, then you need to follow code paths. While ctags will help you there, I don't see much stuff which is capable of showing flow paths in a program.
  • SourceNavigator (Score:2, Informative)

    by schlenk ( 941701 )
    You could also take a look at SourceNavigator at http://sourcenav.sourceforge.net/index.html [sourceforge.net].
  • 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 [gnu.org] 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 ke

  • It doesn't really look maintained, but I really enjoyed Cygnus Source Navigator when I need to read a lot of source bases for a living. You can find it at http://sourcenav.sourceforge.net/ [sourceforge.net] or probably as 'sourcenav' in the distribution of your choice.

    The underlying technology is not the prettiest ever. Yeah it uses TCL. But it has a workmanlike efficacy in terms of interface. Give it a try.

    For most smaller projects I just use vi and ctags, or maybe cscope with those, but I'm sure you're familiar with al
  • Browsing and, incidentally, development. Use ctags (or compatible) and in vim press ^] over a symbol and vim will launch to the location that symbol is defined. Pop back by pressing ^T. See C++ development using vim and ctags [ucla.edu] for more options. Awesome.
  • by heretic108 ( 454817 ) on Thursday June 08, 2006 @06:45AM (#15493336)
    Leo - http://leo.sourceforge.net/ [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.
  • by ceeam ( 39911 ) on Thursday June 08, 2006 @06:45AM (#15493338)
    Just rewrite it. Reading others' code is for wimps.
  • You're doing this the wrong way. Pouring over code is very useful, but doesn't show you the layering. So, whip up trusty old gdb, set a breakpoint and run the damn code. Then use the step and next commands and just see where this leads you.
  • by PurplePhase ( 240281 ) on Thursday June 08, 2006 @08:49AM (#15493710)
    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
  • Source Navigator (Score:3, Informative)

    by avdi ( 66548 ) on Thursday June 08, 2006 @09:37AM (#15494007) Homepage
    Source Navigator [sourceforge.net] 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.
  • For pretty-printing Java, I like jGRASP [jgrasp.org]. It draws outlining-type lines to the left of the code to show nesting and control structures. I always use it to print code for code reviews. It can generate class diagrams, too, but I haven't used that feature.
  • My choice (Score:3, Insightful)

    by idontgno ( 624372 ) on Thursday June 08, 2006 @09:43AM (#15494032) Journal
    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?

  • (1) NEdit [nedit.org] combined with exuberant ctags [sourceforge.net].
    (2) Red Hat's SourceNavigator [sourceforge.net].
    (3) GNU Global [gnu.org] to generate a nice clickable HTML version of a source tree.

    I used to also use CSCOPE, but I can't fine Solaris/Sparc binaries which don't require root access to install (pkg format isn't helpful for me -- I'm just a developer on the box, not an admin).

    On the mainframe side, I usually use a combination of FINDREF, IACULL, and CULL, which together form a sort of superpowered CSCOPE, but I'm not aware of a similar tool in the
  • Well, I sound like Sid [userfriendly.org] from User Friendly, but...

    If you really want to read some code, print it with a good old fashioned chain printer on green bar paper formatted with "pr" for page numbers, and get a set of colored highlighters to mark useful things.

    For code you want to browse through, hack up a little perl script that gives you page number references for each symbol and subroutine/function/method, and print that out on a separate stack.

    Go sit somewhere nice where you can relax, flip through your s

  • You've already got a problem. I would recommend starting to document and refactor the code yourself. Ensure that all objects are self-contained, remove inter-object relationships and break complex object down into multiple smaller objects. Document as you go and test constantly. Add tests if they don't already exist so that you know your refactoring didn't hurt anything--remember a refactor is a change that can be proven not to effect anything else in the system, so be meticulous!

    If you are just looking
  • the key thing here is _browsing_, not _development_
    The best tools for understanding my own code, are also the best tools for understanding someone else's.
  • by sohp ( 22984 )
    While having tools to assist in the actual task of navigating through the codebase is important, a firm handle on the HOW is more critical.

    http://c2.com/cgi/wiki?TipsForReadingCode [c2.com]
    "Comprehension and Visualisation of Object-Oriented Code for Inspections" http://www.cis.strath.ac.uk/research/efocs/abstrac ts.html#EFoCS-33-98 [strath.ac.uk] section 5.
    Demeyer, Serge. Ducasse, Stephane. Nierstrasz, Oscar. Object Oriented Reengineering Patterns ISBN: 1558606394 [amazon.com]
    Feathers, Michael. Working Effectively with Legacy Code ISBN: 013117 [amazon.com]

Beware of Programmers who carry screwdrivers. -- Leonard Brandwein

Working...