From 2c49273e16be7c8f36dbf4b31515069932ccd474 Mon Sep 17 00:00:00 2001 From: Mark Bozeman Date: Tue, 30 Oct 2012 15:18:01 -0500 Subject: 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 IP-Clean: Marc Khouzam Tested-by: Marc Khouzam --- .../eclipse/cdt/dsf/gdb/service/GDBBackend.java | 45 ++++++++++++++++++---- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBBackend.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBBackend.java index 1a679dc8a85..9cb79faecf8 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBBackend.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBBackend.java @@ -10,6 +10,7 @@ * Wind River System * Ericsson * 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; @@ -19,7 +20,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; -import java.io.Reader; import java.util.ArrayList; import java.util.Hashtable; import java.util.List; @@ -561,22 +561,53 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend, IMIBa return Status.OK_STATUS; } + BufferedReader inputReader = null; + BufferedReader errorReader = null; + boolean success = false; try { - Reader r = new InputStreamReader(getMIInputStream()); - BufferedReader reader = new BufferedReader(r); + // Read initial GDB prompt + inputReader = new BufferedReader(new InputStreamReader(getMIInputStream())); String line; - while ((line = reader.readLine()) != null) { + while ((line = inputReader.readLine()) != null) { line = line.trim(); if (line.endsWith("(gdb)")) { //$NON-NLS-1$ + success = true; 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) { - gdbLaunchRequestMonitor.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1, "Error reading GDB STDOUT", e)); //$NON-NLS-1$ - gdbLaunchRequestMonitor.done(); - return Status.OK_STATUS; + success = false; + gdbLaunchRequestMonitor.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, -1, "Error reading GDB output", e)); //$NON-NLS-1$ } + // 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(); return Status.OK_STATUS; } -- cgit v1.2.3