BUG: The debugger steps erratically when you have carriage returns without line feeds (328784)



The information in this article applies to:

  • Microsoft Visual C++ .NET (2003)
  • Microsoft Visual C++ .NET (2002)

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.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Create a new MFC application in Visual Studio .NET that is named TestApp.
  2. 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;
    					
  3. To open TestApp.cpp using Binary Editor, right-click TestApp.cpp in Solution Explorer, click Open With, click Binary Editor, and then click Open.
  4. 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();
    					
  5. Save the file. Compile the project.
  6. Keep a breakpoint at the pMainFrame->ShowWindow(m_nCmdShow); statement.
  7. 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.

REFERENCES

For additional information, see the following Microsoft Developer Network (MSDN) Web site:

Modification Type:MinorLast Reviewed:1/5/2006
Keywords:kbbug kbDebug kbide kbpending KB328784 kbAudDeveloper