From d032a14f34f898d110c11d849c077683110e1ba1 Mon Sep 17 00:00:00 2001
From: Ali Azam Rana <85216275+alirana01@users.noreply.github.com>
Date: Mon, 22 Jul 2024 12:24:58 +0200
Subject: [PATCH 1/7] changes to verify process
---
bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml | 4 ++--
.../com/espressif/idf/debug/gdbjtag/openocd/dsf/Launch.java | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml b/bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml
index c44aa77a0..e38e53e09 100644
--- a/bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml
+++ b/bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml
@@ -152,7 +152,7 @@
resolver="com.espressif.idf.debug.gdbjtag.openocd.SvdPathResolver">
-
-
+ -->
Date: Fri, 13 Sep 2024 12:09:00 +0200
Subject: [PATCH 2/7] Revert "changes to verify process"
This reverts commit 560de098aa3ca616284a4c5cda2ac25030cb03f7.
---
bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml | 4 ++--
.../com/espressif/idf/debug/gdbjtag/openocd/dsf/Launch.java | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml b/bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml
index e38e53e09..c44aa77a0 100644
--- a/bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml
+++ b/bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml
@@ -152,7 +152,7 @@
resolver="com.espressif.idf.debug.gdbjtag.openocd.SvdPathResolver">
-
+
Date: Fri, 13 Sep 2024 12:33:21 +0200
Subject: [PATCH 3/7] fix(port): updated code for port verification To
Improved the code for the port checking and introduced retries and waiting time
---
.../espressif/idf/core/util/PortChecker.java | 44 ++++++++++++++++---
.../idf/debug/gdbjtag/openocd/dsf/Launch.java | 9 ++--
2 files changed, 44 insertions(+), 9 deletions(-)
diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/PortChecker.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/PortChecker.java
index 053777788..593817713 100644
--- a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/PortChecker.java
+++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/PortChecker.java
@@ -4,6 +4,7 @@
*******************************************************************************/
package com.espressif.idf.core.util;
+import java.io.IOException;
import java.net.Socket;
import com.espressif.idf.core.logging.Logger;
@@ -24,14 +25,45 @@ private PortChecker()
public static boolean isPortAvailable(int port)
{
- try (Socket ignored = new Socket("localhost", port)) //$NON-NLS-1$
- {
- return false;
- }
- catch (Exception e)
+ int attempts = 0;
+ int retryCount = 3;
+ long retryDelayMillis = 200;
+
+ while (attempts <= retryCount)
{
- return true;
+ try (Socket ignored = new Socket("localhost", port)) //$NON-NLS-1$
+ {
+ // If the socket opens, the port is in use
+ return false;
+ }
+ catch (IOException e)
+ {
+ // Port is unavailable, retrying if there are attempts left
+ if (attempts == retryCount)
+ {
+ // After exhausting all retries, return false
+ Logger.log("Port " + port + " is not available after " + retryCount + " retries."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ return false; // Failure, port is still not available
+ }
+
+ attempts++;
+
+ // Log retry attempt
+ Logger.log("Attempt " + attempts + " failed, retrying in " + retryDelayMillis + " ms..."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+ try
+ {
+ Thread.sleep(retryDelayMillis);
+ }
+ catch (InterruptedException interruptedException)
+ {
+ Thread.currentThread().interrupt(); // Restore interrupt status
+ Logger.log("Port availability check interrupted."); //$NON-NLS-1$
+ return false; // If interrupted, assume port unavailable and stop
+ }
+ }
}
+ return true; //Fallback not reachable
}
/**
diff --git a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/dsf/Launch.java b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/dsf/Launch.java
index 8749df392..5b96137f2 100644
--- a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/dsf/Launch.java
+++ b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/dsf/Launch.java
@@ -147,9 +147,12 @@ protected void provideDefaults(ILaunchConfigurationWorkingCopy config) throws Co
fDefaultPreferences.getGdbClientExecutable());
}
- int availableRemotePort = PortChecker.getAvailablePort(config.getAttribute(IGDBJtagConstants.ATTR_PORT_NUMBER,
- DefaultPreferences.GDB_SERVER_GDB_PORT_NUMBER_DEFAULT));
- config.setAttribute(IGDBJtagConstants.ATTR_PORT_NUMBER, availableRemotePort);
+ if (Configuration.getDoStartGdbServer(config))
+ {
+ int availableRemotePort = PortChecker.getAvailablePort(config.getAttribute(IGDBJtagConstants.ATTR_PORT_NUMBER,
+ DefaultPreferences.GDB_SERVER_GDB_PORT_NUMBER_DEFAULT));
+ config.setAttribute(IGDBJtagConstants.ATTR_PORT_NUMBER, availableRemotePort);
+ }
config.setAttribute(DebugPlugin.ATTR_PROCESS_FACTORY_ID, CustomIdfProcessFactory.ID);
}
From bc39d6c6fd5801b76944a90f082d9821871e5970 Mon Sep 17 00:00:00 2001
From: Ali Azam Rana <85216275+alirana01@users.noreply.github.com>
Date: Mon, 22 Jul 2024 12:24:58 +0200
Subject: [PATCH 4/7] changes to verify process
---
bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml | 4 ++--
.../com/espressif/idf/debug/gdbjtag/openocd/dsf/Launch.java | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml b/bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml
index c44aa77a0..e38e53e09 100644
--- a/bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml
+++ b/bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml
@@ -152,7 +152,7 @@
resolver="com.espressif.idf.debug.gdbjtag.openocd.SvdPathResolver">
-
-
+ -->
Date: Fri, 13 Sep 2024 12:09:00 +0200
Subject: [PATCH 5/7] Revert "changes to verify process"
This reverts commit 560de098aa3ca616284a4c5cda2ac25030cb03f7.
---
bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml | 4 ++--
.../com/espressif/idf/debug/gdbjtag/openocd/dsf/Launch.java | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml b/bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml
index e38e53e09..c44aa77a0 100644
--- a/bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml
+++ b/bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml
@@ -152,7 +152,7 @@
resolver="com.espressif.idf.debug.gdbjtag.openocd.SvdPathResolver">
-
+
Date: Mon, 16 Sep 2024 14:51:48 +0200
Subject: [PATCH 6/7] fix(debugger_tab): updated code to enable remote gdb only
when server is not started
---
.../idf/debug/gdbjtag/openocd/ui/TabDebugger.java | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/TabDebugger.java b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/TabDebugger.java
index 97fafb379..f854fc656 100644
--- a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/TabDebugger.java
+++ b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/TabDebugger.java
@@ -109,6 +109,7 @@ public class TabDebugger extends AbstractLaunchConfigurationTab
private Text fTargetIpAddress;
private Text fTargetPortNumber;
+ private Group gdbClientGroup;
protected Button fUpdateThreadlistOnSuspend;
@@ -470,6 +471,7 @@ public void widgetSelected(SelectionEvent e)
public void widgetSelected(SelectionEvent e)
{
doStartGdbServerChanged();
+ gdbClientGroup.setEnabled(!fDoStartGdbServer.getSelection());
if (fDoStartGdbServer.getSelection())
{
fTargetIpAddress.setText(DefaultPreferences.REMOTE_IP_ADDRESS_LOCALHOST);
@@ -572,16 +574,16 @@ public void modifyText(ModifyEvent e)
private void createGdbClientControls(Composite parent)
{
- Group group = new Group(parent, SWT.NONE);
+ gdbClientGroup = new Group(parent, SWT.NONE);
{
GridLayout layout = new GridLayout();
- group.setLayout(layout);
+ gdbClientGroup.setLayout(layout);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
- group.setLayoutData(gd);
- group.setText(Messages.getString("DebuggerTab.gdbSetupGroup_Text")); //$NON-NLS-1$
+ gdbClientGroup.setLayoutData(gd);
+ gdbClientGroup.setText(Messages.getString("DebuggerTab.gdbSetupGroup_Text")); //$NON-NLS-1$
}
- Composite comp = new Composite(group, SWT.NONE);
+ Composite comp = new Composite(gdbClientGroup, SWT.NONE);
{
GridLayout layout = new GridLayout();
layout.numColumns = 5;
From d0c28bd479501491797fc908f5e48cd9820dec81 Mon Sep 17 00:00:00 2001
From: Ali Azam Rana <85216275+alirana01@users.noreply.github.com>
Date: Tue, 1 Oct 2024 15:21:54 +0200
Subject: [PATCH 7/7] fix(openocd): fixed the port handler behavior
---
.../espressif/idf/core/util/PortChecker.java | 46 ++++---------------
.../debug/gdbjtag/openocd/Configuration.java | 3 +-
.../idf/debug/gdbjtag/openocd/dsf/Launch.java | 4 +-
3 files changed, 11 insertions(+), 42 deletions(-)
diff --git a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/PortChecker.java b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/PortChecker.java
index 593817713..da45fd49a 100644
--- a/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/PortChecker.java
+++ b/bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/PortChecker.java
@@ -5,6 +5,7 @@
package com.espressif.idf.core.util;
import java.io.IOException;
+import java.net.ServerSocket;
import java.net.Socket;
import com.espressif.idf.core.logging.Logger;
@@ -25,45 +26,16 @@ private PortChecker()
public static boolean isPortAvailable(int port)
{
- int attempts = 0;
- int retryCount = 3;
- long retryDelayMillis = 200;
-
- while (attempts <= retryCount)
+ try (ServerSocket serverSocket = new ServerSocket(port))
{
- try (Socket ignored = new Socket("localhost", port)) //$NON-NLS-1$
- {
- // If the socket opens, the port is in use
- return false;
- }
- catch (IOException e)
- {
- // Port is unavailable, retrying if there are attempts left
- if (attempts == retryCount)
- {
- // After exhausting all retries, return false
- Logger.log("Port " + port + " is not available after " + retryCount + " retries."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- return false; // Failure, port is still not available
- }
-
- attempts++;
-
- // Log retry attempt
- Logger.log("Attempt " + attempts + " failed, retrying in " + retryDelayMillis + " ms..."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-
- try
- {
- Thread.sleep(retryDelayMillis);
- }
- catch (InterruptedException interruptedException)
- {
- Thread.currentThread().interrupt(); // Restore interrupt status
- Logger.log("Port availability check interrupted."); //$NON-NLS-1$
- return false; // If interrupted, assume port unavailable and stop
- }
- }
+ serverSocket.setReuseAddress(true);
+ return true;
+ }
+ catch (Exception e)
+ {
+ Logger.log("Port: " + port + " is not available"); //$NON-NLS-1$ //$NON-NLS-2$
+ return false;
}
- return true; //Fallback not reachable
}
/**
diff --git a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/Configuration.java b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/Configuration.java
index 9ecc95b11..9df696832 100644
--- a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/Configuration.java
+++ b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/Configuration.java
@@ -93,8 +93,7 @@ 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);
lst.add("-c"); //$NON-NLS-1$
lst.add("gdb_port " + port); //$NON-NLS-1$
diff --git a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/dsf/Launch.java b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/dsf/Launch.java
index 5b96137f2..6ddcf79de 100644
--- a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/dsf/Launch.java
+++ b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/dsf/Launch.java
@@ -149,9 +149,7 @@ protected void provideDefaults(ILaunchConfigurationWorkingCopy config) throws Co
if (Configuration.getDoStartGdbServer(config))
{
- int availableRemotePort = PortChecker.getAvailablePort(config.getAttribute(IGDBJtagConstants.ATTR_PORT_NUMBER,
- DefaultPreferences.GDB_SERVER_GDB_PORT_NUMBER_DEFAULT));
- config.setAttribute(IGDBJtagConstants.ATTR_PORT_NUMBER, availableRemotePort);
+ config.setAttribute(IGDBJtagConstants.ATTR_PORT_NUMBER, DefaultPreferences.GDB_SERVER_GDB_PORT_NUMBER_DEFAULT);
}
config.setAttribute(DebugPlugin.ATTR_PROCESS_FACTORY_ID, CustomIdfProcessFactory.ID);