From d6083f49cee657431606fcc417f2a940d1975a17 Mon Sep 17 00:00:00 2001 From: Mykola Morhun Date: Mon, 20 Nov 2017 11:45:28 +0200 Subject: [PATCH] Fix GDB regression (#7423) Fixes GDB regression with stopping on breakpoints. Moves integration tests into docker container. --- plugins/plugin-gdb/che-plugin-gdb-ide/pom.xml | 43 +-------- .../plugin-gdb/che-plugin-gdb-server/pom.xml | 89 ++++++++++++++++++- .../che/plugin/gdb/server/GdbDebugger.java | 20 ++++- .../plugin/gdb/server/GdbDebuggerTest.java | 25 ++---- .../che/plugin/gdb/server/GdbServer.java | 36 -------- .../che/plugin/gdb/server/GdbTest.java | 16 ++-- .../gdb/server/util/GdbDebuggerUtils.java | 36 ++++++++ .../test/resources/GdbDebuggerTestsSuite.xml | 22 +++++ .../src/test/resources/docker/assembly.xml | 29 ++++++ .../src/test/resources/docker/entrypoint.sh | 14 +++ .../src/test/resources/logback-test.xml | 24 +++++ .../debugger/CppProjectDebuggingTest.java | 2 +- 12 files changed, 248 insertions(+), 108 deletions(-) delete mode 100644 plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbServer.java create mode 100644 plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/util/GdbDebuggerUtils.java create mode 100644 plugins/plugin-gdb/che-plugin-gdb-server/src/test/resources/GdbDebuggerTestsSuite.xml create mode 100644 plugins/plugin-gdb/che-plugin-gdb-server/src/test/resources/docker/assembly.xml create mode 100644 plugins/plugin-gdb/che-plugin-gdb-server/src/test/resources/docker/entrypoint.sh create mode 100644 plugins/plugin-gdb/che-plugin-gdb-server/src/test/resources/logback-test.xml diff --git a/plugins/plugin-gdb/che-plugin-gdb-ide/pom.xml b/plugins/plugin-gdb/che-plugin-gdb-ide/pom.xml index 711e6032754..edfb7c349e7 100644 --- a/plugins/plugin-gdb/che-plugin-gdb-ide/pom.xml +++ b/plugins/plugin-gdb/che-plugin-gdb-ide/pom.xml @@ -22,14 +22,6 @@ gwt-lib Che Plugin :: GDB :: GDB IDE - - com.google.guava - guava - - - com.google.gwt - gwt-elemental - com.google.gwt.inject gin @@ -38,30 +30,13 @@ com.google.inject guice - - javax.validation - validation-api - - - org.eclipse.che.core - che-core-api-core - org.eclipse.che.core che-core-api-core - sources org.eclipse.che.core - che-core-api-project - - - org.eclipse.che.core - che-core-api-workspace - - - org.eclipse.che.core - che-core-commons-annotations + che-core-api-debug-shared org.eclipse.che.core @@ -75,10 +50,6 @@ org.eclipse.che.core che-core-ide-app - - org.eclipse.che.core - che-core-ide-ui - org.eclipse.che.plugin che-plugin-debugger-ide @@ -128,18 +99,6 @@ org.eclipse.che.plugin.gdb.Gdb - - org.apache.maven.plugins - maven-dependency-plugin - - - analyze - - true - - - - org.apache.maven.plugins maven-surefire-plugin diff --git a/plugins/plugin-gdb/che-plugin-gdb-server/pom.xml b/plugins/plugin-gdb/che-plugin-gdb-server/pom.xml index c9aa16f2a34..9d6b7b2e394 100644 --- a/plugins/plugin-gdb/che-plugin-gdb-server/pom.xml +++ b/plugins/plugin-gdb/che-plugin-gdb-server/pom.xml @@ -21,6 +21,9 @@ che-plugin-gdb-server jar Che Plugin :: GDB :: GDB Server + + true + com.google.inject @@ -58,6 +61,11 @@ org.slf4j slf4j-api + + ch.qos.logback + logback-classic + test + com.google.guava guava @@ -96,14 +104,30 @@ - gdb-tests + integration + + false + org.apache.maven.plugins - maven-surefire-plugin + maven-failsafe-plugin + + + + integration-test + verify + + + - false + + ${debug.port} + + + ${project.build.testOutputDirectory}/GdbDebuggerTestsSuite.xml + @@ -111,7 +135,7 @@ maven-antrun-plugin - process-test-resources + process-resources process-test-resources run @@ -119,11 +143,68 @@ + + + io.fabric8 + docker-maven-plugin + + + build + process-test-resources + + build + + + + start + pre-integration-test + + stop + start + + + + stop + post-integration-test + + stop + + + + + + + gcc_gdb + gdb-tests + + eclipse/cpp_gcc + + ${project.build.testOutputDirectory}/docker/assembly.xml + + /maven + + ./entrypoint.sh + + + + true + + debug.port:8000 + + + Listening on port 8000 + + + + + + + diff --git a/plugins/plugin-gdb/che-plugin-gdb-server/src/main/java/org/eclipse/che/plugin/gdb/server/GdbDebugger.java b/plugins/plugin-gdb/che-plugin-gdb-server/src/main/java/org/eclipse/che/plugin/gdb/server/GdbDebugger.java index 7afdd60f5f8..acd9dd5aabc 100644 --- a/plugins/plugin-gdb/che-plugin-gdb-server/src/main/java/org/eclipse/che/plugin/gdb/server/GdbDebugger.java +++ b/plugins/plugin-gdb/che-plugin-gdb-server/src/main/java/org/eclipse/che/plugin/gdb/server/GdbDebugger.java @@ -33,6 +33,7 @@ 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.LocationImpl; 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; @@ -180,7 +181,7 @@ public void disconnect() { @Override public void addBreakpoint(Breakpoint breakpoint) throws DebuggerException { try { - Location location = breakpoint.getLocation(); + Location location = relativeToWorkDir(breakpoint.getLocation()); if (location.getTarget() == null) { gdb.breakpoint(location.getLineNumber()); } else { @@ -450,4 +451,21 @@ public StackFrameDump dumpStackFrame() throws DebuggerException { throw new DebuggerException("Can't dump stack frame. " + e.getMessage(), e); } } + + private Location relativeToWorkDir(Location location) + throws InterruptedException, GdbParseException, GdbTerminatedException, IOException { + String targetFilePath = location.getTarget(); + if (targetFilePath.startsWith("/")) { + return new LocationImpl( + targetFilePath.substring(1), + location.getLineNumber(), + location.isExternalResource(), + location.getExternalResourceId(), + location.getResourceProjectPath(), + location.getMethod(), + location.getThreadId()); + } else { + return location; + } + } } diff --git a/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbDebuggerTest.java b/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbDebuggerTest.java index 6ea2b29570c..0521cdcd105 100644 --- a/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbDebuggerTest.java +++ b/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbDebuggerTest.java @@ -45,9 +45,7 @@ import org.eclipse.che.api.debug.shared.model.impl.action.StepOverActionImpl; import org.eclipse.che.api.debugger.server.Debugger; import org.eclipse.che.api.debugger.server.exceptions.DebuggerException; -import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; /** @author Anatoliy Bazko */ @@ -55,34 +53,23 @@ public class GdbDebuggerTest { private String file; private Path sourceDirectory; - private GdbServer gdbServer; private Debugger gdbDebugger; private BlockingQueue events; @BeforeClass public void beforeClass() throws Exception { file = GdbTest.class.getResource("/hello").getFile(); - sourceDirectory = Paths.get(GdbTest.class.getResource("/h.cpp").getFile()); + sourceDirectory = Paths.get(GdbTest.class.getResource("/h.cpp").getFile()).getParent(); events = new ArrayBlockingQueue<>(10); } - @BeforeMethod - public void setUp() throws Exception { - gdbServer = GdbServer.start("localhost", 1111, file); - } - - @AfterMethod - public void tearDown() throws Exception { - gdbServer.stop(); - } - @Test public void testDebugger() throws Exception { initializeDebugger(); addBreakpoint(); startDebugger(); doSetAndGetValues(); - // stepInto(); + // stepInto(); stepOver(); stepOut(); resume(); @@ -217,16 +204,18 @@ private void addBreakpoint() throws DebuggerException, InterruptedException { } private void initializeDebugger() throws DebuggerException { + final String gdbPort = System.getProperty("debug.port"); + Map properties = ImmutableMap.of( "host", "localhost", "port", - "1111", + gdbPort, "binary", file, "sources", - sourceDirectory.getParent().toString()); + sourceDirectory.toString()); GdbDebuggerFactory gdbDebuggerFactory = new GdbDebuggerFactory(); gdbDebugger = gdbDebuggerFactory.create(properties, events::add); @@ -235,7 +224,7 @@ private void initializeDebugger() throws DebuggerException { assertEquals(debuggerInfo.getFile(), file); assertEquals(debuggerInfo.getHost(), "localhost"); - assertEquals(debuggerInfo.getPort(), 1111); + assertEquals(debuggerInfo.getPort(), Integer.parseInt(gdbPort)); assertNotNull(debuggerInfo.getName()); assertNotNull(debuggerInfo.getVersion()); } diff --git a/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbServer.java b/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbServer.java deleted file mode 100644 index 661dcb74eec..00000000000 --- a/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbServer.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2012-2017 Red Hat, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - */ -package org.eclipse.che.plugin.gdb.server; - -import java.io.IOException; -import org.eclipse.che.plugin.gdb.server.exception.GdbParseException; - -/** - * GDB server. - * - * @author Anatoliy Bazko - */ -public class GdbServer extends GdbProcess { - - private static final String PROCESS_NAME = "gdbserver"; - private static final String OUTPUT_SEPARATOR = "\n"; - - private GdbServer(String host, int port, String file) - throws IOException, GdbParseException, InterruptedException { - super(OUTPUT_SEPARATOR, PROCESS_NAME, host + ":" + port, file); - } - - /** Starts gdb server. */ - public static GdbServer start(String host, int port, String file) - throws InterruptedException, GdbParseException, IOException { - return new GdbServer(host, port, file); - } -} diff --git a/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbTest.java b/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbTest.java index a8d6108bee6..48d7761f581 100644 --- a/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbTest.java +++ b/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/GdbTest.java @@ -18,7 +18,10 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; import org.eclipse.che.api.debug.shared.model.Breakpoint; +import org.eclipse.che.api.debug.shared.model.event.DebuggerEvent; 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; @@ -38,11 +41,15 @@ public class GdbTest { private String file; private Path sourceDirectory; private Gdb gdb; + private BlockingQueue events; + private int port; @BeforeClass public void beforeClass() throws Exception { file = GdbTest.class.getResource("/hello").getFile(); sourceDirectory = Paths.get(GdbTest.class.getResource("/h.cpp").getFile()); + port = Integer.parseInt(System.getProperty("debug.port")); + events = new ArrayBlockingQueue<>(10); } @BeforeMethod @@ -75,12 +82,9 @@ public void testFile() throws Exception { @Test public void testTargetRemote() throws Exception { - GdbServer gdbServer = GdbServer.start("localhost", 1111, file); - + gdb.file(file); + gdb.targetRemote("localhost", port); try { - gdb.file(file); - gdb.targetRemote("localhost", 1111); - gdb.breakpoint(7); GdbContinue gdbContinue = gdb.cont(); @@ -90,7 +94,7 @@ public void testTargetRemote() throws Exception { assertEquals(breakpoint.getLocation().getTarget(), "h.cpp"); assertEquals(breakpoint.getLocation().getLineNumber(), 7); } finally { - gdbServer.stop(); + gdb.finish(); } } diff --git a/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/util/GdbDebuggerUtils.java b/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/util/GdbDebuggerUtils.java new file mode 100644 index 00000000000..974163e03e0 --- /dev/null +++ b/plugins/plugin-gdb/che-plugin-gdb-server/src/test/java/org/eclipse/che/plugin/gdb/server/util/GdbDebuggerUtils.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012-2017 Red Hat, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package org.eclipse.che.plugin.gdb.server.util; + +import static java.lang.System.getProperty; +import static java.util.Collections.emptyList; + +import com.google.common.collect.ImmutableMap; +import java.util.Map; +import java.util.concurrent.BlockingQueue; +import org.eclipse.che.api.debug.shared.model.event.DebuggerEvent; +import org.eclipse.che.api.debug.shared.model.impl.action.StartActionImpl; +import org.eclipse.che.plugin.gdb.server.GdbDebugger; +import org.eclipse.che.plugin.gdb.server.GdbDebuggerFactory; + +/** @author Mykola Morhun */ +public class GdbDebuggerUtils { + + public static GdbDebugger connectToGdb(BlockingQueue debuggerEvents) + throws Exception { + Map connectionProperties = + ImmutableMap.of("host", "localhost", "port", getProperty("debug.port")); + GdbDebuggerFactory factory = new GdbDebuggerFactory(); + GdbDebugger debugger = (GdbDebugger) factory.create(connectionProperties, debuggerEvents::add); + debugger.start(new StartActionImpl(emptyList())); + return debugger; + } +} diff --git a/plugins/plugin-gdb/che-plugin-gdb-server/src/test/resources/GdbDebuggerTestsSuite.xml b/plugins/plugin-gdb/che-plugin-gdb-server/src/test/resources/GdbDebuggerTestsSuite.xml new file mode 100644 index 00000000000..8c8641e86f8 --- /dev/null +++ b/plugins/plugin-gdb/che-plugin-gdb-server/src/test/resources/GdbDebuggerTestsSuite.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + diff --git a/plugins/plugin-gdb/che-plugin-gdb-server/src/test/resources/docker/assembly.xml b/plugins/plugin-gdb/che-plugin-gdb-server/src/test/resources/docker/assembly.xml new file mode 100644 index 00000000000..12f51959bc2 --- /dev/null +++ b/plugins/plugin-gdb/che-plugin-gdb-server/src/test/resources/docker/assembly.xml @@ -0,0 +1,29 @@ + + + + + + ${project.build.testOutputDirectory}/h.cpp + . + + + ${project.build.testOutputDirectory}/hello + . + + + ${project.build.testOutputDirectory}/docker/entrypoint.sh + . + + + diff --git a/plugins/plugin-gdb/che-plugin-gdb-server/src/test/resources/docker/entrypoint.sh b/plugins/plugin-gdb/che-plugin-gdb-server/src/test/resources/docker/entrypoint.sh new file mode 100644 index 00000000000..9a8ffdf6295 --- /dev/null +++ b/plugins/plugin-gdb/che-plugin-gdb-server/src/test/resources/docker/entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# +# Copyright (c) 2012-2017 Red Hat, Inc. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Red Hat, Inc. - initial API and implementation +# + +gdbserver :8000 hello +gdbserver :8000 hello diff --git a/plugins/plugin-gdb/che-plugin-gdb-server/src/test/resources/logback-test.xml b/plugins/plugin-gdb/che-plugin-gdb-server/src/test/resources/logback-test.xml new file mode 100644 index 00000000000..86d90d53021 --- /dev/null +++ b/plugins/plugin-gdb/che-plugin-gdb-server/src/test/resources/logback-test.xml @@ -0,0 +1,24 @@ + + + + + + %-41(%date[%.15thread]) %-45([%-5level] [%.30logger{30} %L]) - %msg%n + + + + + + + diff --git a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/CppProjectDebuggingTest.java b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/CppProjectDebuggingTest.java index 4df03853837..5ff7776c3ea 100644 --- a/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/CppProjectDebuggingTest.java +++ b/selenium/che-selenium-test/src/test/java/org/eclipse/che/selenium/debugger/CppProjectDebuggingTest.java @@ -128,7 +128,7 @@ public void shouldDebugCppProject() { // then debugPanel.waitDebugHighlightedText(" std::cout << hello.sayHello(\"man\") << std::endl;"); - debugPanel.waitTextInVariablesPanel("hello: {}"); + debugPanel.waitTextInVariablesPanel("hello={}"); } private String getXpathForDebugConfigurationMenuItem() {