From 36265d4f24af02da303f04d1e6dbb51fc08d4c32 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Wed, 17 May 2017 15:43:06 +0300 Subject: [PATCH] IDEA-172928 Improve notification that line breakpoints won't work in decompiled file (when there's no debug information) --- .../debugger/engine/PositionManagerImpl.java | 43 ++++++++++--------- .../debugger/impl/DebuggerUtilsEx.java | 7 ++- .../ui/breakpoints/LineBreakpoint.java | 8 ++++ .../src/messages/DebuggerBundle.properties | 1 + 4 files changed, 37 insertions(+), 22 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/PositionManagerImpl.java b/java/debugger/impl/src/com/intellij/debugger/engine/PositionManagerImpl.java index 8475a92325af..111aba0f8aaa 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/PositionManagerImpl.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/PositionManagerImpl.java @@ -553,27 +553,30 @@ public class PositionManagerImpl implements PositionManager, MultiRequestPositio int rangeBegin = Integer.MAX_VALUE; int rangeEnd = Integer.MIN_VALUE; - for (Location location : DebuggerUtilsEx.allLineLocations(fromClass)) { - final int lnumber = DebuggerUtilsEx.getLineNumber(location, false); - if (lnumber <= 1) { - // should be a native method, skipping - // sometimes compiler generates location where line number is exactly 1 (e.g. GWT) - // such locations are hardly correspond to real lines in code, so skipping them too - continue; + List locations = DebuggerUtilsEx.allLineLocations(fromClass); + if (locations != null) { + for (Location location : locations) { + final int lnumber = DebuggerUtilsEx.getLineNumber(location, false); + if (lnumber <= 1) { + // should be a native method, skipping + // sometimes compiler generates location where line number is exactly 1 (e.g. GWT) + // such locations are hardly correspond to real lines in code, so skipping them too + continue; + } + final Method method = DebuggerUtilsEx.getMethod(location); + if (method == null || DebuggerUtils.isSynthetic(method) || method.isBridge()) { + // do not take into account synthetic stuff + continue; + } + int locationLine = lnumber - 1; + PsiFile psiFile = position.getFile().getOriginalFile(); + if (psiFile instanceof PsiCompiledFile) { + locationLine = DebuggerUtilsEx.bytecodeToSourceLine(psiFile, locationLine); + if (locationLine < 0) continue; + } + rangeBegin = Math.min(rangeBegin, locationLine); + rangeEnd = Math.max(rangeEnd, locationLine); } - final Method method = DebuggerUtilsEx.getMethod(location); - if (method == null || DebuggerUtils.isSynthetic(method) || method.isBridge()) { - // do not take into account synthetic stuff - continue; - } - int locationLine = lnumber - 1; - PsiFile psiFile = position.getFile().getOriginalFile(); - if (psiFile instanceof PsiCompiledFile) { - locationLine = DebuggerUtilsEx.bytecodeToSourceLine(psiFile, locationLine); - if (locationLine < 0) continue; - } - rangeBegin = Math.min(rangeBegin, locationLine); - rangeEnd = Math.max(rangeEnd, locationLine); } final int positionLine = position.getLine(); diff --git a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsEx.java b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsEx.java index affac13a73a5..fe79337049a5 100644 --- a/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsEx.java +++ b/java/debugger/impl/src/com/intellij/debugger/impl/DebuggerUtilsEx.java @@ -600,12 +600,15 @@ public abstract class DebuggerUtilsEx extends DebuggerUtils { } } - @NotNull + @Nullable public static List allLineLocations(ReferenceType cls) { try { return cls.allLineLocations(); } - catch (AbsentInformationException | ObjectCollectedException ignored) { + catch (AbsentInformationException ignored) { + return null; + } + catch (ObjectCollectedException ignored) { return Collections.emptyList(); } } diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/LineBreakpoint.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/LineBreakpoint.java index e28d980600bf..3cea80f01226 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/LineBreakpoint.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/LineBreakpoint.java @@ -138,6 +138,14 @@ public class LineBreakpoint

extends Breakpoi } } } + else if (DebuggerUtilsEx.allLineLocations(classType) == null) { + // there's no line info in this class + debugProcess.getRequestsManager() + .setInvalid(this, DebuggerBundle.message("error.invalid.breakpoint.no.line.info", classType.name())); + if (LOG.isDebugEnabled()) { + LOG.debug("No line number info in " + classType.name()); + } + } else { // there's no executable code in this class debugProcess.getRequestsManager().setInvalid(this, DebuggerBundle.message( diff --git a/resources-en/src/messages/DebuggerBundle.properties b/resources-en/src/messages/DebuggerBundle.properties index 8ef0782a7772..bdcab100c8cf 100644 --- a/resources-en/src/messages/DebuggerBundle.properties +++ b/resources-en/src/messages/DebuggerBundle.properties @@ -391,6 +391,7 @@ label.filed.breakpoint.properties.panel.field.modification=Field &modification label.group.watch.events=Watch error.failed.evaluating.breakpoint.condition=Failed to evaluate breakpoint condition\n''{0}''\nReason: {1} error.invalid.breakpoint.no.executable.code=No executable code found at line {0} in class {1} +error.invalid.breakpoint.no.line.info=Line numbers info is not available in class {0} error.invalid.breakpoint.bad.line.number=Line number is invalid line.breakpoint.display.name=Line {0} line.breakpoint.display.name.with.class.or.method=Line {0,number,#} in {1}