代码改变世界

Enter debugger when application starts

2004-08-18 15:34  atempcode  阅读(732)  评论(0编辑  收藏  举报
Recently I am debugging a out-of-process COM exe. It crashed some time before I can attach debugger to it. How can I debug the exe when it starts? After check the MSDN, I find that some change to the registry can make it.

 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsdebug/html/vxtskLaunchingDebuggerAutomatically.asp

You can set up your application to start Visual Studio when you launch the application from Windows. Visual Studio will load your application, ready for debugging, but will not commence debugging until you issue an execution command. Having Visual Studio launch the debugger in this way is useful for debugging services and COM out-of-proc servers.

To setup an application to launch the debugger automatically

  1. Start the Registry Editor (regedit).
  2. In the Registry Editor, open the HKEY_LOCAL_MACHINE folder.
  3. Navigate to HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\currentversion\image file execution options.
  4. Under the Image File Execution Options folder, locate the name of the application you want to debug (myapp.exe, for example). If you cannot find the application you want to debug:
    1. Right-click the Image File Execution Options folder and choose New Key from the shortcut menu.
    2. Right-click the new key and choose Rename from the shortcut menu.
    3. Edit the key name to the name of your application, for example, myapp.exe.
  5. Right-click the myapp.exe folder and choose New String Value from the shortcut menu.
  6. Right-click the new string value and choose Rename from the shortcut menu.
  7. Change the name to debugger.
  8. Right-click the new string value and choose Modify from the shortcut menu.

    The Edit String dialog box appears.

  9. In the Value data box, type devenv /debugexe.
  10. Click OK.
  11. From the Registry menu, choose Exit.

    The directory containing devenv.exe must be in your system path.

    Now, use any method to start your application. Visual Studio .NET will start and load the application.