Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio - how to attach debugger to restarted application?

I have an application in C++ developed in VS2010. This application has an ability to restart itself when needed (some changes that requires it to reboot). Now there's some bug that occurs only under certain circumstances on the beginning of the new instance after the restart. The problem is that I can't find out what it is, because the new instance does not have the debugger attached (VS debug mode ends with the initial instance closing). Any idea how to automatically attach a debugger to the new instance?

Thank you

like image 253
Aros Avatar asked Apr 15 '13 15:04

Aros


1 Answers

I "discovered" how this is done after getting infected with some malware that used the same technique to wrap all calls to anti-virus products to redirect them to it's own executable!

Summarising the steps described here, it just involves some registry editing. FWIW, tools like DebugDiag also used to use this method to trap an application launch and activate the debugger:

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. In the Image File Execution Options folder, locate the name of the application you want to debug, such as myapp.exe. If you cannot find the application you want to debug:

    a. Right-click the Image File Execution Options folder, and on the shortcut menu, click New Key.
    b. Right-click the new key, and on the shortcut menu, click Rename.
    c. Edit the key name to the name of your application; myapp.exe, in this example.

  5. Right-click the myapp.exe folder, and on the shortcut menu, click New String Value.

  6. Right-click the new string value, and on the shortcut menu, click Rename.

  7. Change the name to debugger.

  8. Right-click the new string value, and on the shortcut menu, click Modify.

    The Edit String dialog box appears.

  9. In the Value data box, type vsjitdebugger.exe.

  10. Click OK.

  11. From the Registry menu, click Exit.

  12. The directory containing vsjitdebugger.exe must be in your system path. See the above link for the full instructions.

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

like image 130
Roger Rowland Avatar answered Sep 21 '22 17:09

Roger Rowland