Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: e1526a0b435bd3ad1f5b64e9845552991ee244fc (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
/*******************************************************************************
 * Copyright (c) 2008 QNX Software Systems 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:
 * QNX Software Systems - Initial API and implementation
 *******************************************************************************/
package org.eclipse.cdt.debug.core.tests;

import java.io.IOException;

import junit.framework.Test;

import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.debug.core.cdi.CDIException;
import org.eclipse.cdt.debug.core.cdi.ICDILocator;
import org.eclipse.cdt.debug.core.cdi.model.ICDIBreakpoint;
import org.eclipse.cdt.debug.core.cdi.model.ICDIBreakpointManagement3;
import org.eclipse.cdt.debug.core.cdi.model.ICDIEventBreakpoint;
import org.eclipse.cdt.debug.core.model.ICBreakpointType;
import org.eclipse.cdt.debug.mi.core.MIException;
import org.eclipse.cdt.gdb.eventbkpts.IEventBreakpointConstants;

public class EventBreakpointTests extends AbstractDebugTest {
	public static Test suite() {
		return new DebugTestWrapper(EventBreakpointTests.class){};
	}

	protected String getProjectName() {
		return "catchpoints";
	}

	protected String getProjectZip() {
		return "resources/debugCxxTest.zip";
	}

	protected String getProjectBinary() {
		return "catchpoints.exe";
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		createDebugSession();
		assertNotNull(currentTarget);
		currentTarget.deleteAllBreakpoints();
		pause();
	}


	public void testCatch() throws CModelException, IOException, MIException, CDIException {
		eventbreakpoints(IEventBreakpointConstants.EVENT_TYPE_CATCH, "");
	}

	public void testThrow() throws CModelException, IOException, MIException, CDIException {
		eventbreakpoints(IEventBreakpointConstants.EVENT_TYPE_THROW, "");
	}
	
	private void eventbreakpoints(String type, String arg) throws CModelException, IOException, MIException, CDIException {
		ICDIBreakpoint[] breakpoints;
		ICDIEventBreakpoint curbreak;

		setBreakOnMain();
		currentTarget.restart();
		waitSuspend(currentTarget);
		ICDILocator locator = getCurrentLocator();
		assertEquals("Debug should be stopped in function 'main' but it is stopped in: " + locator.getFunction(),
				"main", locator.getFunction());

		currentTarget.deleteAllBreakpoints();
		pause();
		assertTrue(currentTarget instanceof ICDIBreakpointManagement3);
		((ICDIBreakpointManagement3) currentTarget).setEventBreakpoint(type, arg, ICBreakpointType.REGULAR, null, false, true);
		pause();
		breakpoints = currentTarget.getBreakpoints();
		assertNotNull(breakpoints);
		assertEquals(1, breakpoints.length);
		if (breakpoints[0] instanceof ICDIEventBreakpoint) {
			curbreak = (ICDIEventBreakpoint) breakpoints[0];
		} else
			curbreak = null;
		assertNotNull("Found breakpoint is not an event breakpoint",curbreak);
		currentTarget.resume(false);
		waitSuspend(currentTarget);
		// it is stopped we are fine, it did hit breakpoint
	}

}

Back to the top