Microsoft KB Archive/328784

= BUG: The debugger steps erratically when you have carriage returns without line feeds =

Article ID: 328784

Article Last Modified on 1/5/2006

-

APPLIES TO


 * Microsoft Visual C++ .NET 2003 Standard Edition
 * Microsoft Visual C++ .NET 2002 Standard Edition

-



This article was previously published under Q328784



SYMPTOMS
When you use the debugger to step through Visual C++ .NET source code, the debugger might skip certain source lines and step erratically through the code.

If your line endings for the source code have a carriage return (CR) without a line feed (LF), the debugger might skip those source lines.



CAUSE
In Windows, a text file has both the CR (ASCII code: 0x0D) and the LF (ASCII code: 0x0A) together at the end of a line. However if you only have the CR at the end of a line, Windows-based editors (for example, Notepad.exe) display those in the same line. The Visual C++ compiler displays the CR in the same way while creating the executable. However, the Visual Studio .NET editor recognizes and supports various line endings, and displays the source code in different lines. This results in an executable mismatch in line mappings that causes the debugger to step through source code erratically.



RESOLUTION

 * 1) Open the source file in the Visual Studio .NET editor.
 * 2) On the File menu, click Advanced Save Options.
 * 3) In the Line Endings list box, click Windows (CR LF), and then click OK.
 * 4) Save the file.
 * 5) Compile the project.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
 Create a new MFC application in Visual Studio .NET that is named TestApp.  Open TestApp.cpp, and then locate the following function: BOOL CTestAppApp::InitInstance

The last four lines of source code in this function read as follows: // The main window has been initialized. Show and update it   pMainFrame->ShowWindow(m_nCmdShow); pMainFrame->UpdateWindow; return TRUE;  To open TestApp.cpp using Binary Editor, right-click TestApp.cpp in Solution Explorer, click Open With, click Binary Editor, and then click Open.  At the end of the InitInstance function, and remove the LFs (0x0A) from the end of following 3 lines: // The main window has been initialized. Show and update it. pMainFrame->ShowWindow(m_nCmdShow); pMainFrame->UpdateWindow;  Save the file. Compile the project.</li> Keep a breakpoint at the pMainFrame->ShowWindow(m_nCmdShow); statement.</li> Press F5 to start the debugger. When the debugger stops at this breakpoint, press F10. You notice that the debugger next stops inside Winmain.cpp outside InitInstance.</li></ol>

<div class="references_section">