1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 10:46:02 +02:00

Bug: 376203 Launch job never completes if GDB terminates on start.

- Added check to report error (with information from stderr if
available) if initial GDB prompt is not read.

Change-Id: I48ec3cbe8061bc3dc5e3bcb37296e2fc3de0cf61
Reviewed-on: https://git.eclipse.org/r/8401
Reviewed-by: Marc Khouzam <marc.khouzam@ericsson.com>
IP-Clean: Marc Khouzam <marc.khouzam@ericsson.com>
Tested-by: Marc Khouzam <marc.khouzam@ericsson.com>
This commit is contained in:
Mark Bozeman 2012-10-30 15:18:01 -05:00 committed by Marc Khouzam
parent 4d02730830
commit 2c49273e16

View file

@ -10,6 +10,7 @@
* Wind River System * Wind River System
* Ericsson * Ericsson
* Marc Khouzam (Ericsson) - Use the new IMIBackend2 interface (Bug 350837) * Marc Khouzam (Ericsson) - Use the new IMIBackend2 interface (Bug 350837)
* Mark Bozeman (Mentor Graphics) - Report GDB start failures (Bug 376203)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.dsf.gdb.service; package org.eclipse.cdt.dsf.gdb.service;
@ -19,7 +20,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.Reader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.List; import java.util.List;
@ -561,20 +561,51 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend, IMIBa
return Status.OK_STATUS; return Status.OK_STATUS;
} }
BufferedReader inputReader = null;
BufferedReader errorReader = null;
boolean success = false;
try { try {
Reader r = new InputStreamReader(getMIInputStream()); // Read initial GDB prompt
BufferedReader reader = new BufferedReader(r); inputReader = new BufferedReader(new InputStreamReader(getMIInputStream()));
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = inputReader.readLine()) != null) {
line = line.trim(); line = line.trim();
if (line.endsWith("(gdb)")) { //$NON-NLS-1$ if (line.endsWith("(gdb)")) { //$NON-NLS-1$
success = true;
break; break;
} }
} }
// Failed to read initial prompt, check for error
if (!success) {
errorReader = new BufferedReader(new InputStreamReader(getMIErrorStream()));
String errorInfo = errorReader.readLine();
if (errorInfo == null) {
errorInfo = "GDB prompt not read"; //$NON-NLS-1$
}
gdbLaunchRequestMonitor.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1, errorInfo, null));
}
} catch (IOException e) { } catch (IOException e) {
gdbLaunchRequestMonitor.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1, "Error reading GDB STDOUT", e)); //$NON-NLS-1$ success = false;
gdbLaunchRequestMonitor.done(); gdbLaunchRequestMonitor.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1, "Error reading GDB output", e)); //$NON-NLS-1$
return Status.OK_STATUS; }
// In the case of failure, close the MI streams so
// they are not leaked.
if (!success)
{
if (inputReader != null) {
try {
inputReader.close();
} catch (IOException e) {
}
}
if (errorReader != null) {
try {
errorReader.close();
} catch (IOException e) {
}
}
} }
gdbLaunchRequestMonitor.done(); gdbLaunchRequestMonitor.done();