diff --git a/src/com/jpexs/decompiler/flash/gui/DebuggerHandler.java b/src/com/jpexs/decompiler/flash/gui/DebuggerHandler.java index c2cc2a1c3..0579233e6 100644 --- a/src/com/jpexs/decompiler/flash/gui/DebuggerHandler.java +++ b/src/com/jpexs/decompiler/flash/gui/DebuggerHandler.java @@ -257,7 +257,7 @@ public class DebuggerHandler implements DebugConnectionListener { return; } - String cls = modulePaths.get(message.file).toString(); + ClassPath cls = modulePaths.get(message.file); Main.startWork(AppStrings.translate("work.breakat") + cls + ":" + message.line, null); try { @@ -272,7 +272,7 @@ public class DebuggerHandler implements DebugConnectionListener { } catch (IOException ex) { //ignore } - Main.getMainFrame().getPanel().debuggerBreakAt(Main.getMainFrame().getPanel().getCurrentSwf(), cls, message.line); + Main.breakAt(cls, message.line); } } ); diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index 973000d5b..cd3ebc3e9 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -34,6 +34,7 @@ import com.jpexs.decompiler.flash.SWFSourceInfo; import com.jpexs.decompiler.flash.SearchMode; import com.jpexs.decompiler.flash.SwfOpenException; import com.jpexs.decompiler.flash.Version; +import com.jpexs.decompiler.flash.abc.ClassPath; import com.jpexs.decompiler.flash.abc.ScriptPack; import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; import com.jpexs.decompiler.flash.configuration.Configuration; @@ -160,6 +161,8 @@ public class Main { private static Map> breakPointMap = new WeakHashMap<>(); private static Map> invalidBreakPointMap = new WeakHashMap<>(); + private static int ip = 0; + private static ClassPath ipClass = null; public static void clearBreakPoints(ScriptPack pack) { if (breakPointMap.containsKey(pack)) { @@ -167,6 +170,25 @@ public class Main { } } + public static boolean isDebugging() { + return mainFrame.getMenu().isDebugRunning(); + } + + public static int getIp(ScriptPack pack) { + return ip; + } + + public static ClassPath getIpClass() { + return ipClass; + } + + public static void breakAt(ClassPath clsName, int ip) { + Main.ip = ip; + Main.ipClass = clsName; + mainFrame.getPanel().gotoClassLine(getMainFrame().getPanel().getCurrentSwf(), clsName.toString(), ip); + //Main.getMainFrame().getPanel().debuggerBreakAt(Main.getMainFrame().getPanel().getCurrentSwf(), cls, message.line); + } + public static boolean isBreakPointValid(ScriptPack pack, int line) { if (!invalidBreakPointMap.containsKey(pack)) { return true; diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrame.java b/src/com/jpexs/decompiler/flash/gui/MainFrame.java index 7b472a723..5ed9a3d4f 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrame.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrame.java @@ -37,4 +37,6 @@ public interface MainFrame { public Window getWindow(); public void dispose(); + + public MainFrameMenu getMenu(); } diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameClassic.java b/src/com/jpexs/decompiler/flash/gui/MainFrameClassic.java index ab0dbb300..f0a06af67 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameClassic.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameClassic.java @@ -136,4 +136,10 @@ public final class MainFrameClassic extends AppFrame implements MainFrame { Helper.emptyObject(this); super.dispose(); } + + @Override + public MainFrameMenu getMenu() { + return mainMenu; + } + } diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java index 6c00660e8..bc0b40f73 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java @@ -1387,7 +1387,6 @@ public abstract class MainFrameMenu implements MenuBuilder { DebuggerCommands cmd = Main.getDebugHandler().getCommands(); mainFrame.getPanel().clearDebuggerColors(); Main.startWork(AppStrings.translate("work.debugging") + "...", null); - cmd.sendContinue(); } catch (IOException ex) { Main.getDebugHandler().disconnect(); diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbon.java b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbon.java index 76fd86595..3a5081837 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbon.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbon.java @@ -194,4 +194,10 @@ public final class MainFrameRibbon extends AppRibbonFrame { Helper.emptyObject(this); super.dispose(); } + + @Override + public MainFrameMenu getMenu() { + return mainMenu; + } + } diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 5e5dc956e..30e09eb27 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -1537,21 +1537,29 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se if (abcPanel != null) { abcPanel.decompiledTextArea.gotoLine(line); } + refreshBreakPoints(); } public void refreshBreakPoints() { if (abcPanel != null) { - abcPanel.decompiledTextArea.refreshBreakPoints(); + abcPanel.decompiledTextArea.refreshMarkers(); } } + /* + public void debuggerBreakAt(SWF swf, String cls, int line) { + View.execInEventDispatchLater(new Runnable() { - public void debuggerBreakAt(SWF swf, String cls, int line) { - gotoClassLine(swf, cls, line); - if (abcPanel != null) { - abcPanel.decompiledTextArea.addColorMarker(line, DecompiledEditorPane.FG_IP_COLOR, DecompiledEditorPane.BG_IP_COLOR); - } - } + @Override + public void run() { + gotoClassLine(swf, cls, line); + if (abcPanel != null) { + abcPanel.decompiledTextArea.addColorMarker(line, DecompiledEditorPane.FG_IP_COLOR, DecompiledEditorPane.BG_IP_COLOR, DecompiledEditorPane.PRIORITY_IP); + } + } + }); + + }*/ public void gotoClass(SWF swf, String cls) { if (swf == null) { @@ -2813,7 +2821,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se public void clearDebuggerColors() { if (abcPanel != null) { - abcPanel.decompiledTextArea.removeColorMarkerOnAllLines(DecompiledEditorPane.FG_IP_COLOR, DecompiledEditorPane.BG_IP_COLOR); + abcPanel.decompiledTextArea.removeColorMarkerOnAllLines(DecompiledEditorPane.FG_IP_COLOR, DecompiledEditorPane.BG_IP_COLOR, DecompiledEditorPane.PRIORITY_IP); } } @@ -3042,7 +3050,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se setSourceWorker.cancel(true); setSourceWorker = null; } - if (!Main.isWorking()) { + if (!Main.isWorking() || Main.isDebugging()) { CancellableWorker worker = new CancellableWorker() { @Override diff --git a/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java b/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java index ee410f7a8..f5c0d1a25 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java @@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.gui.abc; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.CachedDecompilation; +import com.jpexs.decompiler.flash.abc.ClassPath; import com.jpexs.decompiler.flash.abc.ScriptPack; import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; @@ -92,26 +93,29 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL public static final Color BG_BREAKPOINT_COLOR = new Color(0xfc, 0x9d, 0x9f); public static final Color FG_BREAKPOINT_COLOR = null; + public static final int PRIORITY_BREAKPOINT = 20; public static final Color BG_IP_COLOR = new Color(0xbd, 0xe6, 0xaa); public static final Color FG_IP_COLOR = null; + public static final int PRIORITY_IP = 0; public static final Color BG_INVALID_BREAKPOINT_COLOR = new Color(0xdc, 0xdc, 0xd8); public static final Color FG_INVALID_BREAKPOINT_COLOR = null; + public static final int PRIORITY_INVALID_BREAKPOINT = 10; @Override public void toggled(int line) { boolean on = Main.toggleBreakPoint(script, line); - removeColorMarker(line, FG_INVALID_BREAKPOINT_COLOR, BG_INVALID_BREAKPOINT_COLOR); + removeColorMarker(line, FG_INVALID_BREAKPOINT_COLOR, BG_INVALID_BREAKPOINT_COLOR, PRIORITY_INVALID_BREAKPOINT); if (on) { if (Main.isBreakPointValid(script, line)) { - addColorMarker(line, FG_BREAKPOINT_COLOR, BG_BREAKPOINT_COLOR); + addColorMarker(line, FG_BREAKPOINT_COLOR, BG_BREAKPOINT_COLOR, PRIORITY_BREAKPOINT); } else { - addColorMarker(line, FG_INVALID_BREAKPOINT_COLOR, BG_INVALID_BREAKPOINT_COLOR); + addColorMarker(line, FG_INVALID_BREAKPOINT_COLOR, BG_INVALID_BREAKPOINT_COLOR, PRIORITY_INVALID_BREAKPOINT); } } else { - removeColorMarker(line, FG_BREAKPOINT_COLOR, BG_BREAKPOINT_COLOR); - removeColorMarker(line, FG_INVALID_BREAKPOINT_COLOR, BG_INVALID_BREAKPOINT_COLOR); + removeColorMarker(line, FG_BREAKPOINT_COLOR, BG_BREAKPOINT_COLOR, PRIORITY_BREAKPOINT); + removeColorMarker(line, FG_INVALID_BREAKPOINT_COLOR, BG_INVALID_BREAKPOINT_COLOR, PRIORITY_INVALID_BREAKPOINT); } } @@ -734,25 +738,31 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL return script == null ? null : script.abc; } - public void refreshBreakPoints() { + public void refreshMarkers() { Set bkptLines = Main.getPackBreakPoints(script); - removeColorMarkerOnAllLines(FG_BREAKPOINT_COLOR, BG_BREAKPOINT_COLOR); - removeColorMarkerOnAllLines(FG_INVALID_BREAKPOINT_COLOR, BG_INVALID_BREAKPOINT_COLOR); + removeColorMarkerOnAllLines(FG_BREAKPOINT_COLOR, BG_BREAKPOINT_COLOR, PRIORITY_BREAKPOINT); + removeColorMarkerOnAllLines(FG_INVALID_BREAKPOINT_COLOR, BG_INVALID_BREAKPOINT_COLOR, PRIORITY_INVALID_BREAKPOINT); for (int line : bkptLines) { if (Main.isBreakPointValid(script, line)) { - addColorMarker(line, FG_BREAKPOINT_COLOR, BG_BREAKPOINT_COLOR); + addColorMarker(line, FG_BREAKPOINT_COLOR, BG_BREAKPOINT_COLOR, PRIORITY_BREAKPOINT); } else { - addColorMarker(line, FG_INVALID_BREAKPOINT_COLOR, BG_INVALID_BREAKPOINT_COLOR); + addColorMarker(line, FG_INVALID_BREAKPOINT_COLOR, BG_INVALID_BREAKPOINT_COLOR, PRIORITY_INVALID_BREAKPOINT); } } + removeColorMarkerOnAllLines(FG_IP_COLOR, BG_IP_COLOR, PRIORITY_IP); + int ip = Main.getIp(script); + ClassPath ipPath = Main.getIpClass(); + if (ip > 0 && ipPath != null && ipPath.equals(script.getClassPath())) { + addColorMarker(ip, FG_IP_COLOR, BG_IP_COLOR, PRIORITY_IP); + } } @Override public void setText(String t) { super.setText(t); setCaretPosition(0); - refreshBreakPoints(); + refreshMarkers(); } } diff --git a/src/com/jpexs/decompiler/flash/gui/abc/DetailPanel.java b/src/com/jpexs/decompiler/flash/gui/abc/DetailPanel.java index c2d495149..20b141e77 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/DetailPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/DetailPanel.java @@ -82,6 +82,8 @@ public class DetailPanel extends JPanel implements TagEditorPanel { private boolean buttonsShouldBeShown = false; + private DebuggerHandler.ConnectionListener conListener; + public DetailPanel(ABCPanel abcPanel) { this.abcPanel = abcPanel; innerPanel = new JPanel(); @@ -126,20 +128,30 @@ public class DetailPanel extends JPanel implements TagEditorPanel { layout.show(innerPanel, UNSUPPORTED_TRAIT_CARD); buttonsPanel.setVisible(false); - Main.getDebugHandler().addConnectionListener(new DebuggerHandler.ConnectionListener() { + conListener = new DebuggerHandler.ConnectionListener() { @Override public void connected() { - debugRunning = true; - buttonsPanel.setVisible(false); + synchronized (DetailPanel.this) { + debugRunning = true; + if (buttonsPanel != null) { + buttonsPanel.setVisible(false); + } + } } @Override public void disconnected() { - debugRunning = false; - buttonsPanel.setVisible(buttonsShouldBeShown); + synchronized (DetailPanel.this) { + debugRunning = false; + + if (buttonsPanel != null) { + buttonsPanel.setVisible(buttonsShouldBeShown); + } + } } - }); + }; + Main.getDebugHandler().addConnectionListener(conListener); selectedLabel = new HeaderLabel(""); selectedLabel.setText(selectedCard); @@ -186,8 +198,12 @@ public class DetailPanel extends JPanel implements TagEditorPanel { CardLayout layout = (CardLayout) innerPanel.getLayout(); layout.show(innerPanel, name); boolean b = cardMap.get(name) instanceof TraitDetail; - buttonsShouldBeShown = b; - buttonsPanel.setVisible(b && !debugRunning); + boolean drun; + synchronized (this) { + buttonsShouldBeShown = b; + drun = debugRunning; + } + buttonsPanel.setVisible(b && !drun); TraitDetail newDetail = null; if (b) { diff --git a/src/com/jpexs/decompiler/flash/gui/editor/LineMarkedEditorPane.java b/src/com/jpexs/decompiler/flash/gui/editor/LineMarkedEditorPane.java index 3610a25de..d558924ad 100644 --- a/src/com/jpexs/decompiler/flash/gui/editor/LineMarkedEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/editor/LineMarkedEditorPane.java @@ -33,11 +33,12 @@ import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.SortedSet; +import java.util.TreeSet; import javax.swing.event.CaretEvent; import javax.swing.event.CaretListener; import javax.swing.plaf.TextUI; @@ -49,16 +50,11 @@ import javax.swing.text.Highlighter.HighlightPainter; import javax.swing.text.JTextComponent; import javax.swing.text.Position; import javax.swing.text.Segment; -import javax.swing.text.TabExpander; import javax.swing.text.View; -import jsyntaxpane.DefaultSyntaxKit; import jsyntaxpane.SyntaxDocument; import jsyntaxpane.SyntaxStyle; import jsyntaxpane.Token; import jsyntaxpane.actions.ActionUtils; -import jsyntaxpane.components.BreakPointListener; -import jsyntaxpane.components.LineNumbersRuler; -import jsyntaxpane.components.Markers; /** * @@ -81,21 +77,28 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan private LinkHandler linkHandler = this; - public static class LineMarker { + public static class LineMarker implements Comparable { private Color bgColor; private Color color; private FgPainter fgPainter; private int line; + private int priority; public FgPainter getForegroundPainter() { return fgPainter; } - public LineMarker(int line, Color color, Color bgColor) { + @Override + public String toString() { + return bgColor.toString() + " line " + line + " priority:" + priority; + } + + public LineMarker(int line, Color color, Color bgColor, int priority) { this.line = line; this.bgColor = bgColor; this.color = color; + this.priority = priority; if (color != null) { this.fgPainter = new FgPainter(color, bgColor); } @@ -136,11 +139,15 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan return color; } + @Override + public int compareTo(LineMarker o) { + return priority - o.priority; + } } +//(Map>) + private Map> lineMarkers = Collections.synchronizedMap(new HashMap>()); - private Map> lineMarkers = new HashMap<>(); - - public void setLineMarkers(Map> colorMarkers) { + public void setLineMarkers(Map> colorMarkers) { this.lineMarkers = colorMarkers; } @@ -149,42 +156,40 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan repaint(); } - public void removeColorMarker(int line, Color color, Color bgColor) { + public void removeColorMarker(int line, Color color, Color bgColor, int priority) { if (lineMarkers.containsKey(line)) { - LineMarker lm = new LineMarker(line, color, bgColor); + LineMarker lm = new LineMarker(line, color, bgColor, priority); lineMarkers.get(line).remove(lm); } repaint(); } - public void removeColorMarkerOnAllLines(Color color, Color bgColor) { + public void removeColorMarkerOnAllLines(Color color, Color bgColor, int priority) { for (int line : lineMarkers.keySet()) { - removeColorMarker(line, color, bgColor); + removeColorMarker(line, color, bgColor, priority); } } - public void toggleColorMarker(int line, Color color, Color bgColor) { + public void toggleColorMarker(int line, Color color, Color bgColor, int priority) { if (!lineMarkers.containsKey(line)) { - addColorMarker(line, color, bgColor); + addColorMarker(line, color, bgColor, priority); } else { - if (lineMarkers.get(line).contains(color)) { - removeColorMarker(line, color, bgColor); + LineMarker m = new LineMarker(line, color, bgColor, priority); + if (lineMarkers.get(line).contains(m)) { + removeColorMarker(line, color, bgColor, priority); } else { - addColorMarker(line, color, bgColor); + addColorMarker(line, color, bgColor, priority); } } repaint(); } - public void addColorMarker(int line, Color color, Color bgColor) { + public void addColorMarker(int line, Color color, Color bgColor, int priority) { if (!lineMarkers.containsKey(line)) { - lineMarkers.put(line, new ArrayList<>()); - - } - LineMarker marker = new LineMarker(line, color, bgColor); - if (!lineMarkers.get(line).contains(marker)) { - lineMarkers.get(line).add(marker); + lineMarkers.put(line, Collections.synchronizedSortedSet(new TreeSet<>())); } + LineMarker marker = new LineMarker(line, color, bgColor, priority); + lineMarkers.get(line).add(marker); repaint(); } @@ -279,6 +284,7 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan return false; } }); + } private class LinkAdapter extends MouseAdapter implements KeyListener { @@ -401,12 +407,6 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan } - public void setText(String t, Map> lineMarkers) { - setText(t); - this.lineMarkers = lineMarkers; - repaint(); - } - @Override public void setText(String t) { this.lineMarkers = new HashMap<>(); @@ -588,11 +588,11 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan g.fillRect(0, d + lh * lastLine - 1, getWidth(), lh); } for (int line : lineMarkers.keySet()) { - List cs = lineMarkers.get(line); + SortedSet cs = lineMarkers.get(line); if (cs.isEmpty()) { continue; } - LineMarker lastMarker = cs.get(cs.size() - 1); + LineMarker lastMarker = cs.first(); if (lastMarker.getBgColor() == null) { continue; } @@ -601,14 +601,14 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan } super.paint(g); for (int line : lineMarkers.keySet()) { - List cs = lineMarkers.get(line); + SortedSet cs = lineMarkers.get(line); if (cs.isEmpty()) { continue; } Reference lineStart = new Reference<>(0); Reference lineEnd = new Reference<>(0); getLineBounds(line, lineStart, lineEnd); - FgPainter fgp = cs.get(cs.size() - 1).getForegroundPainter(); + FgPainter fgp = cs.first().getForegroundPainter(); if (fgp != null) { fgp.paint(g, lineStart.getVal(), lineEnd.getVal(), null, this); }