FIX: Extra New Line Added to Debug Output in Visual Debugger

This article was previously published under Q107428
This article has been archived. It is offered "as is" and will no longer be updated.
When using the Visual Workbench debugger, a new line is inserted inthe debugging output window every time debugging information is outputthrough the CDumpContext insertion operator or OutputDebugString().This interferes with formatting done for the debug output.
A new line is inserted by the debugger after every call to the Windows3.1 application programming interface (API) functionOutputDebugString(). In the Microsoft Foundation Classes (MFC), theinsertion operator (<<) for CDumpContext eventually maps to a call toOutputDebugString(), so every invocation of << for a CDumpContextobject also introduces a new line in the output window.
The following are three suggested workarounds:

  • Use the WinDbg debugger that ships with the Microsoft Win32 Software Development Kit (SDK) for Windows NT. WinDbg does not insert uncalled for new lines into the debugging output.
  • Consolidate debugging output into strings that can be displayed with a single call to OutputDebugString or with a single insertion into the dump context.
  • Add additional lines of debugging information to indicate the beginning and end of a sequence of debugging output. For example,
       void CPerson::Dump( CDumpContext &dc ) const    {       dc << "Begin dump of CPerson object";  // identify dump start       CObject::Dump( dc );       dc << "Name: " << m_name;       dc << "Age: " << m_years;       dc << "End dump of CPerson object";    // identify dump end    }
Microsoft has confirmed this to be a bug in the products listed at thebeginning of this article. This problem was corrected in Visual C++ 2.0.
The following code fragment demonstrates the problem that occurs whencalling OutputDebugString directly. The output that would normallyappear on the same line actually displays over three lines:


   OutputDebugString("This");   OutputDebugString("output");   OutputDebugString("takes three lines.\n");				


   This   output   takes three lines.				
The code fragment below demonstrates how each insertion of debuggingtext into the afxDump context causes a new line to appear in theoutput window:
   void CPerson::Dump( CDumpContext &dc ) const   {      CObject::Dump( dc );      dc << m_name << " is ";      dc << m_years << " years old.\n";   }				
A call to myPerson.Dump(afxDump) produces the following output in theVisual Workbench's output window:
   a   CObject    at   $18FC80   FirstName LastName    is   30    years old.				
The following is what is desired:
   a CObject at $3917477E FirstName LastName is 30 years old.				
newline afxDump 1.00 1.10

Article ID: 107428 - Last Review: 01/09/2015 05:02:35 - Revision: 2.0

  • The Integrated Debugger
  • kbnosurvey kbarchive kbbug kbdebug kbfix kbide KB107428