Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonah Graham2017-11-15 10:45:54 +0000
committerJonah Graham2017-11-15 10:46:38 +0000
commit2173d1dd52dc398a33505763fb7eeb5216a29040 (patch)
treea55f13f59324b42fe624a8fdeb76eabccc89f384 /dsf-gdb/org.eclipse.cdt.dsf.gdb/src
parentb721d6a424ff82d9c7c1feab65df53a4fb4c659f (diff)
downloadorg.eclipse.cdt-2173d1dd52dc398a33505763fb7eeb5216a29040.tar.gz
org.eclipse.cdt-2173d1dd52dc398a33505763fb7eeb5216a29040.tar.xz
org.eclipse.cdt-2173d1dd52dc398a33505763fb7eeb5216a29040.zip
Bug 500988: better handle race condition in SourceContainer
Instead of an indiscriminate NPE at termination of a launch, handle it more cleanly with a friendly error message. Change-Id: Ie37e675c3f5e4883c0b160bfe86c4848f1983fa7
Diffstat (limited to 'dsf-gdb/org.eclipse.cdt.dsf.gdb/src')
-rw-r--r--dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbSourceLookupDirector.java32
1 files changed, 31 insertions, 1 deletions
diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbSourceLookupDirector.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbSourceLookupDirector.java
index b52a4d78a19..314eb432262 100644
--- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbSourceLookupDirector.java
+++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/launching/GdbSourceLookupDirector.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.cdt.dsf.gdb.launching;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -17,11 +18,14 @@ import org.eclipse.cdt.debug.core.sourcelookup.IMappingSourceContainer;
import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer;
import org.eclipse.cdt.debug.internal.core.sourcelookup.MapEntrySourceContainer;
import org.eclipse.cdt.dsf.debug.sourcelookup.DsfSourceLookupDirector;
+import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
import org.eclipse.cdt.dsf.gdb.service.IGDBSourceLookup;
import org.eclipse.cdt.dsf.service.DsfSession;
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.sourcelookup.ISourceContainer;
import org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant;
import org.eclipse.debug.core.sourcelookup.containers.DefaultSourceContainer;
@@ -61,7 +65,33 @@ public class GdbSourceLookupDirector extends DsfSourceLookupDirector {
*/
public Map<String, String> getSubstitutionsPaths() {
Map<String, String> entries = new HashMap<>();
- collectSubstitutionsPaths(getSourceContainers(), entries);
+ try {
+ collectSubstitutionsPaths(getSourceContainers(), entries);
+ } catch (NullPointerException npe) {
+ /*
+ * Bug 500988: getting source containers from composite containers has a race
+ * condition around termination. This can lead to a NPE being thrown from within
+ * the above code.
+ *
+ * The reason for the NPE is that termination of a launch can cause the launch
+ * configuration to be updated (e.g. with memory settings memento). This update
+ * causes the source lookups to be recalculated, however that recalculation is
+ * happening while the launch is terminating. The termination causes the source
+ * containers to be disposed in another thread and as the dispose method is not
+ * thread safe, we get NPEs. See CompositeSourceContainer.dispose() where the
+ * race condition is. Unfortunately synchronizing it leads to potential
+ * deadlocks.
+ *
+ * Catching all NPEs and silently discarding them makes it very hard to track
+ * down bugs, so in case the NPE is caused for another reason we are logging it.
+ */
+ GdbPlugin.log(new Status(IStatus.ERROR, GdbPlugin.getUniqueIdentifier(), IStatus.ERROR,
+ "NullPointerException while trying to calculated source lookup path. " //$NON-NLS-1$
+ + "This can be ignored if it occurs while terminating a debug session. " //$NON-NLS-1$
+ + "See Bug 500988.", //$NON-NLS-1$
+ npe));
+ entries = Collections.emptyMap();
+ }
return entries;
}

Back to the top