From 8720297f8a0aed63498ecc3eb73aa9a21538a19b Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Fri, 17 Oct 2003 15:48:37 +0000 Subject: [PATCH] If the target is suspended by a line breakpoint the source manager tries to retrieve the file resource from the breakpoint marker. --- debug/org.eclipse.cdt.debug.core/ChangeLog | 6 ++++ .../internal/core/model/CDebugTarget.java | 28 +++++++++++++++++++ .../core/sourcelookup/CSourceManager.java | 23 +++++++++++++-- 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.core/ChangeLog b/debug/org.eclipse.cdt.debug.core/ChangeLog index 1ecc1a62d15..e14122a4d57 100644 --- a/debug/org.eclipse.cdt.debug.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.core/ChangeLog @@ -1,3 +1,9 @@ +2003-10-17 Mikhail Khodjaiants + If the target is suspended by a line breakpoint the source manager tries to retrieve + the file resource from the breakpoint marker. + * CSourceManager.java + * CDebugTarget.java + 2003-10-15 Mikhail Khodjaiants Improving the source search algorithms. * CDirectorySourceLocation.java diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java index 14b964173a4..a2650912a73 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/CDebugTarget.java @@ -442,6 +442,13 @@ public class CDebugTarget extends CDebugElement ISourceLocator locator = getLaunch().getSourceLocator(); if ( locator instanceof IAdaptable ) { + ICSourceLocator clocator = (ICSourceLocator)((IAdaptable)locator).getAdapter( ICSourceLocator.class ); + if ( clocator instanceof IAdaptable ) + { + CSourceManager sm = (CSourceManager)((IAdaptable)clocator).getAdapter( CSourceManager.class ); + if ( sm != null ) + sm.setDebugTarget( this ); + } IResourceChangeListener listener = (IResourceChangeListener)((IAdaptable)locator).getAdapter( IResourceChangeListener.class ); if ( listener != null ) CCorePlugin.getWorkspace().addResourceChangeListener( listener ); @@ -2777,6 +2784,26 @@ public class CDebugTarget extends CDebugElement return fRunningInfo; } + public IFile getCurrentBreakpointFile() + { + Object info = getCurrentStateInfo(); + if ( info instanceof ICDIBreakpointHit ) + { + ICDIBreakpoint cdiBreakpoint = ((ICDIBreakpointHit)info).getBreakpoint(); + if ( cdiBreakpoint != null ) + { + IBreakpoint breakpoint = findBreakpoint( cdiBreakpoint ); + if ( breakpoint instanceof ICLineBreakpoint ) + { + IResource resource = ((ICLineBreakpoint)breakpoint).getMarker().getResource(); + if ( resource instanceof IFile ) + return (IFile)resource; + } + } + } + return null; + } + protected void setRunningInfo( RunningInfo info ) { fRunningInfo = info; @@ -2802,6 +2829,7 @@ public class CDebugTarget extends CDebugElement } setRunningInfo( info ); } + /* private boolean applyDeferredBreakpoints() { diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceManager.java index 626b8cb2b04..62da46d4b5f 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceManager.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CSourceManager.java @@ -15,6 +15,7 @@ import org.eclipse.cdt.debug.core.model.IStackFrameInfo; import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation; import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator; import org.eclipse.cdt.debug.core.sourcelookup.ISourceMode; +import org.eclipse.cdt.debug.internal.core.model.CDebugTarget; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceChangeListener; @@ -39,7 +40,8 @@ public class CSourceManager implements ICSourceLocator, private ISourceLocator fSourceLocator = null; private int fMode = ISourceMode.MODE_SOURCE; private int fRealMode = fMode; - private ILaunch fLaunch = null; + private ILaunch fLaunch = null; + private CDebugTarget fDebugTarget = null; /** * Constructor for CSourceManager. @@ -132,6 +134,8 @@ public class CSourceManager implements ICSourceLocator, */ public Object getAdapter( Class adapter ) { + if ( adapter.equals( CSourceManager.class ) ) + return this; if ( adapter.equals( IResourceChangeListener.class ) && fSourceLocator instanceof IResourceChangeListener ) return fSourceLocator; @@ -148,7 +152,12 @@ public class CSourceManager implements ICSourceLocator, if ( getMode() == ISourceMode.MODE_SOURCE && getSourceLocator() != null ) { - result = getSourceLocator().getSourceElement( stackFrame ); + // if the target is suspended by a line breakpoint the source manager + // tries to retrieve the file resource from the breakpoint marker. + if ( getDebugTarget() != null ) + result = getDebugTarget().getCurrentBreakpointFile(); + if ( result == null ) + result = getSourceLocator().getSourceElement( stackFrame ); } if ( result == null && ( autoDisassembly || getMode() == ISourceMode.MODE_DISASSEMBLY ) && @@ -256,4 +265,14 @@ public class CSourceManager implements ICSourceLocator, { return ( getCSourceLocator() != null ) ? getCSourceLocator().getProject() : null; } + + public void setDebugTarget( CDebugTarget target ) + { + fDebugTarget = target; + } + + protected CDebugTarget getDebugTarget() + { + return fDebugTarget; + } }