From f3860cc65b7efced123ee0a8fe84e7b45a06f8e9 Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Wed, 24 Sep 2014 08:35:22 +0200 Subject: [PATCH] Bug 444736 - Importing a subset of exported breakpoints often logs exceptions This fixes also Bug 413787 - Occasional "Breakpoint does not have an associated marker" in the log --- .../eclipse/cdt/debug/core/CDebugUtils.java | 40 ++++++++++++------- .../debug/core/DebugCoreMessages.properties | 2 + .../internal/ui/CDebugModelPresentation.java | 7 +++- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugUtils.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugUtils.java index 08100c0aa2e..3d6329c3b9d 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugUtils.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugUtils.java @@ -321,22 +321,32 @@ public class CDebugUtils { } public static String getBreakpointText(IBreakpoint breakpoint, boolean qualified) throws CoreException { - if (breakpoint instanceof ICAddressBreakpoint) { - return getAddressBreakpointText((ICAddressBreakpoint)breakpoint, qualified); + try { + if (breakpoint instanceof ICAddressBreakpoint) { + return getAddressBreakpointText((ICAddressBreakpoint)breakpoint, qualified); + } + if (breakpoint instanceof ICFunctionBreakpoint) { + return getFunctionBreakpointText((ICFunctionBreakpoint)breakpoint, qualified); + } + if (breakpoint instanceof ICLineBreakpoint) { + return getLineBreakpointText((ICLineBreakpoint)breakpoint, qualified); + } + if (breakpoint instanceof ICWatchpoint) { + return getWatchpointText((ICWatchpoint)breakpoint, qualified); + } + // This allows to create a new breakpoint without implementing one of the interfaces above and still see a label + Object message = breakpoint.getMarker().getAttribute(IMarker.MESSAGE); + if (message != null) + return message.toString(); + } catch (CoreException e) { + // don't log if breakpoint has been deleted + IMarker marker = breakpoint.getMarker(); + if (marker == null || !marker.exists()) { + return DebugCoreMessages.getString("CDebugUtils.breakpoint_deleted"); //$NON-NLS-1$ + } + CDebugCorePlugin.log(e); + return DebugCoreMessages.getString("CDebugUtils.exception_occurred"); //$NON-NLS-1$ } - if (breakpoint instanceof ICFunctionBreakpoint) { - return getFunctionBreakpointText((ICFunctionBreakpoint)breakpoint, qualified); - } - if (breakpoint instanceof ICLineBreakpoint) { - return getLineBreakpointText((ICLineBreakpoint)breakpoint, qualified); - } - if (breakpoint instanceof ICWatchpoint) { - return getWatchpointText((ICWatchpoint)breakpoint, qualified); - } - // This allows to create a new breakpoint without implementing one of the interfaces above and still see a label - Object message = breakpoint.getMarker().getAttribute(IMarker.MESSAGE); - if (message != null) - return message.toString(); return ""; //$NON-NLS-1$ } diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/DebugCoreMessages.properties b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/DebugCoreMessages.properties index 504e9b49e67..30dc1e6abc2 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/DebugCoreMessages.properties +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/DebugCoreMessages.properties @@ -32,5 +32,7 @@ CDebugUtils.Program_file_does_not_exist=The program file specified in the launch CDebugUtils.Program_file_not_specified=A program file was not specified in the launch configuration. CDebugUtils.Project_NAME_does_not_exist=Project {0} does not exist. Please check that your launch configuration specifies a valid project in your workspace. CDebugUtils.Project_NAME_is_closed=Project {0} is closed +CDebugUtils.exception_occurred=An exception occurred. See log for details. +CDebugUtils.breakpoint_deleted= CDIDebugModel.0=Unable to parser binary information from file diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugModelPresentation.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugModelPresentation.java index 714370298dc..9e13f55d30f 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugModelPresentation.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/CDebugModelPresentation.java @@ -164,15 +164,18 @@ public class CDebugModelPresentation extends LabelProvider implements IDebugMode } if ( element instanceof ICBreakpoint ) { ICBreakpoint b = (ICBreakpoint)element; + IMarker marker = b.getMarker(); + if (marker == null || !marker.exists()) + return null; // If the BP's marker is on an IFile, job done - IFile file = (IFile)b.getMarker().getResource().getAdapter(IFile.class); + IFile file = (IFile)marker.getResource().getAdapter(IFile.class); if (file == null) { try { // Not backed by an IFile, try its source handle (may be workspace / project based) String handle = b.getSourceHandle(); if (handle != null && Path.ROOT.isValidPath(handle)) { Path path = new Path(handle); - IProject project = b.getMarker().getResource().getProject(); + IProject project = marker.getResource().getProject(); // Select the most 'relevant' IFile for an external location file = ResourceLookup.selectFileForLocation(path, project); if (file == null || !file.isAccessible()) {