Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Cortell2008-04-22 15:25:36 +0000
committerJohn Cortell2008-04-22 15:25:36 +0000
commit7b3681fc19734b4e4a7b21b3e903b682f7e85dd4 (patch)
tree802ae0c0694a421975276438e544640b9320a4d1 /core/org.eclipse.cdt.core
parentf6b2dea934fb59a8192cfc113fd39e097ee45ae5 (diff)
downloadorg.eclipse.cdt-7b3681fc19734b4e4a7b21b3e903b682f7e85dd4.tar.gz
org.eclipse.cdt-7b3681fc19734b4e4a7b21b3e903b682f7e85dd4.tar.xz
org.eclipse.cdt-7b3681fc19734b4e4a7b21b3e903b682f7e85dd4.zip
Applied patch in 227869. Produce an error if user tries to create memory monitor using a literal address that exceeds the range of the address factory used by the debug session. Prior to this change, the monitor would be created based on the truncated value.
Diffstat (limited to 'core/org.eclipse.cdt.core')
-rw-r--r--core/org.eclipse.cdt.core/META-INF/MANIFEST.MF2
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/IAddressFactory2.java47
-rw-r--r--core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/Messages.java1
-rw-r--r--core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/messages.properties2
-rw-r--r--core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr32.java24
-rw-r--r--core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr32Factory.java57
-rw-r--r--core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr64.java32
-rw-r--r--core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr64Factory.java57
8 files changed, 161 insertions, 61 deletions
diff --git a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
index f402dce261..65128f5a62 100644
--- a/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
+++ b/core/org.eclipse.cdt.core/META-INF/MANIFEST.MF
@@ -39,7 +39,7 @@ Export-Package: org.eclipse.cdt.core,
org.eclipse.cdt.core.templateengine,
org.eclipse.cdt.core.templateengine.process,
org.eclipse.cdt.core.templateengine.process.processes,
- org.eclipse.cdt.internal.core;x-friends:="org.eclipse.cdt.ui",
+ org.eclipse.cdt.internal.core;x-friends:="org.eclipse.cdt.ui,org.eclipse.cdt.debug.core",
org.eclipse.cdt.internal.core.browser;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.browser.util;x-friends:="org.eclipse.cdt.ui",
org.eclipse.cdt.internal.core.cdtvariables;x-internal:=true,
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/IAddressFactory2.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/IAddressFactory2.java
new file mode 100644
index 0000000000..7e5f9969a2
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/IAddressFactory2.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Freescale 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Freescale - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.core;
+
+import java.math.BigInteger;
+
+/**
+ * An extension of IAddressFactory that supports throwing an exception rather
+ * than truncating the initialization value if the value is outside the range
+ * supported by the factory.
+ */
+public interface IAddressFactory2 extends IAddressFactory {
+ /**
+ * See {@link IAddressFactory#createAddress(String)}.
+ * Same contract except that the constructor will throw
+ * a NumberFormatException if the supplied initializer value
+ * is out of range (when 'truncate' is false). IAddressFactory
+ * methods implicitly truncate if the value is out of range.
+ */
+ IAddress createAddress(String addr, boolean truncate);
+
+ /**
+ * See {@link IAddressFactory#createAddress(String, int)}.
+ * Same contract except that the constructor will throw
+ * a NumberFormatException if the supplied initializer value
+ * is out of range (when 'truncate' is false). IAddressFactory
+ * methods implicitly truncate if the value is out of range.
+ */
+ IAddress createAddress(String addr, int radix, boolean truncate);
+
+ /**
+ * See {@link IAddressFactory#createAddress(BigInteger)}.
+ * Same contract except that the constructor will throw
+ * a NumberFormatException if the supplied initializer value
+ * is out of range (when 'truncate' is false). IAddressFactory
+ * methods implicitly truncate if the value is out of range.
+ */
+ IAddress createAddress(BigInteger addr, boolean truncate);
+}
diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/Messages.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/Messages.java
index c79ce1dd1b..471b78580c 100644
--- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/Messages.java
+++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/Messages.java
@@ -16,6 +16,7 @@ import org.eclipse.osgi.util.NLS;
public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.core.messages"; //$NON-NLS-1$
public static String Util_unexpectedError;
+ public static String Addr_valueOutOfRange;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/messages.properties b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/messages.properties
index 9b73f8dd51..a2ae101587 100644
--- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/messages.properties
+++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/internal/core/messages.properties
@@ -56,3 +56,5 @@ convention.enum.leadingUnderscore= Enum name starts with underscore
convention.enum.lowercaseName= Enum name starts with lower case
convention.enum.invalidName= Enum name is invalid
Util_unexpectedError=Unexpected error
+
+Addr_valueOutOfRange=Address is outside valid range. \ No newline at end of file
diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr32.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr32.java
index bcca36a7a9..fc9eb96aac 100644
--- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr32.java
+++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr32.java
@@ -14,6 +14,7 @@ package org.eclipse.cdt.utils;
import java.math.BigInteger;
import org.eclipse.cdt.core.IAddress;
+import org.eclipse.cdt.internal.core.Messages;
public class Addr32 implements IAddress {
@@ -44,20 +45,37 @@ public class Addr32 implements IAddress {
}
public Addr32(long rawaddress) {
+ this(rawaddress, true);
+ }
+
+ public Addr32(long rawaddress, boolean truncate) {
if (rawaddress > MAX_ADDR || rawaddress < 0) {
- rawaddress &= MAX_ADDR; // truncate
+ if (truncate) {
+ rawaddress &= MAX_ADDR; // truncate
+ }
+ else {
+ throw (new NumberFormatException(Messages.Addr_valueOutOfRange));
+ }
}
this.address = rawaddress;
}
public Addr32(String addr) {
- this(Long.decode(addr).longValue());
+ this(addr, true);
+ }
+
+ public Addr32(String addr, boolean truncate) {
+ this(Long.decode(addr).longValue(), truncate);
}
public Addr32(String addr, int radix) {
- this(Long.parseLong(addr, radix));
+ this (addr, radix, true);
}
+ public Addr32(String addr, int radix, boolean truncate) {
+ this(Long.parseLong(addr, radix), truncate);
+ }
+
public IAddress add(BigInteger offset) {
return new Addr32(this.address + offset.longValue());
}
diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr32Factory.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr32Factory.java
index 7c642be0f2..707b1405d5 100644
--- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr32Factory.java
+++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr32Factory.java
@@ -13,56 +13,63 @@ package org.eclipse.cdt.utils;
import java.math.BigInteger;
import org.eclipse.cdt.core.IAddress;
-import org.eclipse.cdt.core.IAddressFactory;
+import org.eclipse.cdt.core.IAddressFactory2;
-public class Addr32Factory implements IAddressFactory {
+public class Addr32Factory implements IAddressFactory2 {
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.eclipse.cdt.core.IAddressFactory#getZero()
*/
public IAddress getZero() {
return Addr32.ZERO;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.eclipse.cdt.core.IAddressFactory#getMax()
*/
public IAddress getMax() {
return Addr32.MAX;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.eclipse.cdt.core.IAddressFactory#createAddress(java.lang.String)
*/
public IAddress createAddress(String addr) {
- IAddress address = new Addr32(addr);
- return address;
+ return createAddress(addr, true);
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.IAddressFactory#createAddress(java.lang.String,
- * int)
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.IAddressFactory2#createAddress(java.lang.String, boolean)
+ */
+ public IAddress createAddress(String addr, boolean truncate) {
+ return new Addr32(addr, truncate);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.IAddressFactory#createAddress(java.lang.String, int)
*/
public IAddress createAddress(String addr, int radix) {
- IAddress address = new Addr32(addr, radix);
- return address;
+ return createAddress(addr, radix, true);
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.IAddressFactory2#createAddress(java.lang.String, int, boolean)
+ */
+ public IAddress createAddress(String addr, int radix, boolean truncate) {
+ return new Addr32(addr, radix, truncate);
+ }
+
+ /* (non-Javadoc)
* @see org.eclipse.cdt.core.IAddressFactory#createAddress(java.math.BigInteger)
*/
public IAddress createAddress(BigInteger addr) {
- IAddress address = new Addr32(addr.longValue());
- return address;
+ return createAddress(addr, true);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.IAddressFactory2#createAddress(java.math.BigInteger, boolean)
+ */
+ public IAddress createAddress(BigInteger addr, boolean truncate) {
+ return new Addr32(addr.longValue(), truncate);
}
} \ No newline at end of file
diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr64.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr64.java
index f577a92e88..a0cce78a91 100644
--- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr64.java
+++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr64.java
@@ -14,6 +14,7 @@ package org.eclipse.cdt.utils;
import java.math.BigInteger;
import org.eclipse.cdt.core.IAddress;
+import org.eclipse.cdt.internal.core.Messages;
public class Addr64 implements IAddress {
@@ -31,32 +32,49 @@ public class Addr64 implements IAddress {
private final BigInteger address;
public Addr64(byte[] addrBytes) {
- address = checkAddress(new BigInteger(1, addrBytes));
+ address = checkAddress(new BigInteger(1, addrBytes), true);
}
public Addr64(BigInteger rawaddress) {
- address = checkAddress(rawaddress);
+ this(rawaddress, true);
+ }
+
+ public Addr64(BigInteger rawaddress, boolean truncate) {
+ address = checkAddress(rawaddress, truncate);
}
public Addr64(String addr) {
+ this(addr, true);
+ }
+
+ public Addr64(String addr, boolean truncate) {
addr = addr.toLowerCase();
if (addr.startsWith("0x")) { //$NON-NLS-1$
- address = checkAddress(new BigInteger(addr.substring(2), 16));
+ address = checkAddress(new BigInteger(addr.substring(2), 16), truncate);
} else {
- address = checkAddress(new BigInteger(addr, 10));
+ address = checkAddress(new BigInteger(addr, 10), truncate);
}
}
public Addr64(String addr, int radix) {
- this(new BigInteger(addr, radix));
+ this(addr, radix, true);
+ }
+
+ public Addr64(String addr, int radix, boolean truncate) {
+ this(new BigInteger(addr, radix), truncate);
}
- private BigInteger checkAddress(BigInteger addr) {
+ private BigInteger checkAddress(BigInteger addr, boolean truncate) {
if (addr.signum() == -1) {
throw new IllegalArgumentException("Invalid Address, must be positive value"); //$NON-NLS-1$
}
if (addr.bitLength() > 64 ) {
- return addr.and(MAX.getValue()); // truncate
+ if (truncate) {
+ return addr.and(MAX.getValue()); // truncate
+ }
+ else {
+ throw (new NumberFormatException(Messages.Addr_valueOutOfRange));
+ }
}
return addr;
}
diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr64Factory.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr64Factory.java
index ccd0b6b735..7922eed8b5 100644
--- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr64Factory.java
+++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Addr64Factory.java
@@ -13,56 +13,63 @@ package org.eclipse.cdt.utils;
import java.math.BigInteger;
import org.eclipse.cdt.core.IAddress;
-import org.eclipse.cdt.core.IAddressFactory;
+import org.eclipse.cdt.core.IAddressFactory2;
-public class Addr64Factory implements IAddressFactory {
+public class Addr64Factory implements IAddressFactory2 {
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.eclipse.cdt.core.IAddressFactory#getZero()
*/
public IAddress getZero() {
return Addr64.ZERO;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.eclipse.cdt.core.IAddressFactory#getMax()
*/
public IAddress getMax() {
return Addr64.MAX;
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
* @see org.eclipse.cdt.core.IAddressFactory#createAddress(java.lang.String)
*/
public IAddress createAddress(String addr) {
- IAddress address = new Addr64(addr);
- return address;
+ return createAddress(addr, true);
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.cdt.core.IAddressFactory#createAddress(java.lang.String,
- * int)
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.IAddressFactory2#createAddress(java.lang.String, boolean)
+ */
+ public IAddress createAddress(String addr, boolean truncate) {
+ return new Addr64(addr, truncate);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.IAddressFactory#createAddress(java.lang.String, int)
*/
public IAddress createAddress(String addr, int radix) {
- IAddress address = new Addr64(addr, radix);
- return address;
+ return createAddress(addr, radix, true);
}
- /*
- * (non-Javadoc)
- *
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.IAddressFactory2#createAddress(java.lang.String, int, boolean)
+ */
+ public IAddress createAddress(String addr, int radix, boolean truncate) {
+ return new Addr64(addr, radix, truncate);
+ }
+
+ /* (non-Javadoc)
* @see org.eclipse.cdt.core.IAddressFactory#createAddress(java.math.BigInteger)
*/
public IAddress createAddress(BigInteger addr) {
- IAddress address = new Addr64(addr);
- return address;
+ return createAddress(addr, true);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.IAddressFactory2#createAddress(java.math.BigInteger, boolean)
+ */
+ public IAddress createAddress(BigInteger addr, boolean truncate) {
+ return new Addr64(addr, truncate);
}
} \ No newline at end of file

Back to the top