Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0cfcfedae5793954727c9a7d44e9fb8303fd6117 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/*******************************************************************************
 * Copyright (c) 2007, 2015 Wind River Systems, Inc. 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:
 *     Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.internal.cdt.ui.breakpoints;

import java.math.BigInteger;
import java.util.Map;
import java.util.TreeMap;

import org.eclipse.cdt.debug.core.CDIDebugModel;
import org.eclipse.cdt.debug.core.model.ICBreakpointType;
import org.eclipse.cdt.debug.core.model.ICEventBreakpoint;
import org.eclipse.cdt.debug.core.model.ICFunctionBreakpoint;
import org.eclipse.cdt.debug.core.model.ICLineBreakpoint;
import org.eclipse.cdt.debug.core.model.ICWatchpoint;
import org.eclipse.cdt.debug.ui.breakpoints.AbstractToggleBreakpointAdapter;
import org.eclipse.cdt.dsf.debug.internal.ui.disassembly.provisional.IDisassemblyPart;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.widgets.Event;
import org.eclipse.tcf.internal.cdt.ui.Activator;
import org.eclipse.tcf.internal.cdt.ui.preferences.PreferenceConstants;
import org.eclipse.tcf.internal.debug.model.TCFBreakpointsModel;
import org.eclipse.tcf.internal.debug.model.TCFLaunch;
import org.eclipse.tcf.internal.debug.ui.model.TCFNode;
import org.eclipse.ui.IWorkbenchPart;

/**
 * Toggles a TCF Scoped breakpoint in a C/C++ editor.
 */
public class TCFToggleBreakpointAdapter extends AbstractToggleBreakpointAdapter {

    private final String TOGGLE_TYPE;

    private final TCFDisassemblyToggleBreakpointAdapter fDisassemblyToggleDelegate;

    TCFToggleBreakpointAdapter(String toggle_type) {
        TOGGLE_TYPE = toggle_type;
        fDisassemblyToggleDelegate = new TCFDisassemblyToggleBreakpointAdapter(toggle_type);
    }

    static IStructuredSelection getDebugContext(IWorkbenchPart part) {
        ISelection selection = DebugUITools.getDebugContextManager().
            getContextService(part.getSite().getWorkbenchWindow()).getActiveContext();
        if (selection instanceof IStructuredSelection) {
            return (IStructuredSelection)selection;
        }
        return StructuredSelection.EMPTY;
    }

    static boolean isDefaultBPContextQueryEnabled() {
        return Platform.getPreferencesService().getBoolean(
                Activator.PLUGIN_ID,
                PreferenceConstants.PREF_DEFAULT_TRIGGER_SCOPE_ENABLED,
                false,
                null);
    }

    static String getDefaultBPContextQuery() {
        return Platform.getPreferencesService().getString(
                Activator.PLUGIN_ID,
                PreferenceConstants.PREF_DEFAULT_TRIGGER_SCOPE,
                null,
                null);
    }

    static boolean isLineOffsetLimitEnabled() {
        return Platform.getPreferencesService().getBoolean(
                Activator.PLUGIN_ID,
                PreferenceConstants.PREF_LINE_OFFSET_LIMIT_ENABLED,
                false,
                null);
    }

    static String getLineOffsetLimit() {
        return Platform.getPreferencesService().getString(
                Activator.PLUGIN_ID,
                PreferenceConstants.PREF_LINE_OFFSET_LIMIT,
                "0",
                null);
    }

    static Map<String, Object> getDefaultAttributes(IWorkbenchPart part, final String toggleType) {
        Map<String, Object> attributes = new TreeMap<String, Object>();
        if (part != null) {
            Object obj = getDebugContext(part).getFirstElement();
            if (obj instanceof TCFNode || obj instanceof TCFLaunch) {
                if (toggleType.length() != 0) {
                    if (isDefaultBPContextQueryEnabled()) {
                        String query = getDefaultBPContextQuery();
                        attributes.put(TCFBreakpointsModel.ATTR_CONTEXT_QUERY, query);
                    }
                    if (isLineOffsetLimitEnabled()) {
                        BigInteger n = null;
                        try {
                            n = new BigInteger(getLineOffsetLimit());
                        }
                        catch (Exception x) {
                            n = BigInteger.ZERO;
                        }
                        attributes.put(TCFBreakpointsModel.ATTR_LINE_OFFSET, n.intValue());
                    }
                }
            }
        }
        return attributes;
    }

    /* (non-Javadoc)
     * @see org.eclipse.cdt.debug.internal.ui.actions.AbstractToggleBreakpointAdapter#findLineBreakpoint(java.lang.String, org.eclipse.core.resources.IResource, int)
     */
    @Override
    protected ICLineBreakpoint findLineBreakpoint( String sourceHandle, IResource resource, int lineNumber ) throws CoreException {
            return CDIDebugModel.lineBreakpointExists( sourceHandle, resource, lineNumber );
    }

    /* (non-Javadoc)
     * @see org.eclipse.cdt.debug.internal.ui.actions.AbstractToggleBreakpointAdapter#createLineBreakpoint(java.lang.String, org.eclipse.core.resources.IResource, int)
     */
    @Override
    protected void createLineBreakpoint( boolean interactive, IWorkbenchPart part, final String sourceHandle, final IResource resource, final int lineNumber ) throws CoreException {
        Map<String, Object> attributes = getDefaultAttributes(part, TOGGLE_TYPE);
        ICLineBreakpoint lineBp = CDIDebugModel.createBlankLineBreakpoint();
        CDIDebugModel.setLineBreakpointAttributes(
                attributes, sourceHandle, getBreakpointType(), lineNumber, true, 0, "" ); //$NON-NLS-1$
        if ( !interactive ) {
            CDIDebugModel.createBreakpointMarker(lineBp, resource, attributes, true);
        }
        else {
            openBreakpointPropertiesDialog(lineBp, part, resource, attributes);
        }
    }

    /* (non-Javadoc)
     * @see org.eclipse.cdt.debug.internal.ui.actions.AbstractToggleBreakpointAdapter#findFunctionBreakpoint(java.lang.String, org.eclipse.core.resources.IResource, java.lang.String)
     */
    @Override
    protected ICFunctionBreakpoint findFunctionBreakpoint(String sourceHandle, IResource resource, String functionName) throws CoreException {
        return CDIDebugModel.functionBreakpointExists(sourceHandle, resource, functionName);
    }

    /* (non-Javadoc)
     * @see org.eclipse.cdt.debug.internal.ui.actions.AbstractToggleBreakpointAdapter#createFunctionBreakpoint(java.lang.String, org.eclipse.core.resources.IResource, java.lang.String, int, int, int)
     */
    @Override
    protected void createFunctionBreakpoint(boolean interactive, IWorkbenchPart part, String sourceHandle, IResource resource, String functionName, int charStart, int charEnd,
            int lineNumber) throws CoreException
    {
        Map<String, Object> attributes = getDefaultAttributes(part, TOGGLE_TYPE);
        ICFunctionBreakpoint bp = CDIDebugModel.createBlankFunctionBreakpoint();
        CDIDebugModel.setFunctionBreakpointAttributes( attributes, sourceHandle, getBreakpointType(), functionName,
                charStart, charEnd, lineNumber, true, 0, "" ); //$NON-NLS-1$
        if (!interactive) {
            CDIDebugModel.createBreakpointMarker(bp, resource, attributes, true);
        }
        else {
            openBreakpointPropertiesDialog(bp, part, resource, attributes);
        }
    }

    /* (non-Javadoc)
     * @see org.eclipse.cdt.debug.internal.ui.actions.AbstractToggleBreakpointAdapter#findWatchpoint(java.lang.String, org.eclipse.core.resources.IResource, java.lang.String)
     */
    @Override
    protected ICWatchpoint findWatchpoint( String sourceHandle, IResource resource, String expression ) throws CoreException {
            return CDIDebugModel.watchpointExists( sourceHandle, resource, expression );
    }

    protected int getBreakpointType() {
            return ICBreakpointType.REGULAR;
    }

    @Override
    protected void createWatchpoint(boolean interactive, IWorkbenchPart part, String sourceHandle, IResource resource, int charStart, int charEnd, int lineNumber,
            String expression, String memorySpace, String range) throws CoreException
    {
        Map<String, Object> attributes = getDefaultAttributes(part, TOGGLE_TYPE);
        ICWatchpoint bp = CDIDebugModel.createBlankWatchpoint();
        CDIDebugModel.setWatchPointAttributes(attributes, sourceHandle, resource, true, false,
            expression, memorySpace, new BigInteger(range), true, 0, ""); //$NON-NLS-1$
        openBreakpointPropertiesDialog(bp, part, resource, attributes);
    }

    @Override
    protected void createEventBreakpoint(boolean interactive, IWorkbenchPart part, IResource resource, String type, String arg) throws CoreException {
        Map<String, Object> attributes = getDefaultAttributes(part, TOGGLE_TYPE);
        ICEventBreakpoint bp = CDIDebugModel.createBlankEventBreakpoint();
        CDIDebugModel.setEventBreakpointAttributes(attributes,type, arg);
        openBreakpointPropertiesDialog(bp, part, resource, attributes);
    }

    @Override
    @SuppressWarnings("restriction")
    public void toggleLineBreakpoints( IWorkbenchPart part, ISelection selection ) throws CoreException {
        if (part instanceof IDisassemblyPart) {
            fDisassemblyToggleDelegate.toggleLineBreakpoints(part, selection);
        }
        else {
            super.toggleLineBreakpoints(part, selection);
        }
    }

    @Override
    @SuppressWarnings("restriction")
    public boolean canToggleLineBreakpoints( IWorkbenchPart part, ISelection selection ) {
        if (part instanceof IDisassemblyPart) {
            return fDisassemblyToggleDelegate.canToggleLineBreakpoints(part, selection);
        }
        else {
            return super.canToggleLineBreakpoints(part, selection);
        }
    }

    @Override
    @SuppressWarnings("restriction")
    public void toggleBreakpoints( IWorkbenchPart part, ISelection selection ) throws CoreException {
        if (part instanceof IDisassemblyPart) {
            fDisassemblyToggleDelegate.toggleBreakpoints(part, selection);
        }
        else {
            super.toggleBreakpoints(part, selection);
        }
    }

    @Override
    @SuppressWarnings("restriction")
    public boolean canToggleBreakpoints( IWorkbenchPart part, ISelection selection ) {
        if (part instanceof IDisassemblyPart) {
            return fDisassemblyToggleDelegate.canToggleBreakpoints(part, selection);
        }
        else {
            return super.canToggleBreakpoints(part, selection);
        }
    }

    @Override
    @SuppressWarnings("restriction")
    public void toggleBreakpointsWithEvent(IWorkbenchPart part, ISelection selection, Event event) throws CoreException {
        if (part instanceof IDisassemblyPart) {
            fDisassemblyToggleDelegate.toggleBreakpointsWithEvent(part, selection, event);
        }
        else {
            super.toggleBreakpointsWithEvent(part, selection, event);
        }
    }

    @Override
    @SuppressWarnings("restriction")
    public void createLineBreakpointsInteractive(IWorkbenchPart part, ISelection selection) throws CoreException {
        if (part instanceof IDisassemblyPart) {
            fDisassemblyToggleDelegate.createLineBreakpointsInteractive(part, selection);
        }
        else {
            super.createLineBreakpointsInteractive(part, selection);
        }
    }

    @Override
    @SuppressWarnings("restriction")
    public boolean canCreateLineBreakpointsInteractive(IWorkbenchPart part, ISelection selection) {
        if (part instanceof IDisassemblyPart) {
            return fDisassemblyToggleDelegate.canCreateLineBreakpointsInteractive(part, selection);
        }
        else {
            return super.canCreateLineBreakpointsInteractive(part, selection);
        }
    }
}

Back to the top