Skip to content

Commit c93a3d7

Browse files
awood0727np158kaybcodesSilasVM
committed
Debugger continues to work even if Sketch name and folder are not equal
Signed-off-by: Amante' Woodley <[email protected]> Co-authored-by: Nia Perez <[email protected]> Co-authored-by: Kayla Bobo <[email protected]> Co-authored-by: Silas Morgan <[email protected]>
1 parent 3f36db5 commit c93a3d7

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

java/src/processing/mode/java/debug/Debugger.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,47 @@ public LineID javaToSketchLine(LineID javaLine) {
14431443
}
14441444

14451445

1446+
/**
1447+
* Translate a line (index) from PDE space to sketch space.
1448+
* @param pdeLine the PDE line id
1449+
* @return the corresponding sketch line id or null if failed to translate
1450+
*/
1451+
public LineID pdeToSketchLine(LineID pdeLine) {
1452+
Sketch sketch = editor.getSketch();
1453+
1454+
1455+
// it may belong to a pde file created in the sketch
1456+
// try to find an exact filename match and check the extension
1457+
SketchCode tab = editor.getTab(pdeLine.fileName());
1458+
if (tab != null && tab.isExtension("pde")) {
1459+
// can translate 1:1
1460+
return originalToRuntimeLine(pdeLine);
1461+
}
1462+
1463+
1464+
// check if it is the preprocessed/assembled file for this sketch
1465+
// pde file name needs to match the sketches filename
1466+
if (!pdeLine.fileName().equals(sketch.getName() + ".pde")) {
1467+
return null;
1468+
}
1469+
1470+
1471+
// find the tab (.java file) this line belongs to
1472+
// get the last tab that has an offset not greater than the pde line number
1473+
for (int i = sketch.getCodeCount() - 1; i >= 0; i--) {
1474+
tab = sketch.getCode(i);
1475+
// ignore .pde files
1476+
// the tab's offset must not be greater than the pde line number
1477+
if (tab.isExtension("java") && tab.getPreprocOffset() <= pdeLine.lineIdx()) {
1478+
final int index = pdeLine.lineIdx() - tab.getPreprocOffset();
1479+
return originalToRuntimeLine(new LineID(tab.getFileName(), index));
1480+
}
1481+
}
1482+
return null;
1483+
}
1484+
1485+
1486+
14461487
/**
14471488
* Get the runtime-changed line id for an original sketch line. Used to
14481489
* translate line numbers from the VM (which runs on the original line

java/src/processing/mode/java/debug/LineBreakpoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public String toString() {
208208
protected String className() {
209209
if (line.fileName().endsWith(".pde")) {
210210
// standard tab
211-
return dbg.getEditor().getSketch().getName();
211+
return line.fileName().substring(0, line.fileName().lastIndexOf(".pde"));
212212
}
213213

214214
if (line.fileName().endsWith(".java")) {

0 commit comments

Comments
 (0)