Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly code from the updateSvd method

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


}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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
Expand Down Expand Up @@ -168,12 +169,14 @@ public Image getImage()
@Override
public void createControl(Composite parent)
{

if (Activator.getInstance().isDebugging())
{
System.out.println("openocd.TabDebugger.createControl() ");
}

LaunchBarListener.setIgnoreJtagTargetChange(true);
parent.addDisposeListener(e -> LaunchBarListener.setIgnoreJtagTargetChange(false));

if (!(parent instanceof ScrolledComposite))
{
ScrolledComposite sc = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
Expand Down Expand Up @@ -458,18 +461,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));
Comment on lines 506 to 511
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new hunk has removed some code related to updating the launch configuration when the selected item is not equal to the updated selected target. Ensure that this removal doesn't affect the functionality of the application.

Expand Down Expand Up @@ -1513,19 +1504,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -705,14 +705,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);
Comment on lines 712 to 717
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code for updating the launch configuration with the selected target has been removed from the if block. Instead, the updateLaunchBar method is called directly. This change simplifies the code and removes the need to handle a CoreException here.

Expand Down
Loading