diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/macros/MbsMacroSupplier.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/macros/MbsMacroSupplier.java index 510b59e77b3..aebbaadc103 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/macros/MbsMacroSupplier.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/macros/MbsMacroSupplier.java @@ -33,12 +33,12 @@ import org.eclipse.cdt.managedbuilder.macros.IFileContextBuildMacroValues; import org.eclipse.cdt.managedbuilder.macros.IFileContextData; import org.eclipse.cdt.managedbuilder.macros.IOptionContextData; import org.eclipse.cdt.managedbuilder.makegen.IManagedBuilderMakefileGenerator; +import org.eclipse.cdt.utils.Platform; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.PluginVersionIdentifier; import org.osgi.framework.Bundle; diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/CProjectPlatformPage.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/CProjectPlatformPage.java index 6c846e2feb3..dfe518d0650 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/CProjectPlatformPage.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/wizards/CProjectPlatformPage.java @@ -25,9 +25,10 @@ import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderHelpContextIds; import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderUIMessages; import org.eclipse.cdt.managedbuilder.internal.ui.ManagedBuilderUIPlugin; import org.eclipse.cdt.ui.wizards.NewCProjectWizard; +import org.eclipse.cdt.utils.Platform; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; +//import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.viewers.CheckboxTableViewer; diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Platform.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Platform.java new file mode 100644 index 00000000000..9899e6d2cf0 --- /dev/null +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/Platform.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation 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: + * IBM Corporation - Initial API and implementation (Corey Ashford) + * + *******************************************************************************/ + +package org.eclipse.cdt.utils; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import org.osgi.framework.Bundle; + +public final class Platform { + + // This class duplicates all of the methods in org.eclipse.core.runtime.Platform + // that are used by the CDT. getOSArch() needs a few tweaks because the value returned + // by org.eclipse.core.runtime.Platform.getOSArch represents what the JVM thinks the + // architecture is. In some cases, we may actually be running on a 64-bit machine, + // but the JVM thinks it's running on a 32-bit machine. Without this change, the CDT + // will not handle 64-bit executables on some ppc64. This method could easily be + // extended to handle other platforms with similar issues. + // + // Unfortunately, the org.eclipse.core.runtime.Platform is final, so we cannot just + // extend it and and then override the getOSArch method, so getBundle and getOS just + // encapsulate calls to the same methods in org.eclipse.core.runtime.Platform. + + public static final String OS_LINUX = org.eclipse.core.runtime.Platform.OS_LINUX; + + private static boolean ppcArchIsCached = false; + private static String cachedPpcArch = null; + + public static Bundle getBundle(String symbolicName) { + return org.eclipse.core.runtime.Platform.getBundle(symbolicName); + } + + public static String getOS() { + return org.eclipse.core.runtime.Platform.getOS(); + } + + public static String getOSArch() { + String arch = org.eclipse.core.runtime.Platform.getOSArch(); + if (arch.equals(org.eclipse.core.runtime.Platform.ARCH_PPC)) { + // Determine if the platform is actually a ppc64 machine + if (!ppcArchIsCached) { + Process unameProcess; + String cmd[] = {"uname", "-p"}; + + ppcArchIsCached = true; + try { + unameProcess = Runtime.getRuntime().exec(cmd); + + InputStreamReader inputStreamReader = new InputStreamReader(unameProcess.getInputStream()); + BufferedReader bufferedReader = new BufferedReader(inputStreamReader); + cachedPpcArch = bufferedReader.readLine(); + + } catch (IOException e) { + cachedPpcArch = null; + } + } + if (cachedPpcArch != null) { + return cachedPpcArch; + } else { + return arch; + } + } + return arch; + } +} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/DebugConfiguration.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/DebugConfiguration.java index b940d85a1d0..ea124fd924b 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/DebugConfiguration.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/DebugConfiguration.java @@ -20,12 +20,14 @@ import org.eclipse.cdt.debug.core.CDebugCorePlugin; import org.eclipse.cdt.debug.core.ICDIDebugger; import org.eclipse.cdt.debug.core.ICDebugConfiguration; import org.eclipse.cdt.debug.core.ICDebugger; +import org.eclipse.cdt.utils.Platform; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; + + public class DebugConfiguration implements ICDebugConfiguration { /** * The configuration element of the extension. diff --git a/debug/org.eclipse.cdt.debug.mi.ui/src/org/eclipse/cdt/debug/mi/internal/ui/StandardGDBDebuggerPage.java b/debug/org.eclipse.cdt.debug.mi.ui/src/org/eclipse/cdt/debug/mi/internal/ui/StandardGDBDebuggerPage.java index ba7ce9f510f..783b72e3e67 100644 --- a/debug/org.eclipse.cdt.debug.mi.ui/src/org/eclipse/cdt/debug/mi/internal/ui/StandardGDBDebuggerPage.java +++ b/debug/org.eclipse.cdt.debug.mi.ui/src/org/eclipse/cdt/debug/mi/internal/ui/StandardGDBDebuggerPage.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.debug.mi.internal.ui; import java.io.File; +import java.io.IOException; import java.util.Arrays; import java.util.Comparator; import java.util.Observable; @@ -24,6 +25,7 @@ import org.eclipse.cdt.debug.mi.ui.IMILaunchConfigurationComponent; import org.eclipse.cdt.debug.mi.ui.MIUIUtils; import org.eclipse.cdt.debug.ui.AbstractCDebuggerPage; import org.eclipse.cdt.utils.ui.controls.ControlFactory; +import org.eclipse.cdt.utils.Platform; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; @@ -70,6 +72,10 @@ public class StandardGDBDebuggerPage extends AbstractCDebuggerPage implements Ob private CommandFactoryDescriptor[] fCommandFactoryDescriptors; private boolean fIsInitializing = false; + + private static boolean gdb64ExistsIsCached = false; + + private static boolean cachedGdb64Exists; public void createControl( Composite parent ) { Composite comp = new Composite( parent, SWT.NONE ); @@ -83,14 +89,60 @@ public class StandardGDBDebuggerPage extends AbstractCDebuggerPage implements Ob } public void setDefaults( ILaunchConfigurationWorkingCopy configuration ) { - configuration.setAttribute( IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, IMILaunchConfigurationConstants.DEBUGGER_DEBUG_NAME_DEFAULT ); + configuration.setAttribute( IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, defaultGdbCommand()); configuration.setAttribute( IMILaunchConfigurationConstants.ATTR_GDB_INIT, IMILaunchConfigurationConstants.DEBUGGER_GDB_INIT_DEFAULT ); configuration.setAttribute( IMILaunchConfigurationConstants.ATTR_DEBUGGER_COMMAND_FACTORY, MIPlugin.getDefault().getCommandFactoryManager().getDefaultDescriptor( getDebuggerIdentifier() ).getIdentifier() ); configuration.setAttribute( IMILaunchConfigurationConstants.ATTR_DEBUGGER_VERBOSE_MODE, IMILaunchConfigurationConstants.DEBUGGER_VERBOSE_MODE_DEFAULT ); if ( fSolibBlock != null ) fSolibBlock.setDefaults( configuration ); } + + private static String defaultGdbCommand() { + String gdbCommand = null; + if (Platform.getOS().equals(Platform.OS_LINUX) && + Platform.getOSArch().equals("ppc64")) { + // On SLES 9 and 10 for ppc64 arch, there is a separate + // 64-bit capable gdb called gdb64. It can + // also debug 32-bit executables, so let's see if it exists. + if (!gdb64ExistsIsCached) { + Process unameProcess; + int interruptedRetryCount = 5; + + String cmd[] = {"gdb64", "--version"}; + + gdb64ExistsIsCached = true; + + while (interruptedRetryCount >= 0) { + try { + unameProcess = Runtime.getRuntime().exec(cmd); + int exitStatus = unameProcess.waitFor(); + + cachedGdb64Exists = (exitStatus == 0); + break; + } catch (IOException e) { + cachedGdb64Exists = false; + break; + } catch (InterruptedException e) { + // Never should get here, really. The chances of the command being interrupted + // are very small + cachedGdb64Exists = false; + interruptedRetryCount--; + } + } + } + if (cachedGdb64Exists) { + gdbCommand = "gdb64"; //$NON-NLS-1$ + } else { + gdbCommand = IMILaunchConfigurationConstants.DEBUGGER_DEBUG_NAME_DEFAULT; + } + } else { + gdbCommand = IMILaunchConfigurationConstants.DEBUGGER_DEBUG_NAME_DEFAULT; + } + return gdbCommand; + } + + public boolean isValid( ILaunchConfiguration launchConfig ) { boolean valid = fGDBCommandText.getText().length() != 0; if ( valid ) { @@ -106,10 +158,10 @@ public class StandardGDBDebuggerPage extends AbstractCDebuggerPage implements Ob public void initializeFrom( ILaunchConfiguration configuration ) { setInitializing( true ); - String gdbCommand = IMILaunchConfigurationConstants.DEBUGGER_DEBUG_NAME_DEFAULT; + String gdbCommand = defaultGdbCommand(); String gdbInit = IMILaunchConfigurationConstants.DEBUGGER_GDB_INIT_DEFAULT; try { - gdbCommand = configuration.getAttribute( IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, IMILaunchConfigurationConstants.DEBUGGER_DEBUG_NAME_DEFAULT ); + gdbCommand = configuration.getAttribute( IMILaunchConfigurationConstants.ATTR_DEBUG_NAME, defaultGdbCommand()); } catch( CoreException e ) { } @@ -120,7 +172,6 @@ public class StandardGDBDebuggerPage extends AbstractCDebuggerPage implements Ob } if ( fSolibBlock != null ) fSolibBlock.initializeFrom( configuration ); - fGDBCommandText.setText( gdbCommand ); fGDBInitText.setText( gdbInit ); String debuggerID = getDebuggerIdentifier();