Thursday, July 1, 2010

Debug "Just My Code" for C++ and MFC

One of my biggest annoyances with debugging MFC code is constantly stepping through CString functions and COM object functions. In Visual C++ 6 there was some functionality in autoexp.dat for handing this, but I never got it to work to my satifaction.

This week I was able to solve the problem. Here's how (note that the 10.0 is for Visual Studio 2010. The value will be 9.0 for VS2008. For earlier versions, see the link at the end of this article.)
  1. Open RegEdit
  2. On 32-bit Windows, go to:
    HKEY_LOCAL_MACHINE\Software\Microsoft\
    VisualStudio\10.0\NativeDE\StepOver


    On 64-bit Windows, go to:
    HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\NativeDE\StepOver

    At least for Visual Studio 2010, there are several default functions defined.
  3. Add a new String value. Name it CStringT.
  4. Edit the key and set the value to:

    ATL\:\:CStringT.*

    The colons must be backslashed as shown. CStringT is the template class used for CString, CStringA and CStringW. The CStringT class is shared with ATL, so that's why it's in the ATL namespace, even if you are using MFC. The "dot star" at the end matches anything for the rest of the line.
  5. Here are a couple of other examples:

    Key: CSimpleString
    Value: ATL\:\:CSimpleStringT.*

    Key: CComPtrBase
    Value: ATL\:\:CComPtrBase.*

    Key: vector
    Value: std\:\:vector.*
Update 7/26/2010: There are additional features documented by Andy Pennell at Microsoft.

7 comments:

  1. Does not work. The registry keys are erased when Visual Studio 2010 starts.

    ReplyDelete
  2. Thanks Anonymous, I'm seeing the same behavior. To be precise, it works fine until you restart VS. I'll work on this more as time allows.

    ReplyDelete
  3. The HKCU\Software\Microsoft\
    VisualStudio\10_Config\ key is a settings cache from HKLM\Software\Microsoft\
    VisualStudio\10\ key and various PKGDEF files. You should be able to change the value under HKLM.

    ReplyDelete
  4. Karl, thanks for the fix! I've updated the text of the article.

    ReplyDelete
  5. Nice job, thanks. One minor point: in step 3, "Add a new String key" should be "Add a new String value"

    ReplyDelete
  6. Anonymous, thanks. I fixed the article.

    ReplyDelete
  7. do the above while vs is not running and your changes will be preserved.

    ReplyDelete