Share via


How to: Debug Injected Code

This topic applies to:

Edition

Visual Basic

C#

F#

C++

Web Developer

Express

Topic does not apply Topic does not apply Topic does not apply

Native only

Topic does not apply

Pro, Premium, and Ultimate

Topic does not apply Topic does not apply Topic does not apply

Native only

Topic does not apply

Note

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Working with Settings.

Using attributes can greatly simplify C++ programming. For more information, see Attributed Programming Concepts. Some attributes are interpreted directly by the compiler. Other attributes inject code into the program source, which the compiler then compiles. This injected code makes programming easier by reducing the amount of code you have to write. Sometimes, however, a bug may cause your application to fail while it is executing injected code. When this happens, you will probably want to look at the injected code. Visual Studio provides two ways for you to see injected code:

  • You can view injected code in the Disassembly window.

  • Using /Fx, you can create a merged source file that contains original and injected code.

The Disassembly window shows assembly-language instructions that correspond to the source code and the code injected by attributes. In addition, the Disassembly window can show the source-code annotation.

To turn on Source Annotation

  • Right-click the Disassembly window, and choose Show Source Code from the shortcut menu.

    If you know the location of an attribute in a source window, you can use the shortcut menu to find the injected code in the Disassembly window.

To view injected code

  1. The debugger must be in break mode.

  2. In a source code window, place the cursor in front of the attribute whose injected code you want to view.

  3. Right-click, and select Go To Disassembly from the shortcut menu.

    If the attribute location is near the current execution point, you can select the Disassembly window from the Debug menu.

To view the disassembly code at the current execution point

  1. The debugger must be in break mode.

  2. From the Debug menu, choose Windows, and click Disassembly.

See Also

Concepts

Debugger Security

Other Resources

Debugging Native Code