1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Added support for breakpoint problem markers, bug 170027.

This commit is contained in:
Ken Ryall 2007-01-31 20:16:00 +00:00
parent fe6d691b73
commit f3e2d73cd2
8 changed files with 370 additions and 8 deletions

View file

@ -0,0 +1,26 @@
/*******************************************************************************
* Copyright (c) 2007 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.core.cdi.event;
import org.eclipse.cdt.debug.core.cdi.ICDILocator;
/**
*
* Notifies that a breakpoint has changed location.
*/
public interface ICDIBreakpointMovedEvent extends ICDIEvent {
/** Returns the new location for the breakpoint.
* @return the breakpoint's new location.
*/
ICDILocator getNewLocation();
}

View file

@ -0,0 +1,57 @@
/*******************************************************************************
* Copyright (c) 2007 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.core.cdi.event;
import org.eclipse.cdt.debug.core.cdi.model.ICDIBreakpoint;
/**
*
* Notifies that a breakpoint problem has occurred.
*/
public interface ICDIBreakpointProblemEvent {
/** The problem type is a string that identifies specific
* kinds of breakproblems.
* @return problem type name
*/
String getProblemType();
/** The CDI breakpoint that has the problem
* @return the cdi breakpoint that has the problem
*/
ICDIBreakpoint getBreakpoint();
/** A description of the problem.
* This will be presented in the problems view.
* @return a description of the problem
*/
String getDescription();
/** The severity code maps to the IMarker.SEVERITY_XXX constants.
* @return severity code.
*/
int getSeverity();
/** Indicated that existing problems of this type and at this
* breakpoint's location will be removed, no new ones will
* be added.
* @return only remove existing problems
*/
boolean removeOnly();
/** Indicated that any existing problems of this type
* and at this breakpoint's location will be removed
* before the new problem is added.
* @return remove any existing markers
*/
boolean removeExisting();
}

View file

@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2000, 2006 QNX Software Systems and others.
# Copyright (c) 2000, 2007 QNX Software Systems 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
@ -7,7 +7,8 @@
#
# Contributors:
# QNX Software Systems - Initial API and implementation
# Nokia - Added support for AbsoluteSourceContainer( 159833 )
# Ken Ryall (Nokia) - Added support for AbsoluteSourceContainer( 159833 )
# Ken Ryall (Nokia) - Added support for breakpoint problems( 170027 )
###############################################################################
pluginName=C/C++ Development Tools Debug Model
providerName=Eclipse.org
@ -18,6 +19,7 @@ cLineBreakpoints.name=C/C++ Line Breakpoints
cAddressBreakpoints.name=C/C++ Address Breakpoints
cFunctionBreakpoints.name=C/C++ Function Breakpoints
cWatchpoints.name=C/C++ Watchpoints
breakpointProblem.name=C/C++ Breakpoint Problem
containerName.mapping=Path Mapping
containerDescription.mapping=A path mapping.

View file

@ -97,6 +97,21 @@
name="org.eclipse.cdt.debug.core.read">
</attribute>
</extension>
<extension
id="breakpointproblem"
name="%breakpointProblem.name"
point="org.eclipse.core.resources.markers">
<super
type="org.eclipse.core.resources.problemmarker">
</super>
<super
type="org.eclipse.core.resources.textmarker">
</super>
<persistent
value="false">
</persistent>
<attribute name="externalLocation"/>
</extension>
<extension
point="org.eclipse.debug.core.breakpoints">
<breakpoint

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2006 QNX Software Systems and others.
* Copyright (c) 2004, 2007 QNX Software Systems 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
@ -7,7 +7,8 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Matthias Spycher (matthias@coware.com) - patch for bug #112008
* Matthias Spycher (matthias@coware.com) - patch for bug #112008
* Ken Ryall (Nokia) - bug 170027
*******************************************************************************/
package org.eclipse.cdt.debug.internal.core;
@ -31,6 +32,8 @@ import org.eclipse.cdt.debug.core.cdi.ICDICondition;
import org.eclipse.cdt.debug.core.cdi.ICDIFunctionLocation;
import org.eclipse.cdt.debug.core.cdi.ICDILineLocation;
import org.eclipse.cdt.debug.core.cdi.ICDILocator;
import org.eclipse.cdt.debug.core.cdi.event.ICDIBreakpointMovedEvent;
import org.eclipse.cdt.debug.core.cdi.event.ICDIBreakpointProblemEvent;
import org.eclipse.cdt.debug.core.cdi.event.ICDIChangedEvent;
import org.eclipse.cdt.debug.core.cdi.event.ICDICreatedEvent;
import org.eclipse.cdt.debug.core.cdi.event.ICDIDestroyedEvent;
@ -54,10 +57,12 @@ import org.eclipse.cdt.debug.core.model.ICLineBreakpoint;
import org.eclipse.cdt.debug.core.model.ICThread;
import org.eclipse.cdt.debug.core.model.ICWatchpoint;
import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocator;
import org.eclipse.cdt.debug.internal.core.breakpoints.BreakpointProblems;
import org.eclipse.cdt.debug.internal.core.breakpoints.CBreakpoint;
import org.eclipse.cdt.debug.internal.core.model.CDebugTarget;
import org.eclipse.cdt.debug.internal.core.sourcelookup.CSourceLookupDirector;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IMarkerDelta;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@ -235,6 +240,8 @@ public class CBreakpointManager implements IBreakpointsListener, IBreakpointMana
private BreakpointMap fMap;
private boolean fSkipBreakpoint = false;
private ArrayList fBreakpointProblems = new ArrayList();
public CBreakpointManager( CDebugTarget target ) {
super();
@ -347,6 +354,14 @@ public class CBreakpointManager implements IBreakpointsListener, IBreakpointMana
if ( source instanceof ICDIBreakpoint )
handleBreakpointChangedEvent( (ICDIBreakpoint)source );
}
else if ( event instanceof ICDIBreakpointMovedEvent ) {
if ( source instanceof ICDIBreakpoint )
handleBreakpointMovedEvent( (ICDIBreakpointMovedEvent) event );
}
else if ( event instanceof ICDIBreakpointProblemEvent ) {
if ( source instanceof ICDIBreakpoint )
handleBreakpointProblemEvent( (ICDIBreakpointProblemEvent) event );
}
}
}
}
@ -442,6 +457,7 @@ public class CBreakpointManager implements IBreakpointsListener, IBreakpointMana
// }
try {
BreakpointProblems.removeProblemsForResolvedBreakpoint(breakpoint, getDebugTarget().getInternalID());
breakpoint.setTargetFilter( getDebugTarget() );
((CBreakpoint)breakpoint).register( true );
}
@ -481,6 +497,39 @@ public class CBreakpointManager implements IBreakpointsListener, IBreakpointMana
}
}
private void handleBreakpointMovedEvent( ICDIBreakpointMovedEvent movedEvent )
{
ICBreakpoint breakpoint = getBreakpointMap().getCBreakpoint( (ICDIBreakpoint) movedEvent.getSource() );
if (breakpoint != null)
{
try {
int newLineNumber = movedEvent.getNewLocation().getLineNumber();
int currLineNumber = breakpoint.getMarker().getAttribute(IMarker.LINE_NUMBER, newLineNumber);
breakpoint.getMarker().setAttribute(IMarker.LINE_NUMBER, newLineNumber);
fBreakpointProblems.add(BreakpointProblems.reportBreakpointMoved(
breakpoint, currLineNumber, newLineNumber, getDebugTarget().getName(), getDebugTarget().getInternalID()));
} catch (CoreException e) {}
}
}
private void handleBreakpointProblemEvent( ICDIBreakpointProblemEvent problemEvent )
{
ICBreakpoint breakpoint = getBreakpointMap().getCBreakpoint( problemEvent.getBreakpoint() );
if (breakpoint != null)
{
try {
IMarker marker;
marker = BreakpointProblems.reportBreakpointProblem(breakpoint, problemEvent.getDescription(),
problemEvent.getSeverity(), problemEvent.getProblemType(), problemEvent.removeExisting(),
problemEvent.removeOnly(), getDebugTarget().getName(), getDebugTarget().getInternalID());
if (marker != null)
fBreakpointProblems.add(marker);
} catch (DebugException e) {}
}
}
private void handleBreakpointChangedEvent( ICDIBreakpoint cdiBreakpoint ) {
ICBreakpoint breakpoint = getBreakpointMap().getCBreakpoint( cdiBreakpoint );
if ( breakpoint != null ) {
@ -525,6 +574,9 @@ public class CBreakpointManager implements IBreakpointsListener, IBreakpointMana
catch( CoreException e ) {
}
}
try {
BreakpointProblems.removeProblemsForBreakpoint(breakpoint);
} catch (CoreException e) {}
getBreakpointNotifier().breakpointsRemoved( getDebugTarget(), new IBreakpoint[] { breakpoint } );
}
}
@ -557,6 +609,13 @@ public class CBreakpointManager implements IBreakpointsListener, IBreakpointMana
}
} );
getBreakpointNotifier().breakpointsRemoved( getDebugTarget(), breakpoints );
// Remove all breakpoint problem markers
for (Iterator iter = fBreakpointProblems.iterator(); iter.hasNext();) {
IMarker marker = (IMarker) iter.next();
try {
marker.delete();
} catch (CoreException e) {}
}
}
private ICBreakpoint[] register( IBreakpoint[] breakpoints ) {
@ -594,6 +653,7 @@ public class CBreakpointManager implements IBreakpointsListener, IBreakpointMana
String fileName = breakpoint.getFileName();
ICDIFunctionLocation location = cdiTarget.createFunctionLocation( fileName, function );
ICDICondition condition = createCondition( breakpoint );
fBreakpointProblems.add(BreakpointProblems.reportUnresolvedBreakpoint(breakpoint, getDebugTarget().getName(), getDebugTarget().getInternalID()));
b = cdiTarget.setFunctionBreakpoint( ICDIBreakpoint.REGULAR, location, condition, true );
} else if ( breakpoints[i] instanceof ICAddressBreakpoint ) {
ICAddressBreakpoint breakpoint = (ICAddressBreakpoint)breakpoints[i];
@ -607,6 +667,7 @@ public class CBreakpointManager implements IBreakpointsListener, IBreakpointMana
IPath path = convertPath( handle );
ICDILineLocation location = cdiTarget.createLineLocation( path.toPortableString(), breakpoint.getLineNumber() );
ICDICondition condition = createCondition( breakpoint );
fBreakpointProblems.add(BreakpointProblems.reportUnresolvedBreakpoint(breakpoint, getDebugTarget().getName(), getDebugTarget().getInternalID()));
b = cdiTarget.setLineBreakpoint( ICDIBreakpoint.REGULAR, location, condition, true );
} else if ( breakpoints[i] instanceof ICWatchpoint ) {
ICWatchpoint watchpoint = (ICWatchpoint)breakpoints[i];

View file

@ -0,0 +1,181 @@
/*******************************************************************************
* Copyright (c) 2007 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.internal.core.breakpoints;
import java.text.MessageFormat;
import org.eclipse.cdt.core.ProblemMarkerInfo;
import org.eclipse.cdt.core.model.ICModelMarker;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.cdt.debug.core.model.ICBreakpoint;
import org.eclipse.cdt.debug.core.model.ICLineBreakpoint;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
public class BreakpointProblems {
/**
* The identifier for breakpoint problem markers.
*/
public static final String BREAKPOINT_PROBLEM_MARKER_ID = CDebugCorePlugin.PLUGIN_ID + ".breakpointproblem" ; //$NON-NLS-1$
/**
* Breakpoint problem marker types.
*/
public static final String BREAKPOINT_PROBLEM_TYPE = "bp_problem_type"; //$NON-NLS-1$
public static final String UNRESOLVED = "unresolved"; //$NON-NLS-1$
public static final String BAD_CONDITION = "bad_condition"; //$NON-NLS-1$
public static final String MOVED = "moved"; //$NON-NLS-1$
public static final String BREAKPOINT_CONTEXT_NAME = "bp_context_name"; //$NON-NLS-1$
public static final String BREAKPOINT_CONTEXT_ID = "bp_context_id"; //$NON-NLS-1$
public static IMarker reportBreakpointMoved(ICBreakpoint breakpoint, int oldLineNumber, int newLineNumber, String contextName, String contextID) throws CoreException {
String message = MessageFormat.format("Breakpoint could not be set at line {0}, moved to line {1}", new Object[] { new Integer(oldLineNumber), new Integer(newLineNumber) });
IMarker marker = BreakpointProblems.reportBreakpointProblem(breakpoint, message, IMarker.SEVERITY_INFO, MOVED, true, false, contextName, contextID);
return marker;
}
public static IMarker reportUnresolvedBreakpoint(ICBreakpoint breakpoint, String contextName, String contextID) throws CoreException {
IMarker marker = BreakpointProblems.reportBreakpointProblem(breakpoint, "Unresolved breakpoint", IMarker.SEVERITY_WARNING, UNRESOLVED, true, false, contextName, contextID);
return marker;
}
public static void removeProblemsForBreakpoint(ICBreakpoint breakpoint) throws CoreException {
IMarker marker = breakpoint.getMarker();
if (marker != null)
{
int lineNumber = marker.getAttribute(IMarker.LINE_NUMBER, 0);
IResource bpResource = marker.getResource();
if (bpResource != null)
{
IMarker[] bpProblems = bpResource.findMarkers(BREAKPOINT_PROBLEM_MARKER_ID, true, IResource.DEPTH_INFINITE);
for (int i = 0; i < bpProblems.length; i++) {
if (bpProblems[i].getAttribute(IMarker.LINE_NUMBER, 0) == lineNumber)
{
bpProblems[i].delete();
}
}
}
}
}
public static void removeProblemsForResolvedBreakpoint(ICBreakpoint breakpoint, String contextID) throws CoreException {
IMarker marker = breakpoint.getMarker();
if (marker != null)
{
int lineNumber = marker.getAttribute(IMarker.LINE_NUMBER, 0);
IResource bpResource = marker.getResource();
if (bpResource != null)
{
IMarker[] bpProblems = bpResource.findMarkers(BREAKPOINT_PROBLEM_MARKER_ID, true, IResource.DEPTH_INFINITE);
for (int i = 0; i < bpProblems.length; i++) {
if (bpProblems[i].getAttribute(BREAKPOINT_PROBLEM_TYPE, "").equalsIgnoreCase(UNRESOLVED) &&
bpProblems[i].getAttribute(IMarker.LINE_NUMBER, 0) == lineNumber &&
bpProblems[i].getAttribute(BREAKPOINT_CONTEXT_ID, "").equals(contextID))
{
bpProblems[i].delete();
}
}
}
}
}
public static IMarker reportBreakpointProblem(ICBreakpoint breakpoint,
String description, int severity, String problemType, boolean removePrevious, boolean removeOnly, String contextName, String contextID) {
try {
if (breakpoint instanceof ICLineBreakpoint) {
ICLineBreakpoint lineBreakpoint = (ICLineBreakpoint) breakpoint;
IMarker marker = null;
if (removePrevious)
{
IMarker existingMarker = lineBreakpoint.getMarker();
if (existingMarker != null)
{
IResource bpResource = existingMarker.getResource();
if (bpResource != null)
{
int lineNumber = existingMarker.getAttribute(IMarker.LINE_NUMBER, 0);
IMarker[] bpProblems = bpResource.findMarkers(BREAKPOINT_PROBLEM_MARKER_ID, true, IResource.DEPTH_INFINITE);
for (int i = 0; i < bpProblems.length; i++) {
if (bpProblems[i].getAttribute(BREAKPOINT_PROBLEM_TYPE, "").equalsIgnoreCase(problemType) &&
bpProblems[i].getAttribute(IMarker.LINE_NUMBER, 0) == lineNumber)
{
bpProblems[i].delete();
}
}
}
}
}
if (!removeOnly)
{
marker = reportBreakpointProblem(new ProblemMarkerInfo(
lineBreakpoint.getMarker().getResource(),
lineBreakpoint.getLineNumber(), description, severity,
""));
marker.setAttribute(BREAKPOINT_PROBLEM_TYPE, problemType);
marker.setAttribute(BREAKPOINT_CONTEXT_NAME, contextName);
marker.setAttribute(BREAKPOINT_CONTEXT_ID, contextID);
}
return marker;
}
} catch (CoreException e) {
}
return null;
}
public static IMarker reportBreakpointProblem(ProblemMarkerInfo problemMarkerInfo)
{
IResource markerResource = problemMarkerInfo.file ;
if (markerResource==null) {
return null;
}
try {
IMarker[] cur = markerResource.findMarkers(BREAKPOINT_PROBLEM_MARKER_ID, true, IResource.DEPTH_ONE);
/*
* Try to find matching markers and don't put in duplicates
*/
if ((cur != null) && (cur.length > 0)) {
for (int i = 0; i < cur.length; i++) {
int line = ((Integer) cur[i].getAttribute(IMarker.LOCATION)).intValue();
int sev = ((Integer) cur[i].getAttribute(IMarker.SEVERITY)).intValue();
String mesg = (String) cur[i].getAttribute(IMarker.MESSAGE);
if (line == problemMarkerInfo.lineNumber && sev == problemMarkerInfo.severity && mesg.equals(problemMarkerInfo.description)) {
return cur[i];
}
}
}
IMarker marker = markerResource.createMarker(BREAKPOINT_PROBLEM_MARKER_ID);
marker.setAttribute(IMarker.LOCATION, problemMarkerInfo.lineNumber);
marker.setAttribute(IMarker.MESSAGE, problemMarkerInfo.description);
marker.setAttribute(IMarker.SEVERITY, problemMarkerInfo.severity);
marker.setAttribute(IMarker.LINE_NUMBER, problemMarkerInfo.lineNumber);
marker.setAttribute(IMarker.CHAR_START, -1);
marker.setAttribute(IMarker.CHAR_END, -1);
if (problemMarkerInfo.variableName != null) {
marker.setAttribute(ICModelMarker.C_MODEL_MARKER_VARIABLE, problemMarkerInfo.variableName);
}
if (problemMarkerInfo.externalPath != null) {
marker.setAttribute(ICModelMarker.C_MODEL_MARKER_EXTERNAL_LOCATION, problemMarkerInfo.externalPath.toOSString());
}
return marker;
} catch (CoreException e) {}
return null;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2006 QNX Software Systems and others.
* Copyright (c) 2000, 2007 QNX Software Systems 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
@ -7,7 +7,7 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Ken Ryall (Nokia) - https://bugs.eclipse.org/bugs/show_bug.cgi?id=118894
* Ken Ryall (Nokia) - bugs 118894, 170027
*******************************************************************************/
package org.eclipse.cdt.debug.internal.core.model;
@ -224,6 +224,13 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv
*/
private CMemoryBlockRetrievalExtension fMemoryBlockRetrieval;
/**
* Internal ID that uniquely identifies this CDebugTarget.
*/
private String internalD = Integer.toString(lastInternalID++);
private static int lastInternalID = 1;
/**
* Constructor for CDebugTarget.
*/
@ -1804,4 +1811,8 @@ public class CDebugTarget extends CDebugElement implements ICDebugTarget, ICDIEv
if ( mm != null )
mm.loadSymbolsForAllModules();
}
}
public String getInternalID() {
return internalD;
}
}

View file

@ -72,11 +72,20 @@
</view>
<viewShortcut
id="org.eclipse.cdt.debug.ui.ModulesView">
</viewShortcut>
<view
visible="true"
relative="org.eclipse.ui.console.ConsoleView"
relationship="stack"
id="org.eclipse.ui.views.ProblemView">
</view>
<viewShortcut
id="org.eclipse.ui.views.ProblemView">
</viewShortcut>
<actionSet
id="org.eclipse.cdt.debug.ui.debugActionSet">
</actionSet>
</perspectiveExtension>
</perspectiveExtension>
</extension>
<extension
point="org.eclipse.ui.preferencePages">