annotate agent/src/share/classes/sun/jvm/hotspot/bugspot/RegisterPanel.java @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.bugspot;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.awt.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import javax.swing.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import javax.swing.table.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 /** Displays registers in a window. FIXME: this will need more work to
a61af66fc99e Initial load
duke
parents:
diff changeset
35 understand and handle register windows. */
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 public class RegisterPanel extends JPanel {
a61af66fc99e Initial load
duke
parents:
diff changeset
38 private java.util.List/*<RegisterInfo>*/ registers;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 private AbstractTableModel dataModel;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 private boolean valid;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 private boolean editable;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 private String nullAddressString;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 private ThreadProxy curThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 private JTable table;
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 static class RegisterInfo {
a61af66fc99e Initial load
duke
parents:
diff changeset
47 private String name;
a61af66fc99e Initial load
duke
parents:
diff changeset
48 private Address value;
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 RegisterInfo(String name, Address value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 this.name = name;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 this.value = value;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 }
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 String getName() { return name; }
a61af66fc99e Initial load
duke
parents:
diff changeset
56 Address getValue() { return value; }
a61af66fc99e Initial load
duke
parents:
diff changeset
57 }
a61af66fc99e Initial load
duke
parents:
diff changeset
58
a61af66fc99e Initial load
duke
parents:
diff changeset
59 public RegisterPanel() {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 super();
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 registers = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 dataModel = new AbstractTableModel() {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 public int getColumnCount() { return 2; }
a61af66fc99e Initial load
duke
parents:
diff changeset
66 public int getRowCount() { return registers.size(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
67 public String getColumnName(int col) {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 switch (col) {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 case 0:
a61af66fc99e Initial load
duke
parents:
diff changeset
70 return "Register Name";
a61af66fc99e Initial load
duke
parents:
diff changeset
71 case 1:
a61af66fc99e Initial load
duke
parents:
diff changeset
72 return "Register Value";
a61af66fc99e Initial load
duke
parents:
diff changeset
73 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
74 throw new RuntimeException("Index " + col + " out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76 }
a61af66fc99e Initial load
duke
parents:
diff changeset
77 public Object getValueAt(int row, int col) {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 RegisterInfo info = (RegisterInfo) registers.get(row);
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 switch (col) {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 case 0:
a61af66fc99e Initial load
duke
parents:
diff changeset
82 return info.getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
83 case 1:
a61af66fc99e Initial load
duke
parents:
diff changeset
84 if (valid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 Address val = info.getValue();
a61af66fc99e Initial load
duke
parents:
diff changeset
86 if (val != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 return val;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 return nullAddressString;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 return "-";
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
95 throw new RuntimeException("Index (" + col + ", " + row + ") out of bounds");
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98 public boolean isCellEditable(int row, int col) {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 if (col == 0) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 if (!valid) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 if (curThread == null) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 if (!curThread.canSetContext()) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // FIXME: add listener to watch for register changes
a61af66fc99e Initial load
duke
parents:
diff changeset
105 // return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 };
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // Build user interface
a61af66fc99e Initial load
duke
parents:
diff changeset
111 setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
112 table = new JTable(dataModel);
a61af66fc99e Initial load
duke
parents:
diff changeset
113 table.setCellSelectionEnabled(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
114 table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 table.setDragEnabled(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
116 JTableHeader header = table.getTableHeader();
a61af66fc99e Initial load
duke
parents:
diff changeset
117 header.setReorderingAllowed(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
118 JScrollPane scrollPane = new JScrollPane(table);
a61af66fc99e Initial load
duke
parents:
diff changeset
119 add(scrollPane, BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 /** Updates the register panel with the register set from the
a61af66fc99e Initial load
duke
parents:
diff changeset
124 specified thread. Call this when the process has been suspended
a61af66fc99e Initial load
duke
parents:
diff changeset
125 and the current thread has been set. FIXME: this interface will
a61af66fc99e Initial load
duke
parents:
diff changeset
126 need to change to support register windows. */
a61af66fc99e Initial load
duke
parents:
diff changeset
127 public void update(ThreadProxy curThread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 this.curThread = curThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
129 ThreadContext context = curThread.getContext();
a61af66fc99e Initial load
duke
parents:
diff changeset
130 editable = curThread.canSetContext();
a61af66fc99e Initial load
duke
parents:
diff changeset
131 registers.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
132 for (int i = 0; i < context.getNumRegisters(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 String name = context.getRegisterName(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
134 Address addr = context.getRegisterAsAddress(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
135 if ((nullAddressString == null) && (addr != null)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
136 String addrStr = addr.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
137 StringBuffer buf = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
138 buf.append("0x");
a61af66fc99e Initial load
duke
parents:
diff changeset
139 int len = addrStr.length() - 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
140 for (int j = 0; j < len; j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 buf.append("0");
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
143 nullAddressString = buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145 registers.add(new RegisterInfo(name, addr));
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147 valid = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
148 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
149 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 dataModel.fireTableDataChanged();
a61af66fc99e Initial load
duke
parents:
diff changeset
151 }
a61af66fc99e Initial load
duke
parents:
diff changeset
152 });
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 /** Clears the registers' values. Call this when the processs has
a61af66fc99e Initial load
duke
parents:
diff changeset
156 been resumed. */
a61af66fc99e Initial load
duke
parents:
diff changeset
157 public void clear() {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 valid = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
159 nullAddressString = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
160 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 dataModel.fireTableDataChanged();
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164 });
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 public void setFont(Font font) {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 super.setFont(font);
a61af66fc99e Initial load
duke
parents:
diff changeset
169 if (table != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 table.setFont(font);
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }