diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/DisassemblyStorage.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/DisassemblyStorage.java index 280269f7b35..f5d79f1f7ea 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/DisassemblyStorage.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/DisassemblyStorage.java @@ -146,5 +146,19 @@ public class DisassemblyStorage implements IDisassemblyStorage 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(); } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/DisassemblyManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/DisassemblyManager.java index b6aaeb80a24..5d3364a33bb 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/DisassemblyManager.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/DisassemblyManager.java @@ -6,7 +6,11 @@ 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.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.model.CDebugTarget; import org.eclipse.debug.core.model.IStackFrame; @@ -18,6 +22,9 @@ import org.eclipse.debug.core.model.IStackFrame; */ public class DisassemblyManager { + // move to preferences + final static private int DISASSEMBLY_BLOCK_SIZE = 100; + private CDebugTarget fDebugTarget; private DisassemblyStorage fStorage = null; @@ -31,11 +38,20 @@ public class DisassemblyManager public int getLineNumber( IStackFrameInfo frameInfo ) { + DisassemblyStorage storage = getSourceElement( frameInfo ); + if ( storage != null ) + { + return storage.getLineNumber( frameInfo.getAddress() ); + } return 0; } public Object getSourceElement( IStackFrame stackFrame ) { + if ( stackFrame != null ) + { + return getSourceElement( (IStackFrameInfo)stackFrame.getAdapter( IStackFrameInfo.class ) ); + } return null; } @@ -58,4 +74,64 @@ public class DisassemblyManager { 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(); + } }