Slow execution of application from Visual studio

Today my Visual Studio 2010 started to execute my application super slowly. When I tried to execute my application (without any changes in source-code) the delay between “Start Debugging” and application start was about one minute.

I know that too many breakpoints or breakpoints in templates could caused this, but I don’t see any breakpoint in my Breakpoints window.

Breakpoint window

But as I have found that the problem was really caused by breakpoints. In some special cases – when you’re using some external tools to modified your project file (.sln/.vcxproj) – breakpoints can disappear and begin to make a trouble (I’m using Qt qmake to update my project based on .pro files.)

The solution is pretty easy. Use Delete All Breakpoins from Debug menu:

Delete all breakpoints

And your problem will be solved ;-).

Error in RegEx (atlrx.h) in Visual Studio C++ 2003 and 2005

During our development we found that Microsoft RegEx (Regular expression) implementation contains a bug which caused crashes of our applications. The application module using RegEx passed all unit test, but sometimes under heavy usage the application crashed at our customer. Because we use BugTrap for error and crash notifications, we knew the error was in atlrx.h file.

After several hours of testing and searching we found the bug. The crash didn’t occur after first code execution, but we had to run thousand iterations of the same code over and over. The bug is located in file atlrx.h at line 708.

Original file looks like this:

  case RE_ADVANCE:
    sz = CharTraits::Next(szCurrInput);
    szCurrInput = sz;
    if ( sz == NULL || *sz == '\0')
      goto Error;
    ip = 0;
    pContext->m_nTos = 0;
    break;

Problem is, that variable szCurrInput have in some circumstances NULL value and this causes the crashes.

Updated file with bug fix:

  case RE_ADVANCE:
    if( szCurrInput == NULL || *szCurrInput == '\0' )
      goto Error;
    sz = CharTraits::Next(szCurrInput);
    szCurrInput = sz;
    if ( sz == NULL || *sz == '\0')
      goto Error;
    ip = 0;
    pContext->m_nTos = 0;
    break;

We change the first two lines. It is necessary to test szCurrInput variable for NULL and empty string value. If szCurrInput is NULL or empty string, it’s necessary to stop processing RegEx. Otherwise stack overflow during processing string occurs.

Note

Some time later we had other problems with Microsoft RegEx implementation and non-standard RegEx syntax. So we left MS RegEx parser and moved to Boost.Regex which is really nice piece of code (as well as other libraries of the Boost pack) and supports Perl and POSIX regular expressions. Whole Boost library is carefully unit test and can be relied on.

Qt application crash when compiled for 64-bit VS2010

Callstack

>	QtGui4.dll!00000000652f071f()
 	[Frames below may be incorrect and/or missing, no symbols loaded for QtGui4.dll]
 	QtGui4.dll!00000000652f07ae()
 	QtGui4.dll!0000000065326821()
 	QtGui4.dll!0000000065327f30()
 	QtGui4.dll!00000000653284ba()
 	QtGui4.dll!000000006532a5f5()
 	QtGui4.dll!00000000652f4792()
 	QtGui4.dll!000000006532f701()
 	QtGui4.dll!000000006535be71()
 	QtCore4.dll!0000000059a0ab9f()
 	QtGui4.dll!0000000065306eb9()
 	QtCore4.dll!00000000599f7903()
 	QtGui4.dll!0000000064eaffa2()
 	QtGui4.dll!0000000064eb2e56()
 	QtCore4.dll!00000000599f7792()
 	QtGui4.dll!0000000064eec2a3()
 	QtGui4.dll!0000000064eee85e()
 	QtGui4.dll!0000000064eec265()
 	QtGui4.dll!0000000064eee85e()
 	QtGui4.dll!0000000064eec265()
 	QtGui4.dll!0000000064eee85e()
 	QtGui4.dll!0000000064efa870()
 	QtGui4.dll!0000000065208727()
 	QtGui4.dll!000000006527a082()
 	QtGui4.dll!0000000064eaffb6()
 	QtGui4.dll!0000000064eb2e56()
 	QtCore4.dll!00000000599f7792()
 	QtGui4.dll!0000000064ef264c()
 	QtGui4.dll!0000000064ef26c7()
 	QtGui4.dll!0000000064ef26c7()
 	QtGui4.dll!0000000064ef26c7()
 	QtGui4.dll!0000000064efe30c()
 	OrmDesigner2.exe!000000013f95a2cf()
 	OrmDesigner2.exe!000000013f95dce2()
 	kernel32.dll!000000007794652d()
 	ntdll.dll!0000000077c8c521()

The bug is probably caused by wrong alignment or incorrect VS2010 compiler optimalization.

Found resources:
https://bugreports.qt.nokia.com//browse/QTBUG-11445
https://connect.microsoft.com/VisualStudio/feedback/details/573262/incorrect-alignment-with-x64-optimizer-and-movaps
http://support.microsoft.com/kb/2280741
https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=31433

Workarounds:

First way – Update VS2010 mkspec for Qt

go to $QTDIR/mkspecs/win32-msvc2010/qmake.conf and replace -02 with -01 (ie. reducing the optimzation level).Also /Ob0 could be used.

Microsoft hotfix for VS

http://archive.msdn.microsoft.com/KB2280741
File patch name VS10-KB2268081-x86.exe

Install Visual Studio 2010 SP1

Service pack could also contains required fix.
http://www.microsoft.com/download/en/details.aspx?id=23691

List of usefull links for Visual Studio

How to customize autoexp.dat in Visual Studio 2005

http://mariusbancila.ro/blog/?p=26
http://www.virtualdub.org/blog/pivot/entry.php?id=120

Example visualizator for XString

String::CStringSmart<String::malloc_string_trait<String::string_trait<char> > >{
  preview([$c.m_pszData,s])
  stringview([$c.m_pszData,sb])
}

String::CStringSmart<String::malloc_string_trait<String::string_trait<wchar_t> > >{
  preview([$c.m_pszData,su])
  stringview([$c.m_pszData,sub])
}

How to configure STEP-INTO for Visual Studio 2005

External links:
Google group
www.cprogramming.com

http://blogs.msdn.com/b/andypennell/archive/2004/02/06/69004.aspx

Example how to setup ingoring step-into for MFC CString for VS2005

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\NativeDE\StepOver]
"\"20\""="\\scope:CString.*\\:\\:.*=NoStepInto"
"\"21\""="\\scope:CSmartObjPtr.*\\:\\:.*=NoStepInto"

Example how to setup ingoring step-into for MFC CString for VS2010 on 64bit system

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0_Config\NativeDE\StepOver]
"22"=".*CStringSmart.*=NoStepInto"