Community
Participate
Working Groups
Build Identifier: Eclipse 3.7.0 (Build id: I20110613-1736), CDT 8.0.0 (Build id: 201106081058) Problem Description ------------------- I will start with some background information. Starting from CDT 7, a Windows program that is debugged with CDT and GDB will not get a native Windows console but will instead be integrated with the Eclipse console. Due to this change, CDT 7 and 8 does not support source code debugging with GDB of Windows programs that prints non-newline-terminated strings on stdout. This bug appears both in DSF's and CDI's GDB support but this bug report focuses on DSF. This is not a problem on operating systems that support pseudo terminals (like Linux but not Windows). On Linux, CDT redirects the debugged program's output to a different pseudo terminal (TTY). That lets CDT unambiguously differentiate between GDB's output and the debugged program's output. Windows doesn't have TTYs, so the output from GDB and the debugged program can be interleaved if the debugged program prints non-newline-terminated strings on stdout at the same time as an event occurs in GDB (e.g. the end of a single-step over the offending printf() line in the debugged program). The problem is that the current GDB MI parser fails to recognize this fact and consequently does not react to the MI output that signals the end of the single-step operation, which makes the debug session appear as it has hanged. Solution -------- Since Windows doesn't have pseudo terminals, the GDB MI parser can only make a best effort of differentiating between the output from GDB and the debugged program. Currently, this differentiating is much too weak, as is demonstrated by the the example above. I have only been able to get interleaved output from GDB and its debugged program when I single-step over non-newline-terminated output on stdout from the debugged program. In those cases, the output from the debugged program always precedes the output from GDB, like this: <debugged-program-output><gdb-mi-output>\n So, one straighforward way to make the GDB MI parser much more robust on Windows is to let its main loop (which reads each line of output from GDB and parses it) analyze the line of output from GDB and try to split it up in one debugged program part and in one GDB part (if they occur on the same line) and then send those two separate lines of output to the GDB MI parsing method. The code for splitting up the output from GDB uses a regular expression of the GDB MI output grammar. A patch, relative to CDT 8.0.0, for the GDB MI parser in DSF is provided. The class org.eclipse.cdt.dsf.mi.service.command.AbstractMIControl in the org.eclipse.cdt.dsf.gdb plugin has been updated. Reproducible: Always Steps to Reproduce: 1. Make sure that you have a MinGW or Cygwin GCC/GDB installed. 2. Create an empty C project for executables and choose the toolchain MinGW GCC or Cygwin GCC. 3. Add the attached file test.c to the project and build it. 4. Create a "C/C++ Application" debug launch configuration and choose "GDB (DSF) Create Process Launcher" as launcher. 5. Launch the debugger; you should now be in the main() function in test.c. 6. Try to step over the printf() and fflush() lines; one of them will fail, typically the fflush() line! 7. The debug session is now hanged...
Created attachment 202321 [details] Simple test program for exemplifying the bug
Created attachment 202322 [details] Patch for org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/AbstractMIControl.java
Note that this bug appears both in DSF's and CDI's GDB support but this bug report focuses on DSF (see bug 356085 for the corresponding CDI bug report and fix).
This is a duplicate of Bug 327766. I won't mark as duplicate though because the proposed patch is different and could maybe be ok for Windows. Note that you can somewhat fix this issue by adding the line set new-console on to a gdbinit file for your launch. Can you explain in detail what the regexp is attempting to do? If it specific enough not to break other outputs, we may be able to use it.
I'm downgrading the severity to normal since there is somewhat of a workaround.
The regular expression in the patch aims to embody the most important aspects of the GDM MI output grammar needed for identifying any non-newline-terminated output from the debugged program preceding a line of GDB MI output in order to be able to separate them. The regular expression looks like this: "(.*?)([0-9]*(\\*(stopped|running)|=(thread|library)-|\\^(done|running|connected|error|exit)).*|[~@&]\".*\"|\\(gdb\\))" The regular expression matches the following: * any preceding non-newline-terminated output from the debugged program * optional token * exec-async-output or notify-async-output or result-record or * console-stream-output or target-stream-output or log-stream-output or * prompt The GDB/MI output grammar is defined in section 27.2.2 "GDB/MI Output Syntax" in the document "Debugging with GDB", available here: http://sourceware.org/gdb/download/onlinedocs/gdb/GDB_002fMI-Output-Syntax.html#GDB_002fMI-Output-Syntax
Is there any chance of having this fix included in CDT 8.0.1? Can I do anything to facilitate that?
(In reply to comment #7) > Is there any chance of having this fix included in CDT 8.0.1? Can I do anything > to facilitate that? Sorry, but we are passed RC3 so it would be too big a risk. But we can aim for 8.0.2