1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 12:03:16 +02:00

Bug 476432 - GDB version comparison fails for GDB 7.10

Update sub-classes of GdbDebugServicesFactory.
Add safety checks around Integer.parseInt()

Change-Id: Ibc13c832840ebee2cf461df86fdfbdaadde2bcbf
This commit is contained in:
Marc Khouzam 2015-09-02 13:12:32 -04:00
parent fa640a374a
commit 377202feb1
5 changed files with 46 additions and 30 deletions

View file

@ -311,13 +311,14 @@ public class GdbDebugServicesFactory extends AbstractDsfDebugServicesFactory {
}
/**
* Compares the GDB version of the current debug session with the one specified
* Compares the GDB version of the current debug session with the one specified by
* parameter 'version'.
* Returns -1, 0, or 1 if the current version is less than, equal to, or greater than parameter version respectively
* Returns -1, 0, or 1 if the current version is less than, equal to, or greater than parameter version respectively.
* @param version The version to compare with
* @return -1, 0, or 1 if the current version is less than, equal to, or greater than parameter version respectively
* @return -1, 0, or 1 if the current version is less than, equal to, or greater than parameter version respectively.
* @since 4.8
*/
private int compareVersionWith(String version) {
protected int compareVersionWith(String version) {
return compareVersions(getVersion(), version);
}
@ -334,13 +335,18 @@ public class GdbDebugServicesFactory extends AbstractDsfDebugServicesFactory {
String[] v1Parts = v1.split("\\."); //$NON-NLS-1$
String[] v2Parts = v2.split("\\."); //$NON-NLS-1$
for (int i = 0; i < v1Parts.length && i < v2Parts.length; i++) {
int v1PartValue = Integer.parseInt(v1Parts[i]);
int v2PartValue = Integer.parseInt(v2Parts[i]);
if (v1PartValue > v2PartValue) {
return 1;
} else if (v1PartValue < v2PartValue) {
return -1;
try {
int v1PartValue = Integer.parseInt(v1Parts[i]);
int v2PartValue = Integer.parseInt(v2Parts[i]);
if (v1PartValue > v2PartValue) {
return 1;
} else if (v1PartValue < v2PartValue) {
return -1;
}
} catch (NumberFormatException e) {
// Non-integer part, ignore it
continue;
}
}
@ -351,8 +357,13 @@ public class GdbDebugServicesFactory extends AbstractDsfDebugServicesFactory {
// v2 has extra parts, which implies v1 is a lower version (e.g., v1 = 7.9 v2 = 7.9.1)
// unless each extra part is 0, in which case the two versions are equal (e.g., v1 = 7.9 v2 = 7.9.0)
for (int i = v1Parts.length; i < v2Parts.length; i++) {
if (Integer.parseInt(v2Parts[i]) != 0) {
return -1;
try {
if (Integer.parseInt(v2Parts[i]) != 0) {
return -1;
}
} catch (NumberFormatException e) {
// Non-integer part, ignore it
continue;
}
}
}
@ -360,8 +371,13 @@ public class GdbDebugServicesFactory extends AbstractDsfDebugServicesFactory {
// v1 has extra parts, which implies v1 is a higher version (e.g., v1 = 7.9.1 v2 = 7.9)
// unless each extra part is 0, in which case the two versions are equal (e.g., v1 = 7.9.0 v2 = 7.9)
for (int i = v2Parts.length; i < v1Parts.length; i++) {
if (Integer.parseInt(v1Parts[i]) != 0) {
return 1;
try {
if (Integer.parseInt(v1Parts[i]) != 0) {
return 1;
}
} catch (NumberFormatException e) {
// Non-integer part, ignore it
continue;
}
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2011 Ericsson and others.
* Copyright (c) 2008, 2015 Ericsson 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
@ -26,7 +26,7 @@ public class GdbDebugServicesFactoryNS extends GdbDebugServicesFactory {
@Override
protected IRunControl createRunControlService(DsfSession session) {
if (GDB_7_2_VERSION.compareTo(getVersion()) <= 0) {
if (compareVersionWith(GDB_7_2_VERSION) >= 0) {
return new GDBRunControl_7_2_NS(session);
}
return new GDBRunControl_7_0_NS(session);

View file

@ -38,19 +38,19 @@ public class GdbExtendedDebugServicesFactory extends GdbDebugServicesFactory {
@Override
protected ICommandControl createCommandControl(DsfSession session, ILaunchConfiguration config) {
if (GDB_7_7_VERSION.compareTo(getVersion()) <= 0) {
if (compareVersionWith(GDB_7_7_VERSION) >= 0) {
return new GDBExtendedControl(session, config, new GdbExtendedCommandFactory_6_8());
}
if (GDB_7_4_VERSION.compareTo(getVersion()) <= 0) {
if (compareVersionWith(GDB_7_4_VERSION) >= 0) {
return new GDBControl_7_4(session, config, new GdbExtendedCommandFactory_6_8());
}
if (GDB_7_2_VERSION.compareTo(getVersion()) <= 0) {
if (compareVersionWith(GDB_7_2_VERSION) >= 0) {
return new GDBControl_7_2(session, config, new GdbExtendedCommandFactory_6_8());
}
if (GDB_7_0_VERSION.compareTo(getVersion()) <= 0) {
if (compareVersionWith(GDB_7_0_VERSION) >= 0) {
return new GDBControl_7_0(session, config, new GdbExtendedCommandFactory_6_8());
}
if (GDB_6_8_VERSION.compareTo(getVersion()) <= 0) {
if (compareVersionWith(GDB_6_8_VERSION) >= 0) {
return new GDBControl(session, config, new GdbExtendedCommandFactory_6_8());
}
return new GDBControl(session, config, new CommandFactory());

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2014 Ericsson and others.
* Copyright (c) 2014, 2015 Ericsson 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
@ -23,7 +23,7 @@ public class GdbExtendedDebugServicesFactoryNS extends GdbExtendedDebugServicesF
@Override
protected IRunControl createRunControlService(DsfSession session) {
if (GDB_7_2_VERSION.compareTo(getVersion()) <= 0) {
if (compareVersionWith(GDB_7_2_VERSION) >= 0) {
return new GDBRunControl_7_2_NS(session);
}
return new GDBRunControl_7_0_NS(session);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011,2014 Ericsson and others.
* Copyright (c) 2011,2015 Ericsson 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
@ -30,19 +30,19 @@ public class GdbJtagDebugServicesFactory extends GdbDebugServicesFactory {
@Override
protected ICommandControl createCommandControl(DsfSession session, ILaunchConfiguration config) {
if (GDB_7_7_VERSION.compareTo(getVersion()) <= 0) {
if (compareVersionWith(GDB_7_7_VERSION) >= 0) {
return new GDBJtagControl_7_7(session, config, new CommandFactory_6_8());
}
if (GDB_7_4_VERSION.compareTo(getVersion()) <= 0) {
if (compareVersionWith(GDB_7_4_VERSION) >= 0) {
return new GDBJtagControl_7_4(session, config, new CommandFactory_6_8());
}
if (GDB_7_2_VERSION.compareTo(getVersion()) <= 0) {
if (compareVersionWith(GDB_7_2_VERSION) >= 0) {
return new GDBJtagControl_7_2(session, config, new CommandFactory_6_8());
}
if (GDB_7_0_VERSION.compareTo(getVersion()) <= 0) {
if (compareVersionWith(GDB_7_0_VERSION) >= 0) {
return new GDBJtagControl_7_0(session, config, new CommandFactory_6_8());
}
if (GDB_6_8_VERSION.compareTo(getVersion()) <= 0) {
if (compareVersionWith(GDB_6_8_VERSION) >= 0) {
return new GDBJtagControl(session, config, new CommandFactory_6_8());
}
return new GDBJtagControl(session, config, new CommandFactory());