Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 369720

Summary: gdb messed up with standard output
Product: [Tools] CDT Reporter: Andreas Emmerling <andreas.emmerling>
Component: cdt-debugAssignee: cdt-debug-inbox <cdt-debug-inbox>
Status: CLOSED DUPLICATE QA Contact: Doug Schaefer <cdtdoug>
Severity: normal    
Priority: P3 CC: cdtdoug, marc.khouzam, pawel.1.piech
Version: 8.1.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Andreas Emmerling CLA 2012-01-25 13:27:10 EST
Build Identifier: 20110916-0149

Hi!

I have the problem that after printing something to the standard out without a newline, a following breakpoint is not hit by gdb. Actually it is hit by gdb but Eclipse doesn't recognize it.

example code

#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
	setvbuf(stdout, NULL, _IONBF, 0);
	setvbuf(stderr, NULL, _IONBF, 0);

	printf("Hello");
	printf("\n");
	printf("Hello\n");

	return 0;
}

If you put a breakpoint at line "printf("\n");" it will not be hit. Instead I have the following output in the console:

Hello*stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame={addr="0x00401421",func="main",args=[{name="argc",value="1"},{name="argv",value="0x8f16e0"}],file="..\main.c",fullname="<mypath>\main.c",line="15"},thread-id="1",stopped-threads="all"

and then gdb stops the program but eclipse doesn't think the breakpoint was hit so I have no chance to run it further and I have to terminate the program.

I can be solved bei either the following:
Comment the setvbuf calls like the following (this is actually not an option for me)
	//setvbuf(stdout, NULL, _IONBF, 0);
	//setvbuf(stderr, NULL, _IONBF, 0);

or changing the prints such that all prints have a newline:
	printf("Hello\n");
	printf("\n");
	printf("Hello\n");

I'm using MinGW toolchain (the latest from the installer, with gdb 7.3.1) on Windows.

Reproducible: Always

Steps to Reproduce:
See description
Comment 1 Marc Khouzam CLA 2012-01-26 09:41:30 EST
Try adding 
  set new-console on
to you gdbinit file.

*** This bug has been marked as a duplicate of bug 327766 ***