1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 14:12:10 +02:00

[292557] Import/Export dialogs do not pick up the renderings current base address

This commit is contained in:
John Cortell 2009-10-16 22:44:09 +00:00
parent 547715d30b
commit 64d3465010
13 changed files with 144 additions and 139 deletions

View file

@ -90,7 +90,7 @@ public class Rendering extends Composite implements IDebugEventSetListener
private int fCurrentScrollSelection = 0; // current scroll selection;
private BigInteger fCaretAddress = BigInteger.valueOf(0); // -1 ?
private BigInteger fCaretAddress;
// user settings
@ -463,7 +463,11 @@ public class Rendering extends Composite implements IDebugEventSetListener
protected BigInteger getCaretAddress()
{
return fCaretAddress;
// Return the caret address if it has been set, otherwise return the
// viewport address. When the rendering is first created, the caret is
// unset until the user clicks somewhere in the rendering. It also reset
// (unset) when the user gives us a new viewport address
return (fCaretAddress != null) ? fCaretAddress : fViewportAddress;
}
private void doGoToAddress() {
@ -1469,7 +1473,12 @@ public class Rendering extends Composite implements IDebugEventSetListener
return;
}
fViewportAddress = address; // TODO update fCaretAddress
fViewportAddress = address;
// reset the caret and selection state (no caret and no selection)
fCaretAddress = null;
fSelection = new Selection();
redrawPanes();
}

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.debug.ui.memory.transport;
import java.math.BigInteger;
import java.util.Properties;
import java.util.Vector;
@ -52,13 +53,16 @@ public class ExportMemoryDialog extends SelectionDialog
private Properties fProperties = new Properties();
public ExportMemoryDialog(Shell parent, IMemoryBlock memoryBlock)
private BigInteger fInitialStartAddr;
public ExportMemoryDialog(Shell parent, IMemoryBlock memoryBlock, BigInteger initialStartAddr)
{
super(parent);
super.setTitle("Export Memory");
setShellStyle(getShellStyle() | SWT.RESIZE);
fMemoryBlock = memoryBlock;
fInitialStartAddr = initialStartAddr;
}
/* (non-Javadoc)
@ -181,6 +185,7 @@ public class ExportMemoryDialog extends SelectionDialog
public void widgetSelected(SelectionEvent e) {
if(fCurrentControl != null)
fCurrentControl.dispose();
initProperties(fProperties, fInitialStartAddr);
fCurrentControl = fFormatExporters[fFormatCombo.getSelectionIndex()].createControl(container,
fMemoryBlock, fProperties, ExportMemoryDialog.this);
}
@ -188,12 +193,25 @@ public class ExportMemoryDialog extends SelectionDialog
fFormatCombo.select(0);
initProperties(fProperties, fInitialStartAddr);
fCurrentControl = fFormatExporters[0].createControl(container,
fMemoryBlock, fProperties, ExportMemoryDialog.this);
return composite;
}
/**
* Initializes the start and end address properties to a particular value if
* and only if we have a fresh/clean properties object.
*/
static void initProperties(Properties properties, BigInteger addr) {
final String addrstr = "0x" + addr.toString(16);
if (!properties.containsKey(IMemoryExporter.TRANSFER_START)) {
properties.setProperty(IMemoryExporter.TRANSFER_START, addrstr);
properties.setProperty(IMemoryExporter.TRANSFER_END, addrstr);
}
}
public void setValid(boolean isValid)
{
getButton(IDialogConstants.OK_ID).setEnabled(isValid);

View file

@ -15,6 +15,7 @@ import java.math.BigInteger;
import java.util.Properties;
import java.util.Vector;
import org.eclipse.cdt.debug.ui.memory.transport.model.IMemoryExporter;
import org.eclipse.cdt.debug.ui.memory.transport.model.IMemoryImporter;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
@ -63,7 +64,9 @@ public class ImportMemoryDialog extends SelectionDialog
private IMemoryRenderingSite fMemoryView;
public ImportMemoryDialog(Shell parent, IMemoryBlock memoryBlock, IMemoryRenderingSite renderingSite)
private BigInteger fInitialStartAddr;
public ImportMemoryDialog(Shell parent, IMemoryBlock memoryBlock, BigInteger initialStartAddr, IMemoryRenderingSite renderingSite)
{
super(parent);
super.setTitle("Download to Memory");
@ -71,6 +74,7 @@ public class ImportMemoryDialog extends SelectionDialog
fMemoryBlock = memoryBlock;
fMemoryView = renderingSite;
fInitialStartAddr = initialStartAddr;
}
protected void scrollRenderings(final BigInteger address)
@ -226,18 +230,33 @@ public class ImportMemoryDialog extends SelectionDialog
public void widgetSelected(SelectionEvent e) {
if(fCurrentControl != null)
fCurrentControl.dispose();
initProperties(fProperties, fInitialStartAddr); // use utility from export code
fCurrentControl = fFormatImporters[fFormatCombo.getSelectionIndex()].createControl(container,
fMemoryBlock, fProperties, ImportMemoryDialog.this);
}
});
fFormatCombo.select(0);
initProperties(fProperties, fInitialStartAddr); // use utility from export code
fCurrentControl =
fFormatImporters[0].createControl(container,fMemoryBlock, fProperties, ImportMemoryDialog.this);
return composite;
}
/**
* Initializes the start address properties to a particular value if
* and only if we have a fresh/clean properties object.
*/
static void initProperties(Properties properties, BigInteger addr) {
final String addrstr = "0x" + addr.toString(16);
if (!properties.containsKey(IMemoryExporter.TRANSFER_START)) {
properties.setProperty(IMemoryExporter.TRANSFER_START, addrstr);
}
}
public void setValid(boolean isValid)
{
getButton(IDialogConstants.OK_ID).setEnabled(isValid);

View file

@ -157,26 +157,11 @@ public class PlainTextExporter implements IMemoryExporter {
fFileText.setText(properties.getProperty(TRANSFER_FILE, ""));
try
{
BigInteger startAddress = null;
if(fMemoryBlock instanceof IMemoryBlockExtension)
startAddress = ((IMemoryBlockExtension) fMemoryBlock)
.getBigBaseAddress(); // FIXME use selection/caret address?
else
startAddress = BigInteger.valueOf(fMemoryBlock.getStartAddress());
if(properties.getProperty(TRANSFER_START) != null)
fStartText.setText(properties.getProperty(TRANSFER_START));
else
fStartText.setText("0x" + startAddress.toString(16));
if(properties.getProperty(TRANSFER_END) != null)
fEndText.setText(properties.getProperty(TRANSFER_END));
else
fEndText.setText("0x" + startAddress.toString(16));
fStartText.setText(properties.getProperty(TRANSFER_START));
fEndText.setText(properties.getProperty(TRANSFER_END));
fLengthText.setText(getEndAddress().subtract(getStartAddress()).toString());
}
catch(Exception e)
catch(IllegalArgumentException e)
{
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.INTERNAL_ERROR, "Failure", e));

View file

@ -144,20 +144,9 @@ public class PlainTextImporter implements IMemoryImporter {
fScrollToStart = new Boolean(properties.getProperty(TRANSFER_SCROLL_TO_START, "true"));
try
{
BigInteger startAddress = null;
if(fMemoryBlock instanceof IMemoryBlockExtension)
startAddress = ((IMemoryBlockExtension) fMemoryBlock)
.getBigBaseAddress(); // FIXME use selection/caret address?
else
startAddress = BigInteger.valueOf(fMemoryBlock.getStartAddress());
if(properties.getProperty(TRANSFER_START) != null)
fStartText.setText(properties.getProperty(TRANSFER_START));
else
fStartText.setText("0x" + startAddress.toString(16));
fStartText.setText(properties.getProperty(TRANSFER_START));
}
catch(Exception e)
catch(IllegalArgumentException e)
{
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.INTERNAL_ERROR, "Failure", e));

View file

@ -155,25 +155,11 @@ public class RAWBinaryExporter implements IMemoryExporter
fFileText.setText(properties.getProperty(TRANSFER_FILE, ""));
try
{
BigInteger startAddress = null;
if(fMemoryBlock instanceof IMemoryBlockExtension)
startAddress = ((IMemoryBlockExtension) fMemoryBlock).getBigBaseAddress();
else
startAddress = BigInteger.valueOf(fMemoryBlock.getStartAddress());
if(properties.getProperty(TRANSFER_START) != null)
fStartText.setText(properties.getProperty(TRANSFER_START));
else
fStartText.setText("0x" + startAddress.toString(16));
if(properties.getProperty(TRANSFER_END) != null)
fEndText.setText(properties.getProperty(TRANSFER_END));
else
fEndText.setText("0x" + startAddress.toString(16));
fStartText.setText(properties.getProperty(TRANSFER_START));
fEndText.setText(properties.getProperty(TRANSFER_END));
fLengthText.setText(getEndAddress().subtract(getStartAddress()).toString());
}
catch(Exception e)
catch(IllegalArgumentException e)
{
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.INTERNAL_ERROR, "Failure", e));

View file

@ -121,19 +121,9 @@ public class RAWBinaryImporter implements IMemoryImporter {
fScrollToStart = new Boolean(properties.getProperty(TRANSFER_SCROLL_TO_START, "true"));
try
{
BigInteger startAddress = null;
if(fMemoryBlock instanceof IMemoryBlockExtension)
startAddress = ((IMemoryBlockExtension) fMemoryBlock).getBigBaseAddress();
else
startAddress = BigInteger.valueOf(fMemoryBlock.getStartAddress());
if(properties.getProperty(TRANSFER_START) != null)
fStartText.setText(properties.getProperty(TRANSFER_START));
else
fStartText.setText("0x" + startAddress.toString(16));
fStartText.setText(properties.getProperty(TRANSFER_START));
}
catch(Exception e)
catch(IllegalArgumentException e)
{
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.INTERNAL_ERROR, "Failure", e));

View file

@ -155,26 +155,11 @@ public class SRecordExporter implements IMemoryExporter
fFileText.setText(properties.getProperty(TRANSFER_FILE, ""));
try
{
BigInteger startAddress = null;
if(fMemoryBlock instanceof IMemoryBlockExtension)
startAddress = ((IMemoryBlockExtension) fMemoryBlock)
.getBigBaseAddress(); // FIXME use selection/caret address?
else
startAddress = BigInteger.valueOf(fMemoryBlock.getStartAddress());
if(properties.getProperty(TRANSFER_START) != null)
fStartText.setText(properties.getProperty(TRANSFER_START));
else
fStartText.setText("0x" + startAddress.toString(16));
if(properties.getProperty(TRANSFER_END) != null)
fEndText.setText(properties.getProperty(TRANSFER_END));
else
fEndText.setText("0x" + startAddress.toString(16));
fStartText.setText(properties.getProperty(TRANSFER_START));
fEndText.setText(properties.getProperty(TRANSFER_END));
fLengthText.setText(getEndAddress().subtract(getStartAddress()).toString());
}
catch(Exception e)
catch(IllegalArgumentException e)
{
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.INTERNAL_ERROR, "Failure", e));

View file

@ -159,20 +159,9 @@ public class SRecordImporter implements IMemoryImporter {
fScrollToStart = new Boolean(properties.getProperty(TRANSFER_SCROLL_TO_START, "true"));
try
{
BigInteger startAddress = null;
if(fMemoryBlock instanceof IMemoryBlockExtension)
startAddress = ((IMemoryBlockExtension) fMemoryBlock)
.getBigBaseAddress(); // FIXME use selection/caret address?
else
startAddress = BigInteger.valueOf(fMemoryBlock.getStartAddress());
if(properties.getProperty(TRANSFER_START) != null)
fStartText.setText(properties.getProperty(TRANSFER_START));
else
fStartText.setText("0x" + startAddress.toString(16));
fStartText.setText(properties.getProperty(TRANSFER_START));
}
catch(Exception e)
catch(IllegalArgumentException e)
{
MemoryTransportPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, MemoryTransportPlugin.getUniqueIdentifier(),
DebugException.INTERNAL_ERROR, "Failure", e));

View file

@ -11,11 +11,16 @@
package org.eclipse.cdt.debug.ui.memory.transport.actions;
import java.math.BigInteger;
import org.eclipse.cdt.debug.ui.memory.transport.ExportMemoryDialog;
import org.eclipse.cdt.debug.ui.memory.transport.MemoryTransportPlugin;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.model.IMemoryBlock;
import org.eclipse.debug.core.model.IMemoryBlockExtension;
import org.eclipse.debug.ui.memory.IMemoryRendering;
import org.eclipse.debug.ui.memory.IMemoryRenderingSite;
import org.eclipse.debug.ui.memory.IRepositionableMemoryRendering;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
@ -34,46 +39,89 @@ public class ExportMemoryAction implements IViewActionDelegate {
fView = (IMemoryRenderingSite) view;
}
private IMemoryBlock getMemoryBlock(ISelection selection)
/**
* Utility PODS to return a memory block and an address from a method
*/
static class BlockAndAddress {
static public final BlockAndAddress EMPTY = new BlockAndAddress(null, BigInteger.valueOf(0));
public BlockAndAddress(IMemoryBlock block, BigInteger addr) {
this.block = block;
this.addr = addr;
}
public IMemoryBlock block;
public BigInteger addr;
}
/**
* Returns the memory block and initial base address for the export
* operation.
*
* @return a result object; null is never returned
*/
static BlockAndAddress getMemoryBlockAndInitialStartAddress(ISelection selection)
{
IMemoryBlock memBlock = null;
BigInteger initialStartAddr = null;
if (selection instanceof IStructuredSelection) {
IStructuredSelection strucSel = (IStructuredSelection) selection;
// return if current selection is empty
if (strucSel.isEmpty())
return null;
return BlockAndAddress.EMPTY;
Object obj = strucSel.getFirstElement();
if (obj == null)
return null;
return BlockAndAddress.EMPTY;
// Get the initial start address for the operation.
if (obj instanceof IMemoryRendering) {
memBlock = ((IMemoryRendering) obj).getMemoryBlock();
if (obj instanceof IRepositionableMemoryRendering) {
initialStartAddr = ((IRepositionableMemoryRendering)obj).getSelectedAddress();
}
} else if (obj instanceof IMemoryBlock) {
memBlock = (IMemoryBlock) obj;
}
if (initialStartAddr == null) {
if (memBlock instanceof IMemoryBlockExtension) {
try {
initialStartAddr = ((IMemoryBlockExtension)memBlock).getBigBaseAddress();
} catch (DebugException e) {
initialStartAddr = BigInteger.valueOf(memBlock.getStartAddress());
}
}
else {
initialStartAddr = BigInteger.valueOf(memBlock.getStartAddress());
}
}
}
return memBlock;
return new BlockAndAddress(memBlock, initialStartAddr);
}
public void run(IAction action) {
ISelection selection = fView.getSite().getSelectionProvider()
.getSelection();
IMemoryBlock memBlock = getMemoryBlock(selection);
if(memBlock == null)
BlockAndAddress blockAndAddr = getMemoryBlockAndInitialStartAddress(selection);
if(blockAndAddr.block == null)
return;
ExportMemoryDialog dialog = new ExportMemoryDialog(MemoryTransportPlugin.getShell(), memBlock);
ExportMemoryDialog dialog = new ExportMemoryDialog(MemoryTransportPlugin.getShell(), blockAndAddr.block, blockAndAddr.addr);
dialog.open();
dialog.getResult();
}
public void selectionChanged(IAction action, ISelection selection) {
action.setEnabled(getMemoryBlock(selection) != null);
action.setEnabled(getMemoryBlockAndInitialStartAddress(selection).block != null);
}
}

View file

@ -13,13 +13,9 @@ package org.eclipse.cdt.debug.ui.memory.transport.actions;
import org.eclipse.cdt.debug.ui.memory.transport.ImportMemoryDialog;
import org.eclipse.cdt.debug.ui.memory.transport.MemoryTransportPlugin;
import org.eclipse.debug.core.model.IMemoryBlock;
import org.eclipse.debug.internal.ui.views.memory.MemoryView;
import org.eclipse.debug.ui.memory.IMemoryRendering;
import org.eclipse.debug.ui.memory.IMemoryRenderingSite;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
@ -36,47 +32,25 @@ public class ImportMemoryAction implements IViewActionDelegate {
fView = (IMemoryRenderingSite) view;
}
private IMemoryBlock getMemoryBlock(ISelection selection)
{
IMemoryBlock memBlock = null;
if (selection instanceof IStructuredSelection) {
IStructuredSelection strucSel = (IStructuredSelection) selection;
// return if current selection is empty
if (strucSel.isEmpty())
return null;
Object obj = strucSel.getFirstElement();
if (obj == null)
return null;
if (obj instanceof IMemoryRendering) {
memBlock = ((IMemoryRendering) obj).getMemoryBlock();
} else if (obj instanceof IMemoryBlock) {
memBlock = (IMemoryBlock) obj;
}
}
return memBlock;
}
public void run(IAction action) {
ISelection selection = fView.getSite().getSelectionProvider()
.getSelection();
IMemoryBlock memBlock = getMemoryBlock(selection);
if(memBlock == null)
// use utility function in export code
ExportMemoryAction.BlockAndAddress blockAndAddr = ExportMemoryAction.getMemoryBlockAndInitialStartAddress(selection);
if(blockAndAddr.block == null)
return;
ImportMemoryDialog dialog = new ImportMemoryDialog(MemoryTransportPlugin.getShell(), memBlock, fView);
ImportMemoryDialog dialog = new ImportMemoryDialog(MemoryTransportPlugin.getShell(), blockAndAddr.block, blockAndAddr.addr, fView);
dialog.open();
dialog.getResult();
}
public void selectionChanged(IAction action, ISelection selection) {
action.setEnabled(getMemoryBlock(selection) != null);
// use utility function in export code
action.setEnabled(ExportMemoryAction.getMemoryBlockAndInitialStartAddress(selection).block != null);
}
}

View file

@ -24,6 +24,13 @@ public interface IMemoryExporter
public static final String TRANSFER_START = "Start";
public static final String TRANSFER_END = "End";
/**
* @param parent
* @param memBlock
* @param properties This will contain initial values for TRANSFER_START and TRANSFER_END.
* @param parentDialog
* @return
*/
public Control createControl(Composite parent, IMemoryBlock memBlock, Properties properties, ExportMemoryDialog parentDialog);
public void exportMemory();

View file

@ -22,10 +22,16 @@ public interface IMemoryImporter
{
public static final String TRANSFER_FILE = "File";
public static final String TRANSFER_START = "Start";
public static final String TRANSFER_END = "End";
public static final String TRANSFER_CUSTOM_START_ADDRESS = "CustomStartAddress";
public static final String TRANSFER_SCROLL_TO_START = "ScrollToStart";
/**
* @param parent
* @param memBlock
* @param properties This will contain an initial values for TRANSFER_START
* @param parentDialog
* @return
*/
public Control createControl(Composite parent, IMemoryBlock memBlock, Properties properties, ImportMemoryDialog parentDialog);
public void importMemory();