~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to results/plugins/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/launching/CDebuggerTab.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*******************************************************************************
2
 
 * Copyright (c) 2008 QNX Software Systems and others.
3
 
 * All rights reserved. This program and the accompanying materials
4
 
 * are made available under the terms of the Eclipse Public License v1.0
5
 
 * which accompanies this distribution, and is available at
6
 
 * http://www.eclipse.org/legal/epl-v10.html
7
 
 *
8
 
 * Contributors:
9
 
 * QNX Software Systems - Initial API and implementation
10
 
 * Ken Ryall (Nokia) - https://bugs.eclipse.org/bugs/show_bug.cgi?id=118894
11
 
 * IBM Corporation
12
 
 * Ericsson
13
 
 *******************************************************************************/
14
 
package org.eclipse.cdt.dsf.gdb.internal.ui.launching;
15
 
 
16
 
import java.util.ArrayList;
17
 
import java.util.Arrays;
18
 
import java.util.Comparator;
19
 
import java.util.List;
20
 
 
21
 
import org.eclipse.cdt.core.model.CoreModel;
22
 
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
23
 
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
24
 
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
25
 
import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
26
 
import org.eclipse.cdt.debug.core.ICDebugConfiguration;
27
 
import org.eclipse.cdt.debug.core.ICDebugConstants;
28
 
import org.eclipse.cdt.debug.ui.ICDebuggerPage;
29
 
import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants;
30
 
import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin;
31
 
import org.eclipse.cdt.dsf.gdb.launching.LaunchMessages;
32
 
import org.eclipse.cdt.dsf.gdb.service.SessionType;
33
 
import org.eclipse.core.resources.IProject;
34
 
import org.eclipse.core.resources.ResourcesPlugin;
35
 
import org.eclipse.core.runtime.CoreException;
36
 
import org.eclipse.debug.core.ILaunchConfiguration;
37
 
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
38
 
import org.eclipse.swt.SWT;
39
 
import org.eclipse.swt.accessibility.AccessibleAdapter;
40
 
import org.eclipse.swt.accessibility.AccessibleEvent;
41
 
import org.eclipse.swt.custom.ScrolledComposite;
42
 
import org.eclipse.swt.events.ModifyEvent;
43
 
import org.eclipse.swt.events.ModifyListener;
44
 
import org.eclipse.swt.events.SelectionAdapter;
45
 
import org.eclipse.swt.events.SelectionEvent;
46
 
import org.eclipse.swt.layout.FillLayout;
47
 
import org.eclipse.swt.layout.GridData;
48
 
import org.eclipse.swt.layout.GridLayout;
49
 
import org.eclipse.swt.widgets.Button;
50
 
import org.eclipse.swt.widgets.Composite;
51
 
import org.eclipse.swt.widgets.Shell;
52
 
import org.eclipse.swt.widgets.Text;
53
 
 
54
 
import com.ibm.icu.text.Collator;
55
 
 
56
 
public class CDebuggerTab extends AbstractCDebuggerTab {
57
 
        
58
 
    /**
59
 
     * Tab identifier used for ordering of tabs added using the 
60
 
     * <code>org.eclipse.debug.ui.launchConfigurationTabs</code>
61
 
     * extension point.
62
 
     *   
63
 
     * @since 2.0
64
 
     */
65
 
    public static final String TAB_ID = "org.eclipse.cdt.dsf.gdb.launch.debuggerTab"; //$NON-NLS-1$
66
 
 
67
 
        private final static String LOCAL_DEBUGGER_ID = "org.eclipse.cdt.dsf.gdb.GdbDebugger";//$NON-NLS-1$
68
 
        private final static String REMOTE_DEBUGGER_ID = "org.eclipse.cdt.dsf.gdb.GdbServerDebugger";//$NON-NLS-1$
69
 
        
70
 
        protected boolean fAttachMode = false;
71
 
        protected boolean fRemoteMode = false;
72
 
        protected boolean fCoreMode = false;
73
 
        
74
 
        protected Button fStopInMain;
75
 
        protected Text fStopInMainSymbol;
76
 
 
77
 
        private ScrolledComposite fContainer;
78
 
 
79
 
        private Composite fContents;
80
 
 
81
 
        public CDebuggerTab(SessionType sessionType, boolean attach) {
82
 
                if (sessionType == SessionType.REMOTE) {
83
 
                        fRemoteMode = true;
84
 
                } else if (sessionType == SessionType.CORE) {
85
 
                        fCoreMode = true;
86
 
                }
87
 
                fAttachMode = attach;
88
 
                 
89
 
                ICDebugConfiguration dc = CDebugCorePlugin.getDefault().getDefaultDefaultDebugConfiguration();
90
 
                if (dc == null) {
91
 
                        CDebugCorePlugin.getDefault().getPluginPreferences().setDefault(ICDebugConstants.PREF_DEFAULT_DEBUGGER_TYPE,
92
 
                                                                                                LOCAL_DEBUGGER_ID);
93
 
                }
94
 
        }
95
 
 
96
 
        @Override
97
 
        public String getId() {
98
 
            return TAB_ID;
99
 
        }
100
 
 
101
 
        @Override
102
 
        public void createControl(Composite parent) {
103
 
                fContainer = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
104
 
                fContainer.setLayoutData(new GridData(GridData.FILL_BOTH));
105
 
                fContainer.setLayout(new FillLayout());
106
 
                fContainer.setExpandHorizontal(true);
107
 
                fContainer.setExpandVertical(true);
108
 
                
109
 
                fContents = new Composite(fContainer, SWT.NONE);
110
 
                setControl(fContainer);
111
 
                GdbUIPlugin.getDefault().getWorkbench().getHelpSystem().setHelp(getControl(),
112
 
                                ICDTLaunchHelpContextIds.LAUNCH_CONFIGURATION_DIALOG_DEBBUGER_TAB);
113
 
                int numberOfColumns = (fAttachMode) ? 2 : 1;
114
 
                GridLayout layout = new GridLayout(numberOfColumns, false);
115
 
                fContents.setLayout(layout);
116
 
                GridData gd = new GridData(GridData.BEGINNING, GridData.CENTER, true, false);
117
 
                fContents.setLayoutData(gd);
118
 
 
119
 
                createDebuggerCombo(fContents, (fAttachMode) ? 1 : 2);
120
 
                createOptionsComposite(fContents);
121
 
                createDebuggerGroup(fContents, 2);
122
 
                
123
 
                fContainer.setContent(fContents);
124
 
        }
125
 
 
126
 
        protected void loadDebuggerComboBox(ILaunchConfiguration config, String selection) {
127
 
        ICDebugConfiguration[] debugConfigs = CDebugCorePlugin.getDefault().getActiveDebugConfigurations();
128
 
                Arrays.sort(debugConfigs, new Comparator<ICDebugConfiguration>() {
129
 
                        public int compare(ICDebugConfiguration c1, ICDebugConfiguration c2) {
130
 
                                return Collator.getInstance().compare(c1.getName(), c2.getName());
131
 
                        }
132
 
                });
133
 
                List<ICDebugConfiguration> list = new ArrayList<ICDebugConfiguration>();
134
 
                if (selection.equals("")) { //$NON-NLS-1$
135
 
                        ICDebugConfiguration dc = CDebugCorePlugin.getDefault().getDefaultDebugConfiguration();
136
 
                        if (dc == null) {
137
 
                                CDebugCorePlugin.getDefault().saveDefaultDebugConfiguration(LOCAL_DEBUGGER_ID);
138
 
                                dc = CDebugCorePlugin.getDefault().getDefaultDebugConfiguration();
139
 
                        }
140
 
                        if (dc != null)
141
 
                                selection = dc.getID();
142
 
                }
143
 
                String defaultSelection = selection;
144
 
                for (ICDebugConfiguration debugConfig: debugConfigs) {
145
 
                        // Note that for an attach session, we don't know yet if the user will want to do a
146
 
                        // remote session.  So, we must allow for the remote debugger even if fRemote is false,
147
 
                        // in the case of attach
148
 
                        if (((fRemoteMode || fAttachMode) && debugConfig.getID().equals(REMOTE_DEBUGGER_ID)) ||
149
 
                (!fRemoteMode && debugConfig.getID().equals(LOCAL_DEBUGGER_ID))) {
150
 
                                        list.add(debugConfig);
151
 
                        }
152
 
                }
153
 
                // if no selection meaning nothing in config the force initdefault on tab
154
 
                setInitializeDefault(selection.equals("") ? true : false); //$NON-NLS-1$
155
 
                loadDebuggerCombo(list.toArray(new ICDebugConfiguration[list.size()]), defaultSelection);
156
 
        }
157
 
 
158
 
        @Override
159
 
        protected void updateComboFromSelection() {
160
 
                super.updateComboFromSelection();
161
 
                initializeCommonControls(getLaunchConfiguration());
162
 
        }
163
 
 
164
 
        @Override
165
 
        public void setDefaults(ILaunchConfigurationWorkingCopy config) {
166
 
                super.setDefaults(config);
167
 
                if (fAttachMode && fRemoteMode) {
168
 
                        config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
169
 
                                        IGDBLaunchConfigurationConstants.DEBUGGER_MODE_REMOTE_ATTACH);
170
 
                } else if (fAttachMode) {
171
 
                        config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
172
 
                                        ICDTLaunchConfigurationConstants.DEBUGGER_MODE_ATTACH);
173
 
                } else if (fRemoteMode) {
174
 
                        config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
175
 
                                    IGDBLaunchConfigurationConstants.DEBUGGER_MODE_REMOTE);
176
 
                } else if (fCoreMode){
177
 
                        config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
178
 
                                        ICDTLaunchConfigurationConstants.DEBUGGER_MODE_CORE);
179
 
                } else {
180
 
                        config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
181
 
                                        ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN);
182
 
                }
183
 
                
184
 
                if (!fAttachMode && !fCoreMode) {
185
 
                        config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN,
186
 
                                        ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_DEFAULT);
187
 
                }
188
 
                
189
 
                // Set the default debugger based on the active toolchain on the project (if possible)
190
 
                String defaultDebugger = null;
191
 
                try {
192
 
                        String projectName = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, "");//$NON-NLS-1$
193
 
                        if (projectName.length() > 0) {
194
 
                                IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
195
 
                ICProjectDescription projDesc = CoreModel.getDefault().getProjectDescription(project);
196
 
                ICConfigurationDescription configDesc = projDesc.getActiveConfiguration();
197
 
                String configId = configDesc.getId();
198
 
                        ICDebugConfiguration[] debugConfigs = CDebugCorePlugin.getDefault().getActiveDebugConfigurations();
199
 
                        outer: for (int i = 0; i < debugConfigs.length; ++i) {
200
 
                                ICDebugConfiguration debugConfig = debugConfigs[i];
201
 
                                String[] patterns = debugConfig.getSupportedBuildConfigPatterns();
202
 
                                if (patterns != null) {
203
 
                                        for (int j = 0; j < patterns.length; ++j) {
204
 
                                                if (configId.matches(patterns[j])) {
205
 
                                                        defaultDebugger = debugConfig.getID();
206
 
                                                        break outer;
207
 
                                                }
208
 
                                        }
209
 
                                }
210
 
                        }
211
 
                        }
212
 
                } catch (CoreException e) {
213
 
                }
214
 
                
215
 
                if (defaultDebugger == null) {
216
 
                        ICDebugConfiguration dc = CDebugCorePlugin.getDefault().getDefaultDebugConfiguration();
217
 
                        if (dc != null) {
218
 
                                defaultDebugger = dc.getID();
219
 
                        }
220
 
                }
221
 
                
222
 
                config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, defaultDebugger);
223
 
        }
224
 
 
225
 
        @Override
226
 
        public void initializeFrom(ILaunchConfiguration config) {
227
 
                setInitializing(true);
228
 
                super.initializeFrom(config);
229
 
                try {
230
 
                        String id = config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_ID, ""); //$NON-NLS-1$
231
 
                        loadDebuggerComboBox(config, id);
232
 
                        initializeCommonControls(config);
233
 
                } catch (CoreException e) {
234
 
                }
235
 
                setInitializing(false);
236
 
        }
237
 
 
238
 
        @Override
239
 
        public void performApply(ILaunchConfigurationWorkingCopy config) {
240
 
                super.performApply(config);
241
 
                
242
 
                if (fAttachMode && fRemoteMode) {
243
 
                        config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
244
 
                                        IGDBLaunchConfigurationConstants.DEBUGGER_MODE_REMOTE_ATTACH);
245
 
                } else if (fAttachMode) {
246
 
                        config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
247
 
                                        ICDTLaunchConfigurationConstants.DEBUGGER_MODE_ATTACH);
248
 
                } else if (fRemoteMode) {
249
 
                        config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
250
 
                                    IGDBLaunchConfigurationConstants.DEBUGGER_MODE_REMOTE);
251
 
                } else if (fCoreMode){
252
 
                        config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
253
 
                                        ICDTLaunchConfigurationConstants.DEBUGGER_MODE_CORE);
254
 
                } else {
255
 
                        config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_START_MODE,
256
 
                                        ICDTLaunchConfigurationConstants.DEBUGGER_MODE_RUN);
257
 
                }
258
 
                if (!fAttachMode && !fCoreMode) {
259
 
                        config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN,
260
 
                                        fStopInMain.getSelection());
261
 
                        config.setAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL, 
262
 
                                    fStopInMainSymbol.getText());
263
 
                }
264
 
        }
265
 
 
266
 
        @Override
267
 
        public boolean isValid(ILaunchConfiguration config) {
268
 
                if (!validateDebuggerConfig(config)) {
269
 
                        return false;
270
 
                }
271
 
                if (fStopInMain != null && fStopInMainSymbol != null) {
272
 
                        // The "Stop on startup at" field must not be empty
273
 
                        String mainSymbol = fStopInMainSymbol.getText().trim();
274
 
                        if (fStopInMain.getSelection() && mainSymbol.length() == 0) {
275
 
                                setErrorMessage(LaunchMessages.getString("CDebuggerTab.Stop_on_startup_at_can_not_be_empty")); //$NON-NLS-1$
276
 
                                return false;
277
 
                        }
278
 
                }
279
 
                if (super.isValid(config) == false) {
280
 
                        return false;
281
 
                }
282
 
                return true;
283
 
        }
284
 
 
285
 
        protected boolean validateDebuggerConfig(ILaunchConfiguration config) {
286
 
                ICDebugConfiguration debugConfig = getDebugConfig();
287
 
                if (debugConfig == null) {
288
 
                        setErrorMessage(LaunchMessages.getString("CDebuggerTab.No_debugger_available")); //$NON-NLS-1$
289
 
                        return false;
290
 
                }
291
 
                // We do not validate platform and CPU compatibility to avoid accidentally disabling
292
 
                // a valid configuration. It's much better to let an incompatible configuration through
293
 
                // than to disable a valid one.
294
 
                return true;
295
 
        }
296
 
 
297
 
        /**
298
 
         * @see org.eclipse.debug.ui.AbstractLaunchConfigurationTab#updateLaunchConfigurationDialog()
299
 
         */
300
 
        protected void update() {
301
 
                if (!isInitializing()) {
302
 
                        super.updateLaunchConfigurationDialog();
303
 
                }
304
 
        }
305
 
 
306
 
        protected void createOptionsComposite(Composite parent) {
307
 
                Composite optionsComp = new Composite(parent, SWT.NONE);
308
 
                int numberOfColumns = (fAttachMode) ? 1 : 3;
309
 
                GridLayout layout = new GridLayout(numberOfColumns, false);
310
 
                optionsComp.setLayout(layout);
311
 
                optionsComp.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false, 1, 1));
312
 
                if (!fAttachMode && !fCoreMode) {
313
 
                        fStopInMain = createCheckButton(optionsComp, LaunchMessages.getString("CDebuggerTab.Stop_at_main_on_startup")); //$NON-NLS-1$
314
 
                        fStopInMain.addSelectionListener(new SelectionAdapter() {
315
 
 
316
 
                                @Override
317
 
                                public void widgetSelected(SelectionEvent e) {
318
 
                                        fStopInMainSymbol.setEnabled(fStopInMain.getSelection());
319
 
                                        update();
320
 
                                }
321
 
                        });
322
 
                        fStopInMainSymbol = new Text(optionsComp, SWT.SINGLE | SWT.BORDER);
323
 
                        final GridData gridData = new GridData(GridData.FILL, GridData.CENTER, false, false);
324
 
                        gridData.widthHint = 100;
325
 
                        fStopInMainSymbol.setLayoutData(gridData);
326
 
                        fStopInMainSymbol.addModifyListener(new ModifyListener() {
327
 
                                public void modifyText(ModifyEvent evt) {
328
 
                                        update();
329
 
                                }
330
 
                        });
331
 
                        fStopInMainSymbol.getAccessible().addAccessibleListener(
332
 
                                new AccessibleAdapter() {                       
333
 
                                        @Override
334
 
                                        public void getName(AccessibleEvent e) {
335
 
                            e.result = LaunchMessages.getString("CDebuggerTab.Stop_at_main_on_startup"); //$NON-NLS-1$
336
 
                                        }
337
 
                                }
338
 
                        );
339
 
                }
340
 
        }
341
 
 
342
 
        @Override
343
 
        protected Shell getShell() {
344
 
                return super.getShell();
345
 
        }
346
 
 
347
 
        /*
348
 
         * (non-Javadoc)
349
 
         * 
350
 
         * @see org.eclipse.debug.ui.ILaunchConfigurationTab#dispose()
351
 
         */
352
 
        @Override
353
 
        public void dispose() {
354
 
                ICDebuggerPage debuggerPage = getDynamicTab();
355
 
                if (debuggerPage != null)
356
 
                        debuggerPage.dispose();
357
 
                super.dispose();
358
 
        }
359
 
 
360
 
        protected void initializeCommonControls(ILaunchConfiguration config) {
361
 
                try {
362
 
                        if (!fAttachMode && !fCoreMode) {
363
 
                                fStopInMain.setSelection(config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN,
364
 
                                                ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_DEFAULT));
365
 
                                fStopInMainSymbol.setText(config.getAttribute(ICDTLaunchConfigurationConstants.ATTR_DEBUGGER_STOP_AT_MAIN_SYMBOL,
366
 
                                                ICDTLaunchConfigurationConstants.DEBUGGER_STOP_AT_MAIN_SYMBOL_DEFAULT));
367
 
                                fStopInMainSymbol.setEnabled(fStopInMain.getSelection());
368
 
                        } else if (fAttachMode) {
369
 
                                // In attach mode, figure out if we are doing a remote connect based on the currently
370
 
                                // chosen debugger
371
 
                                if (getDebugConfig().getID().equals(REMOTE_DEBUGGER_ID)) fRemoteMode = true;
372
 
                                else fRemoteMode = false;
373
 
                        }
374
 
                } catch (CoreException e) {
375
 
                }
376
 
        }
377
 
 
378
 
        @Override
379
 
        protected void setInitializeDefault(boolean init) {
380
 
                super.setInitializeDefault(init);
381
 
        }
382
 
        
383
 
        @Override
384
 
        protected void contentsChanged() {
385
 
                fContainer.setMinSize(fContents.computeSize(SWT.DEFAULT, SWT.DEFAULT));
386
 
        }
387
 
}
 
 
b'\\ No newline at end of file'