How to debug a function in release mode

29 07 2015

The Visual Studio IDE provides different optimization options that help us to create code for maximum speed or minimum size. Mostly we select /O1 optimizes code for minimum size when we build our project in release configuration. But you might be observed that the variable values may not be displayed correctly in the watch window if we try to debug our source code in release configuration. Of-course, we have options to enable debugging support in release mode. But just think in case if you want to debug just one function in release mode!!!

Pragma directives specify machine- or operating-specific compiler features. The compiler optimization can be performed on a function-by-function basis using #prgma optimize statement.

#pragma optimize( "[optimization-list]", {on | off} )

We can disable the optimization using the optimize pragma with the empty string (“”).

#pragma optimize( "", off )
void FunctionToDebug()
#pragma optimize( "", on ) 

Some pragmas provide the same functionality as compiler options. When a pragma is encountered in source code, it overrides the behavior specified by the compiler option.

How to convert a ANSI/MB project into a UNICODE

14 05 2013

Most of the time we may need to give multiple language support for our applications. Incase if we need to support Russian or Chinese language means, definitely we have to give Unicode support for our application. So here I would like to share some tips for converting existing ANSI/MultiByte project into Unicode.

If we build our project in Multi-byte character set it will allocate 1 byte for one character. This is enough for representing all English letters. But if we build our project in Unicode character set it will allocate 2 bytes for each letters. It is required for representing Russian and Chinese letters.

Below are some suggestions for converting MBCS to Unicode project

Step 1: Create new configuration from Project Configuration Manager. Give name something like ReleaseUnicode/DebugUnicode.

Step 2: Change Character Set to Unicode from Project Settings.


Step 3: Replace all char datatype with TCHAR. This will automatically switch to normal char or wchar_t based on it is compiled as MBCS or Unicode respectively.

Step 4: Add _T as prefix to each string text. eg: _T(“Hello World”)

Step 5: Replace LPSTR and LPCSTR with LPTSTR and LPCTSTR respectively.

Step 6: Replace following win32 APIs with corresponding Generic equivalent for same.

strstr _tcsstr
strcmp _tcscmp
sprintf_s _stprintf_s
strlen _tcslen
_stricmp _tcscmp
strcpy_s _tcscpy_s
atol _tstol
atoi _tstoi
atof _tstof
strcspn _tcscspn
fopen_s tfopen_s
strtok_s _tcstok_s
strtol _tcstol
strtoul _tcstoul

Shortcut keys to display debugging windows in Visual studio 2005

30 12 2008

Ctrl-Alt-V, A
Displays the Auto window to view the values of variables currently in the scope of the current line of execution within the current procedure
Displays the Call Stack window to display a list of all active procedures or stack frames for the current thread of execution. Available only in break mode
Displays the Disassembly window
Displays the Immediate window, where you can evaluate expressions and execute individual commands
Ctrl-Alt-V, L
Displays the Locals window to view the variables and their values for the currently selected procedure in the stack frame
Ctrl-Alt-M, 1
Displays the Memory 1 window to view memory in the process being debugged. This is particularly useful when you do not have debugging symbols available for the code you are looking at. It is also helpful for looking at large buffers, strings, and other data that does not display clearly in the Watch or Variables window
Ctrl-Alt-M, 2
Displays the Memory 2 window
Ctrl-Alt-M, 3
Displays the Memory 3 window
Ctrl-Alt-M, 4
Displays the Memory 4 window
Displays the Modules window, which allows you to view the .dll or .exe files loaded by the program. In multiprocess debugging, you can right-click and select Show Modules for all programs
Displays the Registers window, which displays CPU register contents
Displays the Running Documents window that displays the set of HTML documents that you are in the process of debugging. Available in break and run modes
Ctrl-Alt-V, T
Displays the This window, which allows you to view the data members of the object associated with the current method
Displays the Threads window to view all of the threads for the current process
Displays the disassembly information for the current source file. Available only in break mode
Ctrl-Alt-W, 1
Displays the Watch 1 window to view the values of variables or watch expressions
Ctrl-Alt-W, 2
Displays the Watch 2 window
Ctrl-Alt-W, 3
Displays the Watch 3 window
Ctrl-Alt-W, 4
Displays the Watch 4 window