Skip to content

Commit

Permalink
Merge pull request #1023 from espressif/IEP-1265
Browse files Browse the repository at this point in the history
IEP-1265: Debug Process Hangs
  • Loading branch information
AndriiFilippov authored Nov 27, 2024
2 parents f0c20d6 + 9fde565 commit 6db7938
Show file tree
Hide file tree
Showing 8 changed files with 1,172 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
*******************************************************************************/
package com.espressif.idf.core.util;

import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

import com.espressif.idf.core.logging.Logger;
Expand All @@ -24,13 +27,15 @@ private PortChecker()

public static boolean isPortAvailable(int port)
{
try (Socket ignored = new Socket("localhost", port)) //$NON-NLS-1$
try (ServerSocket serverSocket = new ServerSocket(port, 50, InetAddress.getByName("127.0.0.1"))) //$NON-NLS-1$
{
return false;
serverSocket.setReuseAddress(true);
return true;
}
catch (Exception e)
{
return true;
Logger.log("Port: " + port + " is not available"); //$NON-NLS-1$ //$NON-NLS-2$
return false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
import java.util.List;

import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.debug.gdbjtag.core.IGDBJtagConstants;
import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants;
import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants;
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.embedcdt.core.EclipseUtils;
import org.eclipse.embedcdt.core.StringUtils;
import org.eclipse.embedcdt.debug.gdbjtag.core.DebugUtils;
Expand Down Expand Up @@ -93,9 +95,12 @@ public static String[] getGdbServerCommandLineArray(ILaunchConfiguration configu
lst.add(executable);

int port = PortChecker
.getAvailablePort(configuration.getAttribute(ConfigurationAttributes.GDB_SERVER_GDB_PORT_NUMBER,
DefaultPreferences.GDB_SERVER_GDB_PORT_NUMBER_DEFAULT));

.getAvailablePort(DefaultPreferences.GDB_SERVER_GDB_PORT_NUMBER_DEFAULT);

ILaunchConfigurationWorkingCopy configurationWorkingCopy = configuration.getWorkingCopy();
configurationWorkingCopy.setAttribute(IGDBJtagConstants.ATTR_PORT_NUMBER, port);
configurationWorkingCopy.doSave();

lst.add("-c"); //$NON-NLS-1$
lst.add("gdb_port " + port); //$NON-NLS-1$

Expand Down
Loading

0 comments on commit 6db7938

Please sign in to comment.