Sunday, May 22, 2016

Remote Debugging Visual C++ 2015

This describes how to configure your system to do remote debugging when you are using Visual Studio 2015. There is no installer for the debug DLLs, so you need to work around this problem.

Among other things, these instructions solve this error message:

The program can't start because ucrtbased.dll is missing from your computer.

These instructions take extra steps to handle the case where you are doing DLL builds instead of static linking MFC and CRT.

Note: These instructions should not be used for release versions of MFC and CRT. Those files can be installed with the files in C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\redist\1033.

1. Install the Remote Debug Tools


The version you install depends on the bitness of Windows. Most people will therefore want to install the 64-bit version. It will debug both 32-bit and 64-bit applications.
  • Click on Tools for Visual Studio 2015 on the left.
  • Click Remote Tools for Visual Studio 2015.
  • Choose the desired version. The section on top is for Visual Studio Update 2. The second section is for other versions of Visual Studio 2015.
  • Select the desired bitness
  • Click Download
  • Run the installer

2. Create a shortcut to the Remote Debug tool

Next create a link to the remote debugger on your desktop. Below is the command I used. All security is disabled because I'm the only user on my local network. Note the useful "/anyuser" parameter that is very helpful when your test VMs are configured with generic user accounts.

"C:\Program Files\Microsoft Visual Studio 14.0\Common7\IDE\Remote Debugger\x64\msvsmon.exe" /noauth /anyuser  /nosecuritywarn /timeout 10000

3. Copy the MFC and CRT DLL's to your application's Debug directory.

There is no installer for the debug DLLs, so you need to work around this problem.

Let's say your application is in:

C:\Projects\MyApp\Debug

Copy the CRT and MFC files as follows. Change MYARCH to be x64 if you are debugging a 64-bit application. This depends on the bitness of your application, not the bitness of Windows.

set MYDEBUG=C:\Projects\MyApp\Debug
set MYARCH=x86

copy "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\redist\debug_nonredist\%MYARCH%\Microsoft.VC140.DebugMFC" %MYDEBUG%

copy "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\redist\debug_nonredist\%MYARCH%\Microsoft.VC140.DebugCRT" %MYDEBUG%

4. Copy ucrtbased.dll into your application's Debug directory

The Universal CRT DLL is from the Windows SDK. It is not in the Visual Studio directory. This is a new file required as of Visual Studio 2015. Make sure you set MYDEBUG and MYARCH as shown in the last step.

copy "C:\Program Files (x86)\Windows Kits\10\bin\%MYARCH%\ucrt\ucrtbased.dll" %MYDEBUG%

Note that the discussion on MSDN about ucrtbased.dll being part of Windows 10 is wrong.


5. Define a network share

Create a network share to your Debug directory. It's a lot easier than copying files around. Let's assume you shared your entire C drive. You can share read-only.

On the VM, mount it as a standard drive. I like to use K:.

Finally, in Visual Studio, in the debugger properties, set the application location to use the network share as the path.

6. Run with remote debugging

Start the remote debugger msvcmon.exe on the VM using the shortcut you created in Step 2.

7. Run the debugger in Visual Studio



5 comments:

  1. Hi,

    I'm very confused. I am trying to run Visual Studio but keep getting the stupid ucrtbased.dll error and do not understand what you are trying to get me to do. I'm not a programmer just taking a class and honestly am not excited about it right now since I can't get to stupid program to work. Please help.

    ReplyDelete
  2. Hi!
    Thank you Jim. It helps me a lot.

    ReplyDelete
  3. Hi,

    I'm still learning programming and did my best to follow your directions. When trying to create a shortcut, I followed to the letter (assuming that command was done in the command prompt) but no shortcut was created to the Debug tool. Instead, I got a strange popup from the debugger "31/01/2017 8:51:09 PM Msvsmon started a new server named 'PC'. Authentication is disabled. Waiting for new connections." and "31/01/2017 8:51:09 PM WARNING: Remote debugging in 'No Authentication' mode is not a secure way to debug your application."

    Not really sure how to continue.

    ReplyDelete
    Replies
    1. Sorry for the confusion. This blog entry was aimed at intermediate to expert developers. I'm afraid you are going to find that several of the steps are missing the exact details, particularly Step 7.

      You create a shortcut on your Desktop by right-clicking in Explorer (but not Internet Explorer.) The command you entered into the command line is the command you should use to create the shortcut.

      The good news is that the window that came up is correct, and you successfully started the Remote Debugger. The shortcut is just a convenience, it's not necessary.

      Delete
    2. Sorry for the confusion. This blog entry was aimed at intermediate to expert developers. I'm afraid you are going to find that several of the steps are missing the exact details, particularly Step 7.

      You create a shortcut on your Desktop by right-clicking in Explorer (but not Internet Explorer.) The command you entered into the command line is the command you should use to create the shortcut.

      The good news is that the window that came up is correct, and you successfully started the Remote Debugger. The shortcut is just a convenience, it's not necessary.

      Delete