Skip to content

Commit 413c0a3

Browse files
authored
Add ability to customize GDB port when auto-starting gdb server (#571)
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
1 parent 4b68046 commit 413c0a3

File tree

8 files changed

+269
-126
lines changed

8 files changed

+269
-126
lines changed

plugins/org.eclipse.embedcdt.debug.gdbjtag.jlink.ui/src/org/eclipse/embedcdt/debug/gdbjtag/jlink/ui/TabDebugger.java

Lines changed: 64 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
import org.eclipse.embedcdt.internal.debug.gdbjtag.jlink.ui.preferences.GlobalMcuPage;
4848
import org.eclipse.embedcdt.internal.debug.gdbjtag.jlink.ui.preferences.WorkspaceMcuPage;
4949
import org.eclipse.embedcdt.internal.debug.gdbjtag.jlink.ui.properties.ProjectMcuPage;
50+
import org.eclipse.jface.fieldassist.ControlDecoration;
51+
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
5052
import org.eclipse.jface.window.Window;
5153
import org.eclipse.swt.SWT;
5254
import org.eclipse.swt.events.ModifyEvent;
@@ -95,6 +97,9 @@ public class TabDebugger extends AbstractLaunchConfigurationTab {
9597

9698
private Text fTargetIpAddress;
9799
private Text fTargetPortNumber;
100+
private ControlDecoration fTargetPortNumberDecoration;
101+
private ControlDecoration fTargetIpAddressDecoration;
102+
98103
private Text fGdbFlashDeviceName;
99104
private Button fGdbEndiannessLittle;
100105

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

699704
if (fDoStartGdbServer.getSelection()) {
700705
fTargetIpAddress.setText(DefaultPreferences.REMOTE_IP_ADDRESS_LOCALHOST);
706+
fTargetPortNumber.setText(fGdbServerGdbPort.getText());
701707
}
702708
scheduleUpdateJob();
703709
}
@@ -1077,6 +1083,10 @@ private void createRemoteControl(Composite parent) {
10771083
GridData gd = new GridData();
10781084
gd.widthHint = 125;
10791085
fTargetIpAddress.setLayoutData(gd);
1086+
fTargetIpAddressDecoration = new ControlDecoration(fTargetIpAddress, SWT.LEFT | SWT.TOP);
1087+
fTargetIpAddressDecoration.setDescriptionText(Messages.getString("DebuggerTab.ipAddressWarningDecoration")); //$NON-NLS-1$
1088+
fTargetIpAddressDecoration.setImage(FieldDecorationRegistry.getDefault()
1089+
.getFieldDecoration(FieldDecorationRegistry.DEC_WARNING).getImage());
10801090

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

10901105
// ---- Actions -------------------------------------------------------
10911106
// Add watchers for user data entry
10921107
fTargetIpAddress.addModifyListener(new ModifyListener() {
10931108
@Override
10941109
public void modifyText(ModifyEvent e) {
1110+
updateDecorations();
10951111
scheduleUpdateJob(); // provides much better performance for
10961112
// Text listeners
10971113
}
@@ -1106,11 +1122,23 @@ public void verifyText(VerifyEvent e) {
11061122
fTargetPortNumber.addModifyListener(new ModifyListener() {
11071123
@Override
11081124
public void modifyText(ModifyEvent e) {
1125+
updateDecorations();
11091126
scheduleUpdateJob(); // provides much better performance for
11101127
// Text listeners
11111128
}
11121129
});
1113-
1130+
fTargetIpAddressDecoration.addSelectionListener(new SelectionAdapter() {
1131+
@Override
1132+
public void widgetSelected(SelectionEvent e) {
1133+
fTargetIpAddress.setText(DefaultPreferences.REMOTE_IP_ADDRESS_DEFAULT);
1134+
}
1135+
});
1136+
fTargetPortNumberDecoration.addSelectionListener(new SelectionAdapter() {
1137+
@Override
1138+
public void widgetSelected(SelectionEvent e) {
1139+
fTargetPortNumber.setText(fGdbServerGdbPort.getText());
1140+
}
1141+
});
11141142
}
11151143

11161144
private void updateGdbServerActualPath() {
@@ -1175,12 +1203,10 @@ private void doStartGdbServerChanged() {
11751203

11761204
fDoGdbServerAllocateSemihostingConsole.setEnabled(enabled);
11771205

1178-
// Disable remote target params when the server is started
1179-
fTargetIpAddress.setEnabled(!enabled);
1180-
fTargetPortNumber.setEnabled(!enabled);
1181-
11821206
fGdbServerPathLabel.setEnabled(enabled);
11831207
fLink.setEnabled(enabled);
1208+
1209+
updateDecorations();
11841210
}
11851211

11861212
private void propagateConnectToRunningChanged() {
@@ -1193,6 +1219,24 @@ private void propagateConnectToRunningChanged() {
11931219
}
11941220
}
11951221

1222+
protected void updateDecorations() {
1223+
if (fDoStartGdbServer.getSelection()) {
1224+
if (DefaultPreferences.REMOTE_IP_ADDRESS_DEFAULT.equals(fTargetIpAddress.getText())) {
1225+
fTargetIpAddressDecoration.hide();
1226+
} else {
1227+
fTargetIpAddressDecoration.show();
1228+
}
1229+
if (fGdbServerGdbPort.getText().equals(fTargetPortNumber.getText())) {
1230+
fTargetPortNumberDecoration.hide();
1231+
} else {
1232+
fTargetPortNumberDecoration.show();
1233+
}
1234+
} else {
1235+
fTargetIpAddressDecoration.hide();
1236+
fTargetPortNumberDecoration.hide();
1237+
}
1238+
}
1239+
11961240
@Override
11971241
public void initializeFrom(ILaunchConfiguration configuration) {
11981242

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

1590-
String portString = Integer.toString(DefaultPreferences.REMOTE_PORT_NUMBER_DEFAULT); // $NON-NLS-1$
1591-
fTargetPortNumber.setText(portString);
1634+
if (fDoStartGdbServer.getSelection()) {
1635+
fTargetPortNumber.setText(fGdbServerGdbPort.getText());
1636+
} else {
1637+
String portString = Integer.toString(DefaultPreferences.REMOTE_PORT_NUMBER_DEFAULT); // $NON-NLS-1$
1638+
fTargetPortNumber.setText(portString);
1639+
}
15921640

15931641
// useRemoteChanged();
15941642
}
@@ -1869,31 +1917,15 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) {
18691917

18701918
// Remote target
18711919
{
1872-
if (fDoStartGdbServer.getSelection()) {
1873-
configuration.setAttribute(IGDBJtagConstants.ATTR_IP_ADDRESS, "localhost");
1874-
1875-
String str = fGdbServerGdbPort.getText().trim();
1876-
if (!str.isEmpty()) {
1877-
try {
1878-
int port;
1879-
port = Integer.parseInt(str);
1880-
configuration.setAttribute(IGDBJtagConstants.ATTR_PORT_NUMBER, port);
1881-
} catch (NumberFormatException e) {
1882-
Activator.log(e);
1883-
}
1884-
}
1885-
} else {
1886-
String ip = fTargetIpAddress.getText().trim();
1887-
configuration.setAttribute(IGDBJtagConstants.ATTR_IP_ADDRESS, ip);
1888-
1889-
String str = fTargetPortNumber.getText().trim();
1890-
if (!str.isEmpty()) {
1891-
try {
1892-
int port = Integer.valueOf(str).intValue();
1893-
configuration.setAttribute(IGDBJtagConstants.ATTR_PORT_NUMBER, port);
1894-
} catch (NumberFormatException e) {
1895-
Activator.log(e);
1896-
}
1920+
String ip = fTargetIpAddress.getText().trim();
1921+
configuration.setAttribute(IGDBJtagConstants.ATTR_IP_ADDRESS, ip);
1922+
String str = fTargetPortNumber.getText().trim();
1923+
if (!str.isEmpty()) {
1924+
try {
1925+
int port = Integer.valueOf(str).intValue();
1926+
configuration.setAttribute(IGDBJtagConstants.ATTR_PORT_NUMBER, port);
1927+
} catch (NumberFormatException e) {
1928+
Activator.log(e);
18971929
}
18981930
}
18991931
}

plugins/org.eclipse.embedcdt.debug.gdbjtag.jlink.ui/src/org/eclipse/embedcdt/internal/debug/gdbjtag/jlink/ui/messages.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ the target. Other useful commands are:\n\
202202

203203
DebuggerTab.remoteGroup_Text=Remote Target
204204
DebuggerTab.ipAddressLabel=Host name or IP address:
205+
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.
205206
DebuggerTab.portNumberLabel=Port number:
207+
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.
206208

207209

208210
DebuggerTab.update_thread_list_on_suspend_Text=Force thread list update on suspend

plugins/org.eclipse.embedcdt.debug.gdbjtag.openocd.ui/src/org/eclipse/embedcdt/debug/gdbjtag/openocd/ui/TabDebugger.java

Lines changed: 68 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
import org.eclipse.embedcdt.internal.debug.gdbjtag.openocd.ui.preferences.GlobalMcuPage;
4747
import org.eclipse.embedcdt.internal.debug.gdbjtag.openocd.ui.preferences.WorkspaceMcuPage;
4848
import org.eclipse.embedcdt.internal.debug.gdbjtag.openocd.ui.properties.ProjectMcuPage;
49+
import org.eclipse.jface.fieldassist.ControlDecoration;
50+
import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
4951
import org.eclipse.jface.window.Window;
5052
import org.eclipse.swt.SWT;
5153
import org.eclipse.swt.events.ModifyEvent;
@@ -107,6 +109,8 @@ public class TabDebugger extends AbstractLaunchConfigurationTab {
107109

108110
private Text fTargetIpAddress;
109111
private Text fTargetPortNumber;
112+
private ControlDecoration fTargetPortNumberDecoration;
113+
private ControlDecoration fTargetIpAddressDecoration;
110114

111115
protected Button fUpdateThreadlistOnSuspend;
112116

@@ -392,6 +396,7 @@ public void widgetSelected(SelectionEvent e) {
392396
doStartGdbServerChanged();
393397
if (fDoStartGdbServer.getSelection()) {
394398
fTargetIpAddress.setText(DefaultPreferences.REMOTE_IP_ADDRESS_LOCALHOST);
399+
fTargetPortNumber.setText(fGdbServerGdbPort.getText());
395400
}
396401
scheduleUpdateJob();
397402
}
@@ -648,6 +653,10 @@ private void createRemoteControl(Composite parent) {
648653
GridData gd = new GridData();
649654
gd.widthHint = 125;
650655
fTargetIpAddress.setLayoutData(gd);
656+
fTargetIpAddressDecoration = new ControlDecoration(fTargetIpAddress, SWT.LEFT | SWT.TOP);
657+
fTargetIpAddressDecoration.setDescriptionText(Messages.getString("DebuggerTab.ipAddressWarningDecoration")); //$NON-NLS-1$
658+
fTargetIpAddressDecoration.setImage(FieldDecorationRegistry.getDefault()
659+
.getFieldDecoration(FieldDecorationRegistry.DEC_WARNING).getImage());
651660

652661
label = new Label(comp, SWT.NONE);
653662
label.setText(Messages.getString("DebuggerTab.portNumberLabel")); //$NON-NLS-1$
@@ -656,6 +665,12 @@ private void createRemoteControl(Composite parent) {
656665
gd = new GridData();
657666
gd.widthHint = 125;
658667
fTargetPortNumber.setLayoutData(gd);
668+
fTargetPortNumberDecoration = new ControlDecoration(fTargetPortNumber, SWT.LEFT | SWT.TOP);
669+
fTargetPortNumberDecoration
670+
.setDescriptionText(Messages.getString("DebuggerTab.portNumberWarningDecoration")); //$NON-NLS-1$
671+
fTargetPortNumberDecoration.setImage(FieldDecorationRegistry.getDefault()
672+
.getFieldDecoration(FieldDecorationRegistry.DEC_WARNING).getImage());
673+
659674
}
660675

661676
// ---- Actions -------------------------------------------------------
@@ -664,6 +679,7 @@ private void createRemoteControl(Composite parent) {
664679
fTargetIpAddress.addModifyListener(new ModifyListener() {
665680
@Override
666681
public void modifyText(ModifyEvent e) {
682+
updateDecorations();
667683
scheduleUpdateJob(); // provides much better performance for
668684
// Text listeners
669685
}
@@ -677,10 +693,24 @@ public void verifyText(VerifyEvent e) {
677693
fTargetPortNumber.addModifyListener(new ModifyListener() {
678694
@Override
679695
public void modifyText(ModifyEvent e) {
696+
updateDecorations();
680697
scheduleUpdateJob(); // provides much better performance for
681698
// Text listeners
682699
}
683700
});
701+
fTargetIpAddressDecoration.addSelectionListener(new SelectionAdapter() {
702+
@Override
703+
public void widgetSelected(SelectionEvent e) {
704+
fTargetIpAddress.setText(DefaultPreferences.REMOTE_IP_ADDRESS_DEFAULT);
705+
}
706+
});
707+
fTargetPortNumberDecoration.addSelectionListener(new SelectionAdapter() {
708+
@Override
709+
public void widgetSelected(SelectionEvent e) {
710+
fTargetPortNumber.setText(fGdbServerGdbPort.getText());
711+
}
712+
});
713+
684714
}
685715

686716
private void updateGdbServerActualPath() {
@@ -723,12 +753,10 @@ private void doStartGdbServerChanged() {
723753
fDoGdbServerAllocateConsole.setEnabled(enabled);
724754
}
725755

726-
// Disable remote target params when the server is started
727-
fTargetIpAddress.setEnabled(!enabled);
728-
fTargetPortNumber.setEnabled(!enabled);
729-
730756
fGdbServerPathLabel.setEnabled(enabled);
731757
fLink.setEnabled(enabled);
758+
759+
updateDecorations();
732760
}
733761

734762
private void doStartGdbClientChanged() {
@@ -742,6 +770,25 @@ private void doStartGdbClientChanged() {
742770
fGdbClientOtherCommands.setEnabled(enabled);
743771
}
744772

773+
protected void updateDecorations() {
774+
if (fDoStartGdbServer.getSelection()) {
775+
if (DefaultPreferences.REMOTE_IP_ADDRESS_DEFAULT.equals(fTargetIpAddress.getText())) {
776+
fTargetIpAddressDecoration.hide();
777+
} else {
778+
fTargetIpAddressDecoration.show();
779+
}
780+
if (fGdbServerGdbPort.getText().equals(fTargetPortNumber.getText())) {
781+
fTargetPortNumberDecoration.hide();
782+
} else {
783+
fTargetPortNumberDecoration.show();
784+
}
785+
} else {
786+
fTargetIpAddressDecoration.hide();
787+
fTargetPortNumberDecoration.hide();
788+
}
789+
790+
}
791+
745792
@Override
746793
public void initializeFrom(ILaunchConfiguration configuration) {
747794

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

915-
String portString = Integer.toString(DefaultPreferences.REMOTE_PORT_NUMBER_DEFAULT); // $NON-NLS-1$
916-
fTargetPortNumber.setText(portString);
962+
if (fDoStartGdbServer.getSelection()) {
963+
fTargetPortNumber.setText(fGdbServerGdbPort.getText());
964+
} else {
965+
String portString = Integer.toString(DefaultPreferences.REMOTE_PORT_NUMBER_DEFAULT); // $NON-NLS-1$
966+
fTargetPortNumber.setText(portString);
967+
}
917968
}
918969

919970
doStartGdbServerChanged();
@@ -1112,31 +1163,17 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) {
11121163
}
11131164

11141165
{
1115-
if (fDoStartGdbServer.getSelection()) {
1116-
configuration.setAttribute(IGDBJtagConstants.ATTR_IP_ADDRESS, "localhost");
1117-
1118-
String str = fGdbServerGdbPort.getText().trim();
1119-
if (!str.isEmpty()) {
1120-
try {
1121-
int port;
1122-
port = Integer.parseInt(str);
1123-
configuration.setAttribute(IGDBJtagConstants.ATTR_PORT_NUMBER, port);
1124-
} catch (NumberFormatException e) {
1125-
Activator.log(e);
1126-
}
1127-
}
1128-
} else {
1129-
String ip = fTargetIpAddress.getText().trim();
1130-
configuration.setAttribute(IGDBJtagConstants.ATTR_IP_ADDRESS, ip);
1131-
1132-
String str = fTargetPortNumber.getText().trim();
1133-
if (!str.isEmpty()) {
1134-
try {
1135-
int port = Integer.valueOf(str).intValue();
1136-
configuration.setAttribute(IGDBJtagConstants.ATTR_PORT_NUMBER, port);
1137-
} catch (NumberFormatException e) {
1138-
Activator.log(e);
1139-
}
1166+
1167+
String ip = fTargetIpAddress.getText().trim();
1168+
configuration.setAttribute(IGDBJtagConstants.ATTR_IP_ADDRESS, ip);
1169+
1170+
String str = fTargetPortNumber.getText().trim();
1171+
if (!str.isEmpty()) {
1172+
try {
1173+
int port = Integer.valueOf(str).intValue();
1174+
configuration.setAttribute(IGDBJtagConstants.ATTR_PORT_NUMBER, port);
1175+
} catch (NumberFormatException e) {
1176+
Activator.log(e);
11401177
}
11411178
}
11421179
}

plugins/org.eclipse.embedcdt.debug.gdbjtag.openocd.ui/src/org/eclipse/embedcdt/internal/debug/gdbjtag/openocd/ui/messages.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ remotetimeout 20'.
135135

136136
DebuggerTab.remoteGroup_Text=Remote Target
137137
DebuggerTab.ipAddressLabel=Host name or IP address:
138+
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.
138139
DebuggerTab.portNumberLabel=Port number:
140+
DebuggerTab.portNumberWarningDecoration=The supplied port number does not match the port OpenOCD is listening on. Click the warning to restore the default.
139141

140142

141143
DebuggerTab.update_thread_list_on_suspend_Text=Force thread list update on suspend

0 commit comments

Comments
 (0)