Skip to content

Commit

Permalink
Add ability to customize GDB port when auto-starting gdb server (#571)
Browse files Browse the repository at this point in the history
When starting a gdbserver (like openocd) connected to a multi-core
SoC the gdb server may open multiple ports. This change allows
user to configure which port GDB connect to rather than forcing
GDB to connect to the first port.

When the ports do not match a warning triangle is displayed which
can be clicked on to restore the matching values.

When a user changes the "GDB port" in the "Start TYPE locally"
section that is reflected in the "Port number" in the "Remote Target"
section.

Changes to "Port number" in the "Remote Target" which lead to the ports
not matching will display the warning triangle.

Fixes #569
  • Loading branch information
jonahgraham committed Jun 19, 2023
1 parent 4b68046 commit 413c0a3
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import org.eclipse.embedcdt.internal.debug.gdbjtag.jlink.ui.preferences.GlobalMcuPage;
import org.eclipse.embedcdt.internal.debug.gdbjtag.jlink.ui.preferences.WorkspaceMcuPage;
import org.eclipse.embedcdt.internal.debug.gdbjtag.jlink.ui.properties.ProjectMcuPage;
import org.eclipse.jface.fieldassist.ControlDecoration;
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
Expand Down Expand Up @@ -95,6 +97,9 @@ public class TabDebugger extends AbstractLaunchConfigurationTab {

private Text fTargetIpAddress;
private Text fTargetPortNumber;
private ControlDecoration fTargetPortNumberDecoration;
private ControlDecoration fTargetIpAddressDecoration;

private Text fGdbFlashDeviceName;
private Button fGdbEndiannessLittle;

Expand Down Expand Up @@ -698,6 +703,7 @@ public void widgetSelected(SelectionEvent e) {

if (fDoStartGdbServer.getSelection()) {
fTargetIpAddress.setText(DefaultPreferences.REMOTE_IP_ADDRESS_LOCALHOST);
fTargetPortNumber.setText(fGdbServerGdbPort.getText());
}
scheduleUpdateJob();
}
Expand Down Expand Up @@ -1077,6 +1083,10 @@ private void createRemoteControl(Composite parent) {
GridData gd = new GridData();
gd.widthHint = 125;
fTargetIpAddress.setLayoutData(gd);
fTargetIpAddressDecoration = new ControlDecoration(fTargetIpAddress, SWT.LEFT | SWT.TOP);
fTargetIpAddressDecoration.setDescriptionText(Messages.getString("DebuggerTab.ipAddressWarningDecoration")); //$NON-NLS-1$
fTargetIpAddressDecoration.setImage(FieldDecorationRegistry.getDefault()
.getFieldDecoration(FieldDecorationRegistry.DEC_WARNING).getImage());

label = new Label(comp, SWT.NONE);
label.setText(Messages.getString("DebuggerTab.portNumberLabel")); //$NON-NLS-1$
Expand All @@ -1085,13 +1095,19 @@ private void createRemoteControl(Composite parent) {
gd = new GridData();
gd.widthHint = 125;
fTargetPortNumber.setLayoutData(gd);
fTargetPortNumberDecoration = new ControlDecoration(fTargetPortNumber, SWT.LEFT | SWT.TOP);
fTargetPortNumberDecoration
.setDescriptionText(Messages.getString("DebuggerTab.portNumberWarningDecoration")); //$NON-NLS-1$
fTargetPortNumberDecoration.setImage(FieldDecorationRegistry.getDefault()
.getFieldDecoration(FieldDecorationRegistry.DEC_WARNING).getImage());
}

// ---- Actions -------------------------------------------------------
// Add watchers for user data entry
fTargetIpAddress.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
updateDecorations();
scheduleUpdateJob(); // provides much better performance for
// Text listeners
}
Expand All @@ -1106,11 +1122,23 @@ public void verifyText(VerifyEvent e) {
fTargetPortNumber.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
updateDecorations();
scheduleUpdateJob(); // provides much better performance for
// Text listeners
}
});

fTargetIpAddressDecoration.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
fTargetIpAddress.setText(DefaultPreferences.REMOTE_IP_ADDRESS_DEFAULT);
}
});
fTargetPortNumberDecoration.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
fTargetPortNumber.setText(fGdbServerGdbPort.getText());
}
});
}

private void updateGdbServerActualPath() {
Expand Down Expand Up @@ -1175,12 +1203,10 @@ private void doStartGdbServerChanged() {

fDoGdbServerAllocateSemihostingConsole.setEnabled(enabled);

// Disable remote target params when the server is started
fTargetIpAddress.setEnabled(!enabled);
fTargetPortNumber.setEnabled(!enabled);

fGdbServerPathLabel.setEnabled(enabled);
fLink.setEnabled(enabled);

updateDecorations();
}

private void propagateConnectToRunningChanged() {
Expand All @@ -1193,6 +1219,24 @@ private void propagateConnectToRunningChanged() {
}
}

protected void updateDecorations() {
if (fDoStartGdbServer.getSelection()) {
if (DefaultPreferences.REMOTE_IP_ADDRESS_DEFAULT.equals(fTargetIpAddress.getText())) {
fTargetIpAddressDecoration.hide();
} else {
fTargetIpAddressDecoration.show();
}
if (fGdbServerGdbPort.getText().equals(fTargetPortNumber.getText())) {
fTargetPortNumberDecoration.hide();
} else {
fTargetPortNumberDecoration.show();
}
} else {
fTargetIpAddressDecoration.hide();
fTargetPortNumberDecoration.hide();
}
}

@Override
public void initializeFrom(ILaunchConfiguration configuration) {

Expand Down Expand Up @@ -1587,8 +1631,12 @@ else if (DefaultPreferences.ENDIANNESS_BIG.equals(endianness))
{
fTargetIpAddress.setText(DefaultPreferences.REMOTE_IP_ADDRESS_DEFAULT); // $NON-NLS-1$

String portString = Integer.toString(DefaultPreferences.REMOTE_PORT_NUMBER_DEFAULT); // $NON-NLS-1$
fTargetPortNumber.setText(portString);
if (fDoStartGdbServer.getSelection()) {
fTargetPortNumber.setText(fGdbServerGdbPort.getText());
} else {
String portString = Integer.toString(DefaultPreferences.REMOTE_PORT_NUMBER_DEFAULT); // $NON-NLS-1$
fTargetPortNumber.setText(portString);
}

// useRemoteChanged();
}
Expand Down Expand Up @@ -1869,31 +1917,15 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) {

// Remote target
{
if (fDoStartGdbServer.getSelection()) {
configuration.setAttribute(IGDBJtagConstants.ATTR_IP_ADDRESS, "localhost");

String str = fGdbServerGdbPort.getText().trim();
if (!str.isEmpty()) {
try {
int port;
port = Integer.parseInt(str);
configuration.setAttribute(IGDBJtagConstants.ATTR_PORT_NUMBER, port);
} catch (NumberFormatException e) {
Activator.log(e);
}
}
} else {
String ip = fTargetIpAddress.getText().trim();
configuration.setAttribute(IGDBJtagConstants.ATTR_IP_ADDRESS, ip);

String str = fTargetPortNumber.getText().trim();
if (!str.isEmpty()) {
try {
int port = Integer.valueOf(str).intValue();
configuration.setAttribute(IGDBJtagConstants.ATTR_PORT_NUMBER, port);
} catch (NumberFormatException e) {
Activator.log(e);
}
String ip = fTargetIpAddress.getText().trim();
configuration.setAttribute(IGDBJtagConstants.ATTR_IP_ADDRESS, ip);
String str = fTargetPortNumber.getText().trim();
if (!str.isEmpty()) {
try {
int port = Integer.valueOf(str).intValue();
configuration.setAttribute(IGDBJtagConstants.ATTR_PORT_NUMBER, port);
} catch (NumberFormatException e) {
Activator.log(e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ the target. Other useful commands are:\n\

DebuggerTab.remoteGroup_Text=Remote Target
DebuggerTab.ipAddressLabel=Host name or IP address:
DebuggerTab.ipAddressWarningDecoration=The supplied value for the Host name or IP address does not match the address the J-Link GDB server is listening on. Click the warning to restore the default.
DebuggerTab.portNumberLabel=Port number:
DebuggerTab.portNumberWarningDecoration=The supplied port number does not match the port the J-Link GDB server is listening on. Click the warning to restore the default.


DebuggerTab.update_thread_list_on_suspend_Text=Force thread list update on suspend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import org.eclipse.embedcdt.internal.debug.gdbjtag.openocd.ui.preferences.GlobalMcuPage;
import org.eclipse.embedcdt.internal.debug.gdbjtag.openocd.ui.preferences.WorkspaceMcuPage;
import org.eclipse.embedcdt.internal.debug.gdbjtag.openocd.ui.properties.ProjectMcuPage;
import org.eclipse.jface.fieldassist.ControlDecoration;
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
Expand Down Expand Up @@ -107,6 +109,8 @@ public class TabDebugger extends AbstractLaunchConfigurationTab {

private Text fTargetIpAddress;
private Text fTargetPortNumber;
private ControlDecoration fTargetPortNumberDecoration;
private ControlDecoration fTargetIpAddressDecoration;

protected Button fUpdateThreadlistOnSuspend;

Expand Down Expand Up @@ -392,6 +396,7 @@ public void widgetSelected(SelectionEvent e) {
doStartGdbServerChanged();
if (fDoStartGdbServer.getSelection()) {
fTargetIpAddress.setText(DefaultPreferences.REMOTE_IP_ADDRESS_LOCALHOST);
fTargetPortNumber.setText(fGdbServerGdbPort.getText());
}
scheduleUpdateJob();
}
Expand Down Expand Up @@ -648,6 +653,10 @@ private void createRemoteControl(Composite parent) {
GridData gd = new GridData();
gd.widthHint = 125;
fTargetIpAddress.setLayoutData(gd);
fTargetIpAddressDecoration = new ControlDecoration(fTargetIpAddress, SWT.LEFT | SWT.TOP);
fTargetIpAddressDecoration.setDescriptionText(Messages.getString("DebuggerTab.ipAddressWarningDecoration")); //$NON-NLS-1$
fTargetIpAddressDecoration.setImage(FieldDecorationRegistry.getDefault()
.getFieldDecoration(FieldDecorationRegistry.DEC_WARNING).getImage());

label = new Label(comp, SWT.NONE);
label.setText(Messages.getString("DebuggerTab.portNumberLabel")); //$NON-NLS-1$
Expand All @@ -656,6 +665,12 @@ private void createRemoteControl(Composite parent) {
gd = new GridData();
gd.widthHint = 125;
fTargetPortNumber.setLayoutData(gd);
fTargetPortNumberDecoration = new ControlDecoration(fTargetPortNumber, SWT.LEFT | SWT.TOP);
fTargetPortNumberDecoration
.setDescriptionText(Messages.getString("DebuggerTab.portNumberWarningDecoration")); //$NON-NLS-1$
fTargetPortNumberDecoration.setImage(FieldDecorationRegistry.getDefault()
.getFieldDecoration(FieldDecorationRegistry.DEC_WARNING).getImage());

}

// ---- Actions -------------------------------------------------------
Expand All @@ -664,6 +679,7 @@ private void createRemoteControl(Composite parent) {
fTargetIpAddress.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
updateDecorations();
scheduleUpdateJob(); // provides much better performance for
// Text listeners
}
Expand All @@ -677,10 +693,24 @@ public void verifyText(VerifyEvent e) {
fTargetPortNumber.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
updateDecorations();
scheduleUpdateJob(); // provides much better performance for
// Text listeners
}
});
fTargetIpAddressDecoration.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
fTargetIpAddress.setText(DefaultPreferences.REMOTE_IP_ADDRESS_DEFAULT);
}
});
fTargetPortNumberDecoration.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
fTargetPortNumber.setText(fGdbServerGdbPort.getText());
}
});

}

private void updateGdbServerActualPath() {
Expand Down Expand Up @@ -723,12 +753,10 @@ private void doStartGdbServerChanged() {
fDoGdbServerAllocateConsole.setEnabled(enabled);
}

// Disable remote target params when the server is started
fTargetIpAddress.setEnabled(!enabled);
fTargetPortNumber.setEnabled(!enabled);

fGdbServerPathLabel.setEnabled(enabled);
fLink.setEnabled(enabled);

updateDecorations();
}

private void doStartGdbClientChanged() {
Expand All @@ -742,6 +770,25 @@ private void doStartGdbClientChanged() {
fGdbClientOtherCommands.setEnabled(enabled);
}

protected void updateDecorations() {
if (fDoStartGdbServer.getSelection()) {
if (DefaultPreferences.REMOTE_IP_ADDRESS_DEFAULT.equals(fTargetIpAddress.getText())) {
fTargetIpAddressDecoration.hide();
} else {
fTargetIpAddressDecoration.show();
}
if (fGdbServerGdbPort.getText().equals(fTargetPortNumber.getText())) {
fTargetPortNumberDecoration.hide();
} else {
fTargetPortNumberDecoration.show();
}
} else {
fTargetIpAddressDecoration.hide();
fTargetPortNumberDecoration.hide();
}

}

@Override
public void initializeFrom(ILaunchConfiguration configuration) {

Expand Down Expand Up @@ -912,8 +959,12 @@ public void initializeFromDefaults() {
{
fTargetIpAddress.setText(DefaultPreferences.REMOTE_IP_ADDRESS_DEFAULT); // $NON-NLS-1$

String portString = Integer.toString(DefaultPreferences.REMOTE_PORT_NUMBER_DEFAULT); // $NON-NLS-1$
fTargetPortNumber.setText(portString);
if (fDoStartGdbServer.getSelection()) {
fTargetPortNumber.setText(fGdbServerGdbPort.getText());
} else {
String portString = Integer.toString(DefaultPreferences.REMOTE_PORT_NUMBER_DEFAULT); // $NON-NLS-1$
fTargetPortNumber.setText(portString);
}
}

doStartGdbServerChanged();
Expand Down Expand Up @@ -1112,31 +1163,17 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) {
}

{
if (fDoStartGdbServer.getSelection()) {
configuration.setAttribute(IGDBJtagConstants.ATTR_IP_ADDRESS, "localhost");

String str = fGdbServerGdbPort.getText().trim();
if (!str.isEmpty()) {
try {
int port;
port = Integer.parseInt(str);
configuration.setAttribute(IGDBJtagConstants.ATTR_PORT_NUMBER, port);
} catch (NumberFormatException e) {
Activator.log(e);
}
}
} else {
String ip = fTargetIpAddress.getText().trim();
configuration.setAttribute(IGDBJtagConstants.ATTR_IP_ADDRESS, ip);

String str = fTargetPortNumber.getText().trim();
if (!str.isEmpty()) {
try {
int port = Integer.valueOf(str).intValue();
configuration.setAttribute(IGDBJtagConstants.ATTR_PORT_NUMBER, port);
} catch (NumberFormatException e) {
Activator.log(e);
}

String ip = fTargetIpAddress.getText().trim();
configuration.setAttribute(IGDBJtagConstants.ATTR_IP_ADDRESS, ip);

String str = fTargetPortNumber.getText().trim();
if (!str.isEmpty()) {
try {
int port = Integer.valueOf(str).intValue();
configuration.setAttribute(IGDBJtagConstants.ATTR_PORT_NUMBER, port);
} catch (NumberFormatException e) {
Activator.log(e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ remotetimeout 20'.

DebuggerTab.remoteGroup_Text=Remote Target
DebuggerTab.ipAddressLabel=Host name or IP address:
DebuggerTab.ipAddressWarningDecoration=The supplied value for the Host name or IP address does not match the address OpenOCD is listening on. Click the warning to restore the default.
DebuggerTab.portNumberLabel=Port number:
DebuggerTab.portNumberWarningDecoration=The supplied port number does not match the port OpenOCD is listening on. Click the warning to restore the default.


DebuggerTab.update_thread_list_on_suspend_Text=Force thread list update on suspend
Expand Down
Loading

0 comments on commit 413c0a3

Please sign in to comment.