From ede128eb5b1631c880838ec379a551b6162a981c Mon Sep 17 00:00:00 2001 From: Zegang Zhang <116530487@qq.com> Date: Mon, 19 May 2025 16:37:12 +0800 Subject: [PATCH] Add connect to running target feature in OpenCD debug configuration and modify an effect bug of connect to running target in jlink --- .../debug/gdbjtag/jlink/ui/TabDebugger.java | 2 + .../debug/gdbjtag/jlink/ui/TabStartup.java | 3 + .../openocd/core/ConfigurationAttributes.java | 2 + .../openocd/core/dsf/DebuggerCommands.java | 61 ++++++++++------- .../core/preferences/DefaultPreferences.java | 1 + .../debug/gdbjtag/openocd/ui/TabDebugger.java | 65 +++++++++++++++++-- .../debug/gdbjtag/openocd/ui/TabStartup.java | 17 +++++ 7 files changed, 121 insertions(+), 30 deletions(-) diff --git a/plugins/org.eclipse.embedcdt.debug.gdbjtag.jlink.ui/src/org/eclipse/embedcdt/debug/gdbjtag/jlink/ui/TabDebugger.java b/plugins/org.eclipse.embedcdt.debug.gdbjtag.jlink.ui/src/org/eclipse/embedcdt/debug/gdbjtag/jlink/ui/TabDebugger.java index 9a8769e24..420eede69 100644 --- a/plugins/org.eclipse.embedcdt.debug.gdbjtag.jlink.ui/src/org/eclipse/embedcdt/debug/gdbjtag/jlink/ui/TabDebugger.java +++ b/plugins/org.eclipse.embedcdt.debug.gdbjtag.jlink.ui/src/org/eclipse/embedcdt/debug/gdbjtag/jlink/ui/TabDebugger.java @@ -1211,6 +1211,8 @@ private void propagateConnectToRunningChanged() { boolean enabled = fDoConnectToRunning.getSelection(); fDoGdbServerInitRegs.setEnabled(!enabled); + + fTabStartup.doConnectToRunningChanged(!enabled); } } diff --git a/plugins/org.eclipse.embedcdt.debug.gdbjtag.jlink.ui/src/org/eclipse/embedcdt/debug/gdbjtag/jlink/ui/TabStartup.java b/plugins/org.eclipse.embedcdt.debug.gdbjtag.jlink.ui/src/org/eclipse/embedcdt/debug/gdbjtag/jlink/ui/TabStartup.java index 15e995cef..cd94cd2af 100644 --- a/plugins/org.eclipse.embedcdt.debug.gdbjtag.jlink.ui/src/org/eclipse/embedcdt/debug/gdbjtag/jlink/ui/TabStartup.java +++ b/plugins/org.eclipse.embedcdt.debug.gdbjtag.jlink.ui/src/org/eclipse/embedcdt/debug/gdbjtag/jlink/ui/TabStartup.java @@ -1339,6 +1339,9 @@ public void initializeFrom(ILaunchConfiguration configuration) { updateUseFileEnablement(); + doConnectToRunningChanged(configuration.getAttribute(ConfigurationAttributes.DO_CONNECT_TO_RUNNING, + DefaultPreferences.DO_CONNECT_TO_RUNNING_DEFAULT)); + } catch (CoreException e) { Activator.log(e.getStatus()); } diff --git a/plugins/org.eclipse.embedcdt.debug.gdbjtag.openocd.core/src/org/eclipse/embedcdt/debug/gdbjtag/openocd/core/ConfigurationAttributes.java b/plugins/org.eclipse.embedcdt.debug.gdbjtag.openocd.core/src/org/eclipse/embedcdt/debug/gdbjtag/openocd/core/ConfigurationAttributes.java index 4bc95f06b..ae3b8c314 100644 --- a/plugins/org.eclipse.embedcdt.debug.gdbjtag.openocd.core/src/org/eclipse/embedcdt/debug/gdbjtag/openocd/core/ConfigurationAttributes.java +++ b/plugins/org.eclipse.embedcdt.debug.gdbjtag.openocd.core/src/org/eclipse/embedcdt/debug/gdbjtag/openocd/core/ConfigurationAttributes.java @@ -30,6 +30,8 @@ public interface ConfigurationAttributes extends org.eclipse.embedcdt.debug.gdbj public static final String DO_START_GDB_SERVER = PREFIX + ".doStartGdbServer"; //$NON-NLS-1$ + public static final String DO_CONNECT_TO_RUNNING = PREFIX + ".doConnectToRunning"; //$NON-NLS-1$ + public static final String GDB_SERVER_EXECUTABLE = PREFIX + ".gdbServerExecutable"; //$NON-NLS-1$ public static final String GDB_SERVER_CONNECTION_ADDRESS = PREFIX + ".gdbServerConnectionAddress"; //$NON-NLS-1$ diff --git a/plugins/org.eclipse.embedcdt.debug.gdbjtag.openocd.core/src/org/eclipse/embedcdt/debug/gdbjtag/openocd/core/dsf/DebuggerCommands.java b/plugins/org.eclipse.embedcdt.debug.gdbjtag.openocd.core/src/org/eclipse/embedcdt/debug/gdbjtag/openocd/core/dsf/DebuggerCommands.java index b607ba529..fc75dbdab 100644 --- a/plugins/org.eclipse.embedcdt.debug.gdbjtag.openocd.core/src/org/eclipse/embedcdt/debug/gdbjtag/openocd/core/dsf/DebuggerCommands.java +++ b/plugins/org.eclipse.embedcdt.debug.gdbjtag.openocd.core/src/org/eclipse/embedcdt/debug/gdbjtag/openocd/core/dsf/DebuggerCommands.java @@ -75,15 +75,19 @@ public IStatus addGnuMcuResetCommands(List commandsList) { return status; } - if (DebugUtils.getAttribute(fAttributes, IGDBJtagConstants.ATTR_LOAD_IMAGE, - IGDBJtagConstants.DEFAULT_LOAD_IMAGE) - && !DebugUtils.getAttribute(fAttributes, ConfigurationAttributes.DO_DEBUG_IN_RAM, - DefaultPreferences.DO_DEBUG_IN_RAM_DEFAULT)) { - - status = addLoadImageCommands(commandsList); - - if (!status.isOK()) { - return status; + boolean doConnectToRunning = DebugUtils.getAttribute(fAttributes, ConfigurationAttributes.DO_CONNECT_TO_RUNNING, + DefaultPreferences.DO_CONNECT_TO_RUNNING_DEFAULT); + if (!doConnectToRunning) { + if (DebugUtils.getAttribute(fAttributes, IGDBJtagConstants.ATTR_LOAD_IMAGE, + IGDBJtagConstants.DEFAULT_LOAD_IMAGE) + && !DebugUtils.getAttribute(fAttributes, ConfigurationAttributes.DO_DEBUG_IN_RAM, + DefaultPreferences.DO_DEBUG_IN_RAM_DEFAULT)) { + + status = addLoadImageCommands(commandsList); + + if (!status.isOK()) { + return status; + } } } @@ -93,7 +97,10 @@ public IStatus addGnuMcuResetCommands(List commandsList) { @Override public IStatus addGnuMcuStartCommands(List commandsList) { - IStatus status = addStartRestartCommands(true, commandsList); + boolean doReset = !DebugUtils.getAttribute(fAttributes, ConfigurationAttributes.DO_CONNECT_TO_RUNNING, + DefaultPreferences.DO_CONNECT_TO_RUNNING_DEFAULT); + + IStatus status = addStartRestartCommands(doReset, commandsList); if (!status.isOK()) { return status; @@ -107,18 +114,24 @@ public IStatus addGnuMcuStartCommands(List commandsList) { @Override public IStatus addFirstResetCommands(List commandsList) { - if (DebugUtils.getAttribute(fAttributes, ConfigurationAttributes.DO_FIRST_RESET, - DefaultPreferences.DO_FIRST_RESET_DEFAULT)) { + boolean noReset = DebugUtils.getAttribute(fAttributes, ConfigurationAttributes.DO_CONNECT_TO_RUNNING, + DefaultPreferences.DO_CONNECT_TO_RUNNING_DEFAULT); - String commandStr = DefaultPreferences.DO_FIRST_RESET_COMMAND; - String resetType = DebugUtils.getAttribute(fAttributes, ConfigurationAttributes.FIRST_RESET_TYPE, - DefaultPreferences.FIRST_RESET_TYPE_DEFAULT); - commandsList.add(commandStr + resetType); + if (!noReset) { + String commandStr; + if (DebugUtils.getAttribute(fAttributes, ConfigurationAttributes.DO_FIRST_RESET, + DefaultPreferences.DO_FIRST_RESET_DEFAULT)) { - // Although the manual claims that reset always does a - // halt, better issue it explicitly - commandStr = DefaultPreferences.HALT_COMMAND; - commandsList.add(commandStr); + commandStr = DefaultPreferences.DO_FIRST_RESET_COMMAND; + String resetType = DebugUtils.getAttribute(fAttributes, ConfigurationAttributes.FIRST_RESET_TYPE, + DefaultPreferences.FIRST_RESET_TYPE_DEFAULT); + commandsList.add(commandStr + resetType); + + // Although the manual claims that reset always does a + // halt, better issue it explicitly + commandStr = DefaultPreferences.HALT_COMMAND; + commandsList.add(commandStr); + } } String otherInits = DebugUtils.getAttribute(fAttributes, ConfigurationAttributes.OTHER_INIT_COMMANDS, @@ -155,17 +168,17 @@ public IStatus addStartRestartCommands(boolean doReset, List commandsLis commandStr = DefaultPreferences.HALT_COMMAND; commandsList.add(commandStr); } - } if (DebugUtils.getAttribute(fAttributes, IGDBJtagConstants.ATTR_LOAD_IMAGE, IGDBJtagConstants.DEFAULT_LOAD_IMAGE) && DebugUtils.getAttribute(fAttributes, ConfigurationAttributes.DO_DEBUG_IN_RAM, DefaultPreferences.DO_DEBUG_IN_RAM_DEFAULT)) { - IStatus status = addLoadImageCommands(commandsList); + IStatus status = addLoadImageCommands(commandsList); - if (!status.isOK()) { - return status; + if (!status.isOK()) { + return status; + } } } diff --git a/plugins/org.eclipse.embedcdt.debug.gdbjtag.openocd.core/src/org/eclipse/embedcdt/debug/gdbjtag/openocd/core/preferences/DefaultPreferences.java b/plugins/org.eclipse.embedcdt.debug.gdbjtag.openocd.core/src/org/eclipse/embedcdt/debug/gdbjtag/openocd/core/preferences/DefaultPreferences.java index ce3271a4f..536d0c67e 100644 --- a/plugins/org.eclipse.embedcdt.debug.gdbjtag.openocd.core/src/org/eclipse/embedcdt/debug/gdbjtag/openocd/core/preferences/DefaultPreferences.java +++ b/plugins/org.eclipse.embedcdt.debug.gdbjtag.openocd.core/src/org/eclipse/embedcdt/debug/gdbjtag/openocd/core/preferences/DefaultPreferences.java @@ -39,6 +39,7 @@ public class DefaultPreferences extends org.eclipse.embedcdt.debug.gdbjtag.core. // Not yet preferences public static final boolean DO_START_GDB_SERVER_DEFAULT = true; + public static final boolean DO_CONNECT_TO_RUNNING_DEFAULT = false; public static final String GDB_SERVER_CONNECTION_ADDRESS_DEFAULT = ""; public static final int GDB_SERVER_GDB_PORT_NUMBER_DEFAULT = 3333; public static final int GDB_SERVER_TELNET_PORT_NUMBER_DEFAULT = 4444; diff --git a/plugins/org.eclipse.embedcdt.debug.gdbjtag.openocd.ui/src/org/eclipse/embedcdt/debug/gdbjtag/openocd/ui/TabDebugger.java b/plugins/org.eclipse.embedcdt.debug.gdbjtag.openocd.ui/src/org/eclipse/embedcdt/debug/gdbjtag/openocd/ui/TabDebugger.java index 3f0e88aa4..5d1cc06f6 100644 --- a/plugins/org.eclipse.embedcdt.debug.gdbjtag.openocd.ui/src/org/eclipse/embedcdt/debug/gdbjtag/openocd/ui/TabDebugger.java +++ b/plugins/org.eclipse.embedcdt.debug.gdbjtag.openocd.ui/src/org/eclipse/embedcdt/debug/gdbjtag/openocd/ui/TabDebugger.java @@ -94,6 +94,8 @@ public class TabDebugger extends AbstractLaunchConfigurationTab { private Text fGdbServerOtherOptions; + private Button fDoConnectToRunning; + private Button fDoGdbServerAllocateConsole; private Button fDoGdbServerAllocateTelnetConsole; @@ -117,11 +119,13 @@ public class TabDebugger extends AbstractLaunchConfigurationTab { private DefaultPreferences fDefaultPreferences; private PersistentPreferences fPersistentPreferences; + private TabStartup fTabStartup; + // ------------------------------------------------------------------------ protected TabDebugger(TabStartup tabStartup) { super(); - + fTabStartup = tabStartup; fDefaultPreferences = Activator.getInstance().getDefaultPreferences(); fPersistentPreferences = Activator.getInstance().getPersistentPreferences(); } @@ -232,12 +236,31 @@ private void createGdbServerGroup(Composite parent) { } { - fDoStartGdbServer = new Button(comp, SWT.CHECK); - fDoStartGdbServer.setText(Messages.DebuggerTab_doStartGdbServer_Text); - fDoStartGdbServer.setToolTipText(Messages.DebuggerTab_doStartGdbServer_ToolTipText); - GridData gd = new GridData(); + + Composite local = new Composite(comp, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + layout.marginHeight = 0; + layout.marginWidth = 0; + local.setLayout(layout); + + GridData gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = ((GridLayout) comp.getLayout()).numColumns; - fDoStartGdbServer.setLayoutData(gd); + local.setLayoutData(gd); + { + fDoStartGdbServer = new Button(local, SWT.CHECK); + fDoStartGdbServer.setText(Messages.DebuggerTab_doStartGdbServer_Text); + fDoStartGdbServer.setToolTipText(Messages.DebuggerTab_doStartGdbServer_ToolTipText); + gd = new GridData(GridData.FILL_HORIZONTAL); + fDoStartGdbServer.setLayoutData(gd); + + fDoConnectToRunning = new Button(local, SWT.CHECK); + fDoConnectToRunning.setText(Messages.DebuggerTab_noReset_Text); + fDoConnectToRunning.setToolTipText(Messages.DebuggerTab_noReset_ToolTipText); + gd = new GridData(GridData.FILL_HORIZONTAL); + fDoConnectToRunning.setLayoutData(gd); + } + } { @@ -399,6 +422,16 @@ public void widgetSelected(SelectionEvent e) { } }); + fDoConnectToRunning.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + // updateLaunchConfigurationDialog(); + fTabStartup.doConnectToRunningChanged(fDoConnectToRunning.getSelection()); + + scheduleUpdateJob(); + } + }); + fGdbServerExecutable.addModifyListener(new ModifyListener() { @Override public void modifyText(ModifyEvent e) { @@ -765,6 +798,15 @@ private void doStartGdbClientChanged() { fGdbClientOtherCommands.setEnabled(enabled); } + private void propagateConnectToRunningChanged() { + + if (fDoStartGdbServer.getSelection()) { + + boolean enabled = fDoConnectToRunning.getSelection(); + fTabStartup.doConnectToRunningChanged(!enabled); + } + } + protected void updateDecorations() { if (fDoStartGdbServer.getSelection()) { if (DefaultPreferences.REMOTE_IP_ADDRESS_DEFAULT.equals(fTargetIpAddress.getText())) { @@ -804,6 +846,10 @@ public void initializeFrom(ILaunchConfiguration configuration) { fDoStartGdbServer.setSelection( configuration.getAttribute(ConfigurationAttributes.DO_START_GDB_SERVER, booleanDefault)); + fDoConnectToRunning + .setSelection(configuration.getAttribute(ConfigurationAttributes.DO_CONNECT_TO_RUNNING, + DefaultPreferences.DO_CONNECT_TO_RUNNING_DEFAULT)); + // Executable stringDefault = fPersistentPreferences.getGdbServerExecutable(); fGdbServerExecutable.setText( @@ -881,6 +927,7 @@ public void initializeFrom(ILaunchConfiguration configuration) { } doStartGdbServerChanged(); + propagateConnectToRunningChanged(); // Force thread update boolean updateThreadsOnSuspend = configuration.getAttribute( @@ -910,6 +957,8 @@ public void initializeFromDefaults() { // Start server locally fDoStartGdbServer.setSelection(DefaultPreferences.DO_START_GDB_SERVER_DEFAULT); + fDoConnectToRunning.setSelection(DefaultPreferences.DO_CONNECT_TO_RUNNING_DEFAULT); + // Executable stringDefault = fDefaultPreferences.getGdbServerExecutable(); fGdbServerExecutable.setText(stringDefault); @@ -1092,6 +1141,10 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) { configuration.setAttribute(ConfigurationAttributes.DO_START_GDB_SERVER, booleanValue); fPersistentPreferences.putGdbServerDoStart(booleanValue); + // Connect to running + configuration.setAttribute(ConfigurationAttributes.DO_CONNECT_TO_RUNNING, + fDoConnectToRunning.getSelection()); + // Executable stringValue = fGdbServerExecutable.getText().trim(); configuration.setAttribute(ConfigurationAttributes.GDB_SERVER_EXECUTABLE, stringValue); diff --git a/plugins/org.eclipse.embedcdt.debug.gdbjtag.openocd.ui/src/org/eclipse/embedcdt/debug/gdbjtag/openocd/ui/TabStartup.java b/plugins/org.eclipse.embedcdt.debug.gdbjtag.openocd.ui/src/org/eclipse/embedcdt/debug/gdbjtag/openocd/ui/TabStartup.java index 5a1a650a1..9b3045cb2 100644 --- a/plugins/org.eclipse.embedcdt.debug.gdbjtag.openocd.ui/src/org/eclipse/embedcdt/debug/gdbjtag/openocd/ui/TabStartup.java +++ b/plugins/org.eclipse.embedcdt.debug.gdbjtag.openocd.ui/src/org/eclipse/embedcdt/debug/gdbjtag/openocd/ui/TabStartup.java @@ -782,6 +782,21 @@ public void widgetSelected(SelectionEvent e) { fDoContinue.addSelectionListener(scheduleUpdateJobSelectionAdapter); } + public void doConnectToRunningChanged(boolean flag) { + + fDoFirstReset.setEnabled(!flag); + fFirstResetType.setEnabled(!flag); + + fDoSecondReset.setEnabled(!flag); + fSecondResetType.setEnabled(!flag); + fSecondResetWarning.setEnabled(!flag); + + fLoadExecutable.setEnabled(!flag); + + fSetPcRegister.setEnabled(!flag); + fPcRegister.setEnabled(!flag); + } + @Override public boolean isValid(ILaunchConfiguration launchConfig) { if (!super.isValid(launchConfig)) @@ -985,6 +1000,8 @@ public void initializeFrom(ILaunchConfiguration configuration) { pcRegisterChanged(); stopAtChanged(); updateUseFileEnablement(); + doConnectToRunningChanged(configuration.getAttribute(ConfigurationAttributes.DO_CONNECT_TO_RUNNING, + DefaultPreferences.DO_CONNECT_TO_RUNNING_DEFAULT)); } catch (CoreException e) { Activator.log(e.getStatus());