blob: 11a83923d1a71141b8b51cbc145bcf4f3541a4f5 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2009, 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
*******************************************************************************/
package org.eclipse.cdt.debug.edc.debugger.tests;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.eclipse.cdt.core.IAddress;
import org.eclipse.cdt.debug.edc.tests.TestUtils;
import org.eclipse.cdt.debug.edc.tests.TestUtils.Condition;
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
import org.eclipse.cdt.dsf.concurrent.Query;
import org.eclipse.cdt.dsf.datamodel.DMContexts;
import org.eclipse.cdt.dsf.debug.service.IDisassembly;
import org.eclipse.cdt.dsf.debug.service.IDisassembly.IDisassemblyDMContext;
import org.eclipse.cdt.dsf.debug.service.IMixedInstruction;
import org.eclipse.cdt.dsf.service.DsfServicesTracker;
public class DisassemblyView extends BaseLaunchTest {
/*
* NOTE: This is the source line and its corresponding code addresses in the
* test case program specified by EXEPATH environemnt variable.
*
* The value below is for BlackFlagWascana.exe I built using Cygwin. Change
* them accordingly if you are using different binary file.
*
* TODO: make it more flexible.
*/
static final String sSrcFile = "C:\\wascana\\workspace\\BlackFlagWascana\\src\\dbg_breakpoints.cpp";
static final int sLineNumber = 82; // line in above source file.
private IDisassembly disassembly;
@Override
protected boolean getStopAtMain() {
return true;
}
@Before
public void launch() throws Exception {
basicLaunch();
}
@After
public void shutdown() {
TestUtils.shutdownDebugSession(launch, session);
session = null;
}
@Test
public void testDisassemblyView() throws Exception {
getDsfDisassemblyService();
assertNotNull(disassembly);
final IDisassemblyDMContext disassemblyDMC
= DMContexts.getAncestorOfType(threadDMC, IDisassemblyDMContext.class);
assertNotNull(disassemblyDMC);
// get assembly code by source file & line number
//
Query<IMixedInstruction[]> query1 = new Query<IMixedInstruction[]>() {
@Override
protected void execute(final DataRequestMonitor<IMixedInstruction[]> drm) {
disassembly.getMixedInstructions(disassemblyDMC, sSrcFile, sLineNumber, 2, drm);
}
};
session.getExecutor().execute(query1);
IMixedInstruction[] result1 = query1.get();
for (IMixedInstruction mi : result1)
System.out.println(mi);
final IAddress sStartAddress = waitGetLineAddress(sSrcFile, 82);
final IAddress sEndAddress = waitGetLineAddress(sSrcFile, 83);
// get assembly code by runtime address (same as logical address on
// Windows & Linux)
//
Query<IMixedInstruction[]> query2 = new Query<IMixedInstruction[]>() {
@Override
protected void execute(final DataRequestMonitor<IMixedInstruction[]> drm) {
disassembly.getMixedInstructions(disassemblyDMC, sStartAddress.getValue(),
sEndAddress.getValue(), drm);
}
};
session.getExecutor().execute(query2);
IMixedInstruction[] result2 = query2.get();
for (IMixedInstruction mi : result2)
System.out.println(mi);
assertEquals(result1[0].getLineNumber(), result2[0].getLineNumber());
assertEquals(result1[0].getInstructions().length, result2[0].getInstructions().length);
for (int i = 0; i < result1[0].getInstructions().length; i++)
assertTrue(TestUtils.stringCompare(result1[0].getInstructions()[i].toString(),
result2[0].getInstructions()[i].toString(), true, // ignoreCase,
true, // ignoreWhite,
false // ignore0x
));
}
private void getDsfDisassemblyService() throws Exception {
assertNotNull(session); // this must be initialized already.
TestUtils.waitOnExecutorThread(session, new Condition() {
public boolean isConditionValid() {
DsfServicesTracker servicesTracker = getDsfServicesTracker(session);
disassembly = servicesTracker.getService(IDisassembly.class);
return true;
}
});
}
}