1
/*******************************************************************************
2
* Copyright (c) 2003, 2008 IBM Corporation 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
9
* QNX Software Systems - Initial API and implementation
10
*******************************************************************************/
12
package org.eclipse.cdt.ui.dialogs;
16
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IConfigurationElement;
19
import org.eclipse.core.runtime.IExtensionPoint;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.NullProgressMonitor;
22
import org.eclipse.core.runtime.Platform;
23
import org.eclipse.core.runtime.Preferences;
24
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.events.ModifyEvent;
26
import org.eclipse.swt.events.ModifyListener;
27
import org.eclipse.swt.events.SelectionAdapter;
28
import org.eclipse.swt.events.SelectionEvent;
29
import org.eclipse.swt.layout.GridData;
30
import org.eclipse.swt.layout.GridLayout;
31
import org.eclipse.swt.widgets.Button;
32
import org.eclipse.swt.widgets.Composite;
33
import org.eclipse.swt.widgets.FileDialog;
34
import org.eclipse.swt.widgets.Group;
35
import org.eclipse.swt.widgets.Label;
36
import org.eclipse.swt.widgets.Text;
38
import org.eclipse.cdt.core.CCorePlugin;
39
import org.eclipse.cdt.core.ICExtensionReference;
40
import org.eclipse.cdt.ui.CUIPlugin;
41
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
43
import org.eclipse.cdt.internal.ui.CUIMessages;
46
* Abstract base binary parser page for GNU binutils based binary parsers
48
public abstract class AbstractGNUBinaryParserPage extends AbstractCOptionPage {
50
public final static String PREF_ADDR2LINE_PATH = CUIPlugin.PLUGIN_ID + ".addr2line"; //$NON-NLS-1$
51
public final static String PREF_CPPFILT_PATH = CUIPlugin.PLUGIN_ID + ".cppfilt"; //$NON-NLS-1$
53
protected Text fAddr2LineCommandText;
54
protected Text fCPPFiltCommandText;
55
private String parserID = null;
60
* @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performApply(org.eclipse.core.runtime.IProgressMonitor)
63
public void performApply(IProgressMonitor monitor) throws CoreException {
64
if (monitor == null) {
65
monitor = new NullProgressMonitor();
68
String addr2line = fAddr2LineCommandText.getText().trim();
69
String cppfilt = fCPPFiltCommandText.getText().trim();
71
monitor.beginTask(CUIMessages.BinaryParserPage_task_savingAttributes, 1);
72
IProject proj = getContainer().getProject();
74
ICExtensionReference[] cext = CCorePlugin.getDefault().getBinaryParserExtensions(proj);
75
if (cext.length > 0) {
77
for (int i = 0; i < cext.length; i++) {
78
if (cext[i].getID().equals(parserID)) {
79
String orig = cext[i].getExtensionData("addr2line"); //$NON-NLS-1$
80
if (orig == null || !orig.equals(addr2line)) {
81
cext[i].setExtensionData("addr2line", addr2line); //$NON-NLS-1$
83
orig = cext[i].getExtensionData("c++filt"); //$NON-NLS-1$
84
if (orig == null || !orig.equals(cppfilt)) {
85
cext[i].setExtensionData("c++filt", cppfilt); //$NON-NLS-1$
91
Preferences store = getContainer().getPreferences();
93
store.setValue(PREF_ADDR2LINE_PATH, addr2line);
94
store.setValue(PREF_CPPFILT_PATH, cppfilt);
99
private void initializeParserId() {
100
if (parserID == null) {
101
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CUIPlugin.PLUGIN_ID, "BinaryParserPage"); //$NON-NLS-1$
102
IConfigurationElement[] infos = point.getConfigurationElements();
103
for (int i = 0; i < infos.length; i++) {
104
String id = infos[i].getAttribute("parserID"); //$NON-NLS-1$
105
String clazz = infos[i].getAttribute("class"); //$NON-NLS-1$
106
String ego = getRealBinaryParserPage().getClass().getName();
107
if (clazz != null && clazz.equals(ego)) {
112
parserID = ""; //$NON-NLS-1$
117
* If this class is inherited from then this method MUST be implemented
118
* in the derived class.
120
abstract protected AbstractGNUBinaryParserPage getRealBinaryParserPage();
125
* @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performDefaults()
128
public void performDefaults() {
129
String addr2line = null;
130
String cppfilt = null;
131
IProject proj = getContainer().getProject();
132
Preferences store = getContainer().getPreferences();
135
addr2line = store.getString(PREF_ADDR2LINE_PATH);
136
cppfilt = store.getString(PREF_CPPFILT_PATH);
138
addr2line = store.getDefaultString(PREF_ADDR2LINE_PATH);
139
cppfilt = store.getDefaultString(PREF_CPPFILT_PATH);
141
fAddr2LineCommandText.setText((addr2line == null || addr2line.length() == 0) ? "addr2line" : addr2line); //$NON-NLS-1$
142
fCPPFiltCommandText.setText((cppfilt == null || cppfilt.length() == 0) ? "c++filt" : cppfilt); //$NON-NLS-1$
149
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
152
public void createControl(Composite parent) {
153
Group comp = new Group(parent, SWT.SHADOW_ETCHED_IN);
154
comp.setText(CUIMessages.BinaryParserBlock_binaryParserOptions);
155
comp.setLayout(new GridLayout(2, true));
156
comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
157
((GridLayout) comp.getLayout()).makeColumnsEqualWidth = false;
159
Label label = ControlFactory.createLabel(comp, CUIMessages.BinaryParserPage_label_addr2lineCommand);
160
GridData gd = new GridData();
161
gd.horizontalSpan = 2;
162
label.setLayoutData(gd);
164
fAddr2LineCommandText = ControlFactory.createTextField(comp, SWT.SINGLE | SWT.BORDER);
165
fAddr2LineCommandText.addModifyListener(new ModifyListener() {
167
public void modifyText(ModifyEvent evt) {
168
//updateLaunchConfigurationDialog();
172
Button button = ControlFactory.createPushButton(comp, CUIMessages.BinaryParserPage_label_browse);
173
button.addSelectionListener(new SelectionAdapter() {
176
public void widgetSelected(SelectionEvent evt) {
177
handleAddr2LineButtonSelected();
178
//updateLaunchConfigurationDialog();
181
private void handleAddr2LineButtonSelected() {
182
FileDialog dialog = new FileDialog(getShell(), SWT.NONE);
183
dialog.setText(CUIMessages.BinaryParserPage_label_addr2lineCommand);
184
String command = fAddr2LineCommandText.getText().trim();
185
int lastSeparatorIndex = command.lastIndexOf(File.separator);
186
if (lastSeparatorIndex != -1) {
187
dialog.setFilterPath(command.substring(0, lastSeparatorIndex));
189
String res = dialog.open();
193
fAddr2LineCommandText.setText(res);
197
label = ControlFactory.createLabel(comp, CUIMessages.BinaryParserPage_label_cppfiltCommand);
199
gd.horizontalSpan = 2;
200
label.setLayoutData(gd);
202
fCPPFiltCommandText = ControlFactory.createTextField(comp, SWT.SINGLE | SWT.BORDER);
203
gd = new GridData(GridData.FILL_HORIZONTAL);
204
fCPPFiltCommandText.setLayoutData(gd);
205
fCPPFiltCommandText.addModifyListener(new ModifyListener() {
207
public void modifyText(ModifyEvent evt) {
208
//updateLaunchConfigurationDialog();
211
button = ControlFactory.createPushButton(comp, CUIMessages.BinaryParserPage_label_browse1);
212
button.addSelectionListener(new SelectionAdapter() {
215
public void widgetSelected(SelectionEvent evt) {
216
handleCPPFiltButtonSelected();
217
//updateLaunchConfigurationDialog();
220
private void handleCPPFiltButtonSelected() {
221
FileDialog dialog = new FileDialog(getShell(), SWT.NONE);
222
dialog.setText(CUIMessages.BinaryParserPage_label_cppfiltCommand);
223
String command = fCPPFiltCommandText.getText().trim();
224
int lastSeparatorIndex = command.lastIndexOf(File.separator);
225
if (lastSeparatorIndex != -1) {
226
dialog.setFilterPath(command.substring(0, lastSeparatorIndex));
228
String res = dialog.open();
232
fCPPFiltCommandText.setText(res);
240
private void initialziedValues() {
241
String addr2line = null;
242
String cppfilt = null;
243
IProject proj = getContainer().getProject();
246
ICExtensionReference[] cext = CCorePlugin.getDefault().getBinaryParserExtensions(proj);
247
if (cext.length > 0) {
248
initializeParserId();
249
for (int i = 0; i < cext.length; i++) {
250
if (cext[i].getID().equals(parserID)) {
251
addr2line = cext[0].getExtensionData("addr2line"); //$NON-NLS-1$
252
cppfilt = cext[0].getExtensionData("c++filt"); //$NON-NLS-1$
257
} catch (CoreException e) {
260
Preferences store = getContainer().getPreferences();
262
addr2line = store.getString(PREF_ADDR2LINE_PATH);
263
cppfilt = store.getString(PREF_CPPFILT_PATH);
266
fAddr2LineCommandText.setText((addr2line == null || addr2line.length() == 0) ? "addr2line" : addr2line); //$NON-NLS-1$
267
fCPPFiltCommandText.setText((cppfilt == null || cppfilt.length() == 0) ? "c++filt" : cppfilt); //$NON-NLS-1$