From 05ea8a4c6fa1d461da500abfa3d002693c351d51 Mon Sep 17 00:00:00 2001 From: Denys Almazov Date: Thu, 2 Nov 2023 17:06:44 +0200 Subject: [PATCH] IEP-1000 Board doesn't match the target after cancel in debug/jtag tab (#799) * fix `board doesn't match the target after cancel` * fix: added workaround to roll back target after Cancel * fix: fixing wrong default target name --- .../plugin.properties | 3 +- .../plugin.xml | 5 + .../gdbjtag/openocd/SvdPathResolver.java | 102 ++++++++ .../debug/gdbjtag/openocd/ui/Messages.java | 2 + .../debug/gdbjtag/openocd/ui/TabDebugger.java | 225 ++++++++++-------- .../gdbjtag/openocd/ui/TabSvdTarget.java | 106 +-------- .../gdbjtag/openocd/ui/messages.properties | 1 + .../serial/ui/internal/CMakeMainTab2.java | 48 +++- .../launch/serial/ui/internal/Messages.java | 1 + .../serial/ui/internal/messages.properties | 1 + .../espressif/idf/ui/LaunchBarListener.java | 39 +-- 11 files changed, 306 insertions(+), 227 deletions(-) create mode 100644 bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/SvdPathResolver.java diff --git a/bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.properties b/bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.properties index df26e541e..3b6a0ed6e 100644 --- a/bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.properties +++ b/bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.properties @@ -52,4 +52,5 @@ properties.mcu=ESP-IDF OpenOCD Path actionType.name = Heap Tracing command.name = Application Level Tracing -variable.description = Default C/C++ application (path to binaries) is determined automatically after build \ No newline at end of file +variable.description = Default C/C++ application (path to binaries) is determined automatically after build +esp_svd_path_desc = The path to the SVD file associated with the selected target will be determined before joining the debug session \ No newline at end of file diff --git a/bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml b/bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml index 5d82c459e..a7360bd8d 100644 --- a/bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml +++ b/bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml @@ -146,6 +146,11 @@ name="default_app" resolver="com.espressif.idf.debug.gdbjtag.openocd.DefaultAppResolver"> + + diff --git a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/SvdPathResolver.java b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/SvdPathResolver.java new file mode 100644 index 000000000..6e21faa92 --- /dev/null +++ b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/SvdPathResolver.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * Copyright 2023 Espressif Systems (Shanghai) PTE LTD. All rights reserved. + * Use is subject to license terms. + *******************************************************************************/ +package com.espressif.idf.debug.gdbjtag.openocd; + +import java.io.File; +import java.io.InputStream; +import java.net.URL; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.variables.IDynamicVariable; +import org.eclipse.core.variables.IDynamicVariableResolver; +import org.eclipse.embedcdt.core.EclipseUtils; +import org.eclipse.launchbar.core.ILaunchBarManager; + +import com.espressif.idf.core.IDFConstants; +import com.espressif.idf.core.build.IDFLaunchConstants; +import com.espressif.idf.core.logging.Logger; +import com.espressif.idf.core.util.StringUtil; +import com.espressif.idf.debug.gdbjtag.openocd.ui.TabSvdTarget; + +/** + * A resolver class for the esp_svd_path dynamic variable. Resolves SVD path by looking for appropriate files inside the + * plugin resources + * + * @author Denys Almazov + */ +public class SvdPathResolver implements IDynamicVariableResolver +{ + + private static final ILaunchBarManager LAUNCH_BAR_MANAGER = Activator.getService(ILaunchBarManager.class); + + public String resolveValue(IDynamicVariable variable, String argument) throws CoreException + { + String selectedTarget = StringUtil.EMPTY; + String selectedTargetPath = StringUtil.EMPTY; + try + { + selectedTarget = LAUNCH_BAR_MANAGER.getActiveLaunchTarget().getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, + StringUtil.EMPTY); + if (StringUtil.isEmpty(selectedTarget)) + return StringUtil.EMPTY; + selectedTargetPath = resolveSvdPath(selectedTarget); + } + catch (Exception e) + { + Logger.log(e); + } + return selectedTargetPath; + } + + private String resolveSvdPath(String target) throws Exception + { + URL svdUrl = Platform.getBundle(Activator.PLUGIN_ID).getResource("svd/".concat(target.concat(".svd"))); //$NON-NLS-1$ //$NON-NLS-2$ + String jarPath = new File(TabSvdTarget.class.getProtectionDomain().getCodeSource().getLocation().toURI()) + .getPath(); + String selectedTargetPath; + if (!jarPath.contains(".jar")) //$NON-NLS-1$ + selectedTargetPath = new File(FileLocator.resolve(svdUrl).toURI()).getPath(); + else + selectedTargetPath = resolveSvdPathFromJar(svdUrl, jarPath); + return selectedTargetPath; + } + + private String resolveSvdPathFromJar(URL svdUrl, String jarPath) throws Exception + { + IProject project = EclipseUtils + .getProjectByLaunchConfiguration(LAUNCH_BAR_MANAGER.getActiveLaunchConfiguration()); + IFolder svdFolder = project.getFolder(IDFConstants.BUILD_FOLDER).getFolder("svd"); //$NON-NLS-1$ + if (!svdFolder.exists()) + { + svdFolder.create(true, true, new NullProgressMonitor()); + } + IFile svdFile = project.getFolder(IDFConstants.BUILD_FOLDER).getFile(svdUrl.getPath()); + if (!svdFile.exists()) + { + try (JarFile jarFile = new JarFile(jarPath)) + { + JarEntry file = (JarEntry) jarFile.getEntry(svdUrl.getFile().substring(1)); + if (file != null) + { + InputStream inputStream = jarFile.getInputStream(file); + svdFile.create(inputStream, true, new NullProgressMonitor()); + inputStream.close(); + } + } + } + project.refreshLocal(IProject.DEPTH_INFINITE, new NullProgressMonitor()); + return svdFile.getRawLocation().toOSString(); + } + + +} diff --git a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/Messages.java b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/Messages.java index 69c458ded..deb0f4f0a 100644 --- a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/Messages.java +++ b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/Messages.java @@ -59,6 +59,8 @@ public class Messages public static String DllNotFound_ExceptionMessage; public static String TabMain_Launch_Config; + + public static String TabDebugger_SettingTargetJob; // ------------------------------------------------------------------------ static diff --git a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/TabDebugger.java b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/TabDebugger.java index 02dbd724b..77cc24a75 100644 --- a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/TabDebugger.java +++ b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/TabDebugger.java @@ -26,12 +26,17 @@ import java.io.File; import java.util.Map; +import java.util.stream.Stream; import org.eclipse.cdt.debug.gdbjtag.core.IGDBJtagConstants; import org.eclipse.cdt.debug.gdbjtag.ui.GDBJtagImages; import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; @@ -85,6 +90,7 @@ import com.espressif.idf.debug.gdbjtag.openocd.ui.properties.ProjectMcuPage; import com.espressif.idf.launch.serial.SerialFlashLaunchTargetProvider; import com.espressif.idf.launch.serial.ui.internal.NewSerialFlashTargetWizard; +import com.espressif.idf.ui.LaunchBarListener; /** * @since 7.0 @@ -94,9 +100,10 @@ public class TabDebugger extends AbstractLaunchConfigurationTab // ------------------------------------------------------------------------ - private static final String TAB_NAME = "Debugger"; - private static final String TAB_ID = Activator.PLUGIN_ID + ".ui.debuggertab"; - private static final String EMPTY_CONFIG_OPTIONS = "-s ${openocd_path}/share/openocd/scripts"; + private static final int JOB_DELAY_MS = 100; + private static final String TAB_NAME = "Debugger"; //$NON-NLS-1$ + private static final String TAB_ID = Activator.PLUGIN_ID + ".ui.debuggertab"; //$NON-NLS-1$ + private static final String EMPTY_CONFIG_OPTIONS = "-s ${openocd_path}/share/openocd/scripts"; //$NON-NLS-1$ // ------------------------------------------------------------------------ private ILaunchConfiguration fConfiguration; @@ -168,12 +175,19 @@ public Image getImage() @Override public void createControl(Composite parent) { - if (Activator.getInstance().isDebugging()) { - System.out.println("openocd.TabDebugger.createControl() "); + System.out.println("openocd.TabDebugger.createControl() "); //$NON-NLS-1$ } + LaunchBarListener.setIgnoreJtagTargetChange(true); + parent.addDisposeListener(event -> { + // TODO: find a better way to roll back target change in the launch bar when Cancel was pressed. + // We have to do like this because we don't have access to the cancel button + scheduleRevertTargetJob(); + LaunchBarListener.setIgnoreJtagTargetChange(false); + }); + if (!(parent instanceof ScrolledComposite)) { ScrolledComposite sc = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL); @@ -203,15 +217,15 @@ public void createControl(Composite parent) createRemoteControl(comp); fUpdateThreadlistOnSuspend = new Button(comp, SWT.CHECK); - fUpdateThreadlistOnSuspend.setText(Messages.getString("DebuggerTab.update_thread_list_on_suspend_Text")); + fUpdateThreadlistOnSuspend.setText(Messages.getString("DebuggerTab.update_thread_list_on_suspend_Text")); //$NON-NLS-1$ fUpdateThreadlistOnSuspend - .setToolTipText(Messages.getString("DebuggerTab.update_thread_list_on_suspend_ToolTipText")); + .setToolTipText(Messages.getString("DebuggerTab.update_thread_list_on_suspend_ToolTipText")); //$NON-NLS-1$ Link restoreDefaults; { restoreDefaults = new Link(comp, SWT.NONE); - restoreDefaults.setText(Messages.getString("DebuggerTab.restoreDefaults_Link")); - restoreDefaults.setToolTipText(Messages.getString("DebuggerTab.restoreDefaults_ToolTipText")); + restoreDefaults.setText(Messages.getString("DebuggerTab.restoreDefaults_Link")); //$NON-NLS-1$ + restoreDefaults.setToolTipText(Messages.getString("DebuggerTab.restoreDefaults_ToolTipText")); //$NON-NLS-1$ GridData gd = new GridData(); gd.grabExcessHorizontalSpace = true; @@ -242,6 +256,40 @@ public void widgetSelected(final SelectionEvent event) }); } + private void scheduleRevertTargetJob() + { + Job revertTargetJob = new Job(Messages.TabDebugger_SettingTargetJob) + { + protected IStatus run(IProgressMonitor monitor) + { + try + { + if (launchBarManager.getActiveLaunchConfiguration() == null) + { + return Status.CANCEL_STATUS; + } + String targetName = launchBarManager.getActiveLaunchConfiguration() + .getAttribute(IDFLaunchConstants.TARGET_FOR_JTAG, StringUtil.EMPTY); + if (!targetName.isEmpty()) + { + ILaunchTargetManager launchTargetManager = Activator.getService(ILaunchTargetManager.class); + ILaunchTarget selectedTarget = Stream.of(launchTargetManager.getLaunchTargets()) + .filter(target -> target.getId().contentEquals((targetName))).findFirst() + .orElseGet(() -> null); + launchBarManager.setActiveLaunchTarget(selectedTarget); + } + return Status.OK_STATUS; + } + catch (CoreException e) + { + Logger.log(e); + return Status.CANCEL_STATUS; + } + } + }; + revertTargetJob.schedule(JOB_DELAY_MS); + } + private void browseButtonSelected(String title, Text text) { FileDialog dialog = new FileDialog(getShell(), SWT.NONE); @@ -295,7 +343,7 @@ private void createGdbServerGroup(Composite parent) group.setLayout(layout); GridData gd = new GridData(GridData.FILL_HORIZONTAL); group.setLayoutData(gd); - group.setText(Messages.getString("DebuggerTab.gdbServerGroup_Text")); + group.setText(Messages.getString("DebuggerTab.gdbServerGroup_Text")); //$NON-NLS-1$ } Composite comp = new Composite(group, SWT.NONE); @@ -321,15 +369,15 @@ private void createGdbServerGroup(Composite parent) local.setLayoutData(gd); fDoStartGdbServer = new Button(local, SWT.CHECK); - fDoStartGdbServer.setText(Messages.getString("DebuggerTab.doStartGdbServer_Text")); - fDoStartGdbServer.setToolTipText(Messages.getString("DebuggerTab.doStartGdbServer_ToolTipText")); + fDoStartGdbServer.setText(Messages.getString("DebuggerTab.doStartGdbServer_Text")); //$NON-NLS-1$ + fDoStartGdbServer.setToolTipText(Messages.getString("DebuggerTab.doStartGdbServer_ToolTipText")); //$NON-NLS-1$ gd = new GridData(GridData.FILL_HORIZONTAL); fDoStartGdbServer.setLayoutData(gd); } { Label label = new Label(comp, SWT.NONE); - label.setText(Messages.getString("DebuggerTab.gdbServerExecutable_Label")); - label.setToolTipText(Messages.getString("DebuggerTab.gdbServerExecutable_ToolTipText")); + label.setText(Messages.getString("DebuggerTab.gdbServerExecutable_Label")); //$NON-NLS-1$ + label.setToolTipText(Messages.getString("DebuggerTab.gdbServerExecutable_ToolTipText")); //$NON-NLS-1$ Composite local = new Composite(comp, SWT.NONE); GridLayout layout = new GridLayout(); @@ -346,16 +394,16 @@ private void createGdbServerGroup(Composite parent) fGdbServerExecutable.setLayoutData(gd); fGdbServerBrowseButton = new Button(local, SWT.NONE); - fGdbServerBrowseButton.setText(Messages.getString("DebuggerTab.gdbServerExecutableBrowse")); + fGdbServerBrowseButton.setText(Messages.getString("DebuggerTab.gdbServerExecutableBrowse")); //$NON-NLS-1$ fGdbServerVariablesButton = new Button(local, SWT.NONE); - fGdbServerVariablesButton.setText(Messages.getString("DebuggerTab.gdbServerExecutableVariable")); + fGdbServerVariablesButton.setText(Messages.getString("DebuggerTab.gdbServerExecutableVariable")); //$NON-NLS-1$ } } { Label label = new Label(comp, SWT.NONE); - label.setText(Messages.getString("DebuggerTab.gdbServerActualPath_Label")); + label.setText(Messages.getString("DebuggerTab.gdbServerActualPath_Label")); //$NON-NLS-1$ fGdbServerPathLabel = new Text(comp, SWT.SINGLE | SWT.BORDER); GridData gd = new GridData(SWT.FILL, 0, true, false); @@ -368,10 +416,10 @@ private void createGdbServerGroup(Composite parent) { Label label = new Label(comp, SWT.NONE); - label.setText(""); + label.setText(""); //$NON-NLS-1$ fLink = new Link(comp, SWT.NONE); - fLink.setText(Messages.getString("DebuggerTab.gdbServerActualPath_link")); + fLink.setText(Messages.getString("DebuggerTab.gdbServerActualPath_link")); //$NON-NLS-1$ GridData gd = new GridData(); gd.horizontalSpan = 4; fLink.setLayoutData(gd); @@ -379,8 +427,8 @@ private void createGdbServerGroup(Composite parent) { Label label = new Label(comp, SWT.NONE); - label.setText(Messages.getString("DebuggerTab.gdbServerGdbPort_Label")); - label.setToolTipText(Messages.getString("DebuggerTab.gdbServerGdbPort_ToolTipText")); + label.setText(Messages.getString("DebuggerTab.gdbServerGdbPort_Label")); //$NON-NLS-1$ + label.setToolTipText(Messages.getString("DebuggerTab.gdbServerGdbPort_ToolTipText")); //$NON-NLS-1$ fGdbServerGdbPort = new Text(comp, SWT.SINGLE | SWT.BORDER); GridData gd = new GridData(); @@ -391,8 +439,8 @@ private void createGdbServerGroup(Composite parent) { Label label = new Label(comp, SWT.NONE); - label.setText(Messages.getString("DebuggerTab.gdbServerTelnetPort_Label")); - label.setToolTipText(Messages.getString("DebuggerTab.gdbServerTelnetPort_ToolTipText")); + label.setText(Messages.getString("DebuggerTab.gdbServerTelnetPort_Label")); //$NON-NLS-1$ + label.setToolTipText(Messages.getString("DebuggerTab.gdbServerTelnetPort_ToolTipText")); //$NON-NLS-1$ fGdbServerTelnetPort = new Text(comp, SWT.SINGLE | SWT.BORDER); GridData gd = new GridData(); @@ -403,8 +451,8 @@ private void createGdbServerGroup(Composite parent) { Label label = new Label(comp, SWT.NONE); - label.setText(Messages.getString("DebuggerTab.gdbServerTclPort_Label")); - label.setToolTipText(Messages.getString("DebuggerTab.gdbServerTclPort_ToolTipText")); + label.setText(Messages.getString("DebuggerTab.gdbServerTclPort_Label")); //$NON-NLS-1$ + label.setToolTipText(Messages.getString("DebuggerTab.gdbServerTclPort_ToolTipText")); //$NON-NLS-1$ fGdbServerTclPort = new Text(comp, SWT.SINGLE | SWT.BORDER); GridData gd = new GridData(); @@ -420,8 +468,8 @@ private void createGdbServerGroup(Composite parent) { { Label label = new Label(comp, SWT.NONE); - label.setText(Messages.getString("DebuggerTab.flashVoltageLabel")); - label.setToolTipText(Messages.getString("DebuggerTab.flashVoltageToolTip")); + label.setText(Messages.getString("DebuggerTab.flashVoltageLabel")); //$NON-NLS-1$ + label.setToolTipText(Messages.getString("DebuggerTab.flashVoltageToolTip")); //$NON-NLS-1$ GridData gd = new GridData(); gd.widthHint = 80; gd.horizontalSpan = ((GridLayout) comp.getLayout()).numColumns - 1; @@ -441,8 +489,8 @@ public void widgetSelected(SelectionEvent e) } { Label label = new Label(comp, SWT.NONE); - label.setText(Messages.getString("DebuggerTab.configTargetLabel")); - label.setToolTipText(Messages.getString("DebuggerTab.configTargetToolTip")); + label.setText(Messages.getString("DebuggerTab.configTargetLabel")); //$NON-NLS-1$ + label.setToolTipText(Messages.getString("DebuggerTab.configTargetToolTip")); //$NON-NLS-1$ GridData gd = new GridData(); gd.widthHint = 80; gd.horizontalSpan = ((GridLayout) comp.getLayout()).numColumns - 1; @@ -458,18 +506,6 @@ public void widgetSelected(SelectionEvent e) String selectedItem = fTarget.getText(); if (!selectedItem.contentEquals(updatedSelectedTarget)) { - try - { - ILaunchConfigurationWorkingCopy wc = launchBarManager.getActiveLaunchConfiguration() - .getWorkingCopy(); - wc.setAttribute(IDFLaunchConstants.TARGET_FOR_JTAG, selectedItem); - TabSvdTarget.updateSvd(selectedItem, wc); - wc.doSave(); - } - catch (CoreException e1) - { - Logger.log(e1); - } updateLaunchBar(selectedItem); } fGdbClientExecutable.setText(IDFUtil.getXtensaToolchainExecutablePathByTarget(selectedItem)); @@ -531,8 +567,8 @@ private ILaunchTarget findSuitableTargetForSelectedItem(String selectedItem) } { Label label = new Label(comp, SWT.NONE); - label.setText(Messages.getString("DebuggerTab.configBoardLabel")); - label.setToolTipText(Messages.getString("DebuggerTab.configBoardTooTip")); + label.setText(Messages.getString("DebuggerTab.configBoardLabel")); //$NON-NLS-1$ + label.setToolTipText(Messages.getString("DebuggerTab.configBoardTooTip")); //$NON-NLS-1$ GridData gd = new GridData(); gd.widthHint = 250; @@ -576,7 +612,7 @@ public void widgetSelected(SelectionEvent e) { Label label = new Label(comp, SWT.NONE); label.setText(Messages.getString("DebuggerTab.gdbServerOther_Label")); //$NON-NLS-1$ - label.setToolTipText(Messages.getString("DebuggerTab.gdbServerOther_ToolTipText")); + label.setToolTipText(Messages.getString("DebuggerTab.gdbServerOther_ToolTipText")); //$NON-NLS-1$ GridData gd = new GridData(); gd.verticalAlignment = SWT.TOP; label.setLayoutData(gd); @@ -601,17 +637,17 @@ public void widgetSelected(SelectionEvent e) local.setLayoutData(gd); fDoGdbServerAllocateConsole = new Button(local, SWT.CHECK); - fDoGdbServerAllocateConsole.setText(Messages.getString("DebuggerTab.gdbServerAllocateConsole_Label")); + fDoGdbServerAllocateConsole.setText(Messages.getString("DebuggerTab.gdbServerAllocateConsole_Label")); //$NON-NLS-1$ fDoGdbServerAllocateConsole - .setToolTipText(Messages.getString("DebuggerTab.gdbServerAllocateConsole_ToolTipText")); + .setToolTipText(Messages.getString("DebuggerTab.gdbServerAllocateConsole_ToolTipText")); //$NON-NLS-1$ gd = new GridData(GridData.FILL_HORIZONTAL); fDoGdbServerAllocateConsole.setLayoutData(gd); fDoGdbServerAllocateTelnetConsole = new Button(local, SWT.CHECK); fDoGdbServerAllocateTelnetConsole - .setText(Messages.getString("DebuggerTab.gdbServerAllocateTelnetConsole_Label")); + .setText(Messages.getString("DebuggerTab.gdbServerAllocateTelnetConsole_Label")); //$NON-NLS-1$ fDoGdbServerAllocateTelnetConsole - .setToolTipText(Messages.getString("DebuggerTab.gdbServerAllocateTelnetConsole_ToolTipText")); + .setToolTipText(Messages.getString("DebuggerTab.gdbServerAllocateTelnetConsole_ToolTipText")); //$NON-NLS-1$ gd = new GridData(GridData.FILL_HORIZONTAL); fDoGdbServerAllocateTelnetConsole.setLayoutData(gd); @@ -670,7 +706,7 @@ public void modifyText(ModifyEvent e) @Override public void widgetSelected(SelectionEvent e) { - browseButtonSelected(Messages.getString("DebuggerTab.gdbServerExecutableBrowse_Title"), + browseButtonSelected(Messages.getString("DebuggerTab.gdbServerExecutableBrowse_Title"), //$NON-NLS-1$ fGdbServerExecutable); } }); @@ -697,17 +733,17 @@ public void widgetSelected(SelectionEvent e) } int ret = -1; - if ("global".equals(text)) + if ("global".equals(text)) //$NON-NLS-1$ { ret = PreferencesUtil.createPreferenceDialogOn(parent.getShell(), GlobalMcuPage.ID, null, null) .open(); } - else if ("workspace".equals(text)) + else if ("workspace".equals(text)) //$NON-NLS-1$ { ret = PreferencesUtil.createPreferenceDialogOn(parent.getShell(), WorkspaceMcuPage.ID, null, null) .open(); } - else if ("project".equals(text)) + else if ("project".equals(text)) //$NON-NLS-1$ { assert (fConfiguration != null); IProject project = EclipseUtils.getProjectByLaunchConfiguration(fConfiguration); @@ -769,7 +805,7 @@ private void createGdbClientControls(Composite parent) group.setLayout(layout); GridData gd = new GridData(GridData.FILL_HORIZONTAL); group.setLayoutData(gd); - group.setText(Messages.getString("DebuggerTab.gdbSetupGroup_Text")); + group.setText(Messages.getString("DebuggerTab.gdbSetupGroup_Text")); //$NON-NLS-1$ } Composite comp = new Composite(group, SWT.NONE); @@ -784,8 +820,8 @@ private void createGdbClientControls(Composite parent) { fDoStartGdbClient = new Button(comp, SWT.CHECK); - fDoStartGdbClient.setText(Messages.getString("DebuggerTab.doStartGdbClient_Text")); - fDoStartGdbClient.setToolTipText(Messages.getString("DebuggerTab.doStartGdbClient_ToolTipText")); + fDoStartGdbClient.setText(Messages.getString("DebuggerTab.doStartGdbClient_Text")); //$NON-NLS-1$ + fDoStartGdbClient.setToolTipText(Messages.getString("DebuggerTab.doStartGdbClient_ToolTipText")); //$NON-NLS-1$ GridData gd = new GridData(); gd.horizontalSpan = ((GridLayout) comp.getLayout()).numColumns; fDoStartGdbClient.setLayoutData(gd); @@ -793,8 +829,8 @@ private void createGdbClientControls(Composite parent) { Label label = new Label(comp, SWT.NONE); - label.setText(Messages.getString("DebuggerTab.gdbCommand_Label")); - label.setToolTipText(Messages.getString("DebuggerTab.gdbCommand_ToolTipText")); + label.setText(Messages.getString("DebuggerTab.gdbCommand_Label")); //$NON-NLS-1$ + label.setToolTipText(Messages.getString("DebuggerTab.gdbCommand_ToolTipText")); //$NON-NLS-1$ Composite local = new Composite(comp, SWT.NONE); GridLayout layout = new GridLayout(); @@ -811,17 +847,17 @@ private void createGdbClientControls(Composite parent) fGdbClientExecutable.setLayoutData(gd); fGdbClientBrowseButton = new Button(local, SWT.NONE); - fGdbClientBrowseButton.setText(Messages.getString("DebuggerTab.gdbCommandBrowse")); + fGdbClientBrowseButton.setText(Messages.getString("DebuggerTab.gdbCommandBrowse")); //$NON-NLS-1$ fGdbClientVariablesButton = new Button(local, SWT.NONE); - fGdbClientVariablesButton.setText(Messages.getString("DebuggerTab.gdbCommandVariable")); + fGdbClientVariablesButton.setText(Messages.getString("DebuggerTab.gdbCommandVariable")); //$NON-NLS-1$ } } { Label label = new Label(comp, SWT.NONE); - label.setText(Messages.getString("DebuggerTab.gdbOtherOptions_Label")); - label.setToolTipText(Messages.getString("DebuggerTab.gdbOtherOptions_ToolTipText")); + label.setText(Messages.getString("DebuggerTab.gdbOtherOptions_Label")); //$NON-NLS-1$ + label.setToolTipText(Messages.getString("DebuggerTab.gdbOtherOptions_ToolTipText")); //$NON-NLS-1$ GridData gd = new GridData(); label.setLayoutData(gd); @@ -833,8 +869,8 @@ private void createGdbClientControls(Composite parent) { Label label = new Label(comp, SWT.NONE); - label.setText(Messages.getString("DebuggerTab.gdbOtherCommands_Label")); - label.setToolTipText(Messages.getString("DebuggerTab.gdbOtherCommands_ToolTipText")); + label.setText(Messages.getString("DebuggerTab.gdbOtherCommands_Label")); //$NON-NLS-1$ + label.setToolTipText(Messages.getString("DebuggerTab.gdbOtherCommands_ToolTipText")); //$NON-NLS-1$ GridData gd = new GridData(); gd.verticalAlignment = SWT.TOP; label.setLayoutData(gd); @@ -893,7 +929,7 @@ public void modifyText(ModifyEvent e) @Override public void widgetSelected(SelectionEvent e) { - browseButtonSelected(Messages.getString("DebuggerTab.gdbCommandBrowse_Title"), fGdbClientExecutable); + browseButtonSelected(Messages.getString("DebuggerTab.gdbCommandBrowse_Title"), fGdbClientExecutable); //$NON-NLS-1$ } }); @@ -912,7 +948,7 @@ private void createRemoteControl(Composite parent) Group group = new Group(parent, SWT.NONE); { - group.setText(Messages.getString("DebuggerTab.remoteGroup_Text")); + group.setText(Messages.getString("DebuggerTab.remoteGroup_Text")); //$NON-NLS-1$ GridLayout layout = new GridLayout(); group.setLayout(layout); GridData gd = new GridData(GridData.FILL_HORIZONTAL); @@ -986,7 +1022,7 @@ private void updateGdbServerActualPath() String fullCommand = Configuration.getGdbServerCommand(fConfiguration, fGdbServerExecutable.getText()); if (Activator.getInstance().isDebugging()) { - System.out.println("openocd.TabDebugger.updateGdbServerActualPath() \"" + fullCommand + "\""); + System.out.println("openocd.TabDebugger.updateGdbServerActualPath() \"" + fullCommand + "\""); //$NON-NLS-1$ //$NON-NLS-2$ } fGdbServerPathLabel.setText(fullCommand); } @@ -998,7 +1034,7 @@ private void updateGdbClientActualPath() String fullCommand = Configuration.getGdbClientCommand(fConfiguration, fGdbClientExecutable.getText()); if (Activator.getInstance().isDebugging()) { - System.out.println("openocd.TabDebugger.updateGdbClientActualPath() \"" + fullCommand + "\""); + System.out.println("openocd.TabDebugger.updateGdbClientActualPath() \"" + fullCommand + "\""); //$NON-NLS-1$ //$NON-NLS-2$ } // fGdbClientPathLabel.setText(fullCommand); } @@ -1053,7 +1089,7 @@ public void initializeFrom(ILaunchConfiguration configuration) if (Activator.getInstance().isDebugging()) { - System.out.println("openocd.TabDebugger.initializeFrom() " + configuration.getName()); + System.out.println("openocd.TabDebugger.initializeFrom() " + configuration.getName()); //$NON-NLS-1$ } fConfiguration = configuration; @@ -1177,7 +1213,7 @@ public void initializeFrom(ILaunchConfiguration configuration) if (Activator.getInstance().isDebugging()) { - System.out.println("openocd.TabDebugger.initializeFrom() completed " + configuration.getName()); + System.out.println("openocd.TabDebugger.initializeFrom() completed " + configuration.getName()); //$NON-NLS-1$ } } @@ -1186,7 +1222,7 @@ public void initializeFromDefaults() if (Activator.getInstance().isDebugging()) { - System.out.println("openocd.TabDebugger.initializeFromDefaults()"); + System.out.println("openocd.TabDebugger.initializeFromDefaults()"); //$NON-NLS-1$ } String stringDefault; @@ -1268,7 +1304,7 @@ public void activated(ILaunchConfigurationWorkingCopy workingCopy) { if (Activator.getInstance().isDebugging()) { - System.out.println("openocd.TabDebugger.activated() " + workingCopy.getName()); + System.out.println("openocd.TabDebugger.activated() " + workingCopy.getName()); //$NON-NLS-1$ } } @@ -1277,7 +1313,7 @@ public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) { if (Activator.getInstance().isDebugging()) { - System.out.println("openocd.TabDebugger.deactivated() " + workingCopy.getName()); + System.out.println("openocd.TabDebugger.deactivated() " + workingCopy.getName()); //$NON-NLS-1$ } } @@ -1286,7 +1322,7 @@ public boolean isValid(ILaunchConfiguration launchConfig) { if (Activator.getInstance().isDebugging()) { - System.out.println("openocd.TabDebugger.isValid() " + launchConfig.getName()); + System.out.println("openocd.TabDebugger.isValid() " + launchConfig.getName()); //$NON-NLS-1$ } setErrorMessage(null); @@ -1301,25 +1337,25 @@ public boolean isValid(ILaunchConfiguration launchConfig) hasContent = true; if (fGdbServerExecutable != null && fGdbServerExecutable.getText().trim().isEmpty()) { - setErrorMessage("GDB server executable path?"); + setErrorMessage("GDB server executable path?"); //$NON-NLS-1$ result = false; } if (fGdbServerGdbPort != null && fGdbServerGdbPort.getText().trim().isEmpty()) { - setErrorMessage("GDB port?"); + setErrorMessage("GDB port?"); //$NON-NLS-1$ result = false; } if (fGdbServerTelnetPort != null && fGdbServerTelnetPort.getText().trim().isEmpty()) { - setErrorMessage("Telnet port?"); + setErrorMessage("Telnet port?"); //$NON-NLS-1$ result = false; } if (fGdbServerTclPort != null && fGdbServerTclPort.getText().trim().isEmpty()) { - setErrorMessage("Tcl port?"); + setErrorMessage("Tcl port?"); //$NON-NLS-1$ result = false; } } @@ -1331,13 +1367,13 @@ public boolean isValid(ILaunchConfiguration launchConfig) if (fGdbClientExecutable != null && fGdbClientExecutable.getText().trim().isEmpty()) { result = false; - setErrorMessage("GDB client executable name?"); + setErrorMessage("GDB client executable name?"); //$NON-NLS-1$ } } if (Activator.getInstance().isDebugging()) { - System.out.println("openocd.TabDebugger.isValid() " + launchConfig.getName() + " = " + result); + System.out.println("openocd.TabDebugger.isValid() " + launchConfig.getName() + " = " + result); //$NON-NLS-1$ //$NON-NLS-2$ } return hasContent && result; } @@ -1378,7 +1414,7 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) if (Activator.getInstance().isDebugging()) { System.out - .println("openocd.TabDebugger.performApply() " + configuration.getName() + ", dirty=" + isDirty()); + .println("openocd.TabDebugger.performApply() " + configuration.getName() + ", dirty=" + isDirty()); //$NON-NLS-1$ //$NON-NLS-2$ } { @@ -1411,7 +1447,7 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) } else { - Activator.log("empty fGdbServerGdbPort"); + Activator.log("empty fGdbServerGdbPort"); //$NON-NLS-1$ } if (!fGdbServerTelnetPort.getText().trim().isEmpty()) { @@ -1420,7 +1456,7 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) } else { - Activator.log("empty fGdbServerTelnetPort"); + Activator.log("empty fGdbServerTelnetPort"); //$NON-NLS-1$ } if (!fGdbServerTclPort.getText().trim().isEmpty()) { @@ -1430,7 +1466,7 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) } else { - Activator.log("empty fGdbServerTclPort"); + Activator.log("empty fGdbServerTclPort"); //$NON-NLS-1$ } // Other options @@ -1472,7 +1508,7 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) { if (fDoStartGdbServer.getSelection()) { - configuration.setAttribute(IGDBJtagConstants.ATTR_IP_ADDRESS, "localhost"); + configuration.setAttribute(IGDBJtagConstants.ATTR_IP_ADDRESS, "localhost"); //$NON-NLS-1$ String str = fGdbServerGdbPort.getText().trim(); if (!str.isEmpty()) @@ -1513,19 +1549,9 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) // JTAG options if (fFlashVoltage != null && fTarget != null && fTargetName != null) { - try - { - ILaunchConfigurationWorkingCopy wc = configuration.getWorkingCopy(); - wc.setAttribute(IDFLaunchConstants.JTAG_FLASH_VOLTAGE, fFlashVoltage.getText()); - wc.setAttribute(IDFLaunchConstants.TARGET_FOR_JTAG, fTarget.getText()); - wc.setAttribute(IDFLaunchConstants.JTAG_BOARD, fTargetName.getText()); - wc.doSave(); - } - catch (CoreException e) - { - Logger.log(e); - } - + configuration.setAttribute(IDFLaunchConstants.JTAG_FLASH_VOLTAGE, fFlashVoltage.getText()); + configuration.setAttribute(IDFLaunchConstants.TARGET_FOR_JTAG, fTarget.getText()); + configuration.setAttribute(IDFLaunchConstants.JTAG_BOARD, fTargetName.getText()); } // Force thread update @@ -1537,7 +1563,7 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) if (Activator.getInstance().isDebugging()) { System.out.println( - "openocd.TabDebugger.performApply() completed " + configuration.getName() + ", dirty=" + isDirty()); + "openocd.TabDebugger.performApply() completed " + configuration.getName() + ", dirty=" + isDirty()); //$NON-NLS-1$ //$NON-NLS-2$ } } @@ -1547,7 +1573,7 @@ public void setDefaults(ILaunchConfigurationWorkingCopy configuration) if (Activator.getInstance().isDebugging()) { - System.out.println("openocd.TabDebugger.setDefaults() " + configuration.getName()); + System.out.println("openocd.TabDebugger.setDefaults() " + configuration.getName()); //$NON-NLS-1$ } configuration.setAttribute(IGDBJtagConstants.ATTR_JTAG_DEVICE_ID, ConfigurationAttributes.JTAG_DEVICE); @@ -1639,4 +1665,5 @@ private String getGdbClientExecutable(ILaunchConfiguration configuration) } // ------------------------------------------------------------------------ + } diff --git a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/TabSvdTarget.java b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/TabSvdTarget.java index c03a65d88..23a20c4b6 100644 --- a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/TabSvdTarget.java +++ b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/TabSvdTarget.java @@ -4,29 +4,10 @@ *******************************************************************************/ package com.espressif.idf.debug.gdbjtag.openocd.ui; -import java.io.File; -import java.io.InputStream; -import java.net.URL; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Platform; -import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.core.variables.VariablesPlugin; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; -import org.eclipse.embedcdt.core.EclipseUtils; +import org.eclipse.embedcdt.debug.gdbjtag.core.ConfigurationAttributes; import org.eclipse.embedcdt.debug.gdbjtag.ui.TabSvd; -import org.eclipse.launchbar.core.ILaunchBarManager; - -import com.espressif.idf.core.IDFConstants; -import com.espressif.idf.core.build.IDFLaunchConstants; -import com.espressif.idf.core.logging.Logger; -import com.espressif.idf.core.util.StringUtil; -import com.espressif.idf.debug.gdbjtag.openocd.Activator; /** * Svd target class for loading the svd files from the plugin directly @@ -36,87 +17,14 @@ */ public class TabSvdTarget extends TabSvd { - public TabSvdTarget() - { - super(); - } + private static final String ESP_SVD_PATH = "esp_svd_path"; //$NON-NLS-1$ @Override - public void initializeFrom(ILaunchConfiguration configuration) + public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { - String selectedTarget = StringUtil.EMPTY; - try - { - ILaunchConfigurationWorkingCopy wc = configuration.getWorkingCopy(); - selectedTarget = wc.getAttribute(IDFLaunchConstants.TARGET_FOR_JTAG, StringUtil.EMPTY); - if (StringUtil.isEmpty(selectedTarget)) - { - selectedTarget = Activator.getService(ILaunchBarManager.class).getActiveLaunchTarget() - .getAttribute(IDFLaunchConstants.ATTR_IDF_TARGET, StringUtil.EMPTY); - } - updateSvd(selectedTarget, wc); - wc.doSave(); - } - catch (Exception e) - { - Logger.log(e); - } - - super.initializeFrom(configuration); + configuration.setAttribute(ConfigurationAttributes.SVD_PATH, + VariablesPlugin.getDefault().getStringVariableManager().generateVariableExpression(ESP_SVD_PATH, null)); + super.setDefaults(configuration); } - public static void updateSvd(String selectedTarget, ILaunchConfigurationWorkingCopy wc) - { - try - { - if (StringUtil.isEmpty(selectedTarget)) - return; - URL svdUrl = Platform.getBundle(Activator.PLUGIN_ID) - .getResource("svd/".concat(selectedTarget.concat(".svd"))); //$NON-NLS-1$ //$NON-NLS-2$ - String jarPath = new File(TabSvdTarget.class.getProtectionDomain().getCodeSource().getLocation().toURI()) - .getPath(); - String selectedTargetPath = StringUtil.EMPTY; - if (!jarPath.contains(".jar")) //$NON-NLS-1$ - { - selectedTargetPath = new File(FileLocator.resolve(svdUrl).toURI()).getPath(); - } - else - { - IProject project = EclipseUtils.getProjectByLaunchConfiguration(wc); - IFolder svdFolder = project.getFolder(IDFConstants.BUILD_FOLDER).getFolder("svd"); //$NON-NLS-1$ - if (!svdFolder.exists()) - { - svdFolder.create(true, true, new NullProgressMonitor()); - } - IFile svdFile = project.getFolder(IDFConstants.BUILD_FOLDER).getFile(svdUrl.getPath()); - if (!svdFile.exists()) - { - JarFile jarFile = new JarFile(jarPath); - JarEntry file = (JarEntry) jarFile.getEntry(svdUrl.getFile().substring(1)); - if (file != null) - { - InputStream inputStream = jarFile.getInputStream(file); - svdFile.create(inputStream, true, new NullProgressMonitor()); - inputStream.close(); - } - jarFile.close(); - } - project.refreshLocal(IProject.DEPTH_INFINITE, new NullProgressMonitor()); - selectedTargetPath = svdFile.getRawLocation().toOSString(); - } - - String currentSvdPath = wc.getAttribute( - org.eclipse.embedcdt.debug.gdbjtag.core.ConfigurationAttributes.SVD_PATH, StringUtil.EMPTY); - if (StringUtil.isEmpty(currentSvdPath) || !currentSvdPath.equals(selectedTargetPath)) - { - wc.setAttribute(org.eclipse.embedcdt.debug.gdbjtag.core.ConfigurationAttributes.SVD_PATH, - selectedTargetPath); - } - } - catch (Exception e) - { - selectedTarget = StringUtil.EMPTY; - Logger.log(e); - } - } } diff --git a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/messages.properties b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/messages.properties index 3c4b9a762..4cdff68d6 100644 --- a/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/messages.properties +++ b/bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/ui/messages.properties @@ -399,4 +399,5 @@ DebugConfigurationNotFoundMsg=No matching debug configuration was found for the AppLvlTracingJob=Launching application level tracing DllNotFound_ExceptionMessage=some required DLL(s) not found +TabDebugger_SettingTargetJob=Setting a target in launch bar... TabMain_Launch_Config=Launch Configuration: diff --git a/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/CMakeMainTab2.java b/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/CMakeMainTab2.java index dd61da8d0..f0e6eba93 100644 --- a/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/CMakeMainTab2.java +++ b/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/CMakeMainTab2.java @@ -38,6 +38,10 @@ import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.variables.VariablesPlugin; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; @@ -81,6 +85,7 @@ @SuppressWarnings("restriction") public class CMakeMainTab2 extends GenericMainTab { + private static final int JOB_DELAY_MS = 100; private static final String EMPTY_CONFIG_OPTIONS = "%s" + File.separator + "%s -s %s"; //$NON-NLS-1$ //$NON-NLS-2$ private Combo flashOverComboButton; private Combo fFlashVoltage; @@ -113,7 +118,10 @@ public static String[] getNames() { @Override public void createControl(Composite parent) { LaunchBarListener.setIgnoreJtagTargetChange(true); - parent.addDisposeListener(e -> LaunchBarListener.setIgnoreJtagTargetChange(false)); + parent.addDisposeListener(event -> { + scheduleRevertTargetJob(); + LaunchBarListener.setIgnoreJtagTargetChange(false); + }); mainComposite = new Composite(parent, SWT.NONE); mainComposite.setFont(parent.getFont()); @@ -559,7 +567,6 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) { wc.setAttribute(IDFLaunchConstants.ATTR_JTAG_FLASH_ARGUMENTS, jtagArgumentsField.getText()); wc.setAttribute(IDFLaunchConstants.ATTR_SERIAL_FLASH_ARGUMENTS, uartAgrumentsField.getText()); wc.setAttribute(IDFLaunchConstants.ATTR_DFU_FLASH_ARGUMENTS, dfuArgumentsField.getText()); - wc.doSave(); } catch (CoreException e) { Logger.log(e); @@ -705,14 +712,6 @@ public void widgetSelected(SelectionEvent e) { } if (!selectedItem.contentEquals(updatedSelectedTarget) && isFlashOverJtag) { - try { - ILaunchConfigurationWorkingCopy wc = launchBarManager.getActiveLaunchConfiguration() - .getWorkingCopy(); - wc.setAttribute(IDFLaunchConstants.TARGET_FOR_JTAG, selectedItem); - wc.doSave(); - } catch (CoreException e2) { - Logger.log(e2); - } updateLaunchBar(selectedItem); } boardConfigsMap = parser.getBoardsConfigs(selectedItem); @@ -856,4 +855,33 @@ protected void updateWorkingDirectory(ILaunchConfiguration configuration) { } } } + + private void scheduleRevertTargetJob() { + Job revertTargetJob = new Job(Messages.CMakeMainTab2_SettingTargetJob) { + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + if (launchBarManager.getActiveLaunchConfiguration() == null) { + return Status.CANCEL_STATUS; + } + + String targetName = launchBarManager.getActiveLaunchConfiguration() + .getAttribute(IDFLaunchConstants.TARGET_FOR_JTAG, StringUtil.EMPTY); + if (!targetName.isEmpty()) { + ILaunchTargetManager launchTargetManager = Activator.getService(ILaunchTargetManager.class); + ILaunchTarget selectedTarget = Stream.of(launchTargetManager.getLaunchTargets()) + .filter(target -> target.getId().contentEquals((targetName))).findFirst() + .orElseGet(() -> null); + launchBarManager.setActiveLaunchTarget(selectedTarget); + } + + return Status.OK_STATUS; + } catch (CoreException e) { + Logger.log(e); + return Status.CANCEL_STATUS; + } + } + }; + revertTargetJob.schedule(JOB_DELAY_MS); + } } diff --git a/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/Messages.java b/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/Messages.java index ba8cf3c94..145ab23f3 100644 --- a/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/Messages.java +++ b/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/Messages.java @@ -42,6 +42,7 @@ public class Messages extends NLS { public static String configBoardTooTip; public static String CMakeMainTab2_OpeonOcdSetupGroupTitle; public static String CMakeMainTab2_JtagFlashingNotSupportedMsg; + public static String CMakeMainTab2_SettingTargetJob; public static String IDFLaunchTargetNotFoundMsg1; public static String IDFLaunchTargetNotFoundMsg2; public static String IDFLaunchTargetNotFoundIDFLaunchTargetNotFoundTitle; diff --git a/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/messages.properties b/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/messages.properties index 0a083edcd..881d23440 100644 --- a/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/messages.properties +++ b/bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/messages.properties @@ -31,6 +31,7 @@ configBoardLabel=Board: configBoardTooTip=Select a board based on ESP target CMakeMainTab2_OpeonOcdSetupGroupTitle=OpenOCD Setup: CMakeMainTab2_JtagFlashingNotSupportedMsg=(JTAG flash functionality isn't available, please update OpenOCD. The minimum required version is v0.10.0-esp32-20210401) +CMakeMainTab2_SettingTargetJob=Setting a target in launch bar... IDFLaunchTargetNotFoundMsg1=IDF Launch Target with IDFLaunchTargetNotFoundMsg2=\ is not found. diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java index 7b867ce9b..29942d607 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java @@ -41,24 +41,21 @@ public static void setIgnoreJtagTargetChange(boolean status) { jtagIgnored = status; } + @Override public void activeLaunchTargetChanged(ILaunchTarget target) { - Display.getDefault().asyncExec(new Runnable() + Display.getDefault().asyncExec(() -> { - - @Override - public void run() - { if (target != null) { - String targetName = target.getAttribute("com.espressif.idf.launch.serial.core.idfTarget", ""); //$NON-NLS-1$ + String targetName = target.getAttribute("com.espressif.idf.launch.serial.core.idfTarget", //$NON-NLS-1$ + StringUtil.EMPTY); if (!StringUtil.isEmpty(targetName)) { update(targetName); } } - } }); } @@ -70,11 +67,13 @@ private void update(String newTarget) { ILaunchBarManager launchBarManager = IDFCorePlugin.getService(ILaunchBarManager.class); ILaunchConfiguration activeConfig = launchBarManager.getActiveLaunchConfiguration(); - if (activeConfig == null) { + if (activeConfig == null) + { return; } - - String projectName = activeConfig.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""); //$NON-NLS-1$ + + String projectName = activeConfig.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, + StringUtil.EMPTY); if (projectName.isEmpty()) { ILaunchDescriptor activeLaunchDescriptor = launchBarManager.getActiveLaunchDescriptor(); @@ -98,25 +97,29 @@ private void update(String newTarget) { // get current target String currentTarget = new SDKConfigJsonReader((IProject) project).getValue("IDF_TARGET"); //$NON-NLS-1$ - final String jtag_device_id = activeConfig.getAttribute("org.eclipse.cdt.debug.gdbjtag.core.jtagDeviceId", ""); //$NON-NLS-1$ //$NON-NLS-2$ - if ((activeConfig.getAttribute(IDFLaunchConstants.FLASH_OVER_JTAG, false) && !jtagIgnored) - || jtag_device_id.contentEquals("ESP-IDF GDB OpenOCD")) //$NON-NLS-1$ + + if ((activeConfig.getAttribute(IDFLaunchConstants.FLASH_OVER_JTAG, false) + || activeConfig.getType().getIdentifier() + .contentEquals(IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE)) + && !jtagIgnored) { - String targetForJtagFlash = activeConfig.getWorkingCopy().getAttribute(IDFLaunchConstants.TARGET_FOR_JTAG, ""); //$NON-NLS-1$ - if (!newTarget.equals(targetForJtagFlash)) + String targetForJtagFlash = activeConfig.getWorkingCopy() + .getAttribute(IDFLaunchConstants.TARGET_FOR_JTAG, StringUtil.EMPTY); + if (!newTarget.equals(targetForJtagFlash)) { boolean isYes = MessageDialog.openQuestion(EclipseUtil.getShell(), Messages.LaunchBarListener_TargetChanged_Title, MessageFormat.format(Messages.LaunchBarListener_TargetDontMatch_Msg, newTarget, targetForJtagFlash, activeConfig.getName())); - if (isYes) { + if (isYes) + { ILaunchBarUIManager uiManager = UIPlugin.getService(ILaunchBarUIManager.class); uiManager.openConfigurationEditor(launchBarManager.getActiveLaunchDescriptor()); return; } } } - + // If both are not same if (currentTarget != null && !newTarget.equals(currentTarget)) { @@ -177,7 +180,7 @@ private boolean deleteDirectory(File directoryToBeDeleted) deleteDirectory(file); } } - return directoryToBeDeleted.getName().equals("build") ? true : directoryToBeDeleted.delete(); //$NON-NLS-1$ + return directoryToBeDeleted.getName().equals("build") || directoryToBeDeleted.delete(); //$NON-NLS-1$ } private void cleanSdkConfig(IResource project)