1 /*
2 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
153 try {
154 this.pidText = pidText;
155 pid = Integer.parseInt(pidText);
156 }
157 catch (NumberFormatException e) {
158 System.err.print("Unable to parse process ID \"" + pidText + "\".\nPlease enter a number.");
159 }
160
161 try {
162 System.err.println("Attaching to process " + pid + ", please wait...");
163
164 // FIXME: display exec'd debugger's output messages during this
165 // lengthy call
166 agent.attach(pid);
167 attached = true;
168 }
169 catch (DebuggerException e) {
170 final String errMsg = formatMessage(e.getMessage(), 80);
171 System.err.println("Unable to connect to process ID " + pid + ":\n\n" + errMsg);
172 agent.detach();
173 return;
174 }
175 }
176
177 /** NOTE we are in a different thread here than either the main
178 thread or the Swing/AWT event handler thread, so we must be very
179 careful when creating or removing widgets */
180 private void attachDebugger(final String executablePath, final String corePath) {
181 // Try to open this core file
182 try {
183 System.err.println("Opening core file, please wait...");
184
185 // FIXME: display exec'd debugger's output messages during this
186 // lengthy call
187 agent.attach(executablePath, corePath);
188 attached = true;
189 }
190 catch (DebuggerException e) {
191 final String errMsg = formatMessage(e.getMessage(), 80);
192 System.err.println("Unable to open core file\n" + corePath + ":\n\n" + errMsg);
193 agent.detach();
194 return;
195 }
196 }
197
198 /** NOTE we are in a different thread here than either the main
199 thread or the Swing/AWT event handler thread, so we must be very
200 careful when creating or removing widgets */
201 private void connect(final String remoteMachineName) {
202 // Try to open this core file
203 try {
204 System.err.println("Connecting to debug server, please wait...");
205 agent.attach(remoteMachineName);
206 attached = true;
207 }
208 catch (DebuggerException e) {
209 final String errMsg = formatMessage(e.getMessage(), 80);
210 System.err.println("Unable to connect to machine \"" + remoteMachineName + "\":\n\n" + errMsg);
211 agent.detach();
212 return;
213 }
214 }
215
216 private void detachDebugger() {
217 if (!attached) {
218 return;
219 }
220 agent.detach();
221 attached = false;
222 }
223
224 private void detach() {
225 detachDebugger();
226 }
227
228 /** Punctuates the given string with \n's where necessary to not
229 exceed the given number of characters per line. Strips
230 extraneous whitespace. */
231 private String formatMessage(String message, int charsPerLine) {
|
1 /*
2 * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
153 try {
154 this.pidText = pidText;
155 pid = Integer.parseInt(pidText);
156 }
157 catch (NumberFormatException e) {
158 System.err.print("Unable to parse process ID \"" + pidText + "\".\nPlease enter a number.");
159 }
160
161 try {
162 System.err.println("Attaching to process " + pid + ", please wait...");
163
164 // FIXME: display exec'd debugger's output messages during this
165 // lengthy call
166 agent.attach(pid);
167 attached = true;
168 }
169 catch (DebuggerException e) {
170 final String errMsg = formatMessage(e.getMessage(), 80);
171 System.err.println("Unable to connect to process ID " + pid + ":\n\n" + errMsg);
172 agent.detach();
173 e.printStackTrace();
174 return;
175 }
176 }
177
178 /** NOTE we are in a different thread here than either the main
179 thread or the Swing/AWT event handler thread, so we must be very
180 careful when creating or removing widgets */
181 private void attachDebugger(final String executablePath, final String corePath) {
182 // Try to open this core file
183 try {
184 System.err.println("Opening core file, please wait...");
185
186 // FIXME: display exec'd debugger's output messages during this
187 // lengthy call
188 agent.attach(executablePath, corePath);
189 attached = true;
190 }
191 catch (DebuggerException e) {
192 final String errMsg = formatMessage(e.getMessage(), 80);
193 System.err.println("Unable to open core file\n" + corePath + ":\n\n" + errMsg);
194 agent.detach();
195 e.printStackTrace();
196 return;
197 }
198 }
199
200 /** NOTE we are in a different thread here than either the main
201 thread or the Swing/AWT event handler thread, so we must be very
202 careful when creating or removing widgets */
203 private void connect(final String remoteMachineName) {
204 // Try to open this core file
205 try {
206 System.err.println("Connecting to debug server, please wait...");
207 agent.attach(remoteMachineName);
208 attached = true;
209 }
210 catch (DebuggerException e) {
211 final String errMsg = formatMessage(e.getMessage(), 80);
212 System.err.println("Unable to connect to machine \"" + remoteMachineName + "\":\n\n" + errMsg);
213 agent.detach();
214 e.printStackTrace();
215 return;
216 }
217 }
218
219 private void detachDebugger() {
220 if (!attached) {
221 return;
222 }
223 agent.detach();
224 attached = false;
225 }
226
227 private void detach() {
228 detachDebugger();
229 }
230
231 /** Punctuates the given string with \n's where necessary to not
232 exceed the given number of characters per line. Strips
233 extraneous whitespace. */
234 private String formatMessage(String message, int charsPerLine) {
|