diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a91a8541..259fc1360 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,8 @@ All notable changes to this project will be documented in this file. - [#1193] FLA export - DefineEditText position and size - FLA export - allow float frame rate - FLA export - font export - allow dot as character +- AS3 Debugging P-code inside nested functions +- AS3 Debugging - show (and click through) proper call stack ### Changed - Basic tag info panel always visible even when nothing to display (to avoid flickering) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java index 3d6de5293..0c665b0af 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java @@ -596,13 +596,7 @@ public class ScriptPack extends AS3ClassTreeItem { Trait trait; int traitIndex = -10; if (trt != null && cls != null) { - traitIndex = (int) trt.getProperties().index; - - trait = abc.findTraitByTraitId(classIndex, traitIndex); - if (((trait instanceof TraitMethodGetterSetter) && (((TraitMethodGetterSetter) trait).method_info != methodIndex)) - || ((trait instanceof TraitFunction) && (((TraitFunction) trait).method_info != methodIndex))) { - continue; //inner anonymous function - ignore. TODO: make work - } + traitIndex = (int) trt.getProperties().index; } bodyToIdentifier.put(bodyIndex, "abc:" + abcIndex + ",script:" + scriptIndex + ",class:" + classIndex + ",trait:" + traitIndex + ",method:" + methodIndex + ",body:" + bodyIndex); break; diff --git a/src/com/jpexs/decompiler/flash/gui/DebugStackPanel.java b/src/com/jpexs/decompiler/flash/gui/DebugStackPanel.java index 0f451ec79..0c0fc8ddc 100644 --- a/src/com/jpexs/decompiler/flash/gui/DebugStackPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/DebugStackPanel.java @@ -43,6 +43,11 @@ public class DebugStackPanel extends JPanel { private int depth = 0; + private int[] classIndices = new int[0]; + private int[] methodIndices = new int[0]; + private int[] traitIndices = new int[0]; + + public DebugStackPanel() { stackTable = new JTable(); Main.getDebugHandler().addFrameChangeListener(new DebuggerHandler.FrameChangeListener() { @@ -90,7 +95,7 @@ public class DebugStackPanel extends JPanel { String scriptName = (String) stackTable.getModel().getValueAt(row, 0); int line = (int) (Integer) stackTable.getModel().getValueAt(row, 1); Main.getMainFrame().getPanel().gotoScriptLine(Main.getMainFrame().getPanel().getCurrentSwf(), - scriptName, line, -1, -1, -1); + scriptName, line, classIndices[row], traitIndices[row], methodIndices[row]); Main.getDebugHandler().setDepth(row); } } @@ -115,11 +120,22 @@ public class DebugStackPanel extends JPanel { } active = true; Object[][] data = new Object[info.files.size()][3]; + int[] newClassIndices = new int[info.files.size()]; + int[] newMethodIndices = new int[info.files.size()]; + int[] newTraitIndices = new int[info.files.size()]; for (int i = 0; i < info.files.size(); i++) { - data[i][0] = Main.getDebugHandler().moduleToString(info.files.get(i)); + int f = info.files.get(i); + data[i][0] = Main.getDebugHandler().moduleToString(f); data[i][1] = info.lines.get(i); - data[i][2] = info.stacks.get(i); + data[i][2] = info.stacks.get(i); + Integer newClassIndex = Main.getDebugHandler().moduleToClassIndex(f); + newClassIndices[i] = newClassIndex == null ? -1 : newClassIndex; + Integer newMethodIndex = Main.getDebugHandler().moduleToMethodIndex(f); + newMethodIndices[i] = newMethodIndex == null ? -1 : newMethodIndex; + Integer newTraitIndex = Main.getDebugHandler().moduleToTraitIndex(f);; + newTraitIndices[i] = newTraitIndex == null ? -1 : newTraitIndex; } + DefaultTableModel tm = new DefaultTableModel(data, new Object[]{ AppStrings.translate("callStack.header.file"), @@ -133,6 +149,9 @@ public class DebugStackPanel extends JPanel { }; stackTable.setModel(tm); + this.classIndices = newClassIndices; + this.methodIndices = newMethodIndices; + this.traitIndices = newTraitIndices; View.execInEventDispatchLater(new Runnable() { @Override diff --git a/src/com/jpexs/decompiler/flash/gui/DebuggerHandler.java b/src/com/jpexs/decompiler/flash/gui/DebuggerHandler.java index 370df3192..c8fa1828f 100644 --- a/src/com/jpexs/decompiler/flash/gui/DebuggerHandler.java +++ b/src/com/jpexs/decompiler/flash/gui/DebuggerHandler.java @@ -374,6 +374,18 @@ public class DebuggerHandler implements DebugConnectionListener { } return modulePaths.get(file); } + + public Integer moduleToMethodIndex(int file) { + return moduleToMethodIndex.get(file); + } + + public Integer moduleToClassIndex(int file) { + return moduleToClassIndex.get(file); + } + + public Integer moduleToTraitIndex(int file) { + return moduleToTraitIndex.get(file); + } public synchronized InBreakAtExt getBreakInfo() { if (!paused) { diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 35d731d72..df22a3808 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -2542,16 +2542,17 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se public void run() { if (Main.isDebugPCode()) { if (classIndex != -1) { - boolean classChanged = false; if (abcPanel.decompiledTextArea.getClassIndex() != classIndex) { abcPanel.decompiledTextArea.setClassIndex(classIndex); - classChanged = true; - } - if (traitIndex != -10 && (classChanged || abcPanel.decompiledTextArea.lastTraitIndex != traitIndex)) { - abcPanel.decompiledTextArea.gotoTrait(traitIndex); } } - abcPanel.detailPanel.methodTraitPanel.methodCodePanel.gotoInstrLine(line); + abcPanel.decompiledTextArea.gotoMethod(methodIndex, new Runnable() { + @Override + public void run() { + abcPanel.detailPanel.methodTraitPanel.methodCodePanel.gotoInstrLine(line); + } + }); + } else { abcPanel.decompiledTextArea.gotoLine(line); } diff --git a/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java b/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java index 628083a9e..9c0432ca9 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java @@ -772,6 +772,10 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL } public void gotoMethod(int methodId) { + gotoMethod(methodId, null); + } + + public void gotoMethod(int methodId, Runnable afterHandler) { Highlighting tm = Highlighting.searchIndex(highlightedText.getMethodHighlights(), methodId); if (tm != null) { int pos = 0; @@ -792,6 +796,9 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL if (fpos <= getDocument().getLength()) { setCaretPosition(fpos); } + if (afterHandler != null) { + afterHandler.run(); + } } }, 100); }