mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-09-09 23:54:32 +00:00
+ shortcut for registering identical breakpoints for all motes of a particular mote type (currently only in popup menu)
This commit is contained in:
parent
4fecf3fe1e
commit
e8ca6d4a4e
@ -26,7 +26,7 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: BreakpointsUI.java,v 1.3 2009/06/11 10:06:47 fros4943 Exp $
|
* $Id: BreakpointsUI.java,v 1.4 2009/06/15 09:45:46 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.mspmote.plugins;
|
package se.sics.cooja.mspmote.plugins;
|
||||||
@ -37,10 +37,22 @@ import java.awt.event.ActionListener;
|
|||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import se.sics.cooja.GUI;
|
||||||
|
import se.sics.cooja.Mote;
|
||||||
|
import se.sics.cooja.MoteType;
|
||||||
|
import se.sics.cooja.Simulation;
|
||||||
|
import se.sics.cooja.Watchpoint;
|
||||||
|
import se.sics.cooja.WatchpointMote;
|
||||||
|
import se.sics.cooja.dialogs.MessageList;
|
||||||
|
import se.sics.cooja.mspmote.MspMote;
|
||||||
|
import se.sics.cooja.mspmote.MspMoteType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays a set of breakpoints.
|
* Displays a set of breakpoints.
|
||||||
*
|
*
|
||||||
@ -52,6 +64,8 @@ public class BreakpointsUI extends JPanel {
|
|||||||
private MspBreakpointContainer breakpoints = null;
|
private MspBreakpointContainer breakpoints = null;
|
||||||
private JTable table = null;
|
private JTable table = null;
|
||||||
|
|
||||||
|
private MspBreakpoint popupBreakpoint = null;
|
||||||
|
|
||||||
public BreakpointsUI(MspBreakpointContainer breakpoints, final MspCodeWatcher codeWatcher) {
|
public BreakpointsUI(MspBreakpointContainer breakpoints, final MspCodeWatcher codeWatcher) {
|
||||||
this.breakpoints = breakpoints;
|
this.breakpoints = breakpoints;
|
||||||
|
|
||||||
@ -88,16 +102,20 @@ public class BreakpointsUI extends JPanel {
|
|||||||
table.getColumnModel().getColumn(3).setPreferredWidth(60);
|
table.getColumnModel().getColumn(3).setPreferredWidth(60);
|
||||||
table.getColumnModel().getColumn(3).setMaxWidth(60);
|
table.getColumnModel().getColumn(3).setMaxWidth(60);
|
||||||
|
|
||||||
|
/* Popup menu: register on all motes */
|
||||||
|
final JPopupMenu popupMenu = new JPopupMenu();
|
||||||
|
popupMenu.add(new JMenuItem(addToMoteTypeAction));
|
||||||
|
popupMenu.add(new JMenuItem(delFromMoteTypeAction));
|
||||||
|
|
||||||
/* Show source file on breakpoint mouse click */
|
/* Show source file on breakpoint mouse click */
|
||||||
table.addMouseListener(new MouseAdapter() {
|
table.addMouseListener(new MouseAdapter() {
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
|
||||||
java.awt.Point p = e.getPoint();
|
java.awt.Point p = e.getPoint();
|
||||||
int rowIndex = table.rowAtPoint(p);
|
int rowIndex = table.rowAtPoint(p);
|
||||||
int colIndex = table.columnAtPoint(p);
|
int colIndex = table.columnAtPoint(p);
|
||||||
int realColumnIndex = table.convertColumnIndexToModel(colIndex);
|
int realColumnIndex = table.convertColumnIndexToModel(colIndex);
|
||||||
|
|
||||||
if (realColumnIndex != 1 && realColumnIndex != 2) {
|
if (realColumnIndex != 0 && realColumnIndex != 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,6 +123,13 @@ public class BreakpointsUI extends JPanel {
|
|||||||
if (rowIndex < 0 || rowIndex >= allBreakpoints.length) {
|
if (rowIndex < 0 || rowIndex >= allBreakpoints.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e.isPopupTrigger() || SwingUtilities.isRightMouseButton(e)) {
|
||||||
|
popupBreakpoint = allBreakpoints[rowIndex];
|
||||||
|
popupMenu.show(table, e.getX(), e.getY());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
File file = allBreakpoints[rowIndex].getCodeFile();
|
File file = allBreakpoints[rowIndex].getCodeFile();
|
||||||
int line = allBreakpoints[rowIndex].getLineNumber();
|
int line = allBreakpoints[rowIndex].getLineNumber();
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
@ -115,7 +140,7 @@ public class BreakpointsUI extends JPanel {
|
|||||||
codeWatcher.displaySourceFile(file, line);
|
codeWatcher.displaySourceFile(file, line);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Update when breakpoints are triggered/added/removed */
|
/* Update when breakpoints are triggered/added/removed */
|
||||||
breakpoints.addWatchpointListener(new ActionListener() {
|
breakpoints.addWatchpointListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
@ -220,4 +245,94 @@ public class BreakpointsUI extends JPanel {
|
|||||||
return getValueAt(0, c).getClass();
|
return getValueAt(0, c).getClass();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private Action addToMoteTypeAction = new AbstractAction("Register on all motes (mote type)") {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (popupBreakpoint == null) {
|
||||||
|
logger.fatal("No breakpoint to add");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Extract all motes of the same mote type */
|
||||||
|
Simulation sim = popupBreakpoint.getMote().getSimulation();
|
||||||
|
MoteType type = popupBreakpoint.getMote().getType();
|
||||||
|
ArrayList<MspMote> motes = new ArrayList<MspMote>();
|
||||||
|
for (Mote m: sim.getMotes()) {
|
||||||
|
if (m.getType() == type) {
|
||||||
|
if (!(m instanceof MspMote)) {
|
||||||
|
logger.fatal("At least one mote was not a MSP mote: " + m);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
motes.add((MspMote)m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Register breakpoints */
|
||||||
|
int reregistered = 0;
|
||||||
|
for (MspMote m: motes) {
|
||||||
|
/* Avoid duplicates (match executable addresses) */
|
||||||
|
MspBreakpointContainer container = m.getBreakpointsContainer();
|
||||||
|
MspBreakpoint[] breakpoints = container.getBreakpoints();
|
||||||
|
for (MspBreakpoint w: breakpoints) {
|
||||||
|
if (popupBreakpoint.getExecutableAddress().intValue() ==
|
||||||
|
w.getExecutableAddress().intValue()) {
|
||||||
|
logger.info("Reregistering breakpoint at mote: " + m);
|
||||||
|
container.removeBreakpoint(w.getExecutableAddress());
|
||||||
|
reregistered++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MspBreakpoint newBreakpoint = container.addBreakpoint(
|
||||||
|
popupBreakpoint.getCodeFile(),
|
||||||
|
popupBreakpoint.getLineNumber(),
|
||||||
|
popupBreakpoint.getExecutableAddress());
|
||||||
|
newBreakpoint.setStopsSimulation(popupBreakpoint.stopsSimulation());
|
||||||
|
}
|
||||||
|
|
||||||
|
JOptionPane.showMessageDialog(GUI.getTopParentContainer(),
|
||||||
|
"Registered " + motes.size() + " breakpoints (" + reregistered + " re-registered)",
|
||||||
|
"Breakpoints added", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
private Action delFromMoteTypeAction = new AbstractAction("Delete from all motes (mote type)") {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (popupBreakpoint == null) {
|
||||||
|
logger.fatal("No breakpoint to delete");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Extract all motes of the same mote type */
|
||||||
|
Simulation sim = popupBreakpoint.getMote().getSimulation();
|
||||||
|
MoteType type = popupBreakpoint.getMote().getType();
|
||||||
|
ArrayList<MspMote> motes = new ArrayList<MspMote>();
|
||||||
|
for (Mote m: sim.getMotes()) {
|
||||||
|
if (m.getType() == type) {
|
||||||
|
if (!(m instanceof MspMote)) {
|
||||||
|
logger.fatal("At least one mote was not a MSP mote: " + m);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
motes.add((MspMote)m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Delete breakpoints */
|
||||||
|
int deleted = 0;
|
||||||
|
for (MspMote m: motes) {
|
||||||
|
/* Avoid duplicates (match executable addresses) */
|
||||||
|
MspBreakpointContainer container = m.getBreakpointsContainer();
|
||||||
|
MspBreakpoint[] breakpoints = container.getBreakpoints();
|
||||||
|
for (MspBreakpoint w: breakpoints) {
|
||||||
|
if (popupBreakpoint.getExecutableAddress().intValue() ==
|
||||||
|
w.getExecutableAddress().intValue()) {
|
||||||
|
container.removeBreakpoint(w.getExecutableAddress());
|
||||||
|
deleted++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JOptionPane.showMessageDialog(GUI.getTopParentContainer(),
|
||||||
|
"Deleted " + deleted + " breakpoints",
|
||||||
|
"Breakpoints deleted", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user