Share via


How to: Generate Dependency Graphs for C and C++ Code

This Visual Studio 2010 feature pack lets you visualize the organization and relationships in C and C++ code by generating dependency graphs in Visual Studio 2010 Ultimate. Use these graphs to help you explore, understand, and manage dependencies in source code, between binary files, and between source files and header files. For example, you can visualize dependencies between binary files, namespaces, and classes. A graph represents code elements and their relationships as a set of nodes that are connected by links, or edges. For more information, see Visual Studio Feature Packs.

Important

You must install a Visual Studio 2010 Feature Pack to use this feature.

To perform this task with Visual C or Visual C++ projects, Visual C# installed must be installed with Visual Studio.

Note the following items when you generate graphs for C and C++ code:

  • When you open a solution that contains C and C++ projects, it might take some time to update the IntelliSense browsing database. During this time, the commands to generate dependency graphs for source files and header files will be unavailable.

    Note

    Before you generate a dependency graph for these files, please wait until the IntelliSense database finishes its updates. You can monitor the progress of these updates in the Visual Studio status bar. For more information about messages that appear because certain IntelliSense settings are disabled, see Troubleshooting.

  • The term "assembly" is used to refer to "binary" in the user interface. For example, to see dependencies between all binary files in the solution, on the Architecture menu, point to Generate Dependency Graph, and then click By Assembly.

    Note

    For binary files, graphs show dependencies at the binary level only. For example, dependencies within the same binary, such as method calls and reference types, are not shown.

  • The default name of the generated graph document for C and C++ code is "AssemblyDependenciesN.dgml" where N is the version number of the document. You can rename this document at any time.

  • You can generate a dependency graph for an entire Visual Studio solution or for specific items.

    Note

    If you have a very large solution, generating a dependency graph might take some time to analyze all the files or cause an out of memory exception. If this occurs, reduce the scope of your solution or use Architecture Explorer to select specific elements and relationships before you generate the graph.

  • Use the same steps to generate a dependency graph for C and C++ code as you would for .NET code. For more information, see How to: Generate Dependency Graphs for .NET Code.

For information about issues that might occur when generating dependency graphs for C or C++ code, see Troubleshooting.

See Dependencies Between Source Files and Header Files

You can visualize dependencies between C and C++ source files and header files. You can choose the following scope of dependencies to visualize:

Dependency graph for native code

Dependency graph for included files in a C++ project

  • All source files and header files in the solution

  • The currently open file and all first-level source files and header files

To see dependencies between

Follow these steps

All source files and header files in the solution

On the Architecture menu, point to Generate Dependency Graph, and then click By Included File.

NoteNote
When you run this command for the first time, Visual Studio must analyze the C or C++ project files. This might take some time. To cancel graph generation, click Cancel in the message box that appears.

The currently open file and all first-level source files and header files

TipTip
To view dependencies at additional levels, use Neighborhood Browse Mode on the graph toolbar to select the level of dependencies that you want to see. For more information, see How to: Browse and Navigate Graph Documents.
  1. Open either a source file or header file.

    The file opens in the code editor window.

  2. Right-click anywhere in the file, and then click Generate Graph for Included Files.

First-level dependency graph for .h file

Dependency graph for a header file with first-level source files and header files

Troubleshooting

The following issues might occur when you generate dependency graphs for C or C++ code:

Issue

Possible cause

Resolution

Visual Studio becomes unresponsive when you try to generate a dependency graph from the Architecture menu.

The program database (.pdb) file might be corrupted.

A .pdb file stores debugging information, such as type, method, and source file information.

For more information, see Program Database Files (C++).

Rebuild the solution and then try again.

Browse information is not enabled on native C++ projects.

This message appears when the browse information compiler option (/FR) is not set on native C++ projects. Setting this option makes it possible for Visual Studio to generate more complete dependency graphs for native C++ projects. For more information about the /FR option, see /FR, /Fr (Create .Sbr File).

To set the /FR option for the current graph only, click OK only. To set the /FR option and hide the message for all subsequent graphs, click Do not ask me again, and then click OK.

To make the message appear for subsequent graphs, edit the following registry key by setting it to 0 or by deleting the key:

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\NativeProvider : AutoEnableSbr

Certain settings for the IntelliSense browsing database are disabled.

Certain IntelliSense settings might be disabled in the Visual Studio Options dialog box.

Turn on the settings to enable them.

For more information, see Advanced, C/C++, Text Editor, Options Dialog Box.

The message Unknown Methods appears on a method node.

This issue occurs because the name of the method cannot be resolved.

The binary file might not have a base relocation table.

Turn on the /FIXED:NO option in the linker.

For more information, see /FIXED (Fixed Base Address).

Only binary files that run on x86 architectures are supported.

The program database (.pdb) file might not be built.

A .pdb file stores debugging information, such as type, method, and source file information.

For more information, see Program Database Files (C++).

Turn on the /DEBUG option in the linker.

For more information, see /DEBUG (Generate Debug Info).

Cannot open or find the .pdb file in the expected locations.

Make sure that the .pdb file exists in the expected locations.

Debug information has been stripped from the .pdb file.

If the /PDBSTRIPED option was used in the linker, include the complete .pdb file instead.

For more information, see /PDBSTRIPPED (Strip Private Symbols).

The caller is not a function and is either a thunk in the binary file or a pointer in the data section.

When the caller is a thunk, try using _declspec(dllimport) to avoid the thunk.

For more information, see:

See Also

Concepts

How to: Browse and Navigate Graph Documents

How to: Explore Code with Dependency Graphs

How to: Edit and Customize Graph Documents

Visualizing Existing Code

Change History

Date

History

Reason

October 2011

Added troubleshooting information about the browse information compiler (/FR) option and how to display the message after it has been hidden.

Information enhancement.