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
|
/*******************************************************************************
* Copyright (c) 2012 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.debug.test;
import java.math.BigInteger;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import org.eclipse.cdt.debug.core.CDIDebugModel;
import org.eclipse.cdt.debug.core.model.ICBreakpoint;
import org.eclipse.cdt.debug.core.model.ICBreakpointType;
import org.eclipse.cdt.debug.core.model.ICLineBreakpoint;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.tcf.debug.test.BreakpointsListener.EventTester;
import org.eclipse.tcf.debug.test.BreakpointsListener.EventType;
import org.eclipse.tcf.debug.test.services.RunControlCM.ContextState;
import org.eclipse.tcf.debug.test.util.Transaction;
import org.eclipse.tcf.internal.debug.ui.launch.TCFLaunchContext;
import org.eclipse.tcf.protocol.Protocol;
import org.eclipse.tcf.services.ILineNumbers.CodeArea;
import org.eclipse.tcf.services.ISymbols.Symbol;
import org.junit.Assert;
@SuppressWarnings("restriction")
public class BreakpointsTest extends AbstractTcfUITest
{
private BreakpointsListener fBpListener;
@Override
protected void setUp() throws Exception {
super.setUp();
fBpListener = new BreakpointsListener();
// CDT Breakpoint integration depends on the TCF-CDT breakpoint
// integration to be active. This is normally triggered by selecting
// a stack frame in the UI. Here force activation of the plugin
// artificially. None of the cdt integration packages are exported, so
// use the TCF Launch Context extension point indirectly to force the
// plugin to load.
TCFLaunchContext.getLaunchContext(null);
}
@Override
protected void tearDown() throws Exception {
fBpListener.dispose();
super.tearDown();
}
private CodeArea getFunctionCodeArea(String functionName) throws Exception {
return new Transaction<CodeArea>() {
@Override
protected CodeArea process() throws InvalidCacheException, ExecutionException {
ContextState state = validate ( fRunControlCM.getState(fThreadId) );
String symId = validate ( fSymbolsCM.find(fProcessId, new BigInteger(state.pc), "tcf_test_func0") );
Symbol sym = validate ( fSymbolsCM.getContext(symId) );
CodeArea[] area = validate ( fLineNumbersCM.mapToSource(
fProcessId,
sym.getAddress(),
new BigInteger(sym.getAddress().toString()).add(BigInteger.valueOf(1))) );
return area[0];
}
}.get();
}
private ICLineBreakpoint createLineBreakpoint(String file, int line) throws CoreException, ExecutionException, InterruptedException {
// Initiate wait for the context changed event.
final Object contextChangedWaitKey = new Object();
Protocol.invokeAndWait(new Runnable() { public void run() {
fBreakpointsCM.waitContextAdded(contextChangedWaitKey);
}});
final ICLineBreakpoint bp = CDIDebugModel.createLineBreakpoint(file, ResourcesPlugin.getWorkspace().getRoot(), ICBreakpointType.REGULAR, line, true, 0, "", true);
Map<String, Object>[] addedBps = new Transaction<Map<String, Object>[]>() {
@Override
protected Map<String, Object>[] process() throws InvalidCacheException ,ExecutionException {
return validate(fBreakpointsCM.waitContextAdded(contextChangedWaitKey));
}
}.get();
fBpListener.setTester(new EventTester() {
public boolean checkEvent(EventType type, IBreakpoint testBp, Map<String, Object> deltaAttributes) {
return (type == EventType.CHANGED && bp == testBp);
}
});
fBpListener.waitForEvent();
Assert.assertEquals(1, addedBps.length);
Assert.assertEquals(1, bp.getMarker().getAttribute(ICBreakpoint.INSTALL_COUNT, -1));
return bp;
}
public void testContextAddedOnLineBrakpointCreate() throws Exception {
initProcessModel("tcf_test_func0");
CodeArea bpCodeArea = getFunctionCodeArea("tcf_test_func0");
ICLineBreakpoint bp = createLineBreakpoint(bpCodeArea.file, bpCodeArea.start_line);
}
}
|