Added #2131 AS1/2 Debugger - show _root variable

Fixed #2131 AS1/2 Debugger - Breakpoint handling - incorrect script names
Fixed #2131 Debugger - Correct walking variables tree
This commit is contained in:
Jindra Petřík
2023-12-30 18:06:08 +01:00
parent 9741e8260a
commit e371372392
14 changed files with 177 additions and 64 deletions
@@ -21,6 +21,7 @@ import com.jpexs.debugger.flash.messages.in.InBreakAtExt;
import com.jpexs.debugger.flash.messages.in.InConstantPool;
import com.jpexs.debugger.flash.messages.in.InFrame;
import com.jpexs.debugger.flash.messages.in.InGetVariable;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.gui.DebuggerHandler.BreakListener;
import com.jpexs.decompiler.flash.gui.abc.ABCPanel;
@@ -504,15 +505,26 @@ public class DebugPanel extends JPanel {
SelectedTab oldSel = selectedTab;
localsTable = null;
SWF swf = Main.getMainFrame().getPanel().getCurrentSwf();
if (swf == null) {
return;
}
boolean as3 = swf.isAS3();
InFrame f = Main.getDebugHandler().getFrame();
if (f != null) {
Variable root = null;
if (!as3) {
root = Main.getDebugHandler().getVariable(0, "_root", false, false).parent;
}
List<Long> regVarIds = new ArrayList<>();
for (int i = 0; i < f.registers.size(); i++) {
regVarIds.add(0L);
}
safeSetTreeModel(debugRegistersTable, new ABCPanel.VariablesTableModel(debugRegistersTable, f.registers, regVarIds));
List<Variable> locals = new ArrayList<>();
if (root != null) {
locals.add(root);
}
locals.addAll(f.arguments);
locals.addAll(f.variables);
@@ -359,15 +359,15 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener<Scr
}
InGetVariable igv;
Long objectId = varToObjectId(var);
//Long objectId = varToObjectId(var);
boolean useGetter = (var.flags & VariableFlags.IS_CONST) == 0;
if (objectId != 0) {
/*if (objectId != 0) {
igv = Main.getDebugHandler().getVariable(objectId, "", true, useGetter);
} else {
igv = Main.getDebugHandler().getVariable(parentObjectId, var.name, true, useGetter);
}
} else {*/
igv = Main.getDebugHandler().getVariable(parentObjectId, var.name, true, useGetter);
//}
//current var is getter function - set it to value really got
if ((var.flags & VariableFlags.HAS_GETTER) > 0) {
@@ -440,6 +440,9 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener<Scr
if (var.vType == VariableType.OBJECT) {
return (Long) var.value;
}
if (var.vType == VariableType.MOVIECLIP) {
return (Long) var.value;
}
return 0L;
}
@@ -262,7 +262,7 @@ public class ASMSourceEditorPane extends DebuggableEditorPane implements CaretLi
}
}
String aname = "#PCODE abc:" + abcIndex + ",body:" + bodyIndex + ";" + scriptPathName;
setScriptName(aname);
setScriptName(aname, aname);
setHex(exportMode, true);
}
@@ -891,7 +891,7 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL
}
String sn = scriptLeaf.getClassPath().toString();
setScriptName(sn);
setScriptName(sn, sn);
abcPanel.scriptNameLabel.setText(sn);
int scriptIndex = scriptLeaf.scriptIndex;
ScriptInfo nscript = null;
@@ -333,11 +333,11 @@ public class ActionPanel extends JPanel implements SearchListener<ScriptSearchRe
return null;
}
private void setDecompiledText(final String scriptName, final String text) {
private void setDecompiledText(final String scriptName, final String breakPointScriptName, final String text) {
View.checkAccess();
ignoreCarret = true;
decompiledEditor.setScriptName(scriptName);
decompiledEditor.setScriptName(scriptName, breakPointScriptName);
decompiledEditor.setText(text);
BrokenScriptDetector det = new BrokenScriptDetector();
if (det.codeIsBroken(text)) {
@@ -349,17 +349,17 @@ public class ActionPanel extends JPanel implements SearchListener<ScriptSearchRe
ignoreCarret = false;
}
private void setEditorText(final String scriptName, final String text, final String contentType) {
private void setEditorText(final String scriptName, final String breakPointScriptName, final String text, final String contentType) {
View.checkAccess();
ignoreCarret = true;
editor.setScriptName("#PCODE " + scriptName);
editor.setScriptName("#PCODE " + scriptName, "#PCODE " + breakPointScriptName);
editor.changeContentType(contentType);
editor.setText(text);
ignoreCarret = false;
}
private void setText(final HighlightedText text, final String contentType, final String scriptName) {
private void setText(final HighlightedText text, final String contentType, final String scriptName, final String breakPointScriptName) {
View.checkAccess();
int pos = editor.getCaretPosition();
@@ -372,7 +372,7 @@ public class ActionPanel extends JPanel implements SearchListener<ScriptSearchRe
}
Long offset = lastH == null ? 0 : lastH.getProperties().offset;
disassembledText = text;
setEditorText(scriptName, text.text, contentType);
setEditorText(scriptName, breakPointScriptName, text.text, contentType);
Highlighting h = Highlighting.searchOffset(disassembledText.getInstructionHighlights(), offset);
if (h != null) {
if (h.startPos <= editor.getDocument().getLength()) {
@@ -410,7 +410,7 @@ public class ActionPanel extends JPanel implements SearchListener<ScriptSearchRe
resolveConstantsButton.setVisible(exportMode != ScriptExportMode.CONSTANTS && exportMode != ScriptExportMode.HEX);
}
private void setHex(ScriptExportMode exportMode, String scriptName, ActionList actions) {
private void setHex(ScriptExportMode exportMode, String scriptName, String breakPointScriptName, ActionList actions) {
View.checkAccess();
updateHexButtons(exportMode);
@@ -420,14 +420,14 @@ public class ActionPanel extends JPanel implements SearchListener<ScriptSearchRe
srcNoHex = getHighlightedText(exportMode, actions);
}
setText(srcNoHex, "text/flasm", scriptName);
setText(srcNoHex, "text/flasm", scriptName, breakPointScriptName);
break;
case PCODE_HEX:
if (srcWithHex == null) {
srcWithHex = getHighlightedText(exportMode, actions);
}
setText(srcWithHex, "text/flasm", scriptName);
setText(srcWithHex, "text/flasm", scriptName, breakPointScriptName);
break;
case HEX:
if (srcHexOnly == null) {
@@ -437,14 +437,14 @@ public class ActionPanel extends JPanel implements SearchListener<ScriptSearchRe
srcHexOnly = new HighlightedText(writer);
}
setText(srcHexOnly, "text/plain", scriptName);
setText(srcHexOnly, "text/plain", scriptName, breakPointScriptName);
break;
case CONSTANTS:
if (srcConstants == null) {
srcConstants = getHighlightedText(exportMode, actions);
}
setText(srcConstants, "text/plain", scriptName);
setText(srcConstants, "text/plain", scriptName, breakPointScriptName);
break;
default:
throw new Error("Export mode not supported: " + exportMode);
@@ -468,7 +468,7 @@ public class ActionPanel extends JPanel implements SearchListener<ScriptSearchRe
// todo: honfika: it is very slow to show every percent
View.execInEventDispatch(() -> {
setEditorText("-", "; " + AppStrings.translate("work.disassembling") + " - " + phase + " " + percent + "%...", "text/flasm");
setEditorText("-", "-", "; " + AppStrings.translate("work.disassembling") + " - " + phase + " " + percent + "%...", "text/flasm");
});
}
}
@@ -533,9 +533,9 @@ public class ActionPanel extends JPanel implements SearchListener<ScriptSearchRe
ActionList innerActions = actions;
if (disassemblingNeeded) {
View.execInEventDispatch(() -> {
setEditorText(asm.getScriptName(), "; " + AppStrings.translate("work.disassembling") + "...", "text/flasm");
setEditorText(asm.getScriptName(), asm.getExportedScriptName(), "; " + AppStrings.translate("work.disassembling") + "...", "text/flasm");
if (decompileNeeded) {
setDecompiledText("-", "// " + AppStrings.translate("work.waitingfordissasembly") + "...");
setDecompiledText("-", "-", "// " + AppStrings.translate("work.waitingfordissasembly") + "...");
}
});
@@ -547,7 +547,7 @@ public class ActionPanel extends JPanel implements SearchListener<ScriptSearchRe
if (decompileNeeded) {
View.execInEventDispatch(() -> {
setDecompiledText("-", "// " + AppStrings.translate("work.decompiling") + "...");
setDecompiledText("-", "-", "// " + AppStrings.translate("work.decompiling") + "...");
});
HighlightedText htext = SWF.getCached(asm, innerActions);
@@ -571,10 +571,10 @@ public class ActionPanel extends JPanel implements SearchListener<ScriptSearchRe
try {
get();
} catch (CancellationException ex) {
setEditorText("-", "; " + AppStrings.translate("work.canceled"), "text/flasm");
setEditorText("-", "-", "; " + AppStrings.translate("work.canceled"), "text/flasm");
} catch (Exception ex) {
logger.log(Level.SEVERE, "Error", ex);
setDecompiledText("-", "// " + AppStrings.translate("decompilationError") + ": " + ex);
setDecompiledText("-", "-", "// " + AppStrings.translate("decompilationError") + ": " + ex);
}
});
}
@@ -601,8 +601,8 @@ public class ActionPanel extends JPanel implements SearchListener<ScriptSearchRe
lastCode = actions;
lastDecompiled = decompiledText;
setHex(getExportMode(), asm.getScriptName(), actions);
setDecompiledText(asm.getScriptName(), decompiledText.text);
setHex(getExportMode(), asm.getScriptName(), asm.getExportedScriptName(), actions);
setDecompiledText(asm.getScriptName(), asm.getExportedScriptName(), decompiledText.text);
scriptLoaded = true;
fireScript();
}
@@ -1117,11 +1117,11 @@ public class ActionPanel extends JPanel implements SearchListener<ScriptSearchRe
if (val) {
if (hexOnlyButton.isSelected()) {
setHex(ScriptExportMode.HEX, src.getScriptName(), lastCode);
setHex(ScriptExportMode.HEX, src.getScriptName(), src.getExportedScriptName(), lastCode);
} else if (constantsViewButton.isSelected()) {
setHex(ScriptExportMode.CONSTANTS, src.getScriptName(), lastCode);
setHex(ScriptExportMode.CONSTANTS, src.getScriptName(), src.getExportedScriptName(), lastCode);
} else {
setHex(ScriptExportMode.PCODE, src.getScriptName(), lastCode);
setHex(ScriptExportMode.PCODE, src.getScriptName(), src.getExportedScriptName(), lastCode);
}
}
@@ -1154,9 +1154,9 @@ public class ActionPanel extends JPanel implements SearchListener<ScriptSearchRe
if (src != null) {
if (val) {
setDecompiledText(src.getScriptName(), lastDecompiled.text);
setDecompiledText(src.getScriptName(), src.getExportedScriptName(), lastDecompiled.text);
} else {
setDecompiledText(src.getScriptName(), lastDecompiled.text);
setDecompiledText(src.getScriptName(), src.getExportedScriptName(), lastDecompiled.text);
}
}
@@ -1200,15 +1200,15 @@ public class ActionPanel extends JPanel implements SearchListener<ScriptSearchRe
}
private void hexButtonActionPerformed(ActionEvent evt) {
setHex(getExportMode(), src.getScriptName(), lastCode);
setHex(getExportMode(), src.getScriptName(), src.getExportedScriptName(), lastCode);
}
private void hexOnlyButtonActionPerformed(ActionEvent evt) {
setHex(getExportMode(), src.getScriptName(), lastCode);
setHex(getExportMode(), src.getScriptName(), src.getExportedScriptName(), lastCode);
}
private void constantsViewButtonActionPerformed(ActionEvent evt) {
setHex(getExportMode(), src.getScriptName(), lastCode);
setHex(getExportMode(), src.getScriptName(), src.getExportedScriptName(), lastCode);
}
private void resolveConstantsButtonActionPerformed(ActionEvent evt) {
@@ -1218,7 +1218,7 @@ public class ActionPanel extends JPanel implements SearchListener<ScriptSearchRe
srcWithHex = null;
srcNoHex = null;
// srcHexOnly = null; is not needed since it does not contains the resolved constant names
setHex(getExportMode(), src.getScriptName(), lastCode);
setHex(getExportMode(), src.getScriptName(), src.getExportedScriptName(), lastCode);
}
private void showFileOffsetInPcodeHexButtonActionPerformed(ActionEvent evt) {
@@ -1226,7 +1226,7 @@ public class ActionPanel extends JPanel implements SearchListener<ScriptSearchRe
Configuration.showFileOffsetInPcodeHex.set(resolve);
srcWithHex = null;
setHex(getExportMode(), src.getScriptName(), lastCode);
setHex(getExportMode(), src.getScriptName(), src.getExportedScriptName(), lastCode);
}
private void showOriginalBytesInPcodeHexButtonActionPerformed(ActionEvent evt) {
@@ -1234,12 +1234,12 @@ public class ActionPanel extends JPanel implements SearchListener<ScriptSearchRe
Configuration.showOriginalBytesInPcodeHex.set(resolve);
srcWithHex = null;
setHex(getExportMode(), src.getScriptName(), lastCode);
setHex(getExportMode(), src.getScriptName(), src.getExportedScriptName(), lastCode);
}
private void cancelActionButtonActionPerformed(ActionEvent evt) {
setEditMode(false);
setHex(getExportMode(), src.getScriptName(), lastCode);
setHex(getExportMode(), src.getScriptName(), src.getExportedScriptName(), lastCode);
mainPanel.clearEditingStatus();
}
@@ -72,6 +72,8 @@ public class DebuggableEditorPane extends LineMarkedEditorPane implements BreakP
public static final LineMarker STACK_MARKER = new LineMarker(FG_STACK_COLOR, BG_STACK_COLOR, PRIORITY_STACK);
protected String scriptName = null;
protected String breakPointScriptName = null;
private LineNumbersBreakpointsRuler ruler;
@@ -85,19 +87,20 @@ public class DebuggableEditorPane extends LineMarkedEditorPane implements BreakP
}
}
public synchronized void setScriptName(String scriptName) {
public synchronized void setScriptName(String scriptName, String breakPointScriptName) {
this.scriptName = scriptName;
this.breakPointScriptName = breakPointScriptName;
}
@Override
public synchronized void toggled(int line) {
if (scriptName == null) {
if (breakPointScriptName == null) {
return;
}
boolean on = Main.toggleBreakPoint(scriptName, line - firstLineOffset());
boolean on = Main.toggleBreakPoint(breakPointScriptName, line - firstLineOffset());
removeColorMarker(line, INVALID_BREAKPOINT_MARKER);
if (on) {
if (Main.isBreakPointValid(scriptName, line - firstLineOffset())) {
if (Main.isBreakPointValid(breakPointScriptName, line - firstLineOffset())) {
addColorMarker(line, BREAKPOINT_MARKER);
} else {
addColorMarker(line, INVALID_BREAKPOINT_MARKER);
@@ -114,22 +117,22 @@ public class DebuggableEditorPane extends LineMarkedEditorPane implements BreakP
removeColorMarkerOnAllLines(IP_MARKER);
removeColorMarkerOnAllLines(STACK_MARKER);
if (scriptName == null) {
if (breakPointScriptName == null) {
return;
}
Set<Integer> bkptLines = Main.getScriptBreakPoints(scriptName, false);
Set<Integer> bkptLines = Main.getScriptBreakPoints(breakPointScriptName, false);
for (int line : bkptLines) {
if (Main.isBreakPointValid(scriptName, line)) {
if (Main.isBreakPointValid(breakPointScriptName, line)) {
addColorMarker(line + firstLineOffset(), BREAKPOINT_MARKER);
} else {
addColorMarker(line + firstLineOffset(), INVALID_BREAKPOINT_MARKER);
}
}
int ip = Main.getIp(scriptName);
int ip = Main.getIp(breakPointScriptName);
String ipPath = Main.getIpClass();
if (ip > 0 && ipPath != null && ipPath.equals(scriptName)) {
if (ip > 0 && ipPath != null && ipPath.equals(breakPointScriptName)) {
addColorMarker(ip + firstLineOffset(), IP_MARKER);
}
List<Integer> stackLines = Main.getStackLines();
@@ -137,7 +140,7 @@ public class DebuggableEditorPane extends LineMarkedEditorPane implements BreakP
for (int i = 1; i < stackClasses.size(); i++) {
String cls = stackClasses.get(i);
int line = stackLines.get(i);
if (cls.equals(scriptName)) {
if (cls.equals(breakPointScriptName)) {
addColorMarker(line + firstLineOffset(), STACK_MARKER);
}
}
@@ -153,6 +156,10 @@ public class DebuggableEditorPane extends LineMarkedEditorPane implements BreakP
return scriptName;
}
public String getBreakPointScriptName() {
return breakPointScriptName;
}
@Override
public void paintLineMarker(Graphics g, int line, int x, int lineY, int textY, int lineHeight, boolean currentLine, int maxLines) {