annotate agent/src/share/classes/sun/jvm/hotspot/bugspot/BugSpot.java @ 1385:bc32f286fae0

6945219: minor SA fixes Reviewed-by: twisti
author never
date Tue, 20 Apr 2010 13:26:33 -0700
parents a61af66fc99e
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 0
diff changeset
2 * Copyright 2001-2010 Sun Microsystems, Inc. All Rights Reserved.
0
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.awt.event.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import java.net.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 import javax.swing.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 import javax.swing.filechooser.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 import sun.jvm.hotspot.debugger.cdbg.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 import sun.jvm.hotspot.debugger.posix.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 import sun.jvm.hotspot.debugger.win32.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 import sun.jvm.hotspot.livejvm.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 import sun.jvm.hotspot.memory.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 import sun.jvm.hotspot.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 import sun.jvm.hotspot.ui.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 /** The BugSpot component. This is embeddable in an application by
a61af66fc99e Initial load
duke
parents:
diff changeset
46 virtue of its being a JComponent. It (currently) requires the use
a61af66fc99e Initial load
duke
parents:
diff changeset
47 of a menu bar which can be fetched via getMenuBar(). This is
a61af66fc99e Initial load
duke
parents:
diff changeset
48 intended ultimately to replace HSDB. */
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 public class BugSpot extends JPanel {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 public BugSpot() {
a61af66fc99e Initial load
duke
parents:
diff changeset
52 super();
a61af66fc99e Initial load
duke
parents:
diff changeset
53 Runtime.getRuntime().addShutdownHook(new java.lang.Thread() {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 detachDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57 });
a61af66fc99e Initial load
duke
parents:
diff changeset
58 }
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 /** Turn on or off MDI (Multiple Document Interface) mode. When MDI
a61af66fc99e Initial load
duke
parents:
diff changeset
61 is enabled, the BugSpot component contains a JDesktopPane and all
a61af66fc99e Initial load
duke
parents:
diff changeset
62 windows are JInternalFrames. When disabled, only the menu bar is
a61af66fc99e Initial load
duke
parents:
diff changeset
63 relevant. */
a61af66fc99e Initial load
duke
parents:
diff changeset
64 public void setMDIMode(boolean onOrOff) {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 mdiMode = onOrOff;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 /** Indicates whether MDI mode is enabled. */
a61af66fc99e Initial load
duke
parents:
diff changeset
69 public boolean getMDIMode() {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 return mdiMode;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 /** Build user interface widgets. This must be called before adding
a61af66fc99e Initial load
duke
parents:
diff changeset
74 the BugSpot component to its parent. */
a61af66fc99e Initial load
duke
parents:
diff changeset
75 public void build() {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 menuBar = new JMenuBar();
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 attachMenuItems = new java.util.ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
81 detachMenuItems = new java.util.ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
82 debugMenuItems = new java.util.ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
83 suspendDebugMenuItems = new java.util.ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
84 resumeDebugMenuItems = new java.util.ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 //
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // File menu
a61af66fc99e Initial load
duke
parents:
diff changeset
88 //
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 JMenu menu = createMenu("File", 'F', 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
91 JMenuItem item;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 item = createMenuItem("Open source file...",
a61af66fc99e Initial load
duke
parents:
diff changeset
93 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
95 openSourceFile();
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97 },
a61af66fc99e Initial load
duke
parents:
diff changeset
98 KeyEvent.VK_O, InputEvent.CTRL_MASK,
a61af66fc99e Initial load
duke
parents:
diff changeset
99 'O', 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
100 menu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
101 detachMenuItems.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 menu.addSeparator();
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 item = createMenuItem("Attach to process...",
a61af66fc99e Initial load
duke
parents:
diff changeset
106 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 showAttachDialog();
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 },
a61af66fc99e Initial load
duke
parents:
diff changeset
111 'A', 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
112 menu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
113 attachMenuItems.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 item = createMenuItem("Detach",
a61af66fc99e Initial load
duke
parents:
diff changeset
116 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
117 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120 },
a61af66fc99e Initial load
duke
parents:
diff changeset
121 'D', 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
122 menu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
123 detachMenuItems.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // Disable detach menu items at first
a61af66fc99e Initial load
duke
parents:
diff changeset
126 setMenuItemsEnabled(detachMenuItems, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 menu.addSeparator();
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 menu.add(createMenuItem("Exit",
a61af66fc99e Initial load
duke
parents:
diff changeset
131 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
134 System.exit(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136 },
a61af66fc99e Initial load
duke
parents:
diff changeset
137 'x', 1));
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 menuBar.add(menu);
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141 //
a61af66fc99e Initial load
duke
parents:
diff changeset
142 // Debug menu
a61af66fc99e Initial load
duke
parents:
diff changeset
143 //
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 debugMenu = createMenu("Debug", 'D', 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
146 item = createMenuItem("Go",
a61af66fc99e Initial load
duke
parents:
diff changeset
147 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
149 if (!attached) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
150 if (!isSuspended()) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
151 resume();
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153 },
a61af66fc99e Initial load
duke
parents:
diff changeset
154 KeyEvent.VK_F5, 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
155 'G', 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
156 debugMenu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
157 resumeDebugMenuItems.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 item = createMenuItem("Break",
a61af66fc99e Initial load
duke
parents:
diff changeset
160 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 if (!attached) {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 System.err.println("Not attached");
a61af66fc99e Initial load
duke
parents:
diff changeset
164 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
166 if (isSuspended()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 System.err.println("Already suspended");
a61af66fc99e Initial load
duke
parents:
diff changeset
168 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 }
a61af66fc99e Initial load
duke
parents:
diff changeset
170 suspend();
a61af66fc99e Initial load
duke
parents:
diff changeset
171 }
a61af66fc99e Initial load
duke
parents:
diff changeset
172 },
a61af66fc99e Initial load
duke
parents:
diff changeset
173 'B', 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
174 debugMenu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
175 suspendDebugMenuItems.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177 debugMenu.addSeparator();
a61af66fc99e Initial load
duke
parents:
diff changeset
178
a61af66fc99e Initial load
duke
parents:
diff changeset
179 item = createMenuItem("Threads...",
a61af66fc99e Initial load
duke
parents:
diff changeset
180 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
181 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
182 showThreadsDialog();
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184 },
a61af66fc99e Initial load
duke
parents:
diff changeset
185 'T', 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
186 debugMenu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
187 debugMenuItems.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
188 // FIXME: belongs under "View -> Debug Windows"
a61af66fc99e Initial load
duke
parents:
diff changeset
189 item = createMenuItem("Memory",
a61af66fc99e Initial load
duke
parents:
diff changeset
190 new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
191 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
192 showMemoryDialog();
a61af66fc99e Initial load
duke
parents:
diff changeset
193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
194 },
a61af66fc99e Initial load
duke
parents:
diff changeset
195 'M', 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
196 debugMenu.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
197 debugMenuItems.add(item);
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 debugMenu.setEnabled(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
200 menuBar.add(debugMenu);
a61af66fc99e Initial load
duke
parents:
diff changeset
201
a61af66fc99e Initial load
duke
parents:
diff changeset
202 if (mdiMode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
203 desktop = new JDesktopPane();
a61af66fc99e Initial load
duke
parents:
diff changeset
204 add(desktop, BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 }
a61af66fc99e Initial load
duke
parents:
diff changeset
206
a61af66fc99e Initial load
duke
parents:
diff changeset
207 fixedWidthFont = GraphicsUtilities.lookupFont("Courier");
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 debugEventTimer = new javax.swing.Timer(100, new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
210 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 pollForDebugEvent();
a61af66fc99e Initial load
duke
parents:
diff changeset
212 }
a61af66fc99e Initial load
duke
parents:
diff changeset
213 });
a61af66fc99e Initial load
duke
parents:
diff changeset
214 }
a61af66fc99e Initial load
duke
parents:
diff changeset
215
a61af66fc99e Initial load
duke
parents:
diff changeset
216 public JMenuBar getMenuBar() {
a61af66fc99e Initial load
duke
parents:
diff changeset
217 return menuBar;
a61af66fc99e Initial load
duke
parents:
diff changeset
218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
219
a61af66fc99e Initial load
duke
parents:
diff changeset
220 public void showAttachDialog() {
a61af66fc99e Initial load
duke
parents:
diff changeset
221 setMenuItemsEnabled(attachMenuItems, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
222 final FrameWrapper attachDialog = newFrame("Attach to process");
a61af66fc99e Initial load
duke
parents:
diff changeset
223 attachDialog.getContentPane().setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
224 attachDialog.setClosable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
225 attachDialog.setResizable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
226
a61af66fc99e Initial load
duke
parents:
diff changeset
227 JPanel panel = new JPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
228 panel.setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
229 panel.setBorder(GraphicsUtilities.newBorder(5));
a61af66fc99e Initial load
duke
parents:
diff changeset
230 attachDialog.setBackground(panel.getBackground());
a61af66fc99e Initial load
duke
parents:
diff changeset
231
a61af66fc99e Initial load
duke
parents:
diff changeset
232 JPanel listPanel = new JPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
233 listPanel.setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
234 final ProcessListPanel plist = new ProcessListPanel(getLocalDebugger());
a61af66fc99e Initial load
duke
parents:
diff changeset
235 panel.add(plist, BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
236 JCheckBox check = new JCheckBox("Update list continuously");
a61af66fc99e Initial load
duke
parents:
diff changeset
237 check.addItemListener(new ItemListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
238 public void itemStateChanged(ItemEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 if (e.getStateChange() == ItemEvent.SELECTED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
240 plist.start();
a61af66fc99e Initial load
duke
parents:
diff changeset
241 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 plist.stop();
a61af66fc99e Initial load
duke
parents:
diff changeset
243 }
a61af66fc99e Initial load
duke
parents:
diff changeset
244 }
a61af66fc99e Initial load
duke
parents:
diff changeset
245 });
a61af66fc99e Initial load
duke
parents:
diff changeset
246 listPanel.add(plist, BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
247 listPanel.add(check, BorderLayout.SOUTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
248 panel.add(listPanel, BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
249 attachDialog.getContentPane().add(panel, BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
250 attachDialog.setClosingActionListener(new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
251 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
252 plist.stop();
a61af66fc99e Initial load
duke
parents:
diff changeset
253 setMenuItemsEnabled(attachMenuItems, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
254 }
a61af66fc99e Initial load
duke
parents:
diff changeset
255 });
a61af66fc99e Initial load
duke
parents:
diff changeset
256
a61af66fc99e Initial load
duke
parents:
diff changeset
257 ActionListener attacher = new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
259 plist.stop();
a61af66fc99e Initial load
duke
parents:
diff changeset
260 attachDialog.setVisible(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
261 removeFrame(attachDialog);
a61af66fc99e Initial load
duke
parents:
diff changeset
262 ProcessInfo info = plist.getSelectedProcess();
a61af66fc99e Initial load
duke
parents:
diff changeset
263 if (info != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
264 attach(info.getPid());
a61af66fc99e Initial load
duke
parents:
diff changeset
265 }
a61af66fc99e Initial load
duke
parents:
diff changeset
266 }
a61af66fc99e Initial load
duke
parents:
diff changeset
267 };
a61af66fc99e Initial load
duke
parents:
diff changeset
268
a61af66fc99e Initial load
duke
parents:
diff changeset
269 Box hbox = Box.createHorizontalBox();
a61af66fc99e Initial load
duke
parents:
diff changeset
270 hbox.add(Box.createGlue());
a61af66fc99e Initial load
duke
parents:
diff changeset
271 JButton button = new JButton("OK");
a61af66fc99e Initial load
duke
parents:
diff changeset
272 button.addActionListener(attacher);
a61af66fc99e Initial load
duke
parents:
diff changeset
273 hbox.add(button);
a61af66fc99e Initial load
duke
parents:
diff changeset
274 hbox.add(Box.createHorizontalStrut(20));
a61af66fc99e Initial load
duke
parents:
diff changeset
275 button = new JButton("Cancel");
a61af66fc99e Initial load
duke
parents:
diff changeset
276 button.addActionListener(new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
277 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
278 plist.stop();
a61af66fc99e Initial load
duke
parents:
diff changeset
279 attachDialog.setVisible(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
280 removeFrame(attachDialog);
a61af66fc99e Initial load
duke
parents:
diff changeset
281 setMenuItemsEnabled(attachMenuItems, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
282 }
a61af66fc99e Initial load
duke
parents:
diff changeset
283 });
a61af66fc99e Initial load
duke
parents:
diff changeset
284 hbox.add(button);
a61af66fc99e Initial load
duke
parents:
diff changeset
285 hbox.add(Box.createGlue());
a61af66fc99e Initial load
duke
parents:
diff changeset
286 panel = new JPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
287 panel.setBorder(GraphicsUtilities.newBorder(5));
a61af66fc99e Initial load
duke
parents:
diff changeset
288 panel.add(hbox);
a61af66fc99e Initial load
duke
parents:
diff changeset
289
a61af66fc99e Initial load
duke
parents:
diff changeset
290 attachDialog.getContentPane().add(panel, BorderLayout.SOUTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
291
a61af66fc99e Initial load
duke
parents:
diff changeset
292 addFrame(attachDialog);
a61af66fc99e Initial load
duke
parents:
diff changeset
293 attachDialog.pack();
a61af66fc99e Initial load
duke
parents:
diff changeset
294 attachDialog.setSize(400, 300);
a61af66fc99e Initial load
duke
parents:
diff changeset
295 GraphicsUtilities.centerInContainer(attachDialog.getComponent(),
a61af66fc99e Initial load
duke
parents:
diff changeset
296 getParentDimension(attachDialog.getComponent()));
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 0
diff changeset
297 attachDialog.setVisible(true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
298 }
a61af66fc99e Initial load
duke
parents:
diff changeset
299
a61af66fc99e Initial load
duke
parents:
diff changeset
300 public void showThreadsDialog() {
a61af66fc99e Initial load
duke
parents:
diff changeset
301 final FrameWrapper threadsDialog = newFrame("Threads");
a61af66fc99e Initial load
duke
parents:
diff changeset
302 threadsDialog.getContentPane().setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
303 threadsDialog.setClosable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
304 threadsDialog.setResizable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
305
a61af66fc99e Initial load
duke
parents:
diff changeset
306 ThreadListPanel threads = new ThreadListPanel(getCDebugger(), getAgent().isJavaMode());
a61af66fc99e Initial load
duke
parents:
diff changeset
307 threads.addListener(new ThreadListPanel.Listener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
308 public void setFocus(ThreadProxy thread, JavaThread jthread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
309 setCurrentThread(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
310 // FIXME: print this to GUI, bring some windows to foreground
a61af66fc99e Initial load
duke
parents:
diff changeset
311 System.err.println("Focus changed to thread " + thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
312 }
a61af66fc99e Initial load
duke
parents:
diff changeset
313 });
a61af66fc99e Initial load
duke
parents:
diff changeset
314 threads.setBorder(GraphicsUtilities.newBorder(5));
a61af66fc99e Initial load
duke
parents:
diff changeset
315 threadsDialog.getContentPane().add(threads);
a61af66fc99e Initial load
duke
parents:
diff changeset
316 addFrame(threadsDialog);
a61af66fc99e Initial load
duke
parents:
diff changeset
317 threadsDialog.pack();
a61af66fc99e Initial load
duke
parents:
diff changeset
318 GraphicsUtilities.reshapeToAspectRatio(threadsDialog.getComponent(),
a61af66fc99e Initial load
duke
parents:
diff changeset
319 3.0f,
a61af66fc99e Initial load
duke
parents:
diff changeset
320 0.9f,
a61af66fc99e Initial load
duke
parents:
diff changeset
321 getParentDimension(threadsDialog.getComponent()));
a61af66fc99e Initial load
duke
parents:
diff changeset
322 GraphicsUtilities.centerInContainer(threadsDialog.getComponent(),
a61af66fc99e Initial load
duke
parents:
diff changeset
323 getParentDimension(threadsDialog.getComponent()));
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 0
diff changeset
324 threadsDialog.setVisible(true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
326
a61af66fc99e Initial load
duke
parents:
diff changeset
327 public void showMemoryDialog() {
a61af66fc99e Initial load
duke
parents:
diff changeset
328 final FrameWrapper memoryDialog = newFrame("Memory");
a61af66fc99e Initial load
duke
parents:
diff changeset
329 memoryDialog.getContentPane().setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
330 memoryDialog.setClosable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
331 memoryDialog.setResizable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
332
a61af66fc99e Initial load
duke
parents:
diff changeset
333 memoryDialog.getContentPane().add(new MemoryViewer(getDebugger(),
a61af66fc99e Initial load
duke
parents:
diff changeset
334 (getDebugger().getMachineDescription().getAddressSize() == 8)),
a61af66fc99e Initial load
duke
parents:
diff changeset
335 BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
336 addFrame(memoryDialog);
a61af66fc99e Initial load
duke
parents:
diff changeset
337 memoryDialog.pack();
a61af66fc99e Initial load
duke
parents:
diff changeset
338 GraphicsUtilities.reshapeToAspectRatio(memoryDialog.getComponent(),
a61af66fc99e Initial load
duke
parents:
diff changeset
339 1.0f,
a61af66fc99e Initial load
duke
parents:
diff changeset
340 0.7f,
a61af66fc99e Initial load
duke
parents:
diff changeset
341 getParentDimension(memoryDialog.getComponent()));
a61af66fc99e Initial load
duke
parents:
diff changeset
342 GraphicsUtilities.centerInContainer(memoryDialog.getComponent(),
a61af66fc99e Initial load
duke
parents:
diff changeset
343 getParentDimension(memoryDialog.getComponent()));
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 0
diff changeset
344 memoryDialog.setVisible(true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
345 }
a61af66fc99e Initial load
duke
parents:
diff changeset
346
a61af66fc99e Initial load
duke
parents:
diff changeset
347 /** Changes the editor factory this debugger uses to display source
a61af66fc99e Initial load
duke
parents:
diff changeset
348 code. Specified factory may be null, in which case the default
a61af66fc99e Initial load
duke
parents:
diff changeset
349 factory is used. */
a61af66fc99e Initial load
duke
parents:
diff changeset
350 public void setEditorFactory(EditorFactory fact) {
a61af66fc99e Initial load
duke
parents:
diff changeset
351 if (fact != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
352 editorFact = fact;
a61af66fc99e Initial load
duke
parents:
diff changeset
353 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
354 editorFact = new DefaultEditorFactory();
a61af66fc99e Initial load
duke
parents:
diff changeset
355 }
a61af66fc99e Initial load
duke
parents:
diff changeset
356 }
a61af66fc99e Initial load
duke
parents:
diff changeset
357
a61af66fc99e Initial load
duke
parents:
diff changeset
358 //----------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
359 // Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
360 //
a61af66fc99e Initial load
duke
parents:
diff changeset
361
a61af66fc99e Initial load
duke
parents:
diff changeset
362 private WorkerThread workerThread;
a61af66fc99e Initial load
duke
parents:
diff changeset
363 private boolean mdiMode;
a61af66fc99e Initial load
duke
parents:
diff changeset
364 private JVMDebugger localDebugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
365 private BugSpotAgent agent = new BugSpotAgent();
a61af66fc99e Initial load
duke
parents:
diff changeset
366 private JMenuBar menuBar;
a61af66fc99e Initial load
duke
parents:
diff changeset
367 /** List <JMenuItem> */
a61af66fc99e Initial load
duke
parents:
diff changeset
368 private java.util.List attachMenuItems;
a61af66fc99e Initial load
duke
parents:
diff changeset
369 private java.util.List detachMenuItems;
a61af66fc99e Initial load
duke
parents:
diff changeset
370 private java.util.List debugMenuItems;
a61af66fc99e Initial load
duke
parents:
diff changeset
371 private java.util.List suspendDebugMenuItems;
a61af66fc99e Initial load
duke
parents:
diff changeset
372 private java.util.List resumeDebugMenuItems;
a61af66fc99e Initial load
duke
parents:
diff changeset
373 private FrameWrapper stackFrame;
a61af66fc99e Initial load
duke
parents:
diff changeset
374 private VariablePanel localsPanel;
a61af66fc99e Initial load
duke
parents:
diff changeset
375 private StackTracePanel stackTracePanel;
a61af66fc99e Initial load
duke
parents:
diff changeset
376 private FrameWrapper registerFrame;
a61af66fc99e Initial load
duke
parents:
diff changeset
377 private RegisterPanel registerPanel;
a61af66fc99e Initial load
duke
parents:
diff changeset
378 // Used for mixed-language stack traces
a61af66fc99e Initial load
duke
parents:
diff changeset
379 private Map threadToJavaThreadMap;
a61af66fc99e Initial load
duke
parents:
diff changeset
380
a61af66fc99e Initial load
duke
parents:
diff changeset
381 private JMenu debugMenu;
a61af66fc99e Initial load
duke
parents:
diff changeset
382
a61af66fc99e Initial load
duke
parents:
diff changeset
383 // MDI mode only: desktop pane
a61af66fc99e Initial load
duke
parents:
diff changeset
384 private JDesktopPane desktop;
a61af66fc99e Initial load
duke
parents:
diff changeset
385
a61af66fc99e Initial load
duke
parents:
diff changeset
386 // Attach/detach state
a61af66fc99e Initial load
duke
parents:
diff changeset
387 private boolean attached;
a61af66fc99e Initial load
duke
parents:
diff changeset
388
a61af66fc99e Initial load
duke
parents:
diff changeset
389 // Suspension (combined Java/C++) state
a61af66fc99e Initial load
duke
parents:
diff changeset
390 private boolean suspended;
a61af66fc99e Initial load
duke
parents:
diff changeset
391
a61af66fc99e Initial load
duke
parents:
diff changeset
392 // Fixed-width font
a61af66fc99e Initial load
duke
parents:
diff changeset
393 private Font fixedWidthFont;
a61af66fc99e Initial load
duke
parents:
diff changeset
394
a61af66fc99e Initial load
duke
parents:
diff changeset
395 // Breakpoint setting
a61af66fc99e Initial load
duke
parents:
diff changeset
396 // Maps Strings to List/*<LineNumberInfo>*/
a61af66fc99e Initial load
duke
parents:
diff changeset
397 private Map sourceFileToLineNumberInfoMap;
a61af66fc99e Initial load
duke
parents:
diff changeset
398 // Maps Strings (file names) to Sets of Integers (line numbers)
a61af66fc99e Initial load
duke
parents:
diff changeset
399 private Map fileToBreakpointMap;
a61af66fc99e Initial load
duke
parents:
diff changeset
400
a61af66fc99e Initial load
duke
parents:
diff changeset
401 // Debug events
a61af66fc99e Initial load
duke
parents:
diff changeset
402 private javax.swing.Timer debugEventTimer;
a61af66fc99e Initial load
duke
parents:
diff changeset
403
a61af66fc99e Initial load
duke
parents:
diff changeset
404 // Java debug events
a61af66fc99e Initial load
duke
parents:
diff changeset
405 private boolean javaEventPending;
a61af66fc99e Initial load
duke
parents:
diff changeset
406
a61af66fc99e Initial load
duke
parents:
diff changeset
407 static class BreakpointResult {
a61af66fc99e Initial load
duke
parents:
diff changeset
408 private boolean success;
a61af66fc99e Initial load
duke
parents:
diff changeset
409 private boolean set;
a61af66fc99e Initial load
duke
parents:
diff changeset
410 private int lineNo;
a61af66fc99e Initial load
duke
parents:
diff changeset
411 private String why;
a61af66fc99e Initial load
duke
parents:
diff changeset
412
a61af66fc99e Initial load
duke
parents:
diff changeset
413 /** For positive results */
a61af66fc99e Initial load
duke
parents:
diff changeset
414 BreakpointResult(boolean success, boolean set, int lineNo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
415 this(success, set, lineNo, null);
a61af66fc99e Initial load
duke
parents:
diff changeset
416 }
a61af66fc99e Initial load
duke
parents:
diff changeset
417
a61af66fc99e Initial load
duke
parents:
diff changeset
418 /** For negative results */
a61af66fc99e Initial load
duke
parents:
diff changeset
419 BreakpointResult(boolean success, boolean set, int lineNo, String why) {
a61af66fc99e Initial load
duke
parents:
diff changeset
420 this.success = success;
a61af66fc99e Initial load
duke
parents:
diff changeset
421 this.set = set;
a61af66fc99e Initial load
duke
parents:
diff changeset
422 this.lineNo = lineNo;
a61af66fc99e Initial load
duke
parents:
diff changeset
423 this.why = why;
a61af66fc99e Initial load
duke
parents:
diff changeset
424 }
a61af66fc99e Initial load
duke
parents:
diff changeset
425
a61af66fc99e Initial load
duke
parents:
diff changeset
426 public boolean succeeded() {
a61af66fc99e Initial load
duke
parents:
diff changeset
427 return success;
a61af66fc99e Initial load
duke
parents:
diff changeset
428 }
a61af66fc99e Initial load
duke
parents:
diff changeset
429
a61af66fc99e Initial load
duke
parents:
diff changeset
430 public boolean set() {
a61af66fc99e Initial load
duke
parents:
diff changeset
431 return set;
a61af66fc99e Initial load
duke
parents:
diff changeset
432 }
a61af66fc99e Initial load
duke
parents:
diff changeset
433
a61af66fc99e Initial load
duke
parents:
diff changeset
434 /** Line at which the breakpoint was actually set; only valid if
a61af66fc99e Initial load
duke
parents:
diff changeset
435 succeeded() returns true */
a61af66fc99e Initial load
duke
parents:
diff changeset
436 public int getLine() {
a61af66fc99e Initial load
duke
parents:
diff changeset
437 return lineNo;
a61af66fc99e Initial load
duke
parents:
diff changeset
438 }
a61af66fc99e Initial load
duke
parents:
diff changeset
439
a61af66fc99e Initial load
duke
parents:
diff changeset
440 public String getWhy() {
a61af66fc99e Initial load
duke
parents:
diff changeset
441 return why;
a61af66fc99e Initial load
duke
parents:
diff changeset
442 }
a61af66fc99e Initial load
duke
parents:
diff changeset
443 }
a61af66fc99e Initial load
duke
parents:
diff changeset
444
a61af66fc99e Initial load
duke
parents:
diff changeset
445
a61af66fc99e Initial load
duke
parents:
diff changeset
446 // Editors for source code. File name-to-Editor mapping.
a61af66fc99e Initial load
duke
parents:
diff changeset
447 private Map editors;
a61af66fc99e Initial load
duke
parents:
diff changeset
448 private EditorFactory editorFact = new DefaultEditorFactory();
a61af66fc99e Initial load
duke
parents:
diff changeset
449 private EditorCommands editorComm = new EditorCommands() {
a61af66fc99e Initial load
duke
parents:
diff changeset
450 public void windowClosed(Editor editor) {
a61af66fc99e Initial load
duke
parents:
diff changeset
451 editors.remove(editor.getSourceFileName());
a61af66fc99e Initial load
duke
parents:
diff changeset
452 }
a61af66fc99e Initial load
duke
parents:
diff changeset
453
a61af66fc99e Initial load
duke
parents:
diff changeset
454 public void toggleBreakpointAtLine(Editor editor, int lineNumber) {
a61af66fc99e Initial load
duke
parents:
diff changeset
455 // FIXME: handle "lazy" breakpoints where the source file has
a61af66fc99e Initial load
duke
parents:
diff changeset
456 // been opened with some other mechanism (File -> Open) and we
a61af66fc99e Initial load
duke
parents:
diff changeset
457 // don't have debug information pointing to that file yet
a61af66fc99e Initial load
duke
parents:
diff changeset
458 // FIXME: NOT FINISHED
a61af66fc99e Initial load
duke
parents:
diff changeset
459
a61af66fc99e Initial load
duke
parents:
diff changeset
460 BreakpointResult res =
a61af66fc99e Initial load
duke
parents:
diff changeset
461 handleBreakpointToggle(editor, lineNumber);
a61af66fc99e Initial load
duke
parents:
diff changeset
462 if (res.succeeded()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
463 if (res.set()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
464 editor.showBreakpointAtLine(res.getLine());
a61af66fc99e Initial load
duke
parents:
diff changeset
465 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
466 editor.clearBreakpointAtLine(res.getLine());
a61af66fc99e Initial load
duke
parents:
diff changeset
467 }
a61af66fc99e Initial load
duke
parents:
diff changeset
468 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
469 String why = res.getWhy();
a61af66fc99e Initial load
duke
parents:
diff changeset
470 if (why == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
471 why = "";
a61af66fc99e Initial load
duke
parents:
diff changeset
472 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
473 why = ": " + why;
a61af66fc99e Initial load
duke
parents:
diff changeset
474 }
a61af66fc99e Initial load
duke
parents:
diff changeset
475 showMessageDialog("Unable to toggle breakpoint" + why,
a61af66fc99e Initial load
duke
parents:
diff changeset
476 "Unable to toggle breakpoint",
a61af66fc99e Initial load
duke
parents:
diff changeset
477 JOptionPane.WARNING_MESSAGE);
a61af66fc99e Initial load
duke
parents:
diff changeset
478 }
a61af66fc99e Initial load
duke
parents:
diff changeset
479 }
a61af66fc99e Initial load
duke
parents:
diff changeset
480 };
a61af66fc99e Initial load
duke
parents:
diff changeset
481
a61af66fc99e Initial load
duke
parents:
diff changeset
482 private void attach(final int pid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
483 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
484 getAgent().attach(pid);
a61af66fc99e Initial load
duke
parents:
diff changeset
485 setMenuItemsEnabled(detachMenuItems, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
486 setMenuItemsEnabled(suspendDebugMenuItems, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
487 setMenuItemsEnabled(resumeDebugMenuItems, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
488 debugMenu.setEnabled(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
489 attached = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
490 suspended = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
491
a61af66fc99e Initial load
duke
parents:
diff changeset
492 if (getAgent().isJavaMode()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
493 System.err.println("Java HotSpot(TM) virtual machine detected.");
a61af66fc99e Initial load
duke
parents:
diff changeset
494 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
495 System.err.println("(No Java(TM) virtual machine detected)");
a61af66fc99e Initial load
duke
parents:
diff changeset
496 }
a61af66fc99e Initial load
duke
parents:
diff changeset
497
a61af66fc99e Initial load
duke
parents:
diff changeset
498 // Set up editor map
a61af66fc99e Initial load
duke
parents:
diff changeset
499 editors = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
500
a61af66fc99e Initial load
duke
parents:
diff changeset
501 // Initialize breakpoints
a61af66fc99e Initial load
duke
parents:
diff changeset
502 fileToBreakpointMap = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
503
a61af66fc99e Initial load
duke
parents:
diff changeset
504 // Create combined stack trace and local variable panel
a61af66fc99e Initial load
duke
parents:
diff changeset
505 JPanel framePanel = new JPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
506 framePanel.setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
507 framePanel.setBorder(GraphicsUtilities.newBorder(5));
a61af66fc99e Initial load
duke
parents:
diff changeset
508 localsPanel = new VariablePanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
509 JTabbedPane tab = new JTabbedPane();
a61af66fc99e Initial load
duke
parents:
diff changeset
510 tab.addTab("Locals", localsPanel);
a61af66fc99e Initial load
duke
parents:
diff changeset
511 tab.setTabPlacement(JTabbedPane.BOTTOM);
a61af66fc99e Initial load
duke
parents:
diff changeset
512 framePanel.add(tab, BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
513 JPanel stackPanel = new JPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
514 stackPanel.setLayout(new BoxLayout(stackPanel, BoxLayout.X_AXIS));
a61af66fc99e Initial load
duke
parents:
diff changeset
515 stackPanel.add(new JLabel("Context:"));
a61af66fc99e Initial load
duke
parents:
diff changeset
516 stackPanel.add(Box.createHorizontalStrut(5));
a61af66fc99e Initial load
duke
parents:
diff changeset
517 stackTracePanel = new StackTracePanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
518 stackTracePanel.addListener(new StackTracePanel.Listener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
519 public void frameChanged(CFrame fr, JavaVFrame jfr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
520 setCurrentFrame(fr, jfr);
a61af66fc99e Initial load
duke
parents:
diff changeset
521 }
a61af66fc99e Initial load
duke
parents:
diff changeset
522 });
a61af66fc99e Initial load
duke
parents:
diff changeset
523 stackPanel.add(stackTracePanel);
a61af66fc99e Initial load
duke
parents:
diff changeset
524 framePanel.add(stackPanel, BorderLayout.NORTH);
a61af66fc99e Initial load
duke
parents:
diff changeset
525 stackFrame = newFrame("Stack");
a61af66fc99e Initial load
duke
parents:
diff changeset
526 stackFrame.getContentPane().setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
527 stackFrame.getContentPane().add(framePanel, BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
528 stackFrame.setResizable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
529 stackFrame.setClosable(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
530 addFrame(stackFrame);
a61af66fc99e Initial load
duke
parents:
diff changeset
531 stackFrame.setSize(400, 200);
a61af66fc99e Initial load
duke
parents:
diff changeset
532 GraphicsUtilities.moveToInContainer(stackFrame.getComponent(), 0.0f, 1.0f, 0, 20);
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 0
diff changeset
533 stackFrame.setVisible(true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
534
a61af66fc99e Initial load
duke
parents:
diff changeset
535 // Create register panel
a61af66fc99e Initial load
duke
parents:
diff changeset
536 registerPanel = new RegisterPanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
537 registerPanel.setFont(fixedWidthFont);
a61af66fc99e Initial load
duke
parents:
diff changeset
538 registerFrame = newFrame("Registers");
a61af66fc99e Initial load
duke
parents:
diff changeset
539 registerFrame.getContentPane().setLayout(new BorderLayout());
a61af66fc99e Initial load
duke
parents:
diff changeset
540 registerFrame.getContentPane().add(registerPanel, BorderLayout.CENTER);
a61af66fc99e Initial load
duke
parents:
diff changeset
541 addFrame(registerFrame);
a61af66fc99e Initial load
duke
parents:
diff changeset
542 registerFrame.setResizable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
543 registerFrame.setClosable(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
544 registerFrame.setSize(225, 200);
a61af66fc99e Initial load
duke
parents:
diff changeset
545 GraphicsUtilities.moveToInContainer(registerFrame.getComponent(),
a61af66fc99e Initial load
duke
parents:
diff changeset
546 1.0f, 0.0f, 0, 0);
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 0
diff changeset
547 registerFrame.setVisible(true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
548
a61af66fc99e Initial load
duke
parents:
diff changeset
549 resetCurrentThread();
a61af66fc99e Initial load
duke
parents:
diff changeset
550 } catch (DebuggerException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
551 final String errMsg = formatMessage(e.getMessage(), 80);
a61af66fc99e Initial load
duke
parents:
diff changeset
552 setMenuItemsEnabled(attachMenuItems, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
553 showMessageDialog("Unable to connect to process ID " + pid + ":\n\n" + errMsg,
a61af66fc99e Initial load
duke
parents:
diff changeset
554 "Unable to Connect",
a61af66fc99e Initial load
duke
parents:
diff changeset
555 JOptionPane.WARNING_MESSAGE);
a61af66fc99e Initial load
duke
parents:
diff changeset
556 getAgent().detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
557 }
a61af66fc99e Initial load
duke
parents:
diff changeset
558 }
a61af66fc99e Initial load
duke
parents:
diff changeset
559
a61af66fc99e Initial load
duke
parents:
diff changeset
560 private synchronized void detachDebugger() {
a61af66fc99e Initial load
duke
parents:
diff changeset
561 if (!attached) {
a61af66fc99e Initial load
duke
parents:
diff changeset
562 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
563 }
a61af66fc99e Initial load
duke
parents:
diff changeset
564 if (isSuspended()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
565 resume(); // Necessary for JVMDI resumption
a61af66fc99e Initial load
duke
parents:
diff changeset
566 }
a61af66fc99e Initial load
duke
parents:
diff changeset
567 getAgent().detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
568 // FIXME: clear out breakpoints (both Java and C/C++) from target
a61af66fc99e Initial load
duke
parents:
diff changeset
569 // process
a61af66fc99e Initial load
duke
parents:
diff changeset
570 sourceFileToLineNumberInfoMap = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
571 fileToBreakpointMap = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
572 threadToJavaThreadMap = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
573 editors = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
574 attached = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
575 }
a61af66fc99e Initial load
duke
parents:
diff changeset
576
a61af66fc99e Initial load
duke
parents:
diff changeset
577 private synchronized void detach() {
a61af66fc99e Initial load
duke
parents:
diff changeset
578 detachDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
579 setMenuItemsEnabled(attachMenuItems, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
580 setMenuItemsEnabled(detachMenuItems, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
581 debugMenu.setEnabled(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
582 if (mdiMode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
583 // FIXME: is this sufficient, or will I have to do anything else
a61af66fc99e Initial load
duke
parents:
diff changeset
584 // to the components to kill them off? What about WorkerThreads?
a61af66fc99e Initial load
duke
parents:
diff changeset
585 desktop.removeAll();
a61af66fc99e Initial load
duke
parents:
diff changeset
586 desktop.invalidate();
a61af66fc99e Initial load
duke
parents:
diff changeset
587 desktop.validate();
a61af66fc99e Initial load
duke
parents:
diff changeset
588 desktop.repaint();
a61af66fc99e Initial load
duke
parents:
diff changeset
589 }
a61af66fc99e Initial load
duke
parents:
diff changeset
590 // FIXME: keep track of all windows and close them even in non-MDI
a61af66fc99e Initial load
duke
parents:
diff changeset
591 // mode
a61af66fc99e Initial load
duke
parents:
diff changeset
592 debugEventTimer.stop();
a61af66fc99e Initial load
duke
parents:
diff changeset
593 }
a61af66fc99e Initial load
duke
parents:
diff changeset
594
a61af66fc99e Initial load
duke
parents:
diff changeset
595 // Returns a Debugger for processes on the local machine. This is
a61af66fc99e Initial load
duke
parents:
diff changeset
596 // only used to fetch the process list.
a61af66fc99e Initial load
duke
parents:
diff changeset
597 private Debugger getLocalDebugger() {
a61af66fc99e Initial load
duke
parents:
diff changeset
598 if (localDebugger == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
599 String os = PlatformInfo.getOS();
a61af66fc99e Initial load
duke
parents:
diff changeset
600 String cpu = PlatformInfo.getCPU();
a61af66fc99e Initial load
duke
parents:
diff changeset
601
a61af66fc99e Initial load
duke
parents:
diff changeset
602 if (os.equals("win32")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
603 if (!cpu.equals("x86")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
604 throw new DebuggerException("Unsupported CPU \"" + cpu + "\" for Windows");
a61af66fc99e Initial load
duke
parents:
diff changeset
605 }
a61af66fc99e Initial load
duke
parents:
diff changeset
606
a61af66fc99e Initial load
duke
parents:
diff changeset
607 localDebugger = new Win32DebuggerLocal(new MachineDescriptionIntelX86(), true);
a61af66fc99e Initial load
duke
parents:
diff changeset
608 } else if (os.equals("linux")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
609 if (!cpu.equals("x86")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
610 throw new DebuggerException("Unsupported CPU \"" + cpu + "\" for Linux");
a61af66fc99e Initial load
duke
parents:
diff changeset
611 }
a61af66fc99e Initial load
duke
parents:
diff changeset
612
a61af66fc99e Initial load
duke
parents:
diff changeset
613 // FIXME: figure out how to specify path to debugger module
a61af66fc99e Initial load
duke
parents:
diff changeset
614 throw new RuntimeException("FIXME: figure out how to specify path to debugger module");
a61af66fc99e Initial load
duke
parents:
diff changeset
615 // localDebugger = new PosixDebuggerLocal(new MachineDescriptionIntelX86(), true);
a61af66fc99e Initial load
duke
parents:
diff changeset
616 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
617 // FIXME: port to Solaris
a61af66fc99e Initial load
duke
parents:
diff changeset
618 throw new DebuggerException("Unsupported OS \"" + os + "\"");
a61af66fc99e Initial load
duke
parents:
diff changeset
619 }
a61af66fc99e Initial load
duke
parents:
diff changeset
620
a61af66fc99e Initial load
duke
parents:
diff changeset
621 // FIXME: we require that the primitive type sizes be configured
a61af66fc99e Initial load
duke
parents:
diff changeset
622 // in order to use basic functionality in class Address such as
a61af66fc99e Initial load
duke
parents:
diff changeset
623 // the fetching of floating-point values. There are a lot of
a61af66fc99e Initial load
duke
parents:
diff changeset
624 // assumptions in the current code that Java floats and doubles
a61af66fc99e Initial load
duke
parents:
diff changeset
625 // are of equivalent size to C values. The configurability of the
a61af66fc99e Initial load
duke
parents:
diff changeset
626 // primitive type sizes hasn't seemed necessary and in this kind
a61af66fc99e Initial load
duke
parents:
diff changeset
627 // of debugging scenario (namely, debugging arbitrary C++
a61af66fc99e Initial load
duke
parents:
diff changeset
628 // processes) it appears difficult to support that kind of
a61af66fc99e Initial load
duke
parents:
diff changeset
629 // flexibility.
a61af66fc99e Initial load
duke
parents:
diff changeset
630 localDebugger.configureJavaPrimitiveTypeSizes(1, 1, 2, 8, 4, 4, 8, 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
631 }
a61af66fc99e Initial load
duke
parents:
diff changeset
632
a61af66fc99e Initial load
duke
parents:
diff changeset
633 return localDebugger;
a61af66fc99e Initial load
duke
parents:
diff changeset
634 }
a61af66fc99e Initial load
duke
parents:
diff changeset
635
a61af66fc99e Initial load
duke
parents:
diff changeset
636 private BugSpotAgent getAgent() {
a61af66fc99e Initial load
duke
parents:
diff changeset
637 return agent;
a61af66fc99e Initial load
duke
parents:
diff changeset
638 }
a61af66fc99e Initial load
duke
parents:
diff changeset
639
a61af66fc99e Initial load
duke
parents:
diff changeset
640 private Debugger getDebugger() {
a61af66fc99e Initial load
duke
parents:
diff changeset
641 return getAgent().getDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
642 }
a61af66fc99e Initial load
duke
parents:
diff changeset
643
a61af66fc99e Initial load
duke
parents:
diff changeset
644 private CDebugger getCDebugger() {
a61af66fc99e Initial load
duke
parents:
diff changeset
645 return getAgent().getCDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
646 }
a61af66fc99e Initial load
duke
parents:
diff changeset
647
a61af66fc99e Initial load
duke
parents:
diff changeset
648 private void resetCurrentThread() {
a61af66fc99e Initial load
duke
parents:
diff changeset
649 setCurrentThread((ThreadProxy) getCDebugger().getThreadList().get(0));
a61af66fc99e Initial load
duke
parents:
diff changeset
650 }
a61af66fc99e Initial load
duke
parents:
diff changeset
651
a61af66fc99e Initial load
duke
parents:
diff changeset
652 private void setCurrentThread(ThreadProxy t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
653 // Create stack trace
a61af66fc99e Initial load
duke
parents:
diff changeset
654 // FIXME: add ability to intermix C/Java frames
a61af66fc99e Initial load
duke
parents:
diff changeset
655 java.util.List trace = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
656 CFrame fr = getCDebugger().topFrameForThread(t);
a61af66fc99e Initial load
duke
parents:
diff changeset
657 while (fr != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
658 trace.add(new StackTraceEntry(fr, getCDebugger()));
a61af66fc99e Initial load
duke
parents:
diff changeset
659 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
660 fr = fr.sender();
a61af66fc99e Initial load
duke
parents:
diff changeset
661 } catch (AddressException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
662 e.printStackTrace();
a61af66fc99e Initial load
duke
parents:
diff changeset
663 showMessageDialog("Error while walking stack; stack trace will be truncated\n(see console for details)",
a61af66fc99e Initial load
duke
parents:
diff changeset
664 "Error walking stack",
a61af66fc99e Initial load
duke
parents:
diff changeset
665 JOptionPane.WARNING_MESSAGE);
a61af66fc99e Initial load
duke
parents:
diff changeset
666 fr = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
667 }
a61af66fc99e Initial load
duke
parents:
diff changeset
668 }
a61af66fc99e Initial load
duke
parents:
diff changeset
669 JavaThread jthread = javaThreadForProxy(t);
a61af66fc99e Initial load
duke
parents:
diff changeset
670 if (jthread != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
671 // Java mode, and we have a Java thread.
a61af66fc99e Initial load
duke
parents:
diff changeset
672 // Find all Java frames on the stack. We currently do this in a
a61af66fc99e Initial load
duke
parents:
diff changeset
673 // manner which involves minimal interaction between the Java
a61af66fc99e Initial load
duke
parents:
diff changeset
674 // and C/C++ debugging systems: any C frame which has a PC in an
a61af66fc99e Initial load
duke
parents:
diff changeset
675 // unknown location (i.e., not in any DSO) is assumed to be a
a61af66fc99e Initial load
duke
parents:
diff changeset
676 // Java frame. We merge stack segments of unknown frames with
a61af66fc99e Initial load
duke
parents:
diff changeset
677 // segments of Java frames beginning with native methods.
a61af66fc99e Initial load
duke
parents:
diff changeset
678 java.util.List javaTrace = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
679 VFrame vf = jthread.getLastJavaVFrameDbg();
a61af66fc99e Initial load
duke
parents:
diff changeset
680 while (vf != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
681 if (vf.isJavaFrame()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
682 javaTrace.add(new StackTraceEntry((JavaVFrame) vf));
a61af66fc99e Initial load
duke
parents:
diff changeset
683 vf = vf.sender();
a61af66fc99e Initial load
duke
parents:
diff changeset
684 }
a61af66fc99e Initial load
duke
parents:
diff changeset
685 }
a61af66fc99e Initial load
duke
parents:
diff changeset
686 // Merge stack traces
a61af66fc99e Initial load
duke
parents:
diff changeset
687 java.util.List mergedTrace = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
688 int c = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
689 int j = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
690 while (c < trace.size()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
691 StackTraceEntry entry = (StackTraceEntry) trace.get(c);
a61af66fc99e Initial load
duke
parents:
diff changeset
692 if (entry.isUnknownCFrame()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
693 boolean gotJavaFrame = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
694 while (j < javaTrace.size()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
695 StackTraceEntry javaEntry = (StackTraceEntry) javaTrace.get(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
696 JavaVFrame jvf = javaEntry.getJavaFrame();
a61af66fc99e Initial load
duke
parents:
diff changeset
697 Method m = jvf.getMethod();
a61af66fc99e Initial load
duke
parents:
diff changeset
698 if (!m.isNative() || !gotJavaFrame) {
a61af66fc99e Initial load
duke
parents:
diff changeset
699 gotJavaFrame = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
700 mergedTrace.add(javaEntry);
a61af66fc99e Initial load
duke
parents:
diff changeset
701 ++j;
a61af66fc99e Initial load
duke
parents:
diff changeset
702 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
703 break; // Reached native method; have intervening C frames
a61af66fc99e Initial load
duke
parents:
diff changeset
704 }
a61af66fc99e Initial load
duke
parents:
diff changeset
705 }
a61af66fc99e Initial load
duke
parents:
diff changeset
706 if (gotJavaFrame) {
a61af66fc99e Initial load
duke
parents:
diff changeset
707 // Skip this sequence of unknown frames, as we've
a61af66fc99e Initial load
duke
parents:
diff changeset
708 // successfully identified it as Java frames
a61af66fc99e Initial load
duke
parents:
diff changeset
709 while (c < trace.size() && entry.isUnknownCFrame()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
710 ++c;
a61af66fc99e Initial load
duke
parents:
diff changeset
711 if (c < trace.size()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
712 entry = (StackTraceEntry) trace.get(c);
a61af66fc99e Initial load
duke
parents:
diff changeset
713 }
a61af66fc99e Initial load
duke
parents:
diff changeset
714 }
a61af66fc99e Initial load
duke
parents:
diff changeset
715 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
716 }
a61af66fc99e Initial load
duke
parents:
diff changeset
717 }
a61af66fc99e Initial load
duke
parents:
diff changeset
718 // If we get here, we either have an unknown frame we didn't
a61af66fc99e Initial load
duke
parents:
diff changeset
719 // know how to categorize or we have a known C frame. Add it
a61af66fc99e Initial load
duke
parents:
diff changeset
720 // to the trace.
a61af66fc99e Initial load
duke
parents:
diff changeset
721 mergedTrace.add(entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
722 ++c;
a61af66fc99e Initial load
duke
parents:
diff changeset
723 }
a61af66fc99e Initial load
duke
parents:
diff changeset
724 trace = mergedTrace;
a61af66fc99e Initial load
duke
parents:
diff changeset
725 }
a61af66fc99e Initial load
duke
parents:
diff changeset
726 stackTracePanel.setTrace(trace);
a61af66fc99e Initial load
duke
parents:
diff changeset
727
a61af66fc99e Initial load
duke
parents:
diff changeset
728 registerPanel.update(t);
a61af66fc99e Initial load
duke
parents:
diff changeset
729 }
a61af66fc99e Initial load
duke
parents:
diff changeset
730
a61af66fc99e Initial load
duke
parents:
diff changeset
731 private void setCurrentFrame(CFrame fr, JavaVFrame jfr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
732 localsPanel.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
733
a61af66fc99e Initial load
duke
parents:
diff changeset
734 if (fr != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
735 localsPanel.update(fr);
a61af66fc99e Initial load
duke
parents:
diff changeset
736
a61af66fc99e Initial load
duke
parents:
diff changeset
737 // FIXME: load source file if we can find it, otherwise display disassembly
a61af66fc99e Initial load
duke
parents:
diff changeset
738 LoadObject lo = getCDebugger().loadObjectContainingPC(fr.pc());
a61af66fc99e Initial load
duke
parents:
diff changeset
739 if (lo != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
740 CDebugInfoDataBase db = lo.getDebugInfoDataBase();
a61af66fc99e Initial load
duke
parents:
diff changeset
741 if (db != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
742 LineNumberInfo info = db.lineNumberForPC(fr.pc());
a61af66fc99e Initial load
duke
parents:
diff changeset
743 if (info != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
744 System.err.println("PC " + fr.pc() + ": Source file \"" +
a61af66fc99e Initial load
duke
parents:
diff changeset
745 info.getSourceFileName() +
a61af66fc99e Initial load
duke
parents:
diff changeset
746 "\", line number " +
a61af66fc99e Initial load
duke
parents:
diff changeset
747 info.getLineNumber() +
a61af66fc99e Initial load
duke
parents:
diff changeset
748 ", PC range [" +
a61af66fc99e Initial load
duke
parents:
diff changeset
749 info.getStartPC() +
a61af66fc99e Initial load
duke
parents:
diff changeset
750 ", " +
a61af66fc99e Initial load
duke
parents:
diff changeset
751 info.getEndPC() +
a61af66fc99e Initial load
duke
parents:
diff changeset
752 ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
753 // OK, here we go...
a61af66fc99e Initial load
duke
parents:
diff changeset
754 showLineNumber(null, info.getSourceFileName(), info.getLineNumber());
a61af66fc99e Initial load
duke
parents:
diff changeset
755 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
756 System.err.println("(No line number information for PC " + fr.pc() + ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
757 // Dump line number information for database
a61af66fc99e Initial load
duke
parents:
diff changeset
758 db.iterate(new LineNumberVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
759 public void doLineNumber(LineNumberInfo info) {
a61af66fc99e Initial load
duke
parents:
diff changeset
760 System.err.println(" Source file \"" +
a61af66fc99e Initial load
duke
parents:
diff changeset
761 info.getSourceFileName() +
a61af66fc99e Initial load
duke
parents:
diff changeset
762 "\", line number " +
a61af66fc99e Initial load
duke
parents:
diff changeset
763 info.getLineNumber() +
a61af66fc99e Initial load
duke
parents:
diff changeset
764 ", PC range [" +
a61af66fc99e Initial load
duke
parents:
diff changeset
765 info.getStartPC() +
a61af66fc99e Initial load
duke
parents:
diff changeset
766 ", " +
a61af66fc99e Initial load
duke
parents:
diff changeset
767 info.getEndPC() +
a61af66fc99e Initial load
duke
parents:
diff changeset
768 ")");
a61af66fc99e Initial load
duke
parents:
diff changeset
769 }
a61af66fc99e Initial load
duke
parents:
diff changeset
770 });
a61af66fc99e Initial load
duke
parents:
diff changeset
771 }
a61af66fc99e Initial load
duke
parents:
diff changeset
772 }
a61af66fc99e Initial load
duke
parents:
diff changeset
773 }
a61af66fc99e Initial load
duke
parents:
diff changeset
774 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
775 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
776 Assert.that(jfr != null, "Must have either C or Java frame");
a61af66fc99e Initial load
duke
parents:
diff changeset
777 }
a61af66fc99e Initial load
duke
parents:
diff changeset
778 localsPanel.update(jfr);
a61af66fc99e Initial load
duke
parents:
diff changeset
779 // See whether we can locate source file and line number
a61af66fc99e Initial load
duke
parents:
diff changeset
780 // FIXME: infer pathmap entries from user's locating of this
a61af66fc99e Initial load
duke
parents:
diff changeset
781 // source file
a61af66fc99e Initial load
duke
parents:
diff changeset
782 // FIXME: figure out what to do for native methods. Possible to
a61af66fc99e Initial load
duke
parents:
diff changeset
783 // go to line number for the native method declaration?
a61af66fc99e Initial load
duke
parents:
diff changeset
784 Method m = jfr.getMethod();
a61af66fc99e Initial load
duke
parents:
diff changeset
785 Symbol sfn = ((InstanceKlass) m.getMethodHolder()).getSourceFileName();
a61af66fc99e Initial load
duke
parents:
diff changeset
786 if (sfn != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
787 int bci = jfr.getBCI();
a61af66fc99e Initial load
duke
parents:
diff changeset
788 int lineNo = m.getLineNumberFromBCI(bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
789 if (lineNo >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
790 // FIXME: show disassembly otherwise
a61af66fc99e Initial load
duke
parents:
diff changeset
791 showLineNumber(packageName(m.getMethodHolder().getName().asString()),
a61af66fc99e Initial load
duke
parents:
diff changeset
792 sfn.asString(), lineNo);
a61af66fc99e Initial load
duke
parents:
diff changeset
793 }
a61af66fc99e Initial load
duke
parents:
diff changeset
794 }
a61af66fc99e Initial load
duke
parents:
diff changeset
795 }
a61af66fc99e Initial load
duke
parents:
diff changeset
796 }
a61af66fc99e Initial load
duke
parents:
diff changeset
797
a61af66fc99e Initial load
duke
parents:
diff changeset
798 private String packageName(String str) {
a61af66fc99e Initial load
duke
parents:
diff changeset
799 int idx = str.lastIndexOf('/');
a61af66fc99e Initial load
duke
parents:
diff changeset
800 if (idx < 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
801 return "";
a61af66fc99e Initial load
duke
parents:
diff changeset
802 }
a61af66fc99e Initial load
duke
parents:
diff changeset
803 return str.substring(0, idx).replace('/', '.');
a61af66fc99e Initial load
duke
parents:
diff changeset
804 }
a61af66fc99e Initial load
duke
parents:
diff changeset
805
a61af66fc99e Initial load
duke
parents:
diff changeset
806 private JavaThread javaThreadForProxy(ThreadProxy t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
807 if (!getAgent().isJavaMode()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
808 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
809 }
a61af66fc99e Initial load
duke
parents:
diff changeset
810 if (threadToJavaThreadMap == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
811 threadToJavaThreadMap = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
812 Threads threads = VM.getVM().getThreads();
a61af66fc99e Initial load
duke
parents:
diff changeset
813 for (JavaThread thr = threads.first(); thr != null; thr = thr.next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
814 threadToJavaThreadMap.put(thr.getThreadProxy(), thr);
a61af66fc99e Initial load
duke
parents:
diff changeset
815 }
a61af66fc99e Initial load
duke
parents:
diff changeset
816 }
a61af66fc99e Initial load
duke
parents:
diff changeset
817 return (JavaThread) threadToJavaThreadMap.get(t);
a61af66fc99e Initial load
duke
parents:
diff changeset
818 }
a61af66fc99e Initial load
duke
parents:
diff changeset
819
a61af66fc99e Initial load
duke
parents:
diff changeset
820 private static JMenu createMenu(String name, char mnemonic, int mnemonicPos) {
a61af66fc99e Initial load
duke
parents:
diff changeset
821 JMenu menu = new JMenu(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
822 menu.setMnemonic(mnemonic);
a61af66fc99e Initial load
duke
parents:
diff changeset
823 menu.setDisplayedMnemonicIndex(mnemonicPos);
a61af66fc99e Initial load
duke
parents:
diff changeset
824 return menu;
a61af66fc99e Initial load
duke
parents:
diff changeset
825 }
a61af66fc99e Initial load
duke
parents:
diff changeset
826
a61af66fc99e Initial load
duke
parents:
diff changeset
827 private static JMenuItem createMenuItem(String name, ActionListener l) {
a61af66fc99e Initial load
duke
parents:
diff changeset
828 JMenuItem item = new JMenuItem(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
829 item.addActionListener(l);
a61af66fc99e Initial load
duke
parents:
diff changeset
830 return item;
a61af66fc99e Initial load
duke
parents:
diff changeset
831 }
a61af66fc99e Initial load
duke
parents:
diff changeset
832
a61af66fc99e Initial load
duke
parents:
diff changeset
833 private static JMenuItem createMenuItemInternal(String name, ActionListener l, int accelerator, int modifiers) {
a61af66fc99e Initial load
duke
parents:
diff changeset
834 JMenuItem item = createMenuItem(name, l);
a61af66fc99e Initial load
duke
parents:
diff changeset
835 item.setAccelerator(KeyStroke.getKeyStroke(accelerator, modifiers));
a61af66fc99e Initial load
duke
parents:
diff changeset
836 return item;
a61af66fc99e Initial load
duke
parents:
diff changeset
837 }
a61af66fc99e Initial load
duke
parents:
diff changeset
838
a61af66fc99e Initial load
duke
parents:
diff changeset
839 private static JMenuItem createMenuItem(String name, ActionListener l, int accelerator) {
a61af66fc99e Initial load
duke
parents:
diff changeset
840 return createMenuItemInternal(name, l, accelerator, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
841 }
a61af66fc99e Initial load
duke
parents:
diff changeset
842
a61af66fc99e Initial load
duke
parents:
diff changeset
843 private static JMenuItem createMenuItem(String name, ActionListener l, char mnemonic, int mnemonicPos) {
a61af66fc99e Initial load
duke
parents:
diff changeset
844 JMenuItem item = createMenuItem(name, l);
a61af66fc99e Initial load
duke
parents:
diff changeset
845 item.setMnemonic(mnemonic);
a61af66fc99e Initial load
duke
parents:
diff changeset
846 item.setDisplayedMnemonicIndex(mnemonicPos);
a61af66fc99e Initial load
duke
parents:
diff changeset
847 return item;
a61af66fc99e Initial load
duke
parents:
diff changeset
848 }
a61af66fc99e Initial load
duke
parents:
diff changeset
849
a61af66fc99e Initial load
duke
parents:
diff changeset
850 private static JMenuItem createMenuItem(String name,
a61af66fc99e Initial load
duke
parents:
diff changeset
851 ActionListener l,
a61af66fc99e Initial load
duke
parents:
diff changeset
852 int accelerator,
a61af66fc99e Initial load
duke
parents:
diff changeset
853 int acceleratorMods,
a61af66fc99e Initial load
duke
parents:
diff changeset
854 char mnemonic,
a61af66fc99e Initial load
duke
parents:
diff changeset
855 int mnemonicPos) {
a61af66fc99e Initial load
duke
parents:
diff changeset
856 JMenuItem item = createMenuItemInternal(name, l, accelerator, acceleratorMods);
a61af66fc99e Initial load
duke
parents:
diff changeset
857 item.setMnemonic(mnemonic);
a61af66fc99e Initial load
duke
parents:
diff changeset
858 item.setDisplayedMnemonicIndex(mnemonicPos);
a61af66fc99e Initial load
duke
parents:
diff changeset
859 return item;
a61af66fc99e Initial load
duke
parents:
diff changeset
860 }
a61af66fc99e Initial load
duke
parents:
diff changeset
861
a61af66fc99e Initial load
duke
parents:
diff changeset
862 /** Punctuates the given string with \n's where necessary to not
a61af66fc99e Initial load
duke
parents:
diff changeset
863 exceed the given number of characters per line. Strips
a61af66fc99e Initial load
duke
parents:
diff changeset
864 extraneous whitespace. */
a61af66fc99e Initial load
duke
parents:
diff changeset
865 private static String formatMessage(String message, int charsPerLine) {
a61af66fc99e Initial load
duke
parents:
diff changeset
866 StringBuffer buf = new StringBuffer(message.length());
a61af66fc99e Initial load
duke
parents:
diff changeset
867 StringTokenizer tokenizer = new StringTokenizer(message);
a61af66fc99e Initial load
duke
parents:
diff changeset
868 int curLineLength = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
869 while (tokenizer.hasMoreTokens()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
870 String tok = tokenizer.nextToken();
a61af66fc99e Initial load
duke
parents:
diff changeset
871 if (curLineLength + tok.length() > charsPerLine) {
a61af66fc99e Initial load
duke
parents:
diff changeset
872 buf.append('\n');
a61af66fc99e Initial load
duke
parents:
diff changeset
873 curLineLength = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
874 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
875 if (curLineLength != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
876 buf.append(' ');
a61af66fc99e Initial load
duke
parents:
diff changeset
877 ++curLineLength;
a61af66fc99e Initial load
duke
parents:
diff changeset
878 }
a61af66fc99e Initial load
duke
parents:
diff changeset
879 }
a61af66fc99e Initial load
duke
parents:
diff changeset
880 buf.append(tok);
a61af66fc99e Initial load
duke
parents:
diff changeset
881 curLineLength += tok.length();
a61af66fc99e Initial load
duke
parents:
diff changeset
882 }
a61af66fc99e Initial load
duke
parents:
diff changeset
883 return buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
884 }
a61af66fc99e Initial load
duke
parents:
diff changeset
885
a61af66fc99e Initial load
duke
parents:
diff changeset
886 private void setMenuItemsEnabled(java.util.List items, boolean enabled) {
a61af66fc99e Initial load
duke
parents:
diff changeset
887 for (Iterator iter = items.iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
888 ((JMenuItem) iter.next()).setEnabled(enabled);
a61af66fc99e Initial load
duke
parents:
diff changeset
889 }
a61af66fc99e Initial load
duke
parents:
diff changeset
890 }
a61af66fc99e Initial load
duke
parents:
diff changeset
891
a61af66fc99e Initial load
duke
parents:
diff changeset
892 private void showMessageDialog(final String message, final String title, final int jOptionPaneKind) {
a61af66fc99e Initial load
duke
parents:
diff changeset
893 SwingUtilities.invokeLater(new Runnable() {
a61af66fc99e Initial load
duke
parents:
diff changeset
894 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
895 if (mdiMode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
896 JOptionPane.showInternalMessageDialog(desktop, message, title, jOptionPaneKind);
a61af66fc99e Initial load
duke
parents:
diff changeset
897 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
898 JOptionPane.showMessageDialog(null, message, title, jOptionPaneKind);
a61af66fc99e Initial load
duke
parents:
diff changeset
899 }
a61af66fc99e Initial load
duke
parents:
diff changeset
900 }
a61af66fc99e Initial load
duke
parents:
diff changeset
901 });
a61af66fc99e Initial load
duke
parents:
diff changeset
902 }
a61af66fc99e Initial load
duke
parents:
diff changeset
903
a61af66fc99e Initial load
duke
parents:
diff changeset
904 private FrameWrapper newFrame(String title) {
a61af66fc99e Initial load
duke
parents:
diff changeset
905 if (mdiMode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
906 return new JInternalFrameWrapper(new JInternalFrame(title));
a61af66fc99e Initial load
duke
parents:
diff changeset
907 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
908 return new JFrameWrapper(new JFrame(title));
a61af66fc99e Initial load
duke
parents:
diff changeset
909 }
a61af66fc99e Initial load
duke
parents:
diff changeset
910 }
a61af66fc99e Initial load
duke
parents:
diff changeset
911
a61af66fc99e Initial load
duke
parents:
diff changeset
912 private void addFrame(FrameWrapper frame) {
a61af66fc99e Initial load
duke
parents:
diff changeset
913 if (mdiMode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
914 desktop.add(frame.getComponent());
a61af66fc99e Initial load
duke
parents:
diff changeset
915 }
a61af66fc99e Initial load
duke
parents:
diff changeset
916 }
a61af66fc99e Initial load
duke
parents:
diff changeset
917
a61af66fc99e Initial load
duke
parents:
diff changeset
918 private void removeFrame(FrameWrapper frame) {
a61af66fc99e Initial load
duke
parents:
diff changeset
919 if (mdiMode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
920 desktop.remove(frame.getComponent());
a61af66fc99e Initial load
duke
parents:
diff changeset
921 desktop.invalidate();
a61af66fc99e Initial load
duke
parents:
diff changeset
922 desktop.validate();
a61af66fc99e Initial load
duke
parents:
diff changeset
923 desktop.repaint();
a61af66fc99e Initial load
duke
parents:
diff changeset
924 }
a61af66fc99e Initial load
duke
parents:
diff changeset
925 // FIXME: do something when not in MDI mode
a61af66fc99e Initial load
duke
parents:
diff changeset
926 }
a61af66fc99e Initial load
duke
parents:
diff changeset
927
a61af66fc99e Initial load
duke
parents:
diff changeset
928 private Dimension getParentDimension(Component c) {
a61af66fc99e Initial load
duke
parents:
diff changeset
929 if (mdiMode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
930 return desktop.getSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
931 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
932 return Toolkit.getDefaultToolkit().getScreenSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
933 }
a61af66fc99e Initial load
duke
parents:
diff changeset
934 }
a61af66fc99e Initial load
duke
parents:
diff changeset
935
a61af66fc99e Initial load
duke
parents:
diff changeset
936 // Default editor implementation
a61af66fc99e Initial load
duke
parents:
diff changeset
937 class DefaultEditor implements Editor {
a61af66fc99e Initial load
duke
parents:
diff changeset
938 private DefaultEditorFactory factory;
a61af66fc99e Initial load
duke
parents:
diff changeset
939 private FrameWrapper editorFrame;
a61af66fc99e Initial load
duke
parents:
diff changeset
940 private String filename;
a61af66fc99e Initial load
duke
parents:
diff changeset
941 private SourceCodePanel code;
a61af66fc99e Initial load
duke
parents:
diff changeset
942 private boolean shown;
a61af66fc99e Initial load
duke
parents:
diff changeset
943 private Object userData;
a61af66fc99e Initial load
duke
parents:
diff changeset
944
a61af66fc99e Initial load
duke
parents:
diff changeset
945 public DefaultEditor(DefaultEditorFactory fact, String filename, final EditorCommands comm) {
a61af66fc99e Initial load
duke
parents:
diff changeset
946 this.filename = filename;
a61af66fc99e Initial load
duke
parents:
diff changeset
947 this.factory = fact;
a61af66fc99e Initial load
duke
parents:
diff changeset
948 editorFrame = newFrame(filename);
a61af66fc99e Initial load
duke
parents:
diff changeset
949 code = new SourceCodePanel();
a61af66fc99e Initial load
duke
parents:
diff changeset
950 // FIXME: when font changes, change font in editors as well
a61af66fc99e Initial load
duke
parents:
diff changeset
951 code.setFont(fixedWidthFont);
a61af66fc99e Initial load
duke
parents:
diff changeset
952 editorFrame.getContentPane().add(code);
a61af66fc99e Initial load
duke
parents:
diff changeset
953 editorFrame.setClosable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
954 editorFrame.setResizable(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
955 editorFrame.setClosingActionListener(new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
956 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
957 comm.windowClosed(DefaultEditor.this);
a61af66fc99e Initial load
duke
parents:
diff changeset
958 removeFrame(editorFrame);
a61af66fc99e Initial load
duke
parents:
diff changeset
959 editorFrame.dispose();
a61af66fc99e Initial load
duke
parents:
diff changeset
960 factory.editorClosed(DefaultEditor.this);
a61af66fc99e Initial load
duke
parents:
diff changeset
961 }
a61af66fc99e Initial load
duke
parents:
diff changeset
962 });
a61af66fc99e Initial load
duke
parents:
diff changeset
963 editorFrame.setActivatedActionListener(new ActionListener() {
a61af66fc99e Initial load
duke
parents:
diff changeset
964 public void actionPerformed(ActionEvent e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
965 factory.makeEditorCurrent(DefaultEditor.this);
a61af66fc99e Initial load
duke
parents:
diff changeset
966 code.requestFocus();
a61af66fc99e Initial load
duke
parents:
diff changeset
967 }
a61af66fc99e Initial load
duke
parents:
diff changeset
968 });
a61af66fc99e Initial load
duke
parents:
diff changeset
969 code.setEditorCommands(comm, this);
a61af66fc99e Initial load
duke
parents:
diff changeset
970 }
a61af66fc99e Initial load
duke
parents:
diff changeset
971
a61af66fc99e Initial load
duke
parents:
diff changeset
972 public boolean openFile() { return code.openFile(filename); }
a61af66fc99e Initial load
duke
parents:
diff changeset
973 public String getSourceFileName() { return filename; }
a61af66fc99e Initial load
duke
parents:
diff changeset
974 public int getCurrentLineNumber() { return code.getCurrentLineNumber(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
975 public void showLineNumber(int lineNo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
976 if (!shown) {
a61af66fc99e Initial load
duke
parents:
diff changeset
977 addFrame(editorFrame);
a61af66fc99e Initial load
duke
parents:
diff changeset
978 GraphicsUtilities.reshapeToAspectRatio(editorFrame.getComponent(),
a61af66fc99e Initial load
duke
parents:
diff changeset
979 1.0f,
a61af66fc99e Initial load
duke
parents:
diff changeset
980 0.85f,
a61af66fc99e Initial load
duke
parents:
diff changeset
981 getParentDimension(editorFrame.getComponent()));
1385
bc32f286fae0 6945219: minor SA fixes
never
parents: 0
diff changeset
982 editorFrame.setVisible(true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
983 shown = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
984 }
a61af66fc99e Initial load
duke
parents:
diff changeset
985 code.showLineNumber(lineNo);
a61af66fc99e Initial load
duke
parents:
diff changeset
986 editorFrame.toFront();
a61af66fc99e Initial load
duke
parents:
diff changeset
987 }
a61af66fc99e Initial load
duke
parents:
diff changeset
988 public void highlightLineNumber(int lineNo) { code.highlightLineNumber(lineNo); }
a61af66fc99e Initial load
duke
parents:
diff changeset
989 public void showBreakpointAtLine(int lineNo) { code.showBreakpointAtLine(lineNo); }
a61af66fc99e Initial load
duke
parents:
diff changeset
990 public boolean hasBreakpointAtLine(int lineNo) { return code.hasBreakpointAtLine(lineNo); }
a61af66fc99e Initial load
duke
parents:
diff changeset
991 public void clearBreakpointAtLine(int lineNo) { code.clearBreakpointAtLine(lineNo); }
a61af66fc99e Initial load
duke
parents:
diff changeset
992 public void clearBreakpoints() { code.clearBreakpoints(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
993 public void setUserData(Object o) { userData = o; }
a61af66fc99e Initial load
duke
parents:
diff changeset
994 public Object getUserData() { return userData; }
a61af66fc99e Initial load
duke
parents:
diff changeset
995 public void toFront() { editorFrame.toFront();
a61af66fc99e Initial load
duke
parents:
diff changeset
996 factory.makeEditorCurrent(this); }
a61af66fc99e Initial load
duke
parents:
diff changeset
997 }
a61af66fc99e Initial load
duke
parents:
diff changeset
998
a61af66fc99e Initial load
duke
parents:
diff changeset
999 class DefaultEditorFactory implements EditorFactory {
a61af66fc99e Initial load
duke
parents:
diff changeset
1000 private LinkedList/*<Editor>*/ editors = new LinkedList();
a61af66fc99e Initial load
duke
parents:
diff changeset
1001
a61af66fc99e Initial load
duke
parents:
diff changeset
1002 public Editor openFile(String filename, EditorCommands commands) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1003 DefaultEditor editor = new DefaultEditor(this, filename, editorComm);
a61af66fc99e Initial load
duke
parents:
diff changeset
1004 if (!editor.openFile()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1005 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1006 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1007 return editor;
a61af66fc99e Initial load
duke
parents:
diff changeset
1008 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1009
a61af66fc99e Initial load
duke
parents:
diff changeset
1010 public Editor getCurrentEditor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1011 if (editors.isEmpty()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1012 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1013 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1014 return (Editor) editors.getFirst();
a61af66fc99e Initial load
duke
parents:
diff changeset
1015 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1016
a61af66fc99e Initial load
duke
parents:
diff changeset
1017 void editorClosed(Editor editor) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1018 editors.remove(editor);
a61af66fc99e Initial load
duke
parents:
diff changeset
1019 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1020
a61af66fc99e Initial load
duke
parents:
diff changeset
1021 void makeEditorCurrent(Editor editor) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1022 editors.remove(editor);
a61af66fc99e Initial load
duke
parents:
diff changeset
1023 editors.addFirst(editor);
a61af66fc99e Initial load
duke
parents:
diff changeset
1024 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1025 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1026
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 // Helper class for loading .java files; show only those with
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 // correct file name which are also in the correct package
a61af66fc99e Initial load
duke
parents:
diff changeset
1029 static class JavaFileFilter extends javax.swing.filechooser.FileFilter {
a61af66fc99e Initial load
duke
parents:
diff changeset
1030 private String packageName;
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 private String fileName;
a61af66fc99e Initial load
duke
parents:
diff changeset
1032
a61af66fc99e Initial load
duke
parents:
diff changeset
1033 JavaFileFilter(String packageName, String fileName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1034 this.packageName = packageName;
a61af66fc99e Initial load
duke
parents:
diff changeset
1035 this.fileName = fileName;
a61af66fc99e Initial load
duke
parents:
diff changeset
1036 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1037
a61af66fc99e Initial load
duke
parents:
diff changeset
1038 public boolean accept(File f) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1039 if (f.isDirectory()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1040 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1041 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1042 // This rejects most files
a61af66fc99e Initial load
duke
parents:
diff changeset
1043 if (!f.getName().equals(fileName)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1044 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1045 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1046 // Ensure selected file is in the correct package
a61af66fc99e Initial load
duke
parents:
diff changeset
1047 PackageScanner scanner = new PackageScanner();
a61af66fc99e Initial load
duke
parents:
diff changeset
1048 String pkg = scanner.scan(f);
a61af66fc99e Initial load
duke
parents:
diff changeset
1049 if (!pkg.equals(packageName)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1050 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1051 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1052 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1053 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1054
a61af66fc99e Initial load
duke
parents:
diff changeset
1055 public String getDescription() { return "Java source files"; }
a61af66fc99e Initial load
duke
parents:
diff changeset
1056 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1057
a61af66fc99e Initial load
duke
parents:
diff changeset
1058 // Auxiliary information used only for Java source files
a61af66fc99e Initial load
duke
parents:
diff changeset
1059 static class JavaUserData {
a61af66fc99e Initial load
duke
parents:
diff changeset
1060 private String packageName; // External format
a61af66fc99e Initial load
duke
parents:
diff changeset
1061 private String sourceFileName;
a61af66fc99e Initial load
duke
parents:
diff changeset
1062
a61af66fc99e Initial load
duke
parents:
diff changeset
1063 /** Source file name is equivalent to that found in the .java
a61af66fc99e Initial load
duke
parents:
diff changeset
1064 file; i.e., not a full path */
a61af66fc99e Initial load
duke
parents:
diff changeset
1065 JavaUserData(String packageName, String sourceFileName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1066 this.packageName = packageName;
a61af66fc99e Initial load
duke
parents:
diff changeset
1067 this.sourceFileName = sourceFileName;
a61af66fc99e Initial load
duke
parents:
diff changeset
1068 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1069
a61af66fc99e Initial load
duke
parents:
diff changeset
1070 String packageName() { return packageName; }
a61af66fc99e Initial load
duke
parents:
diff changeset
1071 String sourceFileName() { return sourceFileName; }
a61af66fc99e Initial load
duke
parents:
diff changeset
1072 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1073
a61af66fc99e Initial load
duke
parents:
diff changeset
1074 // Opens a source file. This makes it available for the setting of
a61af66fc99e Initial load
duke
parents:
diff changeset
1075 // lazy breakpoints.
a61af66fc99e Initial load
duke
parents:
diff changeset
1076 private void openSourceFile() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1077 JFileChooser chooser = new JFileChooser();
a61af66fc99e Initial load
duke
parents:
diff changeset
1078 chooser.setDialogTitle("Open source code file");
a61af66fc99e Initial load
duke
parents:
diff changeset
1079 chooser.setMultiSelectionEnabled(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1080 if (chooser.showOpenDialog(null) != JFileChooser.APPROVE_OPTION) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1081 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1082 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1083 File chosen = chooser.getSelectedFile();
a61af66fc99e Initial load
duke
parents:
diff changeset
1084 if (chosen == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1085 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1086 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1087
a61af66fc99e Initial load
duke
parents:
diff changeset
1088 // See whether we have a Java source file. If so, derive a package
a61af66fc99e Initial load
duke
parents:
diff changeset
1089 // name for it.
a61af66fc99e Initial load
duke
parents:
diff changeset
1090 String path = chosen.getPath();
a61af66fc99e Initial load
duke
parents:
diff changeset
1091 String name = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1092 JavaUserData data = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1093 if (path.endsWith(".java")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1094 PackageScanner scanner = new PackageScanner();
a61af66fc99e Initial load
duke
parents:
diff changeset
1095 String pkg = scanner.scan(chosen);
a61af66fc99e Initial load
duke
parents:
diff changeset
1096 // Now knowing both the package name and file name, we can put
a61af66fc99e Initial load
duke
parents:
diff changeset
1097 // this in the editor map and use it for setting breakpoints
a61af66fc99e Initial load
duke
parents:
diff changeset
1098 // later
a61af66fc99e Initial load
duke
parents:
diff changeset
1099 String fileName = chosen.getName();
a61af66fc99e Initial load
duke
parents:
diff changeset
1100 name = pkg + "." + fileName;
a61af66fc99e Initial load
duke
parents:
diff changeset
1101 data = new JavaUserData(pkg, fileName);
a61af66fc99e Initial load
duke
parents:
diff changeset
1102 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1103 // FIXME: need pathmap mechanism
a61af66fc99e Initial load
duke
parents:
diff changeset
1104 name = path;
a61af66fc99e Initial load
duke
parents:
diff changeset
1105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1106 Editor editor = (Editor) editors.get(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1107 if (editor == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1108 editor = editorFact.openFile(path, editorComm);
a61af66fc99e Initial load
duke
parents:
diff changeset
1109 if (editor == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1110 showMessageDialog("Unable to open file \"" + path + "\" -- unexpected error.",
a61af66fc99e Initial load
duke
parents:
diff changeset
1111 "Unable to open file",
a61af66fc99e Initial load
duke
parents:
diff changeset
1112 JOptionPane.WARNING_MESSAGE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1113 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1114 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1115 editors.put(name, editor);
a61af66fc99e Initial load
duke
parents:
diff changeset
1116 if (data != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1117 editor.setUserData(data);
a61af66fc99e Initial load
duke
parents:
diff changeset
1118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1119 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1120 editor.toFront();
a61af66fc99e Initial load
duke
parents:
diff changeset
1121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1122 editor.showLineNumber(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1123 // Show breakpoints as well if we have any for this file
a61af66fc99e Initial load
duke
parents:
diff changeset
1124 Set set = (Set) fileToBreakpointMap.get(editor.getSourceFileName());
a61af66fc99e Initial load
duke
parents:
diff changeset
1125 if (set != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1126 for (Iterator iter = set.iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1127 editor.showBreakpointAtLine(((Integer) iter.next()).intValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
1128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1131
a61af66fc99e Initial load
duke
parents:
diff changeset
1132 // Package name may be null, in which case the file is assumed to be
a61af66fc99e Initial load
duke
parents:
diff changeset
1133 // a C source file. Otherwise it is assumed to be a Java source file
a61af66fc99e Initial load
duke
parents:
diff changeset
1134 // and certain filtering rules will be applied.
a61af66fc99e Initial load
duke
parents:
diff changeset
1135 private void showLineNumber(String packageName, String fileName, int lineNumber) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1136 String name;
a61af66fc99e Initial load
duke
parents:
diff changeset
1137 if (packageName == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1138 name = fileName;
a61af66fc99e Initial load
duke
parents:
diff changeset
1139 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1140 name = packageName + "." + fileName;
a61af66fc99e Initial load
duke
parents:
diff changeset
1141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1142 Editor editor = (Editor) editors.get(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1143 if (editor == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1144 // See whether file exists
a61af66fc99e Initial load
duke
parents:
diff changeset
1145 File file = new File(fileName);
a61af66fc99e Initial load
duke
parents:
diff changeset
1146 String realFileName = fileName;
a61af66fc99e Initial load
duke
parents:
diff changeset
1147 if (!file.exists()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1148 // User must specify path to file
a61af66fc99e Initial load
duke
parents:
diff changeset
1149 JFileChooser chooser = new JFileChooser();
a61af66fc99e Initial load
duke
parents:
diff changeset
1150 chooser.setDialogTitle("Please locate " + fileName);
a61af66fc99e Initial load
duke
parents:
diff changeset
1151 chooser.setMultiSelectionEnabled(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1152 if (packageName != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1153 chooser.setFileFilter(new JavaFileFilter(packageName, fileName));
a61af66fc99e Initial load
duke
parents:
diff changeset
1154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1155 int res = chooser.showOpenDialog(null);
a61af66fc99e Initial load
duke
parents:
diff changeset
1156 if (res != JFileChooser.APPROVE_OPTION) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1157 // FIXME: show disassembly instead
a61af66fc99e Initial load
duke
parents:
diff changeset
1158 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1160 // FIXME: would like to infer more from the selection; i.e.,
a61af66fc99e Initial load
duke
parents:
diff changeset
1161 // a pathmap leading up to this file
a61af66fc99e Initial load
duke
parents:
diff changeset
1162 File chosen = chooser.getSelectedFile();
a61af66fc99e Initial load
duke
parents:
diff changeset
1163 if (chosen == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1164 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1166 realFileName = chosen.getPath();
a61af66fc99e Initial load
duke
parents:
diff changeset
1167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1168 // Now instruct editor factory to open file
a61af66fc99e Initial load
duke
parents:
diff changeset
1169 editor = editorFact.openFile(realFileName, editorComm);
a61af66fc99e Initial load
duke
parents:
diff changeset
1170 if (editor == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1171 showMessageDialog("Unable to open file \"" + realFileName + "\" -- unexpected error.",
a61af66fc99e Initial load
duke
parents:
diff changeset
1172 "Unable to open file",
a61af66fc99e Initial load
duke
parents:
diff changeset
1173 JOptionPane.WARNING_MESSAGE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1174 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1176 // Got an editor; put it in map
a61af66fc99e Initial load
duke
parents:
diff changeset
1177 editors.put(name, editor);
a61af66fc99e Initial load
duke
parents:
diff changeset
1178 // If Java source file, add additional information for later
a61af66fc99e Initial load
duke
parents:
diff changeset
1179 if (packageName != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1180 editor.setUserData(new JavaUserData(packageName, fileName));
a61af66fc99e Initial load
duke
parents:
diff changeset
1181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1183 // Got editor; show line
a61af66fc99e Initial load
duke
parents:
diff changeset
1184 editor.showLineNumber(lineNumber);
a61af66fc99e Initial load
duke
parents:
diff changeset
1185 editor.highlightLineNumber(lineNumber);
a61af66fc99e Initial load
duke
parents:
diff changeset
1186 // Show breakpoints as well if we have any for this file
a61af66fc99e Initial load
duke
parents:
diff changeset
1187 Set set = (Set) fileToBreakpointMap.get(editor.getSourceFileName());
a61af66fc99e Initial load
duke
parents:
diff changeset
1188 if (set != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1189 for (Iterator iter = set.iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1190 editor.showBreakpointAtLine(((Integer) iter.next()).intValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
1191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1192 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1193 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1194
a61af66fc99e Initial load
duke
parents:
diff changeset
1195 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1196 // Suspend/resume
a61af66fc99e Initial load
duke
parents:
diff changeset
1197 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1198
a61af66fc99e Initial load
duke
parents:
diff changeset
1199 private boolean isSuspended() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1200 return suspended;
a61af66fc99e Initial load
duke
parents:
diff changeset
1201 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1202
a61af66fc99e Initial load
duke
parents:
diff changeset
1203 private synchronized void suspend() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1204 setMenuItemsEnabled(resumeDebugMenuItems, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1205 setMenuItemsEnabled(suspendDebugMenuItems, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1206 BugSpotAgent agent = getAgent();
a61af66fc99e Initial load
duke
parents:
diff changeset
1207 if (agent.canInteractWithJava() && !agent.isJavaSuspended()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1208 agent.suspendJava();
a61af66fc99e Initial load
duke
parents:
diff changeset
1209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1210 agent.suspend();
a61af66fc99e Initial load
duke
parents:
diff changeset
1211 // FIXME: call VM.getVM().fireVMSuspended()
a61af66fc99e Initial load
duke
parents:
diff changeset
1212 resetCurrentThread();
a61af66fc99e Initial load
duke
parents:
diff changeset
1213 debugEventTimer.stop();
a61af66fc99e Initial load
duke
parents:
diff changeset
1214 suspended = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1216
a61af66fc99e Initial load
duke
parents:
diff changeset
1217 private synchronized void resume() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1218 // Note: we don't wipe out the cached state like the
a61af66fc99e Initial load
duke
parents:
diff changeset
1219 // sourceFileToLineNumberInfoMap since it is too expensive to
a61af66fc99e Initial load
duke
parents:
diff changeset
1220 // recompute. Instead we recompute it if any DLLs are loaded or
a61af66fc99e Initial load
duke
parents:
diff changeset
1221 // unloaded.
a61af66fc99e Initial load
duke
parents:
diff changeset
1222 threadToJavaThreadMap = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1223 setMenuItemsEnabled(resumeDebugMenuItems, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1224 setMenuItemsEnabled(suspendDebugMenuItems, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1225 registerPanel.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
1226 // FIXME: call VM.getVM().fireVMResumed()
a61af66fc99e Initial load
duke
parents:
diff changeset
1227 BugSpotAgent agent = getAgent();
a61af66fc99e Initial load
duke
parents:
diff changeset
1228 agent.resume();
a61af66fc99e Initial load
duke
parents:
diff changeset
1229 if (agent.canInteractWithJava()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1230 if (agent.isJavaSuspended()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1231 agent.resumeJava();
a61af66fc99e Initial load
duke
parents:
diff changeset
1232 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1233 if (javaEventPending) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1234 javaEventPending = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1235 // Clear it out before resuming polling for events
a61af66fc99e Initial load
duke
parents:
diff changeset
1236 agent.javaEventContinue();
a61af66fc99e Initial load
duke
parents:
diff changeset
1237 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1238 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1239 agent.enableJavaInteraction();
a61af66fc99e Initial load
duke
parents:
diff changeset
1240 suspended = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1241 debugEventTimer.start();
a61af66fc99e Initial load
duke
parents:
diff changeset
1242 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1243
a61af66fc99e Initial load
duke
parents:
diff changeset
1244 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1245 // Breakpoints
a61af66fc99e Initial load
duke
parents:
diff changeset
1246 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1247
a61af66fc99e Initial load
duke
parents:
diff changeset
1248 private synchronized BreakpointResult handleBreakpointToggle(Editor editor, int lineNumber) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1249 // Currently we only use user data in editors to indicate Java
a61af66fc99e Initial load
duke
parents:
diff changeset
1250 // source files. If this changes then this code will need to
a61af66fc99e Initial load
duke
parents:
diff changeset
1251 // change.
a61af66fc99e Initial load
duke
parents:
diff changeset
1252 JavaUserData data = (JavaUserData) editor.getUserData();
a61af66fc99e Initial load
duke
parents:
diff changeset
1253 String filename = editor.getSourceFileName();
a61af66fc99e Initial load
duke
parents:
diff changeset
1254 if (data == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1255 // C/C++ code
a61af66fc99e Initial load
duke
parents:
diff changeset
1256 // FIXME: as noted above in EditorCommands.toggleBreakpointAtLine,
a61af66fc99e Initial load
duke
parents:
diff changeset
1257 // this needs more work to handle "lazy" breakpoints in files
a61af66fc99e Initial load
duke
parents:
diff changeset
1258 // which we don't know about in the debug information yet
a61af66fc99e Initial load
duke
parents:
diff changeset
1259 CDebugger dbg = getCDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
1260 ProcessControl prctl = dbg.getProcessControl();
a61af66fc99e Initial load
duke
parents:
diff changeset
1261 if (prctl == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1262 return new BreakpointResult(false, false, 0, "Process control not enabled");
a61af66fc99e Initial load
duke
parents:
diff changeset
1263 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1264 boolean mustSuspendAndResume = (!prctl.isSuspended());
a61af66fc99e Initial load
duke
parents:
diff changeset
1265 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
1266 if (mustSuspendAndResume) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1267 prctl.suspend();
a61af66fc99e Initial load
duke
parents:
diff changeset
1268 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1269 // Search debug info for all DSOs
a61af66fc99e Initial load
duke
parents:
diff changeset
1270 LineNumberInfo info = getLineNumberInfo(filename, lineNumber);
a61af66fc99e Initial load
duke
parents:
diff changeset
1271 if (info != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1272 Set bpset = (Set) fileToBreakpointMap.get(filename);
a61af66fc99e Initial load
duke
parents:
diff changeset
1273 if (bpset == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1274 bpset = new HashSet();
a61af66fc99e Initial load
duke
parents:
diff changeset
1275 fileToBreakpointMap.put(filename, bpset);
a61af66fc99e Initial load
duke
parents:
diff changeset
1276 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1277 Integer key = new Integer(info.getLineNumber());
a61af66fc99e Initial load
duke
parents:
diff changeset
1278 if (bpset.contains(key)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1279 // Clear breakpoint at this line's PC
a61af66fc99e Initial load
duke
parents:
diff changeset
1280 prctl.clearBreakpoint(info.getStartPC());
a61af66fc99e Initial load
duke
parents:
diff changeset
1281 bpset.remove(key);
a61af66fc99e Initial load
duke
parents:
diff changeset
1282 return new BreakpointResult(true, false, info.getLineNumber());
a61af66fc99e Initial load
duke
parents:
diff changeset
1283 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1284 // Set breakpoint at this line's PC
a61af66fc99e Initial load
duke
parents:
diff changeset
1285 System.err.println("Setting breakpoint at PC " + info.getStartPC());
a61af66fc99e Initial load
duke
parents:
diff changeset
1286 prctl.setBreakpoint(info.getStartPC());
a61af66fc99e Initial load
duke
parents:
diff changeset
1287 bpset.add(key);
a61af66fc99e Initial load
duke
parents:
diff changeset
1288 return new BreakpointResult(true, true, info.getLineNumber());
a61af66fc99e Initial load
duke
parents:
diff changeset
1289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1290 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1291 return new BreakpointResult(false, false, 0, "No debug information for this source file and line");
a61af66fc99e Initial load
duke
parents:
diff changeset
1292 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1293 } finally {
a61af66fc99e Initial load
duke
parents:
diff changeset
1294 if (mustSuspendAndResume) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1295 prctl.resume();
a61af66fc99e Initial load
duke
parents:
diff changeset
1296 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1297 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1298 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1299 BugSpotAgent agent = getAgent();
a61af66fc99e Initial load
duke
parents:
diff changeset
1300 if (!agent.canInteractWithJava()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1301 String why;
a61af66fc99e Initial load
duke
parents:
diff changeset
1302 if (agent.isJavaInteractionDisabled()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1303 why = "Can not toggle Java breakpoints while stopped because\nof C/C++ debug events (breakpoints, single-stepping)";
a61af66fc99e Initial load
duke
parents:
diff changeset
1304 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1305 why = "Could not talk to SA's JVMDI module to enable Java\nprogramming language breakpoints (run with -Xdebug -Xrunsa)";
a61af66fc99e Initial load
duke
parents:
diff changeset
1306 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1307 return new BreakpointResult(false, false, 0, why);
a61af66fc99e Initial load
duke
parents:
diff changeset
1308 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1309 Set bpset = (Set) fileToBreakpointMap.get(filename);
a61af66fc99e Initial load
duke
parents:
diff changeset
1310 if (bpset == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1311 bpset = new HashSet();
a61af66fc99e Initial load
duke
parents:
diff changeset
1312 fileToBreakpointMap.put(filename, bpset);
a61af66fc99e Initial load
duke
parents:
diff changeset
1313 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1314 boolean mustResumeAndSuspend = isSuspended();
a61af66fc99e Initial load
duke
parents:
diff changeset
1315 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
1316 if (mustResumeAndSuspend) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1317 agent.resume();
a61af66fc99e Initial load
duke
parents:
diff changeset
1318 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1319 ServiceabilityAgentJVMDIModule.BreakpointToggleResult res =
a61af66fc99e Initial load
duke
parents:
diff changeset
1320 getAgent().toggleJavaBreakpoint(data.sourceFileName(),
a61af66fc99e Initial load
duke
parents:
diff changeset
1321 data.packageName(),
a61af66fc99e Initial load
duke
parents:
diff changeset
1322 lineNumber);
a61af66fc99e Initial load
duke
parents:
diff changeset
1323 if (res.getSuccess()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1324 Integer key = new Integer(res.getLineNumber());
a61af66fc99e Initial load
duke
parents:
diff changeset
1325 boolean addRemRes = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1326 if (res.getWasSet()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1327 addRemRes = bpset.add(key);
a61af66fc99e Initial load
duke
parents:
diff changeset
1328 System.err.println("Setting breakpoint at " + res.getMethodName() + res.getMethodSignature() +
a61af66fc99e Initial load
duke
parents:
diff changeset
1329 ", bci " + res.getBCI() + ", line " + res.getLineNumber());
a61af66fc99e Initial load
duke
parents:
diff changeset
1330 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1331 addRemRes = bpset.remove(key);
a61af66fc99e Initial load
duke
parents:
diff changeset
1332 System.err.println("Clearing breakpoint at " + res.getMethodName() + res.getMethodSignature() +
a61af66fc99e Initial load
duke
parents:
diff changeset
1333 ", bci " + res.getBCI() + ", line " + res.getLineNumber());
a61af66fc99e Initial load
duke
parents:
diff changeset
1334 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1335 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1336 Assert.that(addRemRes, "Inconsistent Java breakpoint state with respect to target process");
a61af66fc99e Initial load
duke
parents:
diff changeset
1337 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1338 return new BreakpointResult(true, res.getWasSet(), res.getLineNumber());
a61af66fc99e Initial load
duke
parents:
diff changeset
1339 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1340 return new BreakpointResult(false, false, 0, res.getErrMsg());
a61af66fc99e Initial load
duke
parents:
diff changeset
1341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1342 } finally {
a61af66fc99e Initial load
duke
parents:
diff changeset
1343 if (mustResumeAndSuspend) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1344 agent.suspend();
a61af66fc99e Initial load
duke
parents:
diff changeset
1345 resetCurrentThread();
a61af66fc99e Initial load
duke
parents:
diff changeset
1346 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1347 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1348 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1349 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1350
a61af66fc99e Initial load
duke
parents:
diff changeset
1351 // Must call only when suspended
a61af66fc99e Initial load
duke
parents:
diff changeset
1352 private LineNumberInfo getLineNumberInfo(String filename, int lineNumber) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1353 Map map = getSourceFileToLineNumberInfoMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
1354 java.util.List infos = (java.util.List) map.get(filename);
a61af66fc99e Initial load
duke
parents:
diff changeset
1355 if (infos == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1356 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1357 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1358 // Binary search for line number
a61af66fc99e Initial load
duke
parents:
diff changeset
1359 return searchLineNumbers(infos, lineNumber, 0, infos.size());
a61af66fc99e Initial load
duke
parents:
diff changeset
1360 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1361
a61af66fc99e Initial load
duke
parents:
diff changeset
1362 // Must call only when suspended
a61af66fc99e Initial load
duke
parents:
diff changeset
1363 private Map getSourceFileToLineNumberInfoMap() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1364 if (sourceFileToLineNumberInfoMap == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1365 // Build from debug info
a61af66fc99e Initial load
duke
parents:
diff changeset
1366 java.util.List loadObjects = getCDebugger().getLoadObjectList();
a61af66fc99e Initial load
duke
parents:
diff changeset
1367 final Map map = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
1368 for (Iterator iter = loadObjects.iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1369 LoadObject lo = (LoadObject) iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
1370 CDebugInfoDataBase db = lo.getDebugInfoDataBase();
a61af66fc99e Initial load
duke
parents:
diff changeset
1371 if (db != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1372 db.iterate(new LineNumberVisitor() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1373 public void doLineNumber(LineNumberInfo info) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1374 String name = info.getSourceFileName();
a61af66fc99e Initial load
duke
parents:
diff changeset
1375 if (name != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1376 java.util.List val = (java.util.List) map.get(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1377 if (val == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1378 val = new ArrayList();
a61af66fc99e Initial load
duke
parents:
diff changeset
1379 map.put(name, val);
a61af66fc99e Initial load
duke
parents:
diff changeset
1380 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1381 val.add(info);
a61af66fc99e Initial load
duke
parents:
diff changeset
1382 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1383 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1384 });
a61af66fc99e Initial load
duke
parents:
diff changeset
1385 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1386 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1387 // Sort all lists
a61af66fc99e Initial load
duke
parents:
diff changeset
1388 for (Iterator iter = map.values().iterator(); iter.hasNext(); ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1389 java.util.List list = (java.util.List) iter.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
1390 Collections.sort(list, new Comparator() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1391 public int compare(Object o1, Object o2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1392 LineNumberInfo l1 = (LineNumberInfo) o1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1393 LineNumberInfo l2 = (LineNumberInfo) o2;
a61af66fc99e Initial load
duke
parents:
diff changeset
1394 int n1 = l1.getLineNumber();
a61af66fc99e Initial load
duke
parents:
diff changeset
1395 int n2 = l2.getLineNumber();
a61af66fc99e Initial load
duke
parents:
diff changeset
1396 if (n1 < n2) return -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1397 if (n1 == n2) return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1398 return 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1399 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1400 });
a61af66fc99e Initial load
duke
parents:
diff changeset
1401 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1402 sourceFileToLineNumberInfoMap = map;
a61af66fc99e Initial load
duke
parents:
diff changeset
1403 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1404 return sourceFileToLineNumberInfoMap;
a61af66fc99e Initial load
duke
parents:
diff changeset
1405 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1406
a61af66fc99e Initial load
duke
parents:
diff changeset
1407 private LineNumberInfo searchLineNumbers(java.util.List infoList, int lineNo, int lowIdx, int highIdx) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1408 if (highIdx < lowIdx) return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1409 if (lowIdx == highIdx) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1410 // Base case: see whether start PC is less than or equal to addr
a61af66fc99e Initial load
duke
parents:
diff changeset
1411 if (checkLineNumber(infoList, lineNo, lowIdx)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1412 return (LineNumberInfo) infoList.get(lowIdx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1413 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1414 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1415 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1416 } else if (lowIdx == highIdx - 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1417 if (checkLineNumber(infoList, lineNo, lowIdx)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1418 return (LineNumberInfo) infoList.get(lowIdx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1419 } else if (checkLineNumber(infoList, lineNo, highIdx)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1420 return (LineNumberInfo) infoList.get(highIdx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1421 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1422 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1423 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1424 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1425 int midIdx = (lowIdx + highIdx) >> 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1426 LineNumberInfo info = (LineNumberInfo) infoList.get(midIdx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1427 if (lineNo < info.getLineNumber()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1428 // Always move search down
a61af66fc99e Initial load
duke
parents:
diff changeset
1429 return searchLineNumbers(infoList, lineNo, lowIdx, midIdx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1430 } else if (lineNo == info.getLineNumber()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1431 return info;
a61af66fc99e Initial load
duke
parents:
diff changeset
1432 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1433 // Move search up
a61af66fc99e Initial load
duke
parents:
diff changeset
1434 return searchLineNumbers(infoList, lineNo, midIdx, highIdx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1435 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1436 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1437
a61af66fc99e Initial load
duke
parents:
diff changeset
1438 private boolean checkLineNumber(java.util.List infoList, int lineNo, int idx) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1439 LineNumberInfo info = (LineNumberInfo) infoList.get(idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1440 return (info.getLineNumber() >= lineNo);
a61af66fc99e Initial load
duke
parents:
diff changeset
1441 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1442
a61af66fc99e Initial load
duke
parents:
diff changeset
1443 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1444 // Debug events
a61af66fc99e Initial load
duke
parents:
diff changeset
1445 //
a61af66fc99e Initial load
duke
parents:
diff changeset
1446
a61af66fc99e Initial load
duke
parents:
diff changeset
1447 private synchronized void pollForDebugEvent() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1448 ProcessControl prctl = getCDebugger().getProcessControl();
a61af66fc99e Initial load
duke
parents:
diff changeset
1449 if (prctl == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1450 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1451 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1452 DebugEvent ev = prctl.debugEventPoll();
a61af66fc99e Initial load
duke
parents:
diff changeset
1453 if (ev != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1454 DebugEvent.Type t = ev.getType();
a61af66fc99e Initial load
duke
parents:
diff changeset
1455 if (t == DebugEvent.Type.LOADOBJECT_LOAD ||
a61af66fc99e Initial load
duke
parents:
diff changeset
1456 t == DebugEvent.Type.LOADOBJECT_UNLOAD) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1457 // Conservatively clear cached debug info state
a61af66fc99e Initial load
duke
parents:
diff changeset
1458 sourceFileToLineNumberInfoMap = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
1459 // FIXME: would be very useful to have "stop on load/unload"
a61af66fc99e Initial load
duke
parents:
diff changeset
1460 // events
a61af66fc99e Initial load
duke
parents:
diff changeset
1461 // FIXME: must do work at these events to implement lazy
a61af66fc99e Initial load
duke
parents:
diff changeset
1462 // breakpoints
a61af66fc99e Initial load
duke
parents:
diff changeset
1463 prctl.debugEventContinue();
a61af66fc99e Initial load
duke
parents:
diff changeset
1464 } else if (t == DebugEvent.Type.BREAKPOINT) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1465 // Note: Visual C++ only notifies on breakpoints it doesn't
a61af66fc99e Initial load
duke
parents:
diff changeset
1466 // know about
a61af66fc99e Initial load
duke
parents:
diff changeset
1467
a61af66fc99e Initial load
duke
parents:
diff changeset
1468 // FIXME: put back test
a61af66fc99e Initial load
duke
parents:
diff changeset
1469 // if (!prctl.isBreakpointSet(ev.getPC())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1470 showMessageDialog("Breakpoint reached at PC " + ev.getPC(),
a61af66fc99e Initial load
duke
parents:
diff changeset
1471 "Breakpoint reached",
a61af66fc99e Initial load
duke
parents:
diff changeset
1472 JOptionPane.INFORMATION_MESSAGE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1473 // }
a61af66fc99e Initial load
duke
parents:
diff changeset
1474 agent.disableJavaInteraction();
a61af66fc99e Initial load
duke
parents:
diff changeset
1475 suspend();
a61af66fc99e Initial load
duke
parents:
diff changeset
1476 prctl.debugEventContinue();
a61af66fc99e Initial load
duke
parents:
diff changeset
1477 } else if (t == DebugEvent.Type.SINGLE_STEP) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1478 agent.disableJavaInteraction();
a61af66fc99e Initial load
duke
parents:
diff changeset
1479 suspend();
a61af66fc99e Initial load
duke
parents:
diff changeset
1480 prctl.debugEventContinue();
a61af66fc99e Initial load
duke
parents:
diff changeset
1481 } else if (t == DebugEvent.Type.ACCESS_VIOLATION) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1482 showMessageDialog("Access violation attempting to " +
a61af66fc99e Initial load
duke
parents:
diff changeset
1483 (ev.getWasWrite() ? "write" : "read") +
a61af66fc99e Initial load
duke
parents:
diff changeset
1484 " address " + ev.getAddress() +
a61af66fc99e Initial load
duke
parents:
diff changeset
1485 " at PC " + ev.getPC(),
a61af66fc99e Initial load
duke
parents:
diff changeset
1486 "Access Violation",
a61af66fc99e Initial load
duke
parents:
diff changeset
1487 JOptionPane.WARNING_MESSAGE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1488 agent.disableJavaInteraction();
a61af66fc99e Initial load
duke
parents:
diff changeset
1489 suspend();
a61af66fc99e Initial load
duke
parents:
diff changeset
1490 prctl.debugEventContinue();
a61af66fc99e Initial load
duke
parents:
diff changeset
1491 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1492 String info = "Unknown debug event encountered";
a61af66fc99e Initial load
duke
parents:
diff changeset
1493 if (ev.getUnknownEventDetail() != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1494 info = info + ": " + ev.getUnknownEventDetail();
a61af66fc99e Initial load
duke
parents:
diff changeset
1495 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1496 showMessageDialog(info, "Unknown debug event", JOptionPane.INFORMATION_MESSAGE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1497 suspend();
a61af66fc99e Initial load
duke
parents:
diff changeset
1498 prctl.debugEventContinue();
a61af66fc99e Initial load
duke
parents:
diff changeset
1499 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1500 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1501 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1502
a61af66fc99e Initial load
duke
parents:
diff changeset
1503 // No C++ debug event; poll for Java debug event
a61af66fc99e Initial load
duke
parents:
diff changeset
1504 if (getAgent().canInteractWithJava()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1505 if (!javaEventPending) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1506 if (getAgent().javaEventPending()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1507 suspend();
a61af66fc99e Initial load
duke
parents:
diff changeset
1508 // This does a lot of work and we want to have the page
a61af66fc99e Initial load
duke
parents:
diff changeset
1509 // cache available to us as it runs
a61af66fc99e Initial load
duke
parents:
diff changeset
1510 sun.jvm.hotspot.livejvm.Event jev = getAgent().javaEventPoll();
a61af66fc99e Initial load
duke
parents:
diff changeset
1511 if (jev != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1512 javaEventPending = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1513 if (jev.getType() == sun.jvm.hotspot.livejvm.Event.Type.BREAKPOINT) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1514 BreakpointEvent bpev = (BreakpointEvent) jev;
a61af66fc99e Initial load
duke
parents:
diff changeset
1515 showMessageDialog("Breakpoint reached in method\n" +
a61af66fc99e Initial load
duke
parents:
diff changeset
1516 bpev.methodID().method().externalNameAndSignature() +
a61af66fc99e Initial load
duke
parents:
diff changeset
1517 ",\nbci " + bpev.location(),
a61af66fc99e Initial load
duke
parents:
diff changeset
1518 "Breakpoint reached",
a61af66fc99e Initial load
duke
parents:
diff changeset
1519 JOptionPane.INFORMATION_MESSAGE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1520 } else if (jev.getType() == sun.jvm.hotspot.livejvm.Event.Type.EXCEPTION) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1521 ExceptionEvent exev = (ExceptionEvent) jev;
a61af66fc99e Initial load
duke
parents:
diff changeset
1522 showMessageDialog(exev.exception().getKlass().getName().asString() +
a61af66fc99e Initial load
duke
parents:
diff changeset
1523 "\nthrown in method\n" +
a61af66fc99e Initial load
duke
parents:
diff changeset
1524 exev.methodID().method().externalNameAndSignature() +
a61af66fc99e Initial load
duke
parents:
diff changeset
1525 "\nat BCI " + exev.location(),
a61af66fc99e Initial load
duke
parents:
diff changeset
1526 "Exception thrown",
a61af66fc99e Initial load
duke
parents:
diff changeset
1527 JOptionPane.INFORMATION_MESSAGE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1528 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1529 Assert.that(false, "Should not reach here");
a61af66fc99e Initial load
duke
parents:
diff changeset
1530 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1531 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1532 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1533 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1534 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1535 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1536 }