annotate agent/src/share/classes/sun/jvm/hotspot/CLHSDB.java @ 17467:55fb97c4c58d hs25-b65

8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013 Summary: Copyright year updated for files modified during 2013 Reviewed-by: twisti, iveresov
author mikael
date Tue, 24 Dec 2013 11:48:39 -0800
parents 38ea2efa32a7
children 4ca6dc0799b6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
17467
55fb97c4c58d 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 11054
diff changeset
2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. 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 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
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;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import sun.jvm.hotspot.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import java.io.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 public class CLHSDB {
11054
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 3939
diff changeset
34
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 3939
diff changeset
35 public CLHSDB(JVMDebugger d) {
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 3939
diff changeset
36 jvmDebugger = d;
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 3939
diff changeset
37 }
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 3939
diff changeset
38
0
a61af66fc99e Initial load
duke
parents:
diff changeset
39 public static void main(String[] args) {
a61af66fc99e Initial load
duke
parents:
diff changeset
40 new CLHSDB(args).run();
a61af66fc99e Initial load
duke
parents:
diff changeset
41 }
a61af66fc99e Initial load
duke
parents:
diff changeset
42
11054
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 3939
diff changeset
43 public void run() {
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 3939
diff changeset
44 // If jvmDebugger is already set, we have been given a JVMDebugger.
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 3939
diff changeset
45 // Otherwise, if pidText != null we are supposed to attach to it.
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 3939
diff changeset
46 // Finally, if execPath != null, it is the path of a jdk/bin/java
0
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // and coreFilename is the pathname of a core file we are
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // supposed to attach to.
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 agent = new HotSpotAgent();
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 Runtime.getRuntime().addShutdownHook(new java.lang.Thread() {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 public void run() {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 detachDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
55 }
a61af66fc99e Initial load
duke
parents:
diff changeset
56 });
a61af66fc99e Initial load
duke
parents:
diff changeset
57
11054
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 3939
diff changeset
58 if (jvmDebugger != null) {
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 3939
diff changeset
59 attachDebugger(jvmDebugger);
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 3939
diff changeset
60 } else if (pidText != null) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
61 attachDebugger(pidText);
a61af66fc99e Initial load
duke
parents:
diff changeset
62 } else if (execPath != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 attachDebugger(execPath, coreFilename);
a61af66fc99e Initial load
duke
parents:
diff changeset
64 }
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 CommandProcessor.DebuggerInterface di = new CommandProcessor.DebuggerInterface() {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 public HotSpotAgent getAgent() {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 return agent;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71 public boolean isAttached() {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 return attached;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 }
a61af66fc99e Initial load
duke
parents:
diff changeset
74 public void attach(String pid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 attachDebugger(pid);
a61af66fc99e Initial load
duke
parents:
diff changeset
76 }
a61af66fc99e Initial load
duke
parents:
diff changeset
77 public void attach(String java, String core) {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 attachDebugger(java, core);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80 public void detach() {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 detachDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83 public void reattach() {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 if (attached) {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 detachDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87 if (pidText != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 attach(pidText);
a61af66fc99e Initial load
duke
parents:
diff changeset
89 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 attach(execPath, coreFilename);
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92 }
a61af66fc99e Initial load
duke
parents:
diff changeset
93 };
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95
a61af66fc99e Initial load
duke
parents:
diff changeset
96 BufferedReader in =
a61af66fc99e Initial load
duke
parents:
diff changeset
97 new BufferedReader(new InputStreamReader(System.in));
a61af66fc99e Initial load
duke
parents:
diff changeset
98 CommandProcessor cp = new CommandProcessor(di, in, System.out, System.err);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 cp.run(true);
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
105 //
a61af66fc99e Initial load
duke
parents:
diff changeset
106 private HotSpotAgent agent;
11054
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 3939
diff changeset
107 private JVMDebugger jvmDebugger;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
108 private boolean attached;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 // These had to be made data members because they are referenced in inner classes.
a61af66fc99e Initial load
duke
parents:
diff changeset
110 private String pidText;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 private int pid;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 private String execPath;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 private String coreFilename;
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 private void doUsage() {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 System.out.println("Usage: java CLHSDB [[pid] | [path-to-java-executable [path-to-corefile]] | help ]");
a61af66fc99e Initial load
duke
parents:
diff changeset
117 System.out.println(" pid: attach to the process whose id is 'pid'");
a61af66fc99e Initial load
duke
parents:
diff changeset
118 System.out.println(" path-to-java-executable: Debug a core file produced by this program");
a61af66fc99e Initial load
duke
parents:
diff changeset
119 System.out.println(" path-to-corefile: Debug this corefile. The default is 'core'");
a61af66fc99e Initial load
duke
parents:
diff changeset
120 System.out.println(" If no arguments are specified, you can select what to do from the GUI.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
121 HotSpotAgent.showUsage();
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 private CLHSDB(String[] args) {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 switch (args.length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 case (0):
a61af66fc99e Initial load
duke
parents:
diff changeset
127 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 case (1):
a61af66fc99e Initial load
duke
parents:
diff changeset
130 if (args[0].equals("help") || args[0].equals("-help")) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 doUsage();
11054
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 3939
diff changeset
132 return;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134 // If all numbers, it is a PID to attach to
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // Else, it is a pathname to a .../bin/java for a core file.
a61af66fc99e Initial load
duke
parents:
diff changeset
136 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 int unused = Integer.parseInt(args[0]);
a61af66fc99e Initial load
duke
parents:
diff changeset
138 // If we get here, we have a PID and not a core file name
a61af66fc99e Initial load
duke
parents:
diff changeset
139 pidText = args[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
140 } catch (NumberFormatException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
141 execPath = args[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
142 coreFilename = "core";
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
144 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 case (2):
a61af66fc99e Initial load
duke
parents:
diff changeset
147 execPath = args[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
148 coreFilename = args[1];
a61af66fc99e Initial load
duke
parents:
diff changeset
149 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
152 System.out.println("HSDB Error: Too many options specified");
a61af66fc99e Initial load
duke
parents:
diff changeset
153 doUsage();
11054
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 3939
diff changeset
154 return;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157
11054
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 3939
diff changeset
158 private void attachDebugger(JVMDebugger d) {
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 3939
diff changeset
159 agent.attach(d);
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 3939
diff changeset
160 attached = true;
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 3939
diff changeset
161 }
38ea2efa32a7 8010278: SA: provide mechanism for using an alternative SA debugger back-end.
kevinw
parents: 3939
diff changeset
162
0
a61af66fc99e Initial load
duke
parents:
diff changeset
163 /** NOTE we are in a different thread here than either the main
a61af66fc99e Initial load
duke
parents:
diff changeset
164 thread or the Swing/AWT event handler thread, so we must be very
a61af66fc99e Initial load
duke
parents:
diff changeset
165 careful when creating or removing widgets */
a61af66fc99e Initial load
duke
parents:
diff changeset
166 private void attachDebugger(String pidText) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 this.pidText = pidText;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 pid = Integer.parseInt(pidText);
a61af66fc99e Initial load
duke
parents:
diff changeset
170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
171 catch (NumberFormatException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 System.err.print("Unable to parse process ID \"" + pidText + "\".\nPlease enter a number.");
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 System.err.println("Attaching to process " + pid + ", please wait...");
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 // FIXME: display exec'd debugger's output messages during this
a61af66fc99e Initial load
duke
parents:
diff changeset
179 // lengthy call
a61af66fc99e Initial load
duke
parents:
diff changeset
180 agent.attach(pid);
a61af66fc99e Initial load
duke
parents:
diff changeset
181 attached = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
183 catch (DebuggerException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 final String errMsg = formatMessage(e.getMessage(), 80);
a61af66fc99e Initial load
duke
parents:
diff changeset
185 System.err.println("Unable to connect to process ID " + pid + ":\n\n" + errMsg);
a61af66fc99e Initial load
duke
parents:
diff changeset
186 agent.detach();
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
187 e.printStackTrace();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
188 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190 }
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 /** NOTE we are in a different thread here than either the main
a61af66fc99e Initial load
duke
parents:
diff changeset
193 thread or the Swing/AWT event handler thread, so we must be very
a61af66fc99e Initial load
duke
parents:
diff changeset
194 careful when creating or removing widgets */
a61af66fc99e Initial load
duke
parents:
diff changeset
195 private void attachDebugger(final String executablePath, final String corePath) {
a61af66fc99e Initial load
duke
parents:
diff changeset
196 // Try to open this core file
a61af66fc99e Initial load
duke
parents:
diff changeset
197 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
198 System.err.println("Opening core file, please wait...");
a61af66fc99e Initial load
duke
parents:
diff changeset
199
a61af66fc99e Initial load
duke
parents:
diff changeset
200 // FIXME: display exec'd debugger's output messages during this
a61af66fc99e Initial load
duke
parents:
diff changeset
201 // lengthy call
a61af66fc99e Initial load
duke
parents:
diff changeset
202 agent.attach(executablePath, corePath);
a61af66fc99e Initial load
duke
parents:
diff changeset
203 attached = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
204 }
a61af66fc99e Initial load
duke
parents:
diff changeset
205 catch (DebuggerException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 final String errMsg = formatMessage(e.getMessage(), 80);
a61af66fc99e Initial load
duke
parents:
diff changeset
207 System.err.println("Unable to open core file\n" + corePath + ":\n\n" + errMsg);
a61af66fc99e Initial load
duke
parents:
diff changeset
208 agent.detach();
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
209 e.printStackTrace();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
210 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
211 }
a61af66fc99e Initial load
duke
parents:
diff changeset
212 }
a61af66fc99e Initial load
duke
parents:
diff changeset
213
a61af66fc99e Initial load
duke
parents:
diff changeset
214 /** NOTE we are in a different thread here than either the main
a61af66fc99e Initial load
duke
parents:
diff changeset
215 thread or the Swing/AWT event handler thread, so we must be very
a61af66fc99e Initial load
duke
parents:
diff changeset
216 careful when creating or removing widgets */
a61af66fc99e Initial load
duke
parents:
diff changeset
217 private void connect(final String remoteMachineName) {
a61af66fc99e Initial load
duke
parents:
diff changeset
218 // Try to open this core file
a61af66fc99e Initial load
duke
parents:
diff changeset
219 try {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 System.err.println("Connecting to debug server, please wait...");
a61af66fc99e Initial load
duke
parents:
diff changeset
221 agent.attach(remoteMachineName);
a61af66fc99e Initial load
duke
parents:
diff changeset
222 attached = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
223 }
a61af66fc99e Initial load
duke
parents:
diff changeset
224 catch (DebuggerException e) {
a61af66fc99e Initial load
duke
parents:
diff changeset
225 final String errMsg = formatMessage(e.getMessage(), 80);
a61af66fc99e Initial load
duke
parents:
diff changeset
226 System.err.println("Unable to connect to machine \"" + remoteMachineName + "\":\n\n" + errMsg);
a61af66fc99e Initial load
duke
parents:
diff changeset
227 agent.detach();
3939
f6f3bb0ee072 7088955: add C2 IR support to the SA
never
parents: 1552
diff changeset
228 e.printStackTrace();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
229 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
231 }
a61af66fc99e Initial load
duke
parents:
diff changeset
232
a61af66fc99e Initial load
duke
parents:
diff changeset
233 private void detachDebugger() {
a61af66fc99e Initial load
duke
parents:
diff changeset
234 if (!attached) {
a61af66fc99e Initial load
duke
parents:
diff changeset
235 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237 agent.detach();
a61af66fc99e Initial load
duke
parents:
diff changeset
238 attached = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
239 }
a61af66fc99e Initial load
duke
parents:
diff changeset
240
a61af66fc99e Initial load
duke
parents:
diff changeset
241 private void detach() {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 detachDebugger();
a61af66fc99e Initial load
duke
parents:
diff changeset
243 }
a61af66fc99e Initial load
duke
parents:
diff changeset
244
a61af66fc99e Initial load
duke
parents:
diff changeset
245 /** Punctuates the given string with \n's where necessary to not
a61af66fc99e Initial load
duke
parents:
diff changeset
246 exceed the given number of characters per line. Strips
a61af66fc99e Initial load
duke
parents:
diff changeset
247 extraneous whitespace. */
a61af66fc99e Initial load
duke
parents:
diff changeset
248 private String formatMessage(String message, int charsPerLine) {
a61af66fc99e Initial load
duke
parents:
diff changeset
249 StringBuffer buf = new StringBuffer(message.length());
a61af66fc99e Initial load
duke
parents:
diff changeset
250 StringTokenizer tokenizer = new StringTokenizer(message);
a61af66fc99e Initial load
duke
parents:
diff changeset
251 int curLineLength = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
252 while (tokenizer.hasMoreTokens()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
253 String tok = tokenizer.nextToken();
a61af66fc99e Initial load
duke
parents:
diff changeset
254 if (curLineLength + tok.length() > charsPerLine) {
a61af66fc99e Initial load
duke
parents:
diff changeset
255 buf.append('\n');
a61af66fc99e Initial load
duke
parents:
diff changeset
256 curLineLength = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
257 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 if (curLineLength != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
259 buf.append(' ');
a61af66fc99e Initial load
duke
parents:
diff changeset
260 ++curLineLength;
a61af66fc99e Initial load
duke
parents:
diff changeset
261 }
a61af66fc99e Initial load
duke
parents:
diff changeset
262 }
a61af66fc99e Initial load
duke
parents:
diff changeset
263 buf.append(tok);
a61af66fc99e Initial load
duke
parents:
diff changeset
264 curLineLength += tok.length();
a61af66fc99e Initial load
duke
parents:
diff changeset
265 }
a61af66fc99e Initial load
duke
parents:
diff changeset
266 return buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
268 }