mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Implementation of disassembly mode.
This commit is contained in:
parent
c0dd34d21c
commit
dd2ebb3c74
2 changed files with 90 additions and 0 deletions
|
@ -146,5 +146,19 @@ public class DisassemblyStorage implements IDisassemblyStorage
|
||||||
|
|
||||||
private void initializeAddresses()
|
private void initializeAddresses()
|
||||||
{
|
{
|
||||||
|
if ( fInstructions.length > 0 )
|
||||||
|
{
|
||||||
|
fStartAddress = fInstructions[0].getAdress();
|
||||||
|
fEndAddress = fInstructions[fInstructions.length - 1].getAdress();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getInstructionString( ICDIInstruction instruction )
|
||||||
|
{
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
if ( instruction != null )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,11 @@
|
||||||
|
|
||||||
package org.eclipse.cdt.debug.internal.core.sourcelookup;
|
package org.eclipse.cdt.debug.internal.core.sourcelookup;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
|
||||||
import org.eclipse.cdt.debug.core.IStackFrameInfo;
|
import org.eclipse.cdt.debug.core.IStackFrameInfo;
|
||||||
|
import org.eclipse.cdt.debug.core.cdi.CDIException;
|
||||||
|
import org.eclipse.cdt.debug.core.cdi.ICDISourceManager;
|
||||||
|
import org.eclipse.cdt.debug.core.cdi.model.ICDIInstruction;
|
||||||
import org.eclipse.cdt.debug.internal.core.DisassemblyStorage;
|
import org.eclipse.cdt.debug.internal.core.DisassemblyStorage;
|
||||||
import org.eclipse.cdt.debug.internal.core.model.CDebugTarget;
|
import org.eclipse.cdt.debug.internal.core.model.CDebugTarget;
|
||||||
import org.eclipse.debug.core.model.IStackFrame;
|
import org.eclipse.debug.core.model.IStackFrame;
|
||||||
|
@ -18,6 +22,9 @@ import org.eclipse.debug.core.model.IStackFrame;
|
||||||
*/
|
*/
|
||||||
public class DisassemblyManager
|
public class DisassemblyManager
|
||||||
{
|
{
|
||||||
|
// move to preferences
|
||||||
|
final static private int DISASSEMBLY_BLOCK_SIZE = 100;
|
||||||
|
|
||||||
private CDebugTarget fDebugTarget;
|
private CDebugTarget fDebugTarget;
|
||||||
private DisassemblyStorage fStorage = null;
|
private DisassemblyStorage fStorage = null;
|
||||||
|
|
||||||
|
@ -31,11 +38,20 @@ public class DisassemblyManager
|
||||||
|
|
||||||
public int getLineNumber( IStackFrameInfo frameInfo )
|
public int getLineNumber( IStackFrameInfo frameInfo )
|
||||||
{
|
{
|
||||||
|
DisassemblyStorage storage = getSourceElement( frameInfo );
|
||||||
|
if ( storage != null )
|
||||||
|
{
|
||||||
|
return storage.getLineNumber( frameInfo.getAddress() );
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getSourceElement( IStackFrame stackFrame )
|
public Object getSourceElement( IStackFrame stackFrame )
|
||||||
{
|
{
|
||||||
|
if ( stackFrame != null )
|
||||||
|
{
|
||||||
|
return getSourceElement( (IStackFrameInfo)stackFrame.getAdapter( IStackFrameInfo.class ) );
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,4 +74,64 @@ public class DisassemblyManager
|
||||||
{
|
{
|
||||||
return fStorage;
|
return fStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DisassemblyStorage getSourceElement( IStackFrameInfo frameInfo )
|
||||||
|
{
|
||||||
|
DisassemblyStorage storage = null;
|
||||||
|
if ( frameInfo != null )
|
||||||
|
{
|
||||||
|
long address = frameInfo.getAddress();
|
||||||
|
if ( getDisassemblyStorage() != null && getDisassemblyStorage().containsAddress( address ) )
|
||||||
|
{
|
||||||
|
storage = getDisassemblyStorage();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
storage = loadDisassemblyStorage( frameInfo );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return storage;
|
||||||
|
}
|
||||||
|
|
||||||
|
private DisassemblyStorage loadDisassemblyStorage( IStackFrameInfo frameInfo )
|
||||||
|
{
|
||||||
|
setDisassemblyStorage( null );
|
||||||
|
if ( frameInfo != null && getDebugTarget() != null && getDebugTarget().isSuspended() )
|
||||||
|
{
|
||||||
|
ICDISourceManager sm = getDebugTarget().getCDISession().getSourceManager();
|
||||||
|
if ( sm != null )
|
||||||
|
{
|
||||||
|
String fileName = frameInfo.getFile();
|
||||||
|
int lineNumber = frameInfo.getFrameLineNumber();
|
||||||
|
ICDIInstruction[] instructions = new ICDIInstruction[0];
|
||||||
|
try
|
||||||
|
{
|
||||||
|
instructions = sm.getInstructions( fileName, lineNumber );
|
||||||
|
}
|
||||||
|
catch( CDIException e )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
if ( instructions.length == 0 )
|
||||||
|
{
|
||||||
|
long address = frameInfo.getAddress();
|
||||||
|
if ( address >= 0 )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
instructions = sm.getInstructions( "0x" + Long.toHexString( address ), "0x" + Long.toHexString( address + DISASSEMBLY_BLOCK_SIZE ) );
|
||||||
|
}
|
||||||
|
catch( CDIException e )
|
||||||
|
{
|
||||||
|
CDebugCorePlugin.log( e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( instructions.length > 0 )
|
||||||
|
{
|
||||||
|
setDisassemblyStorage( new DisassemblyStorage( getDebugTarget(), instructions ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getDisassemblyStorage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue