1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 09:55:29 +02:00

Bug 378294 : The SRecord importer/exporter dialogs allow entry of

addresses that are more than 32-bits

Change-Id: I529b9a85d25327c4a48d809f52fd2d87d80a80fd
Reviewed-on: https://git.eclipse.org/r/5787
Reviewed-by: Randy Rohrbach <Randy.Rohrbach@Windriver.com>
IP-Clean: Randy Rohrbach <Randy.Rohrbach@Windriver.com>
Tested-by: Randy Rohrbach <Randy.Rohrbach@Windriver.com>
This commit is contained in:
Randy Rohrbach 2012-05-02 18:38:26 -04:00
parent 6091c93f7b
commit d768c30d0c
2 changed files with 84 additions and 49 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2010 Wind River Systems, Inc. and others.
* Copyright (c) 2006, 2012 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -66,7 +66,6 @@ public class SRecordExporter implements IMemoryExporter
Composite composite = new Composite(parent, SWT.NONE)
{
@Override
public void dispose()
{
fProperties.put(TRANSFER_FILE, fFileText.getText());
@ -192,27 +191,25 @@ public class SRecordExporter implements IMemoryExporter
fStartText.addKeyListener(new KeyListener() {
public void keyReleased(KeyEvent e) {
boolean valid = true;
try
{
getStartAddress();
fStartText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
BigInteger actualLength = getEndAddress().subtract(getStartAddress());
String lengthString = actualLength.toString();
if(!fLengthText.getText().equals(lengthString)) {
if ( ! actualLength.equals( BigInteger.ZERO ) ) {
fLengthText.setText(lengthString);
}
}
validate();
}
catch(Exception ex)
{
valid = false;
fStartText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
validate();
//fParentDialog.setValid(false);
}
fStartText.setForeground(valid ? Display.getDefault().getSystemColor(SWT.COLOR_BLACK) :
Display.getDefault().getSystemColor(SWT.COLOR_RED));
//
BigInteger endAddress = getEndAddress();
BigInteger startAddress = getStartAddress();
fLengthText.setText(endAddress.subtract(startAddress).toString());
validate();
}
public void keyPressed(KeyEvent e) {}
@ -222,23 +219,25 @@ public class SRecordExporter implements IMemoryExporter
public void keyReleased(KeyEvent e) {
try
{
getEndAddress();
fEndText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
BigInteger endAddress = getEndAddress();
BigInteger startAddress = getStartAddress();
String lengthString = endAddress.subtract(startAddress).toString();
BigInteger actualLength = getEndAddress().subtract(getStartAddress());
String lengthString = actualLength.toString();
if(!fLengthText.getText().equals(lengthString))
fLengthText.setText(lengthString);
if(!fLengthText.getText().equals(lengthString)) {
if ( ! actualLength.equals( BigInteger.ZERO ) ) {
fLengthText.setText(lengthString);
}
}
validate();
}
catch(Exception ex)
{
fEndText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
validate();
//fParentDialog.setValid(false);
}
validate();
}
public void keyPressed(KeyEvent e) {}
@ -251,20 +250,22 @@ public class SRecordExporter implements IMemoryExporter
{
BigInteger length = getLength();
fLengthText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
BigInteger startAddress = getStartAddress();
String endString = "0x" + startAddress.add(length).toString(16); //$NON-NLS-1$
if(!fEndText.getText().equals(endString))
String endString = "0x" + getStartAddress().add(length).toString(16); //$NON-NLS-1$
if(!fEndText.getText().equals(endString)) {
if ( ! length.equals( BigInteger.ZERO ) ) {
fLengthText.setText(endString);
}
fEndText.setText(endString);
}
validate();
}
catch(Exception ex)
{
fLengthText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
validate();
//fParentDialog.setValid(false);
}
validate();
}
public void keyPressed(KeyEvent e) {
@ -309,6 +310,10 @@ public class SRecordExporter implements IMemoryExporter
BigInteger endAddress = new BigInteger(hex ? text.substring(2) : text,
hex ? 16 : 10);
if ( endAddress.bitLength() > 32 ) {
throw(new NumberFormatException("End Address is larger than 32 bits"));
}
return endAddress;
}
@ -319,6 +324,10 @@ public class SRecordExporter implements IMemoryExporter
BigInteger startAddress = new BigInteger(hex ? text.substring(2) : text,
hex ? 16 : 10);
if ( startAddress.bitLength() > 32 ) {
throw(new NumberFormatException("Start Address is larger than 32 bits"));
}
return startAddress;
}
@ -329,6 +338,7 @@ public class SRecordExporter implements IMemoryExporter
BigInteger lengthAddress = new BigInteger(hex ? text.substring(2) : text,
hex ? 16 : 10);
return lengthAddress;
}
@ -377,7 +387,6 @@ public class SRecordExporter implements IMemoryExporter
public void exportMemory()
{
Job job = new Job("Memory Export to S-Record File"){ //$NON-NLS-1$
@Override
public IStatus run(IProgressMonitor monitor) {
try
{

View file

@ -28,6 +28,8 @@ import org.eclipse.debug.core.model.IMemoryBlock;
import org.eclipse.debug.core.model.IMemoryBlockExtension;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionEvent;
@ -73,7 +75,6 @@ public class SRecordImporter implements IMemoryImporter {
Composite composite = new Composite(parent, SWT.NONE)
{
@Override
public void dispose()
{
fProperties.put(TRANSFER_FILE, fFileText.getText());
@ -131,7 +132,17 @@ public class SRecordImporter implements IMemoryImporter {
public void widgetDefaultSelected(SelectionEvent e) {}
public void widgetSelected(SelectionEvent e) {
validate();
try
{
fStartText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
getStartAddress();
validate();
}
catch(Exception ex)
{
fStartText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
fParentDialog.setValid(false);
}
}
});
@ -190,27 +201,38 @@ public class SRecordImporter implements IMemoryImporter {
});
fStartText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
boolean valid = true;
fStartText.addKeyListener(new KeyListener() {
public void keyReleased(KeyEvent e) {
try
{
getStartAddress();
boolean restoreToAddress = fComboRestoreToThisAddress.getSelection();
if ( restoreToAddress ) {
fStartText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
getStartAddress();
validate();
}
else {
try
{
getStartAddress();
fStartText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
}
catch(Exception ex)
{
fStartText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
}
}
}
catch(Exception ex)
{
valid = false;
fStartText.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
validate();
}
fStartText.setForeground(valid ? Display.getDefault().getSystemColor(SWT.COLOR_BLACK) :
Display.getDefault().getSystemColor(SWT.COLOR_RED));
//
validate();
}
public void keyPressed(KeyEvent e) {}
});
fFileText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
validate();
@ -276,6 +298,11 @@ public class SRecordImporter implements IMemoryImporter {
BigInteger startAddress = new BigInteger(hex ? text.substring(2) : text,
hex ? 16 : 10);
if ( startAddress.bitLength() > 32 ) {
throw(new NumberFormatException("Start Address is larger than 32 bits"));
}
return startAddress;
}
@ -297,7 +324,6 @@ public class SRecordImporter implements IMemoryImporter {
public void importMemory() {
Job job = new Job("Memory Import from S-Record File"){ //$NON-NLS-1$
@Override
public IStatus run(IProgressMonitor monitor) {
try