Skip to content

Commit

Permalink
IEP-1000 Board doesn't match the target after cancel in debug/jtag tab (
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
sigmaaa authored Nov 2, 2023
1 parent 6f0ffc9 commit 05ea8a4
Show file tree
Hide file tree
Showing 11 changed files with 306 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
5 changes: 5 additions & 0 deletions bundles/com.espressif.idf.debug.gdbjtag.openocd/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@
name="default_app"
resolver="com.espressif.idf.debug.gdbjtag.openocd.DefaultAppResolver">
</variable>
<variable
description="%esp_svd_path_desc"
name="esp_svd_path"
resolver="com.espressif.idf.debug.gdbjtag.openocd.SvdPathResolver">
</variable>
</extension>
<extension
point="org.eclipse.debug.core.processFactories">
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*/
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;

Check warning on line 71 in bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/SvdPathResolver.java

View workflow job for this annotation

GitHub Actions / spotbugs

THROWS_METHOD_THROWS_CLAUSE_BASIC_EXCEPTION

Method lists Exception in its throws clause.
Raw output
Method lists Exception in its throws clause.
When declaring a method, the types of exceptions in the throws clause should be the most specific. Therefore, using Exception in the throws clause would force the caller to either use it in its own throws clause, or use it in a try-catch block (when it does not necessarily contain any meaningful information about the thrown exception).

For more information, see the SEI CERT ERR07-J rule [https://wiki.sei.cmu.edu/confluence/display/java/ERR07-J.+Do+not+throw+RuntimeException%2C+Exception%2C+or+Throwable].
}

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();

Check warning on line 98 in bundles/com.espressif.idf.debug.gdbjtag.openocd/src/com/espressif/idf/debug/gdbjtag/openocd/SvdPathResolver.java

View workflow job for this annotation

GitHub Actions / spotbugs

THROWS_METHOD_THROWS_CLAUSE_BASIC_EXCEPTION

Method lists Exception in its throws clause.
Raw output
Method lists Exception in its throws clause.
When declaring a method, the types of exceptions in the throws clause should be the most specific. Therefore, using Exception in the throws clause would force the caller to either use it in its own throws clause, or use it in a try-catch block (when it does not necessarily contain any meaningful information about the thrown exception).

For more information, see the SEI CERT ERR07-J rule [https://wiki.sei.cmu.edu/confluence/display/java/ERR07-J.+Do+not+throw+RuntimeException%2C+Exception%2C+or+Throwable].
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class Messages

public static String DllNotFound_ExceptionMessage;
public static String TabMain_Launch_Config;

public static String TabDebugger_SettingTargetJob;
// ------------------------------------------------------------------------

static
Expand Down
Loading

0 comments on commit 05ea8a4

Please sign in to comment.