Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*******************************************************************************/
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;
Expand All @@ -24,13 +26,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))
{
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;
Comment on lines +29 to +37
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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 specific IOException, which is the expected exception type for socket operations.

Apply this diff to catch IOException specifically:

-} catch (Exception e) {
+} catch (IOException e) {
    Logger.log("Port: " + port + " is not available"); //$NON-NLS-1$ //$NON-NLS-2$
    return false;
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
try (ServerSocket serverSocket = new ServerSocket(port))
{
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;
try (ServerSocket serverSocket = new ServerSocket(port))
{
serverSocket.setReuseAddress(true);
return true;
}
catch (IOException e)
{
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 @@ -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$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@ 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))
{
config.setAttribute(IGDBJtagConstants.ATTR_PORT_NUMBER, DefaultPreferences.GDB_SERVER_GDB_PORT_NUMBER_DEFAULT);
}

config.setAttribute(DebugPlugin.ATTR_PROCESS_FACTORY_ID, CustomIdfProcessFactory.ID);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public class TabDebugger extends AbstractLaunchConfigurationTab

private Text fTargetIpAddress;
private Text fTargetPortNumber;
private Group gdbClientGroup;

protected Button fUpdateThreadlistOnSuspend;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Loading