Exploring code with VisualGDB 5.0 Preview 4

We have recently released a new preview build of VisualGDB 5.0 featuring a new Clang-based IntelliSense engine. This preview build focuses on greatly improving the experience with navigating large code bases. In this post I will show how to quickly analyze the code structure and navigate in 2 large codebases:

  • The source code of clang itself (~30MB of C++ sources)
  • The source code of the Linux Kernel (~420MB of C sources)

Finding references and definitions

The first powerful feature we have added is a very fast and precise “Find All References” command. Unlike Visual Studio that first searches all files for a certain text and then verifies each occurrence, VisualGDB builds a global cache containing pre-sorted information about the code structure and references. As a result, finding references to the correct method or field, even if its uses are scattered around 10 thousand files, is always instant.

For example, let’s try it with a Decl::PrintStats() function in clang itself. The clang project contains almost 3000 .cpp files and 21 of them contain the ‘PrintStats’ word. However, right-clicking on the function definition and finding all references takes less than a second with no false positives:

findrefsThis is achieved because VisualGDB pre-sorts the references when building the cache, so finding the correct ones is as easy as finding the right word in a dictionary.

Let’s look at another example: search for all uses of panic() in almost 10000 source files of the Linux kernel. This takes a bit longer (3 seconds), but is still much faster than looking through each file manually.

panic

It will also find references behind preprocessor macros. E.g. in this example you will also see all places where a use of IOMMU_WAIT_OP() was expanded to a call to panic():panicmacro

Building the cache initially can take a while for a really large project, however we have optimized that greatly:

  • On multi-core machines the cache building logic uses all the CPU cores. On a powerful 6-core workstation with hyper-threading this can will be up to 12x faster than normal file-after-file compilation!
  • If your code uses precompiled headers (or just tends to include a certain header file before defining anything else), VisualGDB will detect this and automatically precompile those headers improving the cache building speed.
  • Modifying a few files in a large project won’t necessarily result in a long cache rebuilding. The cache is incremental, so most of the changes will be simply added to it, seamlessly replacing the outdated parts.

Go to definition works similarly to “find all references”. It uses the global cache to find the right function or class among thousands of source files.

Exploring code hierarchies

Althrough “Find all references” gives a good overview where a certain function or class is used, sometimes a good hierarchical view can give a much better understanding. E.g. let’s explore the hierarchy of declaration classes in clang sources. Simply right-click on the ‘Decl’ class somewhere in the code and, “Explore class tree” and choose to only explore the tree downwards (from parent to derived classes):hier

You can quickly see what classes are derived from a given class in the entire solution (or browse parent classes if you change tree direction). Each time you expand a tree node, it takes less than a second for VisualGDB to find the matching classes because it takes that data from the fast global cache.

Similarly to class trees you can explore override trees. E.g. if you right-click on the TypeDecl::getSourceRange() method, you will see that it overrides a method in the Decl class and is in turn overridden in 4 derived classes.overridesSimilarly to override trees you can explore call trees (e.g. see that get_random_bytes() calls extract_entropy() that is also called by xfer_seconday_pool()).calls

Tweaking

You can tweak numerous settings related to the new engine via Tools->Options->Text Editor->C/C++(VisualGDB):settingsYou can read more about the features in our new Clang-based IntelliSense engine here.

And if you have further suggestions or encounter bugs, do not hesitate to drop a note to our support so that we can ensure your VisualGDB experience will be flawless.