📄 breakpointsframe.java
字号:
/* JPC: A x86 PC Hardware Emulator for a pure Java Virtual Machine Release Version 2.0 A project from the Physics Dept, The University of Oxford Copyright (C) 2007 Isis Innovation Limited This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Details (including contact information) can be found at: www.physics.ox.ac.uk/jpc*/package org.jpc.debugger;import java.util.*;import java.io.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.table.*;import javax.swing.event.*;import javax.swing.text.*;import javax.swing.undo.*;import org.jpc.emulator.*;import org.jpc.debugger.util.*;import org.jpc.emulator.processor.*;public class BreakpointsFrame extends UtilityFrame implements PCListener, ActionListener{ public static final String BREAKPOINT_FILE = "breakpoints.jpc"; public static final long BREAKPOINT_MAGIC = 0x81057FAB7272F10l; private boolean edited; private Vector<Breakpoint> breakpoints; private BPModel model; private JTable bpTable; private String breakpointFileName; private JCheckBoxMenuItem ignoreBP, breakAtPrimary; private JMenuItem setBP, removeAll; public BreakpointsFrame() { super("Breakpoints"); breakpointFileName = BREAKPOINT_FILE; breakpoints = new Vector<Breakpoint>(); model = new BPModel(); edited = false; bpTable = new JTable(model); model.setupColumnWidths(bpTable); String delBP = "Del BP"; InputMap in = new InputMap(); in.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), delBP); ActionMap ac = new ActionMap(); ac.setParent(bpTable.getActionMap()); ac.put(delBP, new Deleter()); bpTable.setInputMap(JComponent.WHEN_FOCUSED, in); bpTable.setActionMap(ac); add("Center", new JScrollPane(bpTable)); JMenu options = new JMenu("Options"); setBP = options.add("Set Breakpoint"); setBP.addActionListener(this); options.addSeparator(); removeAll = options.add("Remove All Breakpoints"); removeAll.addActionListener(this); options.addSeparator(); ignoreBP = new JCheckBoxMenuItem("Ignore Breakpoints"); options.add(ignoreBP); breakAtPrimary = new JCheckBoxMenuItem("Break at 'Primary' breakpoints only"); options.add(breakAtPrimary); JMenuBar bar = new JMenuBar(); bar.add(new BPFileMenu()); bar.add(options); setJMenuBar(bar); setPreferredSize(new Dimension(450, 300)); JPC.getInstance().objects().addObject(this); loadBreakpoints(); } public boolean breakAtPrimaryOnly() { return breakAtPrimary.getState(); } public boolean ignoreBreakpoints() { return ignoreBP.getState(); } public boolean isEdited() { return edited; } public void frameClosed() { if (edited) { if (JOptionPane.showConfirmDialog(this, "Do you want to save the changes to the breakpoints?", "Save Breakpoints", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) saveBreakpoints(); edited = false; } JPC.getInstance().objects().removeObject(this); } public void actionPerformed(ActionEvent evt) { if (evt.getSource() == setBP) { try { String input = JOptionPane.showInputDialog(this, "Enter the address (in Hex) for the breakpoint: ", "Breakpoint", JOptionPane.QUESTION_MESSAGE); int address = (int) Long.parseLong(input.toLowerCase(), 16); setBreakpoint(address); } catch (Exception e){} } else if (evt.getSource() == removeAll) removeAllBreakpoints(); } class BPFileMenu extends JMenu implements ActionListener { private JMenuItem load, save, saveAs, importBP; BPFileMenu() { super("File"); load = add("Load Breakpoints"); load.addActionListener(this); save = add("Save Breakpoints"); save.addActionListener(this); saveAs = add("Save Breakpoints As"); saveAs.addActionListener(this); addSeparator(); importBP = add("Import Breakpoints"); importBP.addActionListener(this); } private String deriveBPFileName(String name) { String nm = name.toLowerCase(); if (nm.endsWith(".jpc")) return name; int dot = nm.indexOf("."); if (dot < 0) dot = nm.length(); return name.substring(0, dot)+".jpc"; } public void actionPerformed(ActionEvent evt) { JFileChooser chooser = (JFileChooser) JPC.getObject(JFileChooser.class); if (evt.getSource() == load) { if (chooser.showOpenDialog(JPC.getInstance()) != chooser.APPROVE_OPTION) return; breakpointFileName = chooser.getSelectedFile().getAbsolutePath(); removeAllBreakpoints(); loadBreakpoints(); } else if (evt.getSource() == save) { saveBreakpoints(); } else if (evt.getSource() == importBP) { if (chooser.showOpenDialog(JPC.getInstance()) != chooser.APPROVE_OPTION) return; removeAllBreakpoints(); String fileName = chooser.getSelectedFile().getAbsolutePath(); importBreakpoints(fileName, false); } else if (evt.getSource() == saveAs) { if (chooser.showSaveDialog(JPC.getInstance()) != chooser.APPROVE_OPTION) return; breakpointFileName = chooser.getSelectedFile().getAbsolutePath(); saveBreakpoints(); } } } class Deleter extends AbstractAction { public void actionPerformed(ActionEvent evt) { deleteBreakpoint(bpTable.getSelectedRow()); } } public boolean isBreakpoint(int address) { Breakpoint bp = new Breakpoint(address); return breakpoints.contains(bp); } public void setBreakpoint(int address) { setBreakpoint(address, false); } public void setBreakpoint(int address, boolean isPrimary) { Breakpoint bp = new Breakpoint(address); int idx = breakpoints.indexOf(bp); if (idx < 0) breakpoints.add(bp); else bp = breakpoints.elementAt(idx); if (isPrimary) bp.isPrimary = isPrimary; edited = true; JPC.getInstance().refresh(); } public void removeAllBreakpoints() { breakpoints.removeAllElements(); edited = true; JPC.getInstance().refresh(); } public void removeBreakpoint(int address) { Breakpoint bp = new Breakpoint(address); int idx = breakpoints.indexOf(bp); if (idx < 0) return; deleteBreakpoint(idx); } public Breakpoint checkForBreak(int start, int end) { return checkForBreak(start, end, breakAtPrimary.getState()); } public Breakpoint checkForBreak(int start, int end, boolean isPrimary) { if (ignoreBP.getState()) return null; for (int i=0; i<breakpoints.size(); i++) { Breakpoint bp = breakpoints.elementAt(i); if ((bp.address >= start) && (bp.address < end)) { if (isPrimary && !bp.isPrimary) continue; return bp; } } return null; } public void deleteBreakpoint(int index) { try { breakpoints.removeElementAt(index); } catch (Exception e) {} edited = true; JPC.getInstance().refresh(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -