Debugging the Add-In


An add-in is just a DLL, so debugging an add-in project is no different from debugging any other Class Library project. Because a DLL can't run on its own, it needs a host application. For an add-in, that host is Visual Studio (devenv.exe) or the Macros IDE (vsaenv.exe). The Add-in Wizard sets the debugging properties of the add-in project so that Visual Studio is the host. You can examine and modify the project's debugging properties by right-clicking the add-in project in Solution Explorer, choosing Properties from the shortcut menu, and selecting Debug in the Project Designer window shown in Figure 6-4. For most purposes, however, the default settings work just fine.

image from book
Figure 6-4: The add-in project's debugging properties

In a typical debugging session, you open the add-in project in Visual Studio, set breakpoints in the add-in source code, and then start the debugger by choosing Start from the Debug menu (or pressing F5). The debugger, in turn, launches a second instance of Visual Studio and attaches itself to this new process. You load the add-in to be debugged in the second instance of Visual Studio, and when the add-in code hits a breakpoint, execution passes to the debugger running in the first instance of Visual Studio. From there you can step through the code, examine the contents of variables and registers, and perform other sundry debugging tasks.

Debugging add-ins in the Macros IDE is almost as easy as debugging add-ins in Visual Studio. The one difference is that you can't simply open the Macros IDE from an instance of Visual Studio and then attach the debugger from that instance to the Macros IDE. Why not? Because the two processes will deadlock if Visual Studio fires a macro event while execution is stopped in the debugger. Instead, the recommended way to debug add-ins in the Macros IDE is similar to the way you debug add-ins in Visual Studio:

  1. Open the add-in project in Visual Studio.

  2. Start a second instance of Visual Studio.

  3. Open the Macros IDE from the second instance of Visual Studio.

  4. Attach the debugger from the first instance of Visual Studio to the Macros IDE process. To do so, choose Debug | Attach To Process, select vsaenv.exe in the Attach To Process dialog box, and then click Attach.

  5. Load the add-in in the Macros IDE, and then debug as normal.

Finally, you shouldn't feel obligated to run the Visual Studio debugger if you have a favorite debugger you'd rather use. Any debugger that can handle delay-load DLLs will do.




Working with Microsoft Visual Studio 2005
Working with Microsoft Visual Studio 2005
ISBN: 0735623155
EAN: 2147483647
Year: 2006
Pages: 100

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net