blob: ecd67ec5e23b13a42a734d54eb224508fd673efa [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2010 Nokia 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:
* Nokia - Initial API and implementation. Mar, 2010
*******************************************************************************/
package org.eclipse.cdt.debug.edc.debugger.tests;
import org.eclipse.cdt.debug.edc.internal.services.dsf.Breakpoints;
import org.eclipse.cdt.debug.edc.tests.TestUtils;
import org.eclipse.cdt.debug.edc.tests.TestUtils.Condition;
import org.eclipse.cdt.dsf.debug.service.IBreakpoints.IBreakpointDMContext;
import org.eclipse.cdt.dsf.debug.service.IRunControl2;
import org.eclipse.cdt.dsf.debug.service.IStack;
import org.eclipse.cdt.dsf.service.DsfServicesTracker;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* Test run-to-line, move-to-line and resume-at-line.
*
*/
public class ResumeFromLineAtBreakpoint extends BaseLaunchTest {
protected IStack stackService;
protected Breakpoints breakpointsService;
protected IRunControl2 runControlService;
protected IBreakpointDMContext userBPContext;
final private String dbg_derived_types_cpp
= "C:\\myprog\\BlackFlagWascana\\src\\dbg_derived_types.cpp";
@Override
protected String getExeFileName() {
// This is the executable built by Cygwin gcc 3.4.4
// All source files are built from this folder:
// "C:\\myprog\\BlackFlagWascana\\src\\"
// Note we don't need any source file to perform the test.
//
return "BlackFlagMinGW_NoHardcodedBreak.exe";
}
@Override
protected IStack getStackService() {
return stackService;
}
@Override
protected boolean getStopAtMain() {
return true;
}
@Before
public void launch() throws Exception {
basicLaunch();
}
@After
public void shutdown() {
TestUtils.shutdownDebugSession(launch, session);
session = null;
}
/**
* test resuming from a line with a breakpoint set on it
*
* @throws Exception
*/
@Test
public void testRunFromLineWithBreakpoint() throws Exception {
getDsfServices();
updateSuspendedFrame(1000);
/// TODO initial breakpoint currently isn't stopping at main, but somewhere earlier.
// assertControlIsAt("BlackFlagWascana.cpp", "main", 15);
TestUtils.waitForUIUpdate(1000);
/*
* Now we test control in structs() function of
* dbg_derived_type.cpp in Blackflag.
* Here's the snippet of the source lines in structs():
*
52 lstruct.achar = '1';
53 lstruct.auchar = 2;
54 lstruct.aschar = '3';
55 lstruct.ashort = 4;
56 lstruct.aushort = 5;
57 lstruct.asshort = 6;
58 lstruct.aint = 7;
59 lstruct.auint = 8;
*
* Here's what's done below:
* 1) Run to line 53.
* 2) Set a breakpoint on line 53
* 3) Run to line 57.
* it should continue from the line with the breakpoint,
* and the next point of stoppage should set all values.
*/
// run to line 53, so "lstruct.achar = '1'" is executed.
waitRunToLine(runControlService, dbg_derived_types_cpp, 53);
updateSuspendedFrame(800);
assertEquals("0 ('\\0')", TestUtils.getExpressionValue(session, frame, "lstruct.auchar"));// 53
assertEquals("0 ('\\0')", TestUtils.getExpressionValue(session, frame, "lstruct.aschar"));// 54
assertEquals("0", TestUtils.getExpressionValue(session, frame, "lstruct.ashort")); // 55
assertEquals("0", TestUtils.getExpressionValue(session, frame, "lstruct.aushort")); // 56
assertEquals("0", TestUtils.getExpressionValue(session, frame, "lstruct.asshort")); // 57
assertControlIsAt("dbg_derived_types.cpp", "structs", 53);
// Set user breakpoint at line 56.
userBPContext = setUserBreakpoint(breakpointsService, dbg_derived_types_cpp, 53);
TestUtils.waitForUIUpdate(400);
// run to line 57, then later demonstrate that all lines in between were executed.
waitRunToLine(runControlService, dbg_derived_types_cpp, 57);
updateSuspendedFrame(400);
assertControlIsAt("dbg_derived_types.cpp", "structs", 57);
assertEquals("2 ('\\002')", TestUtils.getExpressionValue(session, frame, "lstruct.auchar"));// 53
assertEquals("51 ('3')", TestUtils.getExpressionValue(session, frame, "lstruct.aschar")); // 54
assertEquals("4", TestUtils.getExpressionValue(session, frame, "lstruct.ashort")); // 55
assertEquals("5", TestUtils.getExpressionValue(session, frame, "lstruct.aushort")); // 56
assertEquals("0", TestUtils.getExpressionValue(session, frame, "lstruct.asshort")); // 57
TestUtils.waitForUIUpdate(500);
removeUserBreakpoint(breakpointsService, userBPContext);
}
private void getDsfServices() throws Exception {
assertNotNull(session); // this must be initialized already.
TestUtils.waitOnExecutorThread(session, new Condition() {
public boolean isConditionValid() {
DsfServicesTracker servicesTracker = getDsfServicesTracker(session);
stackService = servicesTracker.getService(IStack.class);
breakpointsService = servicesTracker.getService(Breakpoints.class);
runControlService = servicesTracker.getService(IRunControl2.class);
return true;
}
});
}
}