mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 14:55:41 +02:00
[263527] Give ability to override the way to find the GDB version.
This commit is contained in:
parent
2a589c0f4b
commit
f725205888
2 changed files with 53 additions and 23 deletions
|
@ -129,7 +129,7 @@ public class GdbLaunchDelegate extends LaunchConfigurationDelegate
|
||||||
|
|
||||||
monitor.worked( 1 );
|
monitor.worked( 1 );
|
||||||
|
|
||||||
String gdbVersion = LaunchUtils.getGDBVersion(config);
|
String gdbVersion = getGDBVersion(config);
|
||||||
|
|
||||||
// First make sure non-stop is supported, if the user want to use this mode
|
// First make sure non-stop is supported, if the user want to use this mode
|
||||||
if (isNonStopSession && !isNonStopSupported(gdbVersion)) {
|
if (isNonStopSession && !isNonStopSupported(gdbVersion)) {
|
||||||
|
@ -211,6 +211,16 @@ public class GdbLaunchDelegate extends LaunchConfigurationDelegate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the GDB version on the local host.
|
||||||
|
* Subclass can override for special need.
|
||||||
|
*
|
||||||
|
* @since 2.0
|
||||||
|
*/
|
||||||
|
protected String getGDBVersion(ILaunchConfiguration config) throws CoreException {
|
||||||
|
return LaunchUtils.getGDBVersion(config);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This method can be overridden by subclasses to allow to change the final launch sequence without
|
* This method can be overridden by subclasses to allow to change the final launch sequence without
|
||||||
* having to change the entire GdbLaunchDelegate
|
* having to change the entire GdbLaunchDelegate
|
||||||
|
|
|
@ -198,9 +198,43 @@ public class LaunchUtils {
|
||||||
}
|
}
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getGDBVersion(final ILaunchConfiguration configuration) throws CoreException {
|
/**
|
||||||
String line, version = "";//$NON-NLS-1$
|
* Find gdb version info from a string object which is supposed to
|
||||||
|
* contain output text of "gdb --version" command.
|
||||||
|
*
|
||||||
|
* @param versionOutput
|
||||||
|
* output text from "gdb --version" command .
|
||||||
|
* @return
|
||||||
|
* String representation of version of gdb such as "6.8" on success;
|
||||||
|
* empty string otherwise.
|
||||||
|
* @since 2.0
|
||||||
|
*/
|
||||||
|
public static String getGDBVersionFromText(String versionOutput) {
|
||||||
|
String version = "";//$NON-NLS-1$
|
||||||
|
|
||||||
|
// These are the GDB version patterns I have seen up to now
|
||||||
|
// The pattern works for all of them extracting the version of 6.8.50.20080730
|
||||||
|
// GNU gdb 6.8.50.20080730
|
||||||
|
// GNU gdb (GDB) 6.8.50.20080730-cvs
|
||||||
|
// GNU gdb (Ericsson GDB 1.0-10) 6.8.50.20080730-cvs
|
||||||
|
Pattern pattern = Pattern.compile(" gdb( \\(.*\\))? (\\d*(\\.\\d*)*)", Pattern.MULTILINE); //$NON-NLS-1$
|
||||||
|
|
||||||
|
Matcher matcher = pattern.matcher(versionOutput);
|
||||||
|
if (matcher.find()) {
|
||||||
|
version = matcher.group(2);
|
||||||
|
// Temporary for cygwin, until GDB 7 is released
|
||||||
|
// Any cygwin GDB staring with 6.8 should be treated as plain 6.8
|
||||||
|
if (versionOutput.toLowerCase().indexOf("cygwin") != -1 && //$NON-NLS-1$
|
||||||
|
version.startsWith("6.8")) { //$NON-NLS-1$
|
||||||
|
version = "6.8"; //$NON-NLS-1$
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getGDBVersion(final ILaunchConfiguration configuration) throws CoreException {
|
||||||
Process process = null;
|
Process process = null;
|
||||||
String cmd = getGDBPath(configuration).toOSString() + " --version"; //$NON-NLS-1$
|
String cmd = getGDBPath(configuration).toOSString() + " --version"; //$NON-NLS-1$
|
||||||
try {
|
try {
|
||||||
|
@ -209,37 +243,23 @@ public class LaunchUtils {
|
||||||
throw new DebugException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED,
|
throw new DebugException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED,
|
||||||
"Error while launching command: " + cmd, e.getCause()));//$NON-NLS-1$
|
"Error while launching command: " + cmd, e.getCause()));//$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringBuilder cmdOutput = new StringBuilder(200);
|
||||||
try {
|
try {
|
||||||
InputStream stream = process.getInputStream();
|
InputStream stream = process.getInputStream();
|
||||||
Reader r = new InputStreamReader(stream);
|
Reader r = new InputStreamReader(stream);
|
||||||
BufferedReader reader = new BufferedReader(r);
|
BufferedReader reader = new BufferedReader(r);
|
||||||
|
|
||||||
// These are the GDB version patterns I have seen up to now
|
String line;
|
||||||
// The pattern works for all of them extracting the version of 6.8.50.20080730
|
|
||||||
// GNU gdb 6.8.50.20080730
|
|
||||||
// GNU gdb (GDB) 6.8.50.20080730-cvs
|
|
||||||
// GNU gdb (Ericsson GDB 1.0-10) 6.8.50.20080730-cvs
|
|
||||||
Pattern pattern = Pattern.compile(" gdb( \\(.*\\))? (\\d*(\\.\\d*)*)", Pattern.MULTILINE); //$NON-NLS-1$
|
|
||||||
|
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
Matcher matcher = pattern.matcher(line);
|
cmdOutput.append(line);
|
||||||
if (matcher.find()) {
|
|
||||||
version = matcher.group(2);
|
|
||||||
// Temporary for cygwin, until GDB 7 is released
|
|
||||||
// Any cygwin GDB staring with 6.8 should be treated as plain 6.8
|
|
||||||
if (line.toLowerCase().indexOf("cygwin") != -1 && //$NON-NLS-1$
|
|
||||||
version.startsWith("6.8")) { //$NON-NLS-1$
|
|
||||||
version = "6.8"; //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new DebugException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED,
|
throw new DebugException(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, DebugException.REQUEST_FAILED,
|
||||||
"Error reading GDB STDOUT after sending: " + cmd, e.getCause()));//$NON-NLS-1$
|
"Error reading GDB STDOUT after sending: " + cmd, e.getCause()));//$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
return version;
|
return getGDBVersionFromText(cmdOutput.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean getIsAttach(ILaunchConfiguration config) {
|
public static boolean getIsAttach(ILaunchConfiguration config) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue