debug.jsp
17.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ page import="java.util.Properties"%>
<%@ page import="java.io.File"%>
<%@ page import="java.io.InputStreamReader"%>
<%@ page import="java.io.LineNumberReader"%>
<%@ page import="java.io.FileInputStream"%>
<%@ page import="java.io.FileOutputStream"%>
<%@ page import="java.io.BufferedInputStream"%>
<%@ page import="java.io.BufferedOutputStream"%>
<%@ page import="java.io.IOException"%>
<%@ page import="java.lang.management.ManagementFactory"%>
<%@ page import="java.lang.management.MemoryPoolMXBean"%>
<%@ page import="java.lang.management.MemoryUsage"%>
<%@ page import="java.lang.management.RuntimeMXBean"%>
<%@ page import="com.sun.tools.attach.VirtualMachine"%>
<%@ page import="java.lang.reflect.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.util.regex.*"%>
<%@ page import="com.caucho.util.LruCache"%>
<%@ page import="com.caucho.vfs.Path"%>
<%
response.setHeader("cache-control", "no-cache");
response.setHeader("pragma", "no-cache");
response.setHeader("expires", "Mon 1 Jan 1990 00:00:00 GMT");
%>
<%@ include file="init.jsp" %>
<%
try{
boolean isUse = false;
Class debugAgent = null;
if (!isInitDebug()) {
loadAgent();
debugAgent = Class.forName("com.weaver.onlinedebug.DebugAgent");
long maxPermGenSize = 0;
Long maxPermGenSizeObj = (Long) debugAgent.getDeclaredMethod("getMaxPermSize", new Class[] {}).invoke(null, new Object[] {});
if(maxPermGenSizeObj != null){
maxPermGenSize = maxPermGenSizeObj.longValue();
}
if(maxPermGenSize < 192 *1024 * 1024){
out.append("java 启动参数 -XX:MaxPermSize="+(int)(maxPermGenSize/1024/1024)+"m 设置的太小,调试会造成不稳定,请使用 -XX:MaxPermSize=256m 或者大于256m 启动虚拟机");
return;
}
String jspRoot = getServletConfig().getServletContext().getRealPath("/");
String loader = debugAgent.getClassLoader().getClass().getName();
if(loader.indexOf("SystemClassLoader") != -1){
out.print("第一次在resin3上进行调试,必须进行一次重启才可以调试,请重启resin服务");
return;
}
// System.out.println("~~~debugAgent="+debugAgent.getClassLoader());
Method method = debugAgent.getDeclaredMethod("initDebug", new Class[] { String.class });
method.invoke(null, new Object[]{jspRoot});
}
debugAgent = Class.forName("com.weaver.onlinedebug.DebugAgent");
Class dataClass = Class.forName("com.weaver.onlinedebug.data.DebugData");
Object debugData = session.getAttribute(debugDataKey);
if(debugData == null){
debugData = dataClass.newInstance();
session.setAttribute(debugDataKey, debugData);
}
String trackType = ""+dataClass.getDeclaredMethod("getTrackType",(Class[])null).invoke(debugData, new Object[]{});
String isTrackSeq = ""+dataClass.getDeclaredMethod("isTrackSeq",(Class[])null).invoke(debugData, new Object[]{});
String action = request.getParameter("action");
String message = "";
Integer seq = (Integer)session.getAttribute(debugCurrentSeqKey);
if(seq == null){
seq = (Integer)debugAgent.getDeclaredMethod("getManualSeq", new Class[] {}).invoke(null, new Object[] {});
session.setAttribute(debugCurrentSeqKey, seq);
}
if ("start".equals(action)) {
String currentUser = (String)user.getClass().getDeclaredMethod("getLoginid",(Class[])null).invoke(user, new Object[]{});
String cu = (String) debugAgent.getDeclaredMethod("startDebug", new Class[] { dataClass, String.class, int.class}).invoke(null, new Object[]{ debugData, currentUser, seq});
if (!"".equals(cu)) {
isUse = true;
message = "当前系统正在被"+cu+"调试,请先停止";
} else {
isUse = true;
message = "启动成功,请进行需要调试的操作,然后后停止,生成调试数据";
}
} else if ("stop".equals(action)) {
boolean success = ((Boolean) debugAgent.getDeclaredMethod("stopDebug", null).invoke(null, new Object[]{})).booleanValue();
isUse = false;
if (success) {
message = "请下载调试数据";
} else {
message = "发生错误,未能生成调试数据";
}
}
%>
<HTML>
<HEAD>
<TITLE> 远程调试</TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<meta http-equiv=Content-Type content="text/html; charset=utf8">
<link type='text/css' rel='stylesheet' href='css/main_wev8.css'/>
<script type="text/javascript" src="javascripts/jquery-1.4.2.min_wev8.js"></script>
<script type="text/javascript" src="javascripts/main_wev8.js"></script>
<script type="text/javascript">
var debugCurrentClass = '<%=debugCurrentClass%>';
var debugCurrentLine = '<%=debugCurrentLine%>';
function setCurrent(className, line){
debugCurrentClass = className;
debugCurrentLine = line;
var box = document.getElementById('vardataedit');
box.src = 'debugAction.jsp?action=setcurrent&classname='+className+'&line='+line;
}
/**
删除断点
*/
function deleteCurrent(){
var box = document.getElementById('vardatalist');
box.src = 'debugAction.jsp?action=deletecurrent&classname='+debugCurrentClass+'&line='+debugCurrentLine;
}
function deleteAll(){
var box = document.getElementById('vardatalist');
box.src = 'debugAction.jsp?action=deleteall';
}
</script>
<style type="text/css">
<!--
body{
overflow:hidden;
}
-->
</style>
</HEAD>
<BODY>
<!--正文区-->
<div id="content">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td class="contentHead"> </td>
<td class="contentCenter"></td>
<td class="contentBottom"></td>
</tr>
<tr>
<td class="cLeft"> </td>
<td class="cCenter">
<!--顶部工具区-->
<div id="top">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td>
<div class="btnStart">
<% if (!isUse) { %>
<input type="hidden" name="flag" id="flag" value="0"/>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td><div><img src="images/start_wev8.png" style="margin-top:5px;margin-left:15px" id="sos"></img></div></td>
<td><div id="sosTxt" onclick="startOrStop(this);" class="debug">开始调试</div></td>
</tr>
</table>
<% }else{ %>
<input type="hidden" name="flag" id="flag" value="1"/>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td><div style="float:left;"><img src="images/stop_wev8.png" style="margin-top:5px;margin-left:15px" id="sos"></img></div></td>
<td><div id="sosTxt" onclick="startOrStop(this);" class="debug">停止调试</div></td>
</tr>
</table>
<%} %>
</div>
</td>
<td>
<div class="btnPoint">
<form id='statusForm' action='debugAction.jsp' target='emptyiframe'>
<div style="margin-top:5px;">
<span style="margin-left:3px;cursor:pointer;padding-right:30px;" onclick="setTrackType1(this);">
<%if("1".equals(trackType) || trackType==null){ %>
<img src="images/radio_true_wev8.png" class="imgTxt"/> 只跟踪断点类
<%}else{%>
<img src="images/radio_false_wev8.png"class="imgTxt"/> 只跟踪断点类
<%}%>
</span>
<span style="cursor:pointer;padding-right:30px;" onclick="setTrackType2(this);">
<%if("2".equals(trackType) || trackType==null){ %>
<img src="images/radio_true_wev8.png"class="imgTxt"/> 跟踪所有类
<%}else{%>
<img src="images/radio_false_wev8.png"class="imgTxt"/> 跟踪所有类
<%}%>
</span>
<span style="cursor:pointer;" onclick="setTrackSeq(this);">
<%if("true".equals(isTrackSeq) || isTrackSeq==null){ %>
<img src="images/checkbox_true_wev8.png"class="imgTxt"/> 跟踪执行过程
<%}else{%>
<img src="images/checkbox_false_wev8.png"class="imgTxt"/> 跟踪执行过程
<%}%>
</span>
</div>
<input type="hidden" name="tracktype" value="<%= "2".equals(trackType)?"all":"var"%>" id="tracktype"/>
<span id="trackseqspan">
<% if("true".equals(isTrackSeq)){ %>
<input type='hidden' name='trackseq' id="trackseq" value="trackseq" />
<% } %>
</span>
<input type='hidden' name='action' value='updatestatus' style='display:none'>
</form>
<iframe name='emptyiframe' style='display:none'></iframe>
</div>
</td>
<td>
<div>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="downloadLeft"></td>
<td class="downloadCenter">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div style="cursor:pointer;margin-top:5px;padding-right:5px;display:inline;" onclick="javascript:window.location='log.txt'">下载日志文件 </div></td>
<td><span><img src="images/btn_center_line_wev8.png" width="2px;"></span></td>
<td><div style="cursor:pointer;margin-top:5px;padding-left:5px;display:inline;" onclick="javascript:window.location='tracklog/manual/<%=seq%>.zip'" >下载跟踪文件</div></td>
</tr>
</table>
</td>
<td class="downloadRight"></td>
</tr>
</table>
</div>
</td>
<td>
<form id='uploadForm' action='upload.jsp' action='upload.jsp' method='post' enctype='multipart/form-data' style="margin-top:10px;">
<div>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="uploadL"></td>
<td class="uploadC">
<input type="file" name="file"/>
</td>
<td class="uploadR"></td>
</tr>
</table>
</div>
</form>
</td>
<td>
<div class="btnUpload" align="center">
<div onclick="$('#uploadForm').submit();" class="btnImp">上传跟踪文件</div>
</div>
</td>
</tr>
</table>
</div>
<div style="margin-top:10px;">
<!--调试信息输出区-->
<div id="left">
<table border="0" style="width:100%;height:100%" cellspacing="0" cellpadding="0">
<tr>
<td class="debugTL" height="15px"></td>
<td class="debugTC" height="15px"></td>
<td class="debugTR" height="15px"></td>
</tr>
<tr>
<td class="debugCL"></td>
<td class="debugCC" id="outputTD">
<iframe frameborder="no" marginheight="0" marginwidth="0" border="0" src="viewLog.jsp" style="width:100%;height:100%">
</iframe>
</td>
<td class="debugCR"></td>
</tr>
<tr>
<td class="debugFL" height="15px"></td>
<td class="debugFC" height="15px"></td>
<td class="debugFR" height="15px"></td>
</tr>
</table>
<div style="margin-top:10px;"><%= message %></div>
</div>
<!--调试设置区-->
<div id="right">
<table border="0" style="width:100%;height:100%" cellspacing="0" cellpadding="0">
<tr>
<td class="pointTL"></td>
<td class="pointTC" height="15px"></td>
<td class="pointTR" height="15px"></td>
</tr>
<tr>
<td class="pointCL"></td>
<td class="pointCC">
<!--断点设置-->
<div id="classLine">
<form action='debugAction.jsp?action=addvardata' target='vardatalist' id="addvardataForm">
<input type="hidden" value="addvardata" name="action"/>
<div>
<span>类:</span>
<span>
<input type="text" name="classname" style="width:80%;padding-right:10px;"/>
</span>
</div>
<div>
<table border="0" style="width:100%;" cellspacing="0" cellpadding="0">
<tr>
<td width="60%">
<div style="margin-top:10px;">
<span>行:</span>
<span>
<input type="text" name="line" style="width:80%;padding-right:10px;"/>
</span>
</div>
</td>
<td>
<div style="margin-top:10px;width:100%;margin-left:10px">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="pointList"></td>
<td height="27px;" class="pointOper">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div style="cursor:pointer" onclick="$('#addvardataForm').submit();">添加断点</div></td>
</tr>
</table>
</td>
<td class="btnCR"></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</form>
<div style="margin-top:10px;">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><span>断点列表:</span></td>
<td class="pointList"></td>
<td height="27px;" class="pointOper">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div style="cursor:pointer;margin-top:5px;padding-right:5px;display:inline;" onclick="deleteCurrent();">删除</div></td>
<td><span><img src="images/btn_center_line_wev8.png" width="2px;"></span></td>
<td><div style="cursor:pointer;margin-top:5px;padding-left:5px;display:inline;" onclick="deleteAll();" >删除所有</div></td>
</tr>
</table>
</td>
<td class="btnCR"></td>
</tr>
</table>
</div>
</div>
<!--断点列表区-->
<div id="breakpoint" style="margin-top:10px;background-color:#fff">
<iframe frameborder="no" marginheight="0" marginwidth="0" border="0" src="varDataList.jsp" name="vardatalist" id="vardatalist" style="width:100%"></iframe>
</div>
<!--断点详细信息-->
<div id="bpLabel" style="margin-top:10px;">断点详细信息:</div>
<div id="bpDetail" style="margin-top:10px;background-color:#fff">
<iframe frameborder="no" marginheight="0" marginwidth="0" border="0" src="varDataEdit.jsp" id="vardataedit" name="vardataedit" style="width:100%"></iframe>
</div>
</td>
<td class="pointCR"></td>
</tr>
<tr>
<td class="pointFL" height="15px"></td>
<td class="pointFC" height="15px"></td>
<td class="pointFR" height="15px"></td>
</tr>
</table>
</div>
<div style="clear:both"></div>
</div>
</td>
<td class="cRight"></td>
</tr>
<tr>
<td class="bodyFL"> </td>
<td class="bodyFC"></td>
<td class="bodyFR"></td>
</tr>
</table>
</div>
</BODY>
</HTML>
<%
}catch(Exception e){
e.printStackTrace();
}
%>
<%!
private void loadAgent(){
String workRoot = "";
String resinHome = "";
try {
try {
Class csClass = Thread.currentThread().getContextClassLoader().loadClass("com.caucho.util.CauchoSystem");
Path workPath = (Path) csClass.getDeclaredMethod("getWorkPath", new Class[] {}).invoke(null, new Object[] {});
Path resinPath = (Path) csClass.getDeclaredMethod("getResinHome", new Class[] {}).invoke(null, new Object[] {});
workRoot = workPath.getNativePath().replace('\\', '/');
resinHome = resinPath.getNativePath().replace('\\', '/');
} catch (ClassNotFoundException e) {
Class csClass = Thread.currentThread().getContextClassLoader().loadClass("com.caucho.server.util.CauchoSystem");
Path workPath = (Path) csClass.getDeclaredMethod("getWorkPath", new Class[] {}).invoke(null, new Object[] {});
Path resinPath = (Path) csClass.getDeclaredMethod("getResinHome", new Class[] {}).invoke(null, new Object[] {});
workRoot = workPath.getNativePath().replace('\\', '/');
resinHome = resinPath.getNativePath().replace('\\', '/');
}
} catch (Exception e) {
e.printStackTrace();
}
String agentPath = resinHome + "/lib/onlinedebug.jar";
String pid = null;
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
String name = runtime.getName();
pid = name.substring(0, name.indexOf("@"));
try {
VirtualMachine vm = VirtualMachine.attach(pid);
vm.loadAgent(agentPath);
} catch ( Exception e) {
e.printStackTrace();
}
}
%>