Skip to content

Commit

Permalink
CHE-1058: Debugger connection failure: Indicate reasons (#1396)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anatoliy Bazko committed May 31, 2016
1 parent b4ea261 commit 68bbf75
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public interface DebuggerLocalizationConstant extends com.google.gwt.i18n.client
String debuggerAlreadyConnected();

@Key("failed.to.connect.to.remote.debugger.description")
String failedToConnectToRemoteDebuggerDescription(String address);
String failedToConnectToRemoteDebuggerDescription(String address, String cause);

@Key("failed.to.get.variable.value.title")
String failedToGetVariableValueTitle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public void apply(Void arg) throws OperationException {
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
notification.setTitle(constant.failedToConnectToRemoteDebuggerDescription(address));
notification.setTitle(constant.failedToConnectToRemoteDebuggerDescription(address, arg.getMessage()));
notification.setStatus(FAIL);
notification.setDisplayMode(FLOAT_MODE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,11 @@ showHideDebuggerPanelDescription=Show/Hide Debugger Panel
############### Messages ################
debugger.connecting.title = Connecting to {0}
debugger.connected.title=Remote debugger connected
debugger.connected.description = Connected to the target VM, address: {0}.
debugger.connected.description = Connected to: {0}.
debugger.disconnected.title=Remote debugger disconnected
debugger.disconnected.description = Disconnected from: {0}
debugger.already.connected=Debugger already connected
failed.to.connect.to.remote.debugger.description=Can not connect to the target VM, address: {0}
failed.to.connect.to.remote.debugger.description=Can not connect to: {0}
failed.to.connect.to.remote.debugger.description=Can not connect to: {0}. {1}
failed.to.get.variable.value.title=Failed to get variable value

############### ChangeValueView ################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.che.plugin.gdb.server;

import org.eclipse.che.api.debugger.server.exceptions.DebuggerException;
import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.plugin.gdb.server.parser.GdbClear;
import org.eclipse.che.plugin.gdb.server.parser.GdbContinue;
Expand Down Expand Up @@ -211,7 +212,7 @@ public void delete() throws IOException, InterruptedException, GdbParseException
/**
* `target remote` command.
*/
public void targetRemote(String host, int port) throws IOException, InterruptedException, GdbParseException {
public void targetRemote(String host, int port) throws IOException, InterruptedException, GdbParseException, DebuggerException {
String command = "target remote " + (host != null ? host : "") + ":" + port;
sendCommand(command);
GdbTargetRemote.parse(outputs.take());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
*******************************************************************************/
package org.eclipse.che.plugin.gdb.server;

import org.eclipse.che.api.debug.shared.model.SimpleValue;
import org.eclipse.che.api.debugger.server.Debugger;
import org.eclipse.che.api.debugger.server.exceptions.DebuggerException;
import org.eclipse.che.api.debug.shared.model.Breakpoint;
import org.eclipse.che.api.debug.shared.model.DebuggerInfo;
import org.eclipse.che.api.debug.shared.model.Location;
import org.eclipse.che.api.debug.shared.model.SimpleValue;
import org.eclipse.che.api.debug.shared.model.StackFrameDump;
import org.eclipse.che.api.debug.shared.model.Variable;
import org.eclipse.che.api.debug.shared.model.VariablePath;
Expand All @@ -25,13 +23,15 @@
import org.eclipse.che.api.debug.shared.model.action.StepOutAction;
import org.eclipse.che.api.debug.shared.model.action.StepOverAction;
import org.eclipse.che.api.debug.shared.model.impl.DebuggerInfoImpl;
import org.eclipse.che.api.debug.shared.model.impl.StackFrameDumpImpl;
import org.eclipse.che.api.debug.shared.model.impl.SimpleValueImpl;
import org.eclipse.che.api.debug.shared.model.impl.StackFrameDumpImpl;
import org.eclipse.che.api.debug.shared.model.impl.VariableImpl;
import org.eclipse.che.api.debug.shared.model.impl.VariablePathImpl;
import org.eclipse.che.api.debug.shared.model.impl.event.BreakpointActivatedEventImpl;
import org.eclipse.che.api.debug.shared.model.impl.event.DisconnectEventImpl;
import org.eclipse.che.api.debug.shared.model.impl.event.SuspendEventImpl;
import org.eclipse.che.api.debugger.server.Debugger;
import org.eclipse.che.api.debugger.server.exceptions.DebuggerException;
import org.eclipse.che.plugin.gdb.server.parser.GdbContinue;
import org.eclipse.che.plugin.gdb.server.parser.GdbDirectory;
import org.eclipse.che.plugin.gdb.server.parser.GdbInfoBreak;
Expand All @@ -45,11 +45,13 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import static java.nio.file.Files.exists;
import static java.util.Collections.singletonList;

/**
Expand Down Expand Up @@ -110,8 +112,16 @@ public static GdbDebugger newInstance(String host,
String file,
String srcDirectory,
DebuggerCallback debuggerCallback) throws DebuggerException {
Gdb gdb;
Gdb gdb = null;
try {
if (!exists(Paths.get(file))) {
throw new IOException("Binary " + file + " not found");
}

if (!exists(Paths.get(srcDirectory))) {
throw new IOException("Source directory " + srcDirectory + " does not exist");
}

gdb = Gdb.start();
GdbDirectory directory = gdb.directory(srcDirectory);
LOG.debug("Source directories: " + directory.getDirectories());
Expand All @@ -120,8 +130,15 @@ public static GdbDebugger newInstance(String host,
if (port > 0) {
gdb.targetRemote(host, port);
}
} catch (IOException | GdbParseException | InterruptedException e) {
throw new DebuggerException("Can't initialize GDB", e);
} catch (DebuggerException | IOException | GdbParseException | InterruptedException e) {
if (gdb != null) {
try {
gdb.quit();
} catch (IOException e1) {
LOG.error("Can't stop GDB: " + e1.getMessage(), e);
}
}
throw new DebuggerException("Can't start GDB: " + e.getMessage(), e);
}

GdbVersion gdbVersion = gdb.getGdbVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ public Debugger create(Map<String, String> properties, Debugger.DebuggerCallback

String host = normalizedProps.get("host");

String portProp = normalizedProps.get("port");
int port;
try {
port = portProp != null ? Integer.parseInt(portProp) : 0;
port = Integer.parseInt(normalizedProps.getOrDefault("port", "0"));
} catch (NumberFormatException e) {
throw new DebuggerException("Unknown port property format: " + portProp);
throw new DebuggerException("Unknown port property format: " + normalizedProps.get("port"));
}

String file = normalizedProps.get("binary");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.che.plugin.gdb.server.parser;

import org.eclipse.che.api.debugger.server.exceptions.DebuggerException;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -21,6 +23,7 @@
public class GdbTargetRemote {

private static final Pattern GDB_TARGET_REMOTE = Pattern.compile("Remote debugging using (.*):(.*)\n.*");
private static final Pattern CONNECTION_TIMED_OUT = Pattern.compile(".*Connection timed out.*");

private final String host;
private final String port;
Expand All @@ -41,14 +44,16 @@ public String getPort() {
/**
* Factory method.
*/
public static GdbTargetRemote parse(GdbOutput gdbOutput) throws GdbParseException {
public static GdbTargetRemote parse(GdbOutput gdbOutput) throws GdbParseException, DebuggerException {
String output = gdbOutput.getOutput();

Matcher matcher = GDB_TARGET_REMOTE.matcher(output);
if (matcher.find()) {
String host = matcher.group(1);
String port = matcher.group(2);
return new GdbTargetRemote(host, port);
} else if (CONNECTION_TIMED_OUT.matcher(output).find()) {
throw new DebuggerException(output);
}

throw new GdbParseException(GdbTargetRemote.class, output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
package org.eclipse.che.plugin.gdb.server;

import org.eclipse.che.api.debug.shared.model.Breakpoint;
import org.eclipse.che.api.debugger.server.exceptions.DebuggerException;
import org.eclipse.che.plugin.gdb.server.parser.GdbContinue;
import org.eclipse.che.plugin.gdb.server.parser.GdbInfoBreak;
import org.eclipse.che.plugin.gdb.server.parser.GdbInfoLine;
import org.eclipse.che.plugin.gdb.server.parser.GdbInfoProgram;
import org.eclipse.che.plugin.gdb.server.parser.GdbPType;
import org.eclipse.che.plugin.gdb.server.parser.GdbParseException;
import org.eclipse.che.plugin.gdb.server.parser.GdbPrint;
import org.eclipse.che.plugin.gdb.server.parser.GdbRun;
import org.testng.annotations.AfterMethod;
Expand Down Expand Up @@ -97,7 +97,7 @@ public void testTargetRemote() throws Exception {
}
}

@Test(expectedExceptions = GdbParseException.class)
@Test(expectedExceptions = DebuggerException.class)
public void testTargetRemoteFailWhenNoGdbServer() throws Exception {
gdb.file(file);
gdb.targetRemote("localhost", 1111);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.che.plugin.gdb.server.parser;

import org.eclipse.che.api.debugger.server.exceptions.DebuggerException;
import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;
Expand Down Expand Up @@ -37,4 +38,11 @@ public void testParseFail() throws Exception {
GdbOutput gdbOutput = GdbOutput.of("some text");
GdbTargetRemote.parse(gdbOutput);
}

@Test(expectedExceptions = DebuggerException.class, expectedExceptionsMessageRegExp = "localhost:1223: Connection timed out.")
public void testShouldThrowDebuggerExceptionIfConnectionTimedOut() throws Exception {
GdbOutput gdbOutput = GdbOutput.of("localhost:1223: Connection timed out.");

GdbTargetRemote.parse(gdbOutput);
}
}

0 comments on commit 68bbf75

Please sign in to comment.