-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IEP-1265: Debug Process Hangs #1023
Changes from 7 commits
24988ac
d595bee
88a2c15
de00153
03c8344
2ac0d8a
e0fa1a5
a926bd6
d07c76f
2c91af0
63705af
abe20e5
122d853
f1d737c
ea0c653
9fde565
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Dynamic port selection improved, but Telnet port requires attention The implementation of However, the
🔗 Analysis chainApprove the dynamic port selection, but suggest improvements The introduction of
Here's a suggested implementation for applying the dynamic port selection to all ports: private static int getAvailablePort(int defaultPort, int maxRetries) {
for (int i = 0; i < maxRetries; i++) {
int port = PortChecker.getAvailablePort(defaultPort);
if (port != defaultPort) {
return port;
}
}
throw new RuntimeException("Unable to find an available port after " + maxRetries + " attempts");
}
// In getGdbServerCommandLineArray method:
int gdbPort = getAvailablePort(DefaultPreferences.GDB_SERVER_GDB_PORT_NUMBER_DEFAULT, 10);
lst.add("-c");
lst.add("gdb_port " + gdbPort);
int telnetPort = getAvailablePort(DefaultPreferences.GDB_SERVER_TELNET_PORT_NUMBER_DEFAULT, 10);
lst.add("-c");
lst.add("telnet_port " + telnetPort);
int tclPort = getAvailablePort(DefaultPreferences.GDB_SERVER_TCL_PORT_NUMBER_DEFAULT, 10);
lst.add("-c");
lst.add("tcl_port " + tclPort); This implementation applies the dynamic port selection to all ports and includes a retry limit to prevent endless loops. To ensure this change resolves the reported issues, please run the following verification steps: Please run these tests and provide the results to ensure the changes work as expected across different environments. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Verify the changes across different platforms and ESP-IDF versions
# Test on different platforms
platforms=("windows" "linux" "macos")
for platform in "${platforms[@]}"; do
echo "Testing on $platform"
# Add platform-specific test commands here
done
# Test with different ESP-IDF versions
versions=("4.4" "5.0" "5.1")
for version in "${versions[@]}"; do
echo "Testing with ESP-IDF v$version"
# Add version-specific test commands here
done
# Verify port selection logic
echo "Verifying port selection logic"
rg "PortChecker.getAvailablePort" -A 10
Length of output: 2411 Script: #!/bin/bash
# Verify dynamic port selection for telnet_port
echo "Searching for PortChecker.getAvailablePort usage in telnet_port"
rg "telnet_port" -A 10 | rg "PortChecker.getAvailablePort"
# Check implementation of getAvailablePort for retry limits
echo "Checking implementation of getAvailablePort for retry limits"
rg "getAvailablePort" -A 10 bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/PortChecker.java
Length of output: 761 Script: #!/bin/bash
# Locate the PortChecker.java file in the repository
echo "Searching for PortChecker.java in the repository"
fd "PortChecker.java" . -type f
# If the file is found, check for the implementation of getAvailablePort with retry limits
# Replace <path_to_PortChecker.java> with the actual path from the previous command's output
# Example:
# rg "def getAvailablePort" <path_to_PortChecker.java> -A 10
# Verify if PortChecker.getAvailablePort is used for telnet_port
echo "Searching for PortChecker.getAvailablePort usage in telnet_port"
rg "telnet_port" -A 10 | rg "PortChecker.getAvailablePort"
Length of output: 654 Script: #!/bin/bash
# Corrected script to locate PortChecker.java and verify its implementation
# Locate the PortChecker.java file in the repository
echo "Searching for PortChecker.java in the repository"
fd "PortChecker.java" . --type f
# If the file is found, check for the implementation of getAvailablePort with retry limits
# Replace <path_to_PortChecker.java> with the actual path from the previous command's output
# Example:
# rg "getAvailablePort" <path_to_PortChecker.java> -A 10
# Assuming the file was found at bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/PortChecker.java
echo "Inspecting getAvailablePort method for retry limits"
rg "getAvailablePort" -A 10 bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/PortChecker.java
# Verify if PortChecker.getAvailablePort is used for telnet_port
echo "Searching for PortChecker.getAvailablePort usage in telnet_port"
rg "telnet_port" -A 10 | rg "PortChecker.getAvailablePort"
Length of output: 965 Script: #!/bin/bash
# Corrected script to locate PortChecker.java and verify its implementation
# Locate the PortChecker.java file in the repository
echo "Searching for PortChecker.java in the repository"
fd "PortChecker.java" . --type file
# Check implementation of getAvailablePort for retry limits in the correct PortChecker.java
echo "Inspecting getAvailablePort method for retry limits"
rg "getAvailablePort" -A 10 bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/PortChecker.java
# Verify if PortChecker.getAvailablePort is used for telnet_port
echo "Searching for PortChecker.getAvailablePort usage in telnet_port"
rg "telnet_port" -A 10 | rg "PortChecker.getAvailablePort"
Length of output: 1095 |
||
lst.add("-c"); //$NON-NLS-1$ | ||
lst.add("gdb_port " + port); //$NON-NLS-1$ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/******************************************************************************* | ||
Check warning on line 1 in bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/dsf/Launch.java GitHub Actions / spotbugsTHROWS_METHOD_THROWS_CLAUSE_BASIC_EXCEPTION
Raw output
|
||
* Copyright (c) 2013 Liviu Ionescu. | ||
* | ||
* This program and the accompanying materials | ||
|
@@ -70,7 +70,7 @@ | |
System.out.println("openocd.Launch.launch(" + launchConfiguration.getName() + "," + mode + ") " + this); | ||
} | ||
|
||
fConfig = launchConfiguration; | ||
Check warning on line 73 in bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/dsf/Launch.java GitHub Actions / spotbugsEI_EXPOSE_REP2
Raw output
|
||
fExecutor = (DefaultDsfExecutor) getDsfExecutor(); | ||
fSession = getSession(); | ||
} | ||
|
@@ -147,9 +147,10 @@ | |
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)) | ||
{ | ||
config.setAttribute(IGDBJtagConstants.ATTR_PORT_NUMBER, DefaultPreferences.GDB_SERVER_GDB_PORT_NUMBER_DEFAULT); | ||
} | ||
Comment on lines
+166
to
+169
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Port handling logic needs improvement The current implementation sets a fixed default port when the GDB server starts, but according to PR feedback, this doesn't handle port conflicts effectively. When the default port (3333) is occupied, the system should retry with alternative ports. Consider implementing a more robust port selection mechanism: if (Configuration.getDoStartGdbServer(config))
{
- config.setAttribute(IGDBJtagConstants.ATTR_PORT_NUMBER, DefaultPreferences.GDB_SERVER_GDB_PORT_NUMBER_DEFAULT);
+ int port = PortChecker.findAvailablePort(DefaultPreferences.GDB_SERVER_GDB_PORT_NUMBER_DEFAULT);
+ if (port == -1) {
+ throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
+ "Unable to find available port for GDB server"));
+ }
+ config.setAttribute(IGDBJtagConstants.ATTR_PORT_NUMBER, port);
}
|
||
|
||
config.setAttribute(DebugPlugin.ATTR_PROCESS_FACTORY_ID, CustomIdfProcessFactory.ID); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catch Specific Exceptions Instead of Generic
Exception
Catching the generic
Exception
can mask other unintended exceptions and make debugging harder. It's better to catch the more specificIOException
, which is the expected exception type for socket operations.Apply this diff to catch
IOException
specifically:📝 Committable suggestion