Search in sources :

Example 6 with IBinary

use of org.eclipse.cdt.core.model.IBinary in project linuxtools by eclipse.

the class SystemTapOptionsTab method setDefaults.

@Override
public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_VERBOSE, LaunchConfigurationConstants.DEFAULT_COMMAND_VERBOSE);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_KEEP_TEMPORARY, LaunchConfigurationConstants.DEFAULT_COMMAND_KEEP_TEMPORARY);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_GURU, LaunchConfigurationConstants.DEFAULT_COMMAND_GURU);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_PROLOGUE_SEARCH, LaunchConfigurationConstants.DEFAULT_COMMAND_PROLOGUE_SEARCH);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_NO_CODE_ELISION, LaunchConfigurationConstants.DEFAULT_COMMAND_NO_CODE_ELISION);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_DISABLE_WARNINGS, LaunchConfigurationConstants.DEFAULT_COMMAND_DISABLE_WARNINGS);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_BULK_MODE, LaunchConfigurationConstants.DEFAULT_COMMAND_BULK_MODE);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_TIMING_INFO, LaunchConfigurationConstants.DEFAULT_COMMAND_TIMING_INFO);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_SKIP_BADVARS, LaunchConfigurationConstants.DEFAULT_COMMAND_SKIP_BADVARS);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_IGNORE_DWARF, LaunchConfigurationConstants.DEFAULT_COMMAND_IGNORE_DWARF);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_TAPSET_COVERAGE, LaunchConfigurationConstants.DEFAULT_COMMAND_TAPSET_COVERAGE);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_LEAVE_RUNNING, LaunchConfigurationConstants.DEFAULT_COMMAND_LEAVE_RUNNING);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_PASS, LaunchConfigurationConstants.DEFAULT_COMMAND_PASS);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_BUFFER_BYTES, LaunchConfigurationConstants.DEFAULT_COMMAND_BUFFER_BYTES);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_TARGET_PID, LaunchConfigurationConstants.DEFAULT_COMMAND_TARGET_PID);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_C_DIRECTIVES, LaunchConfigurationConstants.DEFAULT_COMMAND_C_DIRECTIVES);
    configuration.setAttribute(LaunchConfigurationConstants.BINARY_PATH, LaunchConfigurationConstants.DEFAULT_BINARY_PATH);
    configuration.setAttribute(LaunchConfigurationConstants.SCRIPT_PATH, LaunchConfigurationConstants.DEFAULT_SCRIPT_PATH);
    configuration.setAttribute(LaunchConfigurationConstants.OUTPUT_PATH, LaunchConfigurationConstants.DEFAULT_OUTPUT_PATH);
    configuration.setAttribute(LaunchConfigurationConstants.ARGUMENTS, LaunchConfigurationConstants.DEFAULT_ARGUMENTS);
    configuration.setAttribute(LaunchConfigurationConstants.BINARY_ARGUMENTS, LaunchConfigurationConstants.DEFAULT_BINARY_ARGUMENTS);
    configuration.setAttribute(LaunchConfigurationConstants.GENERATED_SCRIPT, LaunchConfigurationConstants.DEFAULT_GENERATED_SCRIPT);
    configuration.setAttribute(LaunchConfigurationConstants.NEED_TO_GENERATE, LaunchConfigurationConstants.DEFAULT_NEED_TO_GENERATE);
    configuration.setAttribute(LaunchConfigurationConstants.PARSER_CLASS, LaunchConfigurationConstants.DEFAULT_PARSER_CLASS);
    configuration.setAttribute(LaunchConfigurationConstants.VIEW_CLASS, LaunchConfigurationConstants.DEFAULT_VIEW_CLASS);
    configuration.setAttribute(LaunchConfigurationConstants.USE_COLOUR, LaunchConfigurationConstants.DEFAULT_USE_COLOUR);
    configuration.setAttribute(LaunchConfigurationConstants.COMMAND_LIST, ConfigurationOptionsSetter.setOptions(configuration));
    ICElement cElement = null;
    cElement = getContext(configuration, getPlatform(configuration));
    if (cElement != null) {
        initializeCProject(cElement, configuration);
    } else {
        // don't want to remember the interim value from before
        configuration.setMappedResources(null);
    }
    IBinary bin = getBinary(configuration);
    if (bin != null) {
        String programName = bin.getResource().getProjectRelativePath().toString();
        configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, programName);
        configuration.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null);
        LaunchStapGraph launch = new LaunchStapGraph();
        // Do not run callgraph
        launch.setTestMode(true);
        // $NON-NLS-1$
        launch.launch(bin, "", configuration);
    }
}
Also used : IBinary(org.eclipse.cdt.core.model.IBinary) ICElement(org.eclipse.cdt.core.model.ICElement)

Example 7 with IBinary

use of org.eclipse.cdt.core.model.IBinary in project linuxtools by eclipse.

the class OpenGmonAction method getDefaultBinary.

private String getDefaultBinary(IPath file) {
    IProject project = null;
    IFile c = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(file);
    if (c != null) {
        project = c.getProject();
        if (project != null && project.exists()) {
            ICProject cproject = CoreModel.getDefault().create(project);
            if (cproject != null) {
                try {
                    IBinary[] b = cproject.getBinaryContainer().getBinaries();
                    if (b != null && b.length > 0 && b[0] != null) {
                        IResource r = b[0].getResource();
                        return r.getLocation().toOSString();
                    }
                } catch (CModelException e) {
                }
            }
        }
    }
    // $NON-NLS-1$
    return "";
}
Also used : IFile(org.eclipse.core.resources.IFile) ICProject(org.eclipse.cdt.core.model.ICProject) CModelException(org.eclipse.cdt.core.model.CModelException) IBinary(org.eclipse.cdt.core.model.IBinary) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource)

Example 8 with IBinary

use of org.eclipse.cdt.core.model.IBinary in project linuxtools by eclipse.

the class ProfileLaunchShortcut method searchAndLaunch.

/**
 * Search and launch binary.
 *
 * @param elements Binaries to search.
 * @param mode Launch mode.
 */
private void searchAndLaunch(final Object[] elements, String mode) {
    if (elements != null && elements.length > 0) {
        IBinary bin = null;
        if (elements.length == 1 && elements[0] instanceof IBinary) {
            bin = (IBinary) elements[0];
        } else {
            final List<IBinary> results = new ArrayList<>();
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(getActiveWorkbenchShell());
            IRunnableWithProgress runnable = pm -> {
                int nElements = elements.length;
                pm.beginTask(Messages.ProfileLaunchShortcut_Looking_for_executables, nElements);
                try {
                    IProgressMonitor sub = SubMonitor.convert(pm, 1);
                    for (int i = 0; i < nElements; i++) {
                        if (elements[i] instanceof IAdaptable) {
                            IResource r = ((IAdaptable) elements[i]).getAdapter(IResource.class);
                            if (r != null) {
                                ICProject cproject = CoreModel.getDefault().create(r.getProject());
                                if (cproject != null) {
                                    try {
                                        IBinary[] bins = cproject.getBinaryContainer().getBinaries();
                                        for (IBinary bin1 : bins) {
                                            if (bin1.isExecutable()) {
                                                results.add(bin1);
                                            }
                                        }
                                    } catch (CModelException e) {
                                    // TODO should this be simply ignored ?
                                    }
                                }
                            }
                        }
                        if (pm.isCanceled()) {
                            throw new InterruptedException();
                        }
                        sub.done();
                    }
                } finally {
                    pm.done();
                }
            };
            try {
                dialog.run(true, true, runnable);
            } catch (InterruptedException e) {
                return;
            } catch (InvocationTargetException e) {
                handleFail(e.getMessage());
                return;
            }
            int count = results.size();
            if (count == 0) {
                handleFail(Messages.ProfileLaunchShortcut_Binary_not_found);
            } else if (count > 1) {
                bin = chooseBinary(results, mode);
            } else {
                bin = results.get(0);
            }
        }
        if (bin != null) {
            launch(bin, mode);
        }
    } else {
        handleFail(Messages.ProfileLaunchShortcut_no_project_selected);
    }
}
Also used : IDebugModelPresentation(org.eclipse.debug.ui.IDebugModelPresentation) DebugPlugin(org.eclipse.debug.core.DebugPlugin) SubMonitor(org.eclipse.core.runtime.SubMonitor) CoreModel(org.eclipse.cdt.core.model.CoreModel) CoreException(org.eclipse.core.runtime.CoreException) DebugUITools(org.eclipse.debug.ui.DebugUITools) ArrayList(java.util.ArrayList) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) TwoPaneElementSelector(org.eclipse.ui.dialogs.TwoPaneElementSelector) Messages(org.eclipse.linuxtools.internal.profiling.launch.Messages) ILaunchShortcut(org.eclipse.debug.ui.ILaunchShortcut) IPath(org.eclipse.core.runtime.IPath) ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) ICProject(org.eclipse.cdt.core.model.ICProject) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) IEditorPart(org.eclipse.ui.IEditorPart) IAdaptable(org.eclipse.core.runtime.IAdaptable) CDebugUtils(org.eclipse.cdt.debug.core.CDebugUtils) Shell(org.eclipse.swt.widgets.Shell) ProfileLaunchPlugin(org.eclipse.linuxtools.internal.profiling.launch.ProfileLaunchPlugin) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IBinary(org.eclipse.cdt.core.model.IBinary) CModelException(org.eclipse.cdt.core.model.CModelException) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchManager(org.eclipse.debug.core.ILaunchManager) InvocationTargetException(java.lang.reflect.InvocationTargetException) CElementLabelProvider(org.eclipse.cdt.ui.CElementLabelProvider) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) List(java.util.List) Window(org.eclipse.jface.window.Window) ICDTLaunchConfigurationConstants(org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants) IResource(org.eclipse.core.resources.IResource) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Collections(java.util.Collections) IAdaptable(org.eclipse.core.runtime.IAdaptable) ICProject(org.eclipse.cdt.core.model.ICProject) CModelException(org.eclipse.cdt.core.model.CModelException) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) IBinary(org.eclipse.cdt.core.model.IBinary) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IResource(org.eclipse.core.resources.IResource)

Example 9 with IBinary

use of org.eclipse.cdt.core.model.IBinary in project linuxtools by eclipse.

the class ProfileLaunchShortcut method chooseBinary.

/**
 * Prompts the user to select a  binary
 * @param binList The list of binaries.
 * @param mode Old and not used parameter.
 *
 * @return the selected binary or <code>null</code> if none.
 */
// TODO remove unused mode parameter for 4.0
protected IBinary chooseBinary(List<IBinary> binList, String mode) {
    ILabelProvider programLabelProvider = new CElementLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof IBinary) {
                return ((IBinary) element).getPath().lastSegment();
            }
            return super.getText(element);
        }
    };
    ILabelProvider qualifierLabelProvider = new CElementLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof IBinary) {
                IBinary bin = (IBinary) element;
                StringBuilder name = new StringBuilder();
                // $NON-NLS-1$ //$NON-NLS-2$
                name.append(bin.getCPU() + (bin.isLittleEndian() ? "le" : "be"));
                // $NON-NLS-1$
                name.append(" - ");
                name.append(bin.getPath().toString());
                return name.toString();
            }
            return super.getText(element);
        }
    };
    TwoPaneElementSelector dialog = new TwoPaneElementSelector(getActiveWorkbenchShell(), programLabelProvider, qualifierLabelProvider);
    dialog.setElements(binList.toArray());
    dialog.setTitle(Messages.ProfileLaunchShortcut_Profile);
    dialog.setMessage(Messages.ProfileLaunchShortcut_Choose_a_local_application);
    dialog.setUpperListLabel(Messages.ProfileLaunchShortcut_Binaries);
    dialog.setLowerListLabel(Messages.ProfileLaunchShortcut_Qualifier);
    dialog.setMultipleSelection(false);
    if (dialog.open() == Window.OK) {
        return (IBinary) dialog.getFirstResult();
    }
    return null;
}
Also used : CElementLabelProvider(org.eclipse.cdt.ui.CElementLabelProvider) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) IBinary(org.eclipse.cdt.core.model.IBinary) TwoPaneElementSelector(org.eclipse.ui.dialogs.TwoPaneElementSelector)

Example 10 with IBinary

use of org.eclipse.cdt.core.model.IBinary in project linuxtools by eclipse.

the class RemoteProxyCMainTab method initializeProgramName.

/**
 * Set the program name attributes on the working copy based on the
 * ICElement.
 * @param cElement The element to get data from.
 * @param config The configuration to initialize
 */
protected void initializeProgramName(ICElement cElement, ILaunchConfigurationWorkingCopy config) {
    boolean renamed = false;
    if (!(cElement instanceof IBinary)) {
        cElement = cElement.getCProject();
    }
    if (cElement instanceof ICProject) {
        IProject project = cElement.getCProject().getProject();
        String name = project.getName();
        ICProjectDescription projDes = CCorePlugin.getDefault().getProjectDescription(project);
        if (projDes != null) {
            String buildConfigName = projDes.getActiveConfiguration().getName();
            // Bug 234951
            name = NLS.bind(LaunchMessages.CMainTab_Configuration_name, name, buildConfigName);
        }
        name = getLaunchConfigurationDialog().generateName(name);
        config.rename(name);
        renamed = true;
    }
    IBinary binary = null;
    if (cElement instanceof ICProject) {
        IBinary[] bins = getBinaryFiles((ICProject) cElement);
        if (bins != null && bins.length == 1) {
            binary = bins[0];
        }
    } else if (cElement instanceof IBinary) {
        binary = (IBinary) cElement;
    }
    String projectDir = EMPTY_STRING;
    IProject project = null;
    try {
        project = ConfigUtils.getProject(ConfigUtils.getProjectName(config));
    } catch (CoreException e) {
        setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.error_accessing_working_directory);
    }
    if (project != null) {
        try {
            projectDir = RemoteProxyManager.getInstance().getRemoteProjectLocation(project);
        } catch (CoreException e) {
            setErrorMessage(fPreviouslyCheckedWorkingDirErrorMsg = ProxyLaunchMessages.error_accessing_working_directory);
        }
    }
    String path = EMPTY_STRING;
    if (binary != null) {
        path = binary.getResource().getProjectRelativePath().toOSString();
        if (!renamed) {
            String name = binary.getElementName();
            int index = name.lastIndexOf('.');
            if (index > 0) {
                name = name.substring(0, index);
            }
            name = getLaunchConfigurationDialog().generateName(name);
            config.rename(name);
            renamed = true;
        }
    }
    config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, projectDir + IPath.SEPARATOR + path);
    if (!renamed) {
        String name = getLaunchConfigurationDialog().generateName(cElement.getCProject().getElementName());
        config.rename(name);
    }
}
Also used : ICProjectDescription(org.eclipse.cdt.core.settings.model.ICProjectDescription) ICProject(org.eclipse.cdt.core.model.ICProject) CoreException(org.eclipse.core.runtime.CoreException) IBinary(org.eclipse.cdt.core.model.IBinary) IProject(org.eclipse.core.resources.IProject)

Aggregations

IBinary (org.eclipse.cdt.core.model.IBinary)12 ICProject (org.eclipse.cdt.core.model.ICProject)7 CoreException (org.eclipse.core.runtime.CoreException)5 CElementLabelProvider (org.eclipse.cdt.ui.CElementLabelProvider)4 IProject (org.eclipse.core.resources.IProject)4 IResource (org.eclipse.core.resources.IResource)4 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)4 TwoPaneElementSelector (org.eclipse.ui.dialogs.TwoPaneElementSelector)4 CModelException (org.eclipse.cdt.core.model.CModelException)3 IFile (org.eclipse.core.resources.IFile)3 IPath (org.eclipse.core.runtime.IPath)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ICElement (org.eclipse.cdt.core.model.ICElement)2 Path (org.eclipse.core.runtime.Path)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URI (java.net.URI)1 Collections (java.util.Collections)1 List (java.util.List)1 CoreModel (org.eclipse.cdt.core.model.CoreModel)1