From 288e94d28e58e9e919cb33249e4690e266ea40bd Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Wed, 29 Jun 2005 21:15:28 +0000 Subject: [PATCH] Bug 41725: I can't set a breakpoint in a function where I used attach source. Bug 45514: Breakpoints made is assembly view do not show in C view. --- debug/org.eclipse.cdt.debug.core/ChangeLog | 12 ++ .../eclipse/cdt/debug/core/CDIDebugModel.java | 36 +++++- .../cdt/debug/core/model/IAsmSourceLine.java | 7 ++ .../cdt/debug/core/model/ICBreakpoint.java | 29 ++++- .../debug/core/model/IDisassemblyBlock.java | 9 ++ .../internal/core/CBreakpointManager.java | 76 +++++++------ .../core/breakpoints/CBreakpoint.java | 14 +++ .../internal/core/model/AsmSourceLine.java | 17 +++ .../internal/core/model/DisassemblyBlock.java | 48 +++++--- debug/org.eclipse.cdt.debug.ui/ChangeLog | 9 ++ debug/org.eclipse.cdt.debug.ui/plugin.xml | 6 + .../ui/DebugMarkerAnnotationModel.java | 103 ++++++++++++++++++ .../ui/DebugMarkerAnnotationModelFactory.java | 37 +++++++ .../ui/actions/ToggleBreakpointAdapter.java | 25 ++++- .../disassembly/DisassemblyEditorInput.java | 30 +++++ 15 files changed, 402 insertions(+), 56 deletions(-) create mode 100644 debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/DebugMarkerAnnotationModel.java create mode 100644 debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/DebugMarkerAnnotationModelFactory.java diff --git a/debug/org.eclipse.cdt.debug.core/ChangeLog b/debug/org.eclipse.cdt.debug.core/ChangeLog index f923c97f656..4c26875664f 100644 --- a/debug/org.eclipse.cdt.debug.core/ChangeLog +++ b/debug/org.eclipse.cdt.debug.core/ChangeLog @@ -1,3 +1,15 @@ +2005-06-29 Mikhail Khodjaiants + Bug 41725: I can't set a breakpoint in a function where I used attach source. + Bug 45514: Breakpoints made is assembly view do not show in C view. + * CDIDebugModel.java + * IAsmSourceLine.java + * ICBreakpoint.java + * IDisassemblyBlock.java + * CBreakpointManager.java + * CBreakpoint.java + * AsmSourceLine.java + * DisassemblyBlock.java + 2005-06-28 Mikhail Khodjaiants Bug 101188: Breakpoints don't work with MingW gdb. Use "toPortableString" instead of "toOsString" when setting the source search paths. diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java index 637e5ceb3cb..f7be4e426ff 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java @@ -174,6 +174,7 @@ public class CDIDebugModel { * given source handle, at the given address. The marker associated with the * breakpoint will be created on the specified resource. * + * @param module the module name the breakpoint is set in * @param sourceHandle the handle to the breakpoint source * @param resource the resource on which to create the associated breakpoint marker * @param address the address on which the breakpoint is set @@ -189,17 +190,44 @@ public class CDIDebugModel { * failure. * */ - public static ICAddressBreakpoint createAddressBreakpoint( String sourceHandle, IResource resource, IAddress address, boolean enabled, int ignoreCount, String condition, boolean register ) throws CoreException { + public static ICAddressBreakpoint createAddressBreakpoint( String module, String sourceHandle, IResource resource, IAddress address, boolean enabled, int ignoreCount, String condition, boolean register ) throws CoreException { + return createAddressBreakpoint( module, sourceHandle, resource, -1, address, enabled, ignoreCount, condition, register ); + } + + /** + * Creates and returns an address breakpoint for the source defined by the + * given source handle, at the given address. The marker associated with the + * breakpoint will be created on the specified resource. + * + * @param module the module name the breakpoint is set in + * @param sourceHandle the handle to the breakpoint source + * @param resource the resource on which to create the associated breakpoint marker + * @param lineNumber the line number in the source file + * @param address the address on which the breakpoint is set + * @param enabled whether to enable or disable this breakpoint + * @param ignoreCount the number of times this breakpoint will be ignored + * @param condition the breakpoint condition + * @param register whether to add this breakpoint to the breakpoint manager + * @return an address breakpoint + * @throws CoreException if this method fails. Reasons include: + * + */ + public static ICAddressBreakpoint createAddressBreakpoint( String module, String sourceHandle, IResource resource, int lineNumber, IAddress address, boolean enabled, int ignoreCount, String condition, boolean register ) throws CoreException { HashMap attributes = new HashMap( 10 ); attributes.put( IBreakpoint.ID, getPluginIdentifier() ); - attributes.put( IMarker.CHAR_START, new Integer( 0 ) ); - attributes.put( IMarker.CHAR_END, new Integer( 0 ) ); - attributes.put( IMarker.LINE_NUMBER, new Integer( -1 ) ); + attributes.put( IMarker.CHAR_START, new Integer( -1 ) ); + attributes.put( IMarker.CHAR_END, new Integer( -1 ) ); + attributes.put( IMarker.LINE_NUMBER, new Integer( lineNumber ) ); attributes.put( ICLineBreakpoint.ADDRESS, address.toHexAddressString() ); attributes.put( IBreakpoint.ENABLED, new Boolean( enabled ) ); attributes.put( ICBreakpoint.IGNORE_COUNT, new Integer( ignoreCount ) ); attributes.put( ICBreakpoint.CONDITION, condition ); attributes.put( ICBreakpoint.SOURCE_HANDLE, sourceHandle ); + attributes.put( ICBreakpoint.MODULE, module ); return new CAddressBreakpoint( resource, attributes, register ); } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IAsmSourceLine.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IAsmSourceLine.java index e812a0ef153..ca69864302f 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IAsmSourceLine.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IAsmSourceLine.java @@ -21,4 +21,11 @@ public interface IAsmSourceLine { * @return the array of the disassembly instructions associated with this source line */ IAsmInstruction[] getInstructions(); + + /** + * Returns the number of this line in the source file + * + * @return the line number + */ + int getLineNumber(); } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICBreakpoint.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICBreakpoint.java index 2012356352f..97732c373e0 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICBreakpoint.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/ICBreakpoint.java @@ -54,12 +54,21 @@ public interface ICBreakpoint extends IBreakpoint { public static final String THREAD_ID = "org.eclipse.cdt.debug.core.threadId"; //$NON-NLS-1$ /** - * Breakpoint attribute storing a source handle this breakpoint + * Breakpoint attribute storing the source handle of the file this breakpoint * is set in (value "org.eclipse.cdt.debug.core.sourceHandle"). * This attribute is a String. */ public static final String SOURCE_HANDLE = "org.eclipse.cdt.debug.core.sourceHandle"; //$NON-NLS-1$ + /** + * Breakpoint attribute storing the module name this breakpoint + * is set in (value "org.eclipse.cdt.debug.core.module"). + * This attribute is a String. + * + * @since 3.0 + */ + public static final String MODULE = "org.eclipse.cdt.debug.core.module"; //$NON-NLS-1$ + /** * Returns whether this breakpoint is installed in at least one debug * target. @@ -134,6 +143,24 @@ public interface ICBreakpoint extends IBreakpoint { */ public void setThreadId( String threadId ) throws CoreException; + /** + * Returns the module name this breakpoint is set in. + * + * @return the module name + * @exception CoreException if unable to access the property on this breakpoint's + * underlying marker + */ + public String getModule() throws CoreException; + + /** + * Sets the module name of this breakpoint. + * + * @param module the module name + * @exception CoreException if unable to access the property on this breakpoint's + * underlying marker + */ + public void setModule( String module ) throws CoreException; + /** * Returns the source handle this breakpoint is set in. * diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IDisassemblyBlock.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IDisassemblyBlock.java index 3ff3f1acaeb..17502e1a0e8 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IDisassemblyBlock.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IDisassemblyBlock.java @@ -30,6 +30,15 @@ public interface IDisassemblyBlock { */ String getModuleFile(); + + /** + * Returns the source element (IFile or File>) + * of the source file associated with this segment or null if no source file is associated. + * + * @return the source element + */ + Object getSourceElement(); + /** * Returns whether this block contains given stack frame. * diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CBreakpointManager.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CBreakpointManager.java index 77ec7465e90..2ede7139414 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CBreakpointManager.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/CBreakpointManager.java @@ -253,8 +253,17 @@ public class CBreakpointManager implements IBreakpointManagerListener, ICDIEvent } public boolean supportsAddressBreakpoint( ICAddressBreakpoint breakpoint ) { + String module = null; try { - return ( getExecFilePath().toOSString().equals( breakpoint.getSourceHandle() ) ); + module = breakpoint.getModule(); + } + catch( CoreException e ) { + } + if ( module != null ) + return getExecFilePath().toOSString().equals( module ); + // supporting old breakpoints (> 3.0) + try { + return getExecFilePath().toOSString().equals( breakpoint.getSourceHandle() ); } catch( CoreException e ) { } @@ -435,9 +444,9 @@ public class CBreakpointManager implements IBreakpointManagerListener, ICDIEvent if ( breakpoint instanceof ICLineBreakpoint ) { ICDILocator locator = cdiBreakpoint.getLocator(); if ( locator != null ) { - BigInteger address = locator.getAddress(); + IAddress address = getDebugTarget().getAddressFactory().createAddress( locator.getAddress() ); if ( address != null ) { - ((ICLineBreakpoint)breakpoint).setAddress( address.toString() ); + ((ICLineBreakpoint)breakpoint).setAddress( address.toHexAddressString() ); } } } @@ -578,11 +587,9 @@ public class CBreakpointManager implements IBreakpointManagerListener, ICDIEvent final boolean enabled = breakpoint.isEnabled(); final ICDITarget cdiTarget = getCDITarget(); String address = breakpoint.getAddress(); - if ( address.startsWith( "0x" ) ) { //$NON-NLS-1$ - final ICDIAddressLocation location = cdiTarget.createAddressLocation( new BigInteger ( breakpoint.getAddress().substring( 2 ), 16 ) ); - final ICDICondition condition = createCondition( breakpoint ); - setLocationBreakpointOnTarget( breakpoint, cdiTarget, location, condition, enabled ); - } + final ICDIAddressLocation location = cdiTarget.createAddressLocation( new BigInteger ( ( address.startsWith( "0x" ) ) ? address.substring( 2 ) : address, 16 ) ); //$NON-NLS-1$ + final ICDICondition condition = createCondition( breakpoint ); + setLocationBreakpointOnTarget( breakpoint, cdiTarget, location, condition, enabled ); } private void setLineBreakpoint( ICLineBreakpoint breakpoint ) throws CDIException, CoreException { @@ -648,28 +655,22 @@ public class CBreakpointManager implements IBreakpointManagerListener, ICDIEvent ICLineBreakpoint breakpoint = null; try { ICDILocator location = cdiBreakpoint.getLocator(); - if ( !isEmpty( location.getFile() ) ) { - ISourceLocator locator = getSourceLocator(); - if ( locator instanceof ICSourceLocator || locator instanceof CSourceLookupDirector ) { - String sourceHandle = location.getFile(); - IResource resource = getProject(); - Object sourceElement = null; - if ( locator instanceof ICSourceLocator ) - sourceElement = ((ICSourceLocator)locator).findSourceElement( location.getFile() ); - else - sourceElement = ((CSourceLookupDirector)locator).getSourceElement( location.getFile() ); - if ( sourceElement instanceof IFile || sourceElement instanceof IStorage ) { - sourceHandle = ( sourceElement instanceof IFile ) ? ((IFile)sourceElement).getLocation().toOSString() : ((IStorage)sourceElement).getFullPath().toOSString(); - resource = ( sourceElement instanceof IFile ) ? (IResource)sourceElement : ResourcesPlugin.getWorkspace().getRoot(); - } - breakpoint = createLineBreakpoint( sourceHandle, resource, cdiBreakpoint ); -// else if ( !isEmpty( cdiBreakpoint.getLocation().getFunction() ) ) { -// breakpoint = createFunctionBreakpoint( cdiBreakpoint ); -// } -// else if ( ! cdiBreakpoint.getLocation().getAddress().equals( BigInteger.ZERO ) ) { -// breakpoint = createAddressBreakpoint( cdiBreakpoint ); -// } + String file = location.getFile(); + if ( !isEmpty( file ) ) { + Object sourceElement = getSourceElement( file ); + String sourceHandle = file; + IResource resource = getProject(); + if ( sourceElement instanceof IFile || sourceElement instanceof IStorage ) { + sourceHandle = ( sourceElement instanceof IFile ) ? ((IFile)sourceElement).getLocation().toOSString() : ((IStorage)sourceElement).getFullPath().toOSString(); + resource = ( sourceElement instanceof IFile ) ? (IResource)sourceElement : ResourcesPlugin.getWorkspace().getRoot(); } + breakpoint = createLineBreakpoint( sourceHandle, resource, cdiBreakpoint ); +// else if ( !isEmpty( cdiBreakpoint.getLocation().getFunction() ) ) { +// breakpoint = createFunctionBreakpoint( cdiBreakpoint ); +// } +// else if ( ! cdiBreakpoint.getLocation().getAddress().equals( BigInteger.ZERO ) ) { +// breakpoint = createAddressBreakpoint( cdiBreakpoint ); +// } } else if ( !isEmpty( location.getFunction() ) ) { breakpoint = createFunctionBreakpoint( cdiBreakpoint ); @@ -727,8 +728,9 @@ public class CBreakpointManager implements IBreakpointManagerListener, ICDIEvent IPath execFile = getExecFilePath(); String sourceHandle = execFile.toOSString(); IAddress address = getDebugTarget().getAddressFactory().createAddress( cdiBreakpoint.getLocator().getAddress() ); - ICAddressBreakpoint breakpoint = CDIDebugModel.createAddressBreakpoint( sourceHandle, - getProject(), + ICAddressBreakpoint breakpoint = CDIDebugModel.createAddressBreakpoint( sourceHandle, + sourceHandle, + ResourcesPlugin.getWorkspace().getRoot(), address, cdiBreakpoint.isEnabled(), cdiBreakpoint.getCondition().getIgnoreCount(), @@ -874,4 +876,16 @@ public class CBreakpointManager implements IBreakpointManagerListener, ICDIEvent } return path; } + + private Object getSourceElement( String file ) { + Object sourceElement = null; + ISourceLocator locator = getSourceLocator(); + if ( locator instanceof ICSourceLocator || locator instanceof CSourceLookupDirector ) { + if ( locator instanceof ICSourceLocator ) + sourceElement = ((ICSourceLocator)locator).findSourceElement( file ); + else + sourceElement = ((CSourceLookupDirector)locator).getSourceElement( file ); + } + return sourceElement; + } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CBreakpoint.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CBreakpoint.java index 6bdc635cc88..07816bd1bcc 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CBreakpoint.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/breakpoints/CBreakpoint.java @@ -351,4 +351,18 @@ public abstract class CBreakpoint extends Breakpoint implements ICBreakpoint, ID DebugPlugin.getDefault().getBreakpointManager().fireBreakpointChanged( this ); } } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.model.ICBreakpoint#getModule() + */ + public String getModule() throws CoreException { + return ensureMarker().getAttribute( MODULE, null ); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.model.ICBreakpoint#setModule(java.lang.String) + */ + public void setModule( String module ) throws CoreException { + setAttribute( MODULE, module ); + } } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AsmSourceLine.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AsmSourceLine.java index f78cf7390cd..6ee24803a0a 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AsmSourceLine.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/AsmSourceLine.java @@ -24,17 +24,34 @@ public class AsmSourceLine implements IAsmSourceLine { private IAsmInstruction[] fInstructions = null; + private int fLineNumber; + /** * Constructor for AsmSourceLine. */ public AsmSourceLine( IAddressFactory factory, String text, ICDIInstruction[] cdiInstructions ) { + this( factory, text, -1, cdiInstructions ); + } + + /** + * Constructor for AsmSourceLine. + */ + public AsmSourceLine( IAddressFactory factory, String text, int lineNumber, ICDIInstruction[] cdiInstructions ) { fText = text; + fLineNumber = lineNumber; fInstructions = new IAsmInstruction[cdiInstructions.length]; for ( int i = 0; i < fInstructions.length; ++i ) { fInstructions[i] = new AsmInstruction( factory, cdiInstructions[i] ); } } + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.model.IAsmSourceLine#getLineNumber() + */ + public int getLineNumber() { + return fLineNumber; + } + /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.model.IAsmSourceLine#getInstructions() */ diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/DisassemblyBlock.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/DisassemblyBlock.java index 1dc1a832091..40ef60bc861 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/DisassemblyBlock.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/model/DisassemblyBlock.java @@ -39,7 +39,9 @@ import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector; public class DisassemblyBlock implements IDisassemblyBlock, IAdaptable { private IDisassembly fDisassembly; - + + private Object fSourceElement; + private IAsmSourceLine[] fSourceLines; private IAddress fStartAddress = null; @@ -57,23 +59,31 @@ public class DisassemblyBlock implements IDisassemblyBlock, IAdaptable { public static DisassemblyBlock create( IDisassembly disassembly, ICDIMixedInstruction[] instructions ) { DisassemblyBlock block = new DisassemblyBlock( disassembly ); - block.setMixedMode( true ); ISourceLocator locator = disassembly.getDebugTarget().getLaunch().getSourceLocator(); IAddressFactory factory = ((CDebugTarget)disassembly.getDebugTarget()).getAddressFactory(); - block.setSourceLines( createSourceLines( factory, locator, instructions ) ); - block.initializeAddresses(); + block.initialize( factory, locator, instructions ); return block; } public static DisassemblyBlock create( IDisassembly disassembly, ICDIInstruction[] instructions ) { DisassemblyBlock block = new DisassemblyBlock( disassembly ); IAddressFactory factory = ((CDebugTarget)disassembly.getDebugTarget()).getAddressFactory(); - block.setMixedMode( false ); - block.setSourceLines( createSourceLines( factory, instructions ) ); - block.initializeAddresses(); + block.initialize( factory, instructions ); return block; } + private void initialize( IAddressFactory factory, ICDIInstruction[] instructions ) { + setMixedMode( false ); + createSourceLines( factory, instructions ); + initializeAddresses(); + } + + private void initialize( IAddressFactory factory, ISourceLocator locator, ICDIMixedInstruction[] mi ) { + setMixedMode( true ); + createSourceLines( factory, locator, mi ); + initializeAddresses(); + } + /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.model.IDisassemblyBlock#getDisassembly() */ @@ -95,6 +105,13 @@ public class DisassemblyBlock implements IDisassemblyBlock, IAdaptable { return ""; //$NON-NLS-1$ } + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.core.model.IDisassemblyBlock#getSourceElement() + */ + public Object getSourceElement() { + return fSourceElement; + } + /* (non-Javadoc) * @see org.eclipse.cdt.debug.core.model.IDisassemblyBlock#contains(org.eclipse.cdt.debug.core.model.ICStackFrame) */ @@ -133,7 +150,7 @@ public class DisassemblyBlock implements IDisassemblyBlock, IAdaptable { public void dispose() { } - private static IAsmSourceLine[] createSourceLines( IAddressFactory factory, ISourceLocator locator, ICDIMixedInstruction[] mi ) { + private void createSourceLines( IAddressFactory factory, ISourceLocator locator, ICDIMixedInstruction[] mi ) { IAsmSourceLine[] result = new IAsmSourceLine[mi.length]; LineNumberReader reader = null; if ( result.length > 0 && locator != null ) { @@ -145,6 +162,7 @@ public class DisassemblyBlock implements IDisassemblyBlock, IAdaptable { if ( locator instanceof ICSourceLocator ) { element = ((ICSourceLocator)locator).findSourceElement( fileName ); } + fSourceElement = element; File file= null; if ( element instanceof IFile ) { file = ((IFile)element).getLocation().toFile(); @@ -162,8 +180,8 @@ public class DisassemblyBlock implements IDisassemblyBlock, IAdaptable { } for ( int i = 0; i < result.length; ++i ) { String text = null; + int lineNumber = mi[i].getLineNumber(); if ( reader != null ) { - int lineNumber = mi[i].getLineNumber(); while( reader.getLineNumber() + 1 < lineNumber ) { try { reader.readLine(); @@ -179,13 +197,13 @@ public class DisassemblyBlock implements IDisassemblyBlock, IAdaptable { } } } - result[i] = new AsmSourceLine( factory, text, mi[i].getInstructions() ); + result[i] = new AsmSourceLine( factory, text, lineNumber, mi[i].getInstructions() ); } - return result; + fSourceLines = result; } - private static IAsmSourceLine[] createSourceLines( IAddressFactory factory, ICDIInstruction[] instructions ) { - return new IAsmSourceLine[] { new AsmSourceLine( factory, "", instructions ) }; //$NON-NLS-1$ + private void createSourceLines( IAddressFactory factory, ICDIInstruction[] instructions ) { + fSourceLines = new IAsmSourceLine[] { new AsmSourceLine( factory, "", instructions ) }; //$NON-NLS-1$ } private void initializeAddresses() { @@ -202,8 +220,4 @@ public class DisassemblyBlock implements IDisassemblyBlock, IAdaptable { private void setMixedMode( boolean mixedMode ) { this.fMixedMode = mixedMode; } - - private void setSourceLines( IAsmSourceLine[] sourceLines ) { - this.fSourceLines = sourceLines; - } } diff --git a/debug/org.eclipse.cdt.debug.ui/ChangeLog b/debug/org.eclipse.cdt.debug.ui/ChangeLog index b0c20c82720..e6fb2939f07 100644 --- a/debug/org.eclipse.cdt.debug.ui/ChangeLog +++ b/debug/org.eclipse.cdt.debug.ui/ChangeLog @@ -1,3 +1,12 @@ +2005-06-29 Mikhail Khodjaiants + Bug 41725: I can't set a breakpoint in a function where I used attach source. + Bug 45514: Breakpoints made is assembly view do not show in C view. + + DebugMarkerAnnotationModel.java + + DebugMarkerAnnotationModelFactory.java + * ToggleBreakpointAdapter.java + * DisassemblyEditorInput.java + * plugin.xml + 2005-06-29 Mikhail Khodjaiants Removed unused imports. * CBreapointWorkbencAdapterFactory.java diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.xml b/debug/org.eclipse.cdt.debug.ui/plugin.xml index 96be8272d88..0fb0291b6da 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.xml +++ b/debug/org.eclipse.cdt.debug.ui/plugin.xml @@ -1240,5 +1240,11 @@ icon="icons/obj16/folder_obj.gif" id="org.eclipse.cdt.debug.ui.containerPresentation.directory"/> + + + diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/DebugMarkerAnnotationModel.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/DebugMarkerAnnotationModel.java new file mode 100644 index 00000000000..002411253f4 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/DebugMarkerAnnotationModel.java @@ -0,0 +1,103 @@ +/********************************************************************** + * Copyright (c) 2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + ***********************************************************************/ +package org.eclipse.cdt.debug.internal.ui; + +import java.io.File; +import org.eclipse.cdt.debug.core.CDIDebugModel; +import org.eclipse.cdt.debug.core.model.ICBreakpoint; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IMarkerDelta; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.IBreakpointsListener; +import org.eclipse.debug.core.model.IBreakpoint; +import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel; + +public class DebugMarkerAnnotationModel extends AbstractMarkerAnnotationModel implements IBreakpointsListener { + + private File fFile; + + public DebugMarkerAnnotationModel( File file ) { + super(); + fFile = file; + } + + protected IMarker[] retrieveMarkers() throws CoreException { + IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints( CDIDebugModel.getPluginIdentifier() ); + IMarker[] markers = new IMarker[breakpoints.length]; + for ( int i = 0; i < markers.length; ++i ) { + markers[i] = breakpoints[i].getMarker(); + } + return markers; + } + + protected void deleteMarkers( IMarker[] markers ) throws CoreException { + } + + protected void listenToMarkerChanges( boolean listen ) { + if ( listen ) + DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener( this ); + else + DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener( this ); + } + + protected boolean isAcceptable( IMarker marker ) { + IBreakpoint b = DebugPlugin.getDefault().getBreakpointManager().getBreakpoint( marker ); + if ( b != null ) { + return isAcceptable( b ); + } + return false; + } + + protected File getFile() { + return fFile; + } + + public void breakpointsAdded( IBreakpoint[] breakpoints ) { + for ( int i = 0; i < breakpoints.length; ++i ) { + if ( isAcceptable( breakpoints[i] ) ) { + addMarkerAnnotation( breakpoints[i].getMarker() ); + fireModelChanged(); + } + } + } + + public void breakpointsRemoved( IBreakpoint[] breakpoints, IMarkerDelta[] deltas ) { + for ( int i = 0; i < breakpoints.length; ++i ) { + if ( isAcceptable( breakpoints[i] ) ) { + removeMarkerAnnotation( breakpoints[i].getMarker() ); + fireModelChanged(); + } + } + } + + public void breakpointsChanged( IBreakpoint[] breakpoints, IMarkerDelta[] deltas ) { + for ( int i = 0; i < breakpoints.length; ++i ) { + if ( isAcceptable( breakpoints[i] ) ) { + modifyMarkerAnnotation( breakpoints[i].getMarker() ); + fireModelChanged(); + } + } + } + + private boolean isAcceptable( IBreakpoint b ) { + if ( b instanceof ICBreakpoint ) { + try { + String handle = ((ICBreakpoint)b).getSourceHandle(); + File file = new File( handle ); + return file.equals( getFile() ); + } + catch( CoreException e ) { + } + } + return false; + } +} diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/DebugMarkerAnnotationModelFactory.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/DebugMarkerAnnotationModelFactory.java new file mode 100644 index 00000000000..3d6d3db60b9 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/DebugMarkerAnnotationModelFactory.java @@ -0,0 +1,37 @@ +/********************************************************************** + * Copyright (c) 2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + ***********************************************************************/ +package org.eclipse.cdt.debug.internal.ui; + +import java.io.File; +import org.eclipse.core.filebuffers.FileBuffers; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jface.text.source.IAnnotationModel; +import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModelFactory; + +public class DebugMarkerAnnotationModelFactory extends ResourceMarkerAnnotationModelFactory { + + /* (non-Javadoc) + * @see org.eclipse.ui.texteditor.ResourceMarkerAnnotationModelFactory#createAnnotationModel(org.eclipse.core.runtime.IPath) + */ + public IAnnotationModel createAnnotationModel( IPath location ) { + IFile file = FileBuffers.getWorkspaceFileAtLocation( location ); + if ( file != null ) { + return super.createAnnotationModel( location ); + } + File osFile = new File( location.toOSString() ); + if ( osFile.exists() ) { + return new DebugMarkerAnnotationModel( osFile ); + } + return null; + } + +} diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleBreakpointAdapter.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleBreakpointAdapter.java index c8d03cddb9a..7ce81d2437b 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleBreakpointAdapter.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleBreakpointAdapter.java @@ -33,7 +33,9 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget; @@ -125,10 +127,13 @@ public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget { DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint( breakpoint, true ); } else { - IResource resource = ResourcesPlugin.getWorkspace().getRoot(); + String module = ((DisassemblyEditorInput)input).getModuleFile(); + IResource resource = getAddressBreakpointResource( ((DisassemblyEditorInput)input).getSourceFile() ); String sourceHandle = getSourceHandle( input ); - CDIDebugModel.createAddressBreakpoint( sourceHandle, - resource, + CDIDebugModel.createAddressBreakpoint( module, + sourceHandle, + resource, + ((DisassemblyEditorInput)input).getSourceLine( lineNumber ), address, true, 0, @@ -314,6 +319,10 @@ public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget { return ((IStorageEditorInput)input).getStorage().getFullPath().toOSString(); } if ( input instanceof DisassemblyEditorInput ) { + String sourceFile = ((DisassemblyEditorInput)input).getSourceFile(); + if ( sourceFile != null ) { + return sourceFile; + } return ((DisassemblyEditorInput)input).getModuleFile(); } return ""; //$NON-NLS-1$ @@ -465,4 +474,14 @@ public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget { true ); } } + + private IResource getAddressBreakpointResource( String fileName ) { + IPath path = new Path( fileName ); + if ( path.isValidPath( fileName ) ) { + IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation( path ); + if ( files.length > 0 ) + return files[0]; + } + return ResourcesPlugin.getWorkspace().getRoot(); + } } diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyEditorInput.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyEditorInput.java index af9f77abbf3..c508481c3d7 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyEditorInput.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/views/disassembly/DisassemblyEditorInput.java @@ -21,6 +21,8 @@ import org.eclipse.cdt.debug.core.model.ICLineBreakpoint; import org.eclipse.cdt.debug.core.model.ICStackFrame; import org.eclipse.cdt.debug.core.model.IDisassembly; import org.eclipse.cdt.debug.core.model.IDisassemblyBlock; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IStorage; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugPlugin; @@ -186,6 +188,34 @@ public class DisassemblyEditorInput implements IEditorInput { return ( fBlock != null ) ? fBlock.getModuleFile() : null; } + public String getSourceFile() { + if ( fBlock != null ) { + Object element = fBlock.getSourceElement(); + if ( element instanceof IFile ) { + return ((IFile)element).getLocation().toOSString(); + } + else if ( element instanceof IStorage ) { + return ((IStorage)element).getFullPath().toOSString(); + } + } + return null; + } + + public int getSourceLine( int instrNumber ) { + if ( fBlock != null ) { + IAsmSourceLine[] sl = fBlock.getSourceLines(); + int current = 0; + for ( int i = 0; i < sl.length; ++i ) { + ++current; + IAsmInstruction[] ins = sl[i].getInstructions(); + if ( instrNumber >= current && instrNumber <= current + ins.length ) + return sl[i].getLineNumber(); + current += ins.length; + } + } + return -1; + } + public static DisassemblyEditorInput create( ICStackFrame frame ) throws DebugException { DisassemblyEditorInput input = null; ICDebugTarget target = ((ICDebugTarget)frame.getDebugTarget());