diff --git a/java/src/processing/mode/java/debug/Debugger.java b/java/src/processing/mode/java/debug/Debugger.java index 0136793200..508b94b261 100644 --- a/java/src/processing/mode/java/debug/Debugger.java +++ b/java/src/processing/mode/java/debug/Debugger.java @@ -1443,6 +1443,47 @@ public LineID javaToSketchLine(LineID javaLine) { } + /** + * Translate a line (index) from PDE space to sketch space. + * @param pdeLine the PDE line id + * @return the corresponding sketch line id or null if failed to translate + */ + public LineID pdeToSketchLine(LineID pdeLine) { + Sketch sketch = editor.getSketch(); + + + // it may belong to a pde file created in the sketch + // try to find an exact filename match and check the extension + SketchCode tab = editor.getTab(pdeLine.fileName()); + if (tab != null && tab.isExtension("pde")) { + // can translate 1:1 + return originalToRuntimeLine(pdeLine); + } + + + // check if it is the preprocessed/assembled file for this sketch + // pde file name needs to match the sketches filename + if (!pdeLine.fileName().equals(sketch.getName() + ".pde")) { + return null; + } + + + // find the tab (.java file) this line belongs to + // get the last tab that has an offset not greater than the pde line number + for (int i = sketch.getCodeCount() - 1; i >= 0; i--) { + tab = sketch.getCode(i); + // ignore .pde files + // the tab's offset must not be greater than the pde line number + if (tab.isExtension("java") && tab.getPreprocOffset() <= pdeLine.lineIdx()) { + final int index = pdeLine.lineIdx() - tab.getPreprocOffset(); + return originalToRuntimeLine(new LineID(tab.getFileName(), index)); + } + } + return null; + } + + + /** * Get the runtime-changed line id for an original sketch line. Used to * translate line numbers from the VM (which runs on the original line diff --git a/java/src/processing/mode/java/debug/LineBreakpoint.java b/java/src/processing/mode/java/debug/LineBreakpoint.java index e7327446f5..0e8d467555 100644 --- a/java/src/processing/mode/java/debug/LineBreakpoint.java +++ b/java/src/processing/mode/java/debug/LineBreakpoint.java @@ -208,7 +208,7 @@ public String toString() { protected String className() { if (line.fileName().endsWith(".pde")) { // standard tab - return dbg.getEditor().getSketch().getName(); + return line.fileName().substring(0, line.fileName().lastIndexOf(".pde")); } if (line.fileName().endsWith(".java")) {