Skip to content

Debugger continues to work despite Sketch name and folder name are not equal #1197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions java/src/processing/mode/java/debug/Debugger.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion java/src/processing/mode/java/debug/LineBreakpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
Loading