- 浏览: 43125 次
- 性别:
- 来自: 上海
最新评论
Debugging Tomcat Using JDB
Submitted by mmorsi on Tue, 2007-11-20 17:56
As a fan of Vim and console development and a staunchent opponent of IDEs (not that they don't have their merrits, they are simply too complicated and too prone to breaking when some miniscule setting is changed IMO), I attempted to figure out how to debug Tomcat using the command line java debugger yesterday. To do so, you will need todo a few things; mainly enable debugging support in the server, locate the source code corresponding to the servlet you will be debugging, and familiarize yourself with the JDB tool.
By default if you run the tomcat startup script catalina.sh with parameters "jpda start" the server will automatically be placed in debugging mode. There are a few caveats to this, and you can configure the behavior of this by opening up catalina.sh and looking at the config options described at the beginning of the file. Whatever you decide to change will need to exported before the script is run, so for example to change the default behavior to force the server to wait until a debugger is attached and the "run" command is invoked (before it tries to load any servled) you would issue a
"JPDA_SUSPEND='y'"
You may desire to change some of the other default values, for example the default debugging port Tomcat uses (8000) as it may be employed by some other service (in Fedora 7, the network audio server (nas) is enabled by default and uses that port)
Next you will need to have access to the source code backing the servlet you are debugging. Unfortunately jdb cannot read source out of a jar so you will need to uncompress any source directories that you may have and specify their location to jdb via the command line (though now irrelevant, I discovered yesterday maven can create a source-jar with the "maven-source-plugin" plugin). To start debugging, simply issue the following command:
"jdb -attach 8000 -sourcepath dir1:dir2:dir3"
(obviously changing the port and colon seperated source directory list). If the sourcepath isn't specified, the default will be '.'. Furthermore, since java uses the full package/class name to refer to classes, which ties into the paths which they are located, you will need the entire correct directory structure setup correctly under the sourcedir(s) (eg. if you want to debug com.foobar.Class you will need com/foobar/Class.java under one of the sourcedirs specified
You should now be in debugging mode (recall that if the Tomcat suspend option is set, you will have to issue 'run' before the server execution continues). Though I do not have the space to detail everything here, I will list some of the more useful commands that I've found:
* stop at com.foobar.Class:42 - will insert a breakpoint at the specified line in the specified class
* stop in com.foobar.Class.myMethod - will insert a breakpoint at the specified method in the specified class
* clear - list the location based breakpoints currently in place
* clear com.foobar.Class.myMethod - delete the specified location based breakpoint
* catch java.lang.Exception - will break whenever an Exception (or one of its derivatives) is thrown
* ignore - list the exception based breakpoints currently in place
* ignore java.lang.Exception - delete the specified location based breakpoint
* step - step though one line of source
* step up - execute until the current function/method returns
* next - step over one line of source
* print var - prints out the value of var
* where - prints out the stack trace of the current thread
If everything went as expected you should now be able to debug any servlet running in Tomcat. Pretty simple huh? While JDB isn't the most user friendly debugger, it is very simple and intuitive, a value which I hold dearly.
Submitted by mmorsi on Tue, 2007-11-20 17:56
As a fan of Vim and console development and a staunchent opponent of IDEs (not that they don't have their merrits, they are simply too complicated and too prone to breaking when some miniscule setting is changed IMO), I attempted to figure out how to debug Tomcat using the command line java debugger yesterday. To do so, you will need todo a few things; mainly enable debugging support in the server, locate the source code corresponding to the servlet you will be debugging, and familiarize yourself with the JDB tool.
By default if you run the tomcat startup script catalina.sh with parameters "jpda start" the server will automatically be placed in debugging mode. There are a few caveats to this, and you can configure the behavior of this by opening up catalina.sh and looking at the config options described at the beginning of the file. Whatever you decide to change will need to exported before the script is run, so for example to change the default behavior to force the server to wait until a debugger is attached and the "run" command is invoked (before it tries to load any servled) you would issue a
"JPDA_SUSPEND='y'"
You may desire to change some of the other default values, for example the default debugging port Tomcat uses (8000) as it may be employed by some other service (in Fedora 7, the network audio server (nas) is enabled by default and uses that port)
Next you will need to have access to the source code backing the servlet you are debugging. Unfortunately jdb cannot read source out of a jar so you will need to uncompress any source directories that you may have and specify their location to jdb via the command line (though now irrelevant, I discovered yesterday maven can create a source-jar with the "maven-source-plugin" plugin). To start debugging, simply issue the following command:
"jdb -attach 8000 -sourcepath dir1:dir2:dir3"
(obviously changing the port and colon seperated source directory list). If the sourcepath isn't specified, the default will be '.'. Furthermore, since java uses the full package/class name to refer to classes, which ties into the paths which they are located, you will need the entire correct directory structure setup correctly under the sourcedir(s) (eg. if you want to debug com.foobar.Class you will need com/foobar/Class.java under one of the sourcedirs specified
You should now be in debugging mode (recall that if the Tomcat suspend option is set, you will have to issue 'run' before the server execution continues). Though I do not have the space to detail everything here, I will list some of the more useful commands that I've found:
* stop at com.foobar.Class:42 - will insert a breakpoint at the specified line in the specified class
* stop in com.foobar.Class.myMethod - will insert a breakpoint at the specified method in the specified class
* clear - list the location based breakpoints currently in place
* clear com.foobar.Class.myMethod - delete the specified location based breakpoint
* catch java.lang.Exception - will break whenever an Exception (or one of its derivatives) is thrown
* ignore - list the exception based breakpoints currently in place
* ignore java.lang.Exception - delete the specified location based breakpoint
* step - step though one line of source
* step up - execute until the current function/method returns
* next - step over one line of source
* print var - prints out the value of var
* where - prints out the stack trace of the current thread
If everything went as expected you should now be able to debug any servlet running in Tomcat. Pretty simple huh? While JDB isn't the most user friendly debugger, it is very simple and intuitive, a value which I hold dearly.
发表评论
-
阅读文章 最简单解决CHM文件无法显示的办法
2009-12-03 10:07 978在CHM文件右键——属性——解除锁定!万事大吉! -
log4j:ERROR LogMananger.repositorySelector was null likely due to error in class
2009-11-28 13:13 4754Log4j 1.2.15存在一个bug -
Hibernate: Log SQL Statements
2009-11-28 13:12 1315Hibernate: Log SQL Statements A ... -
程序员修炼之道:正交软件架构方法
2009-11-28 13:09 1105程序员修炼之道:正交软 ... -
程序设计语言正交特性的一点思考
2009-11-28 13:04 1037程序设计语言正交特性 ... -
ICEFaces 值修改事件处理 ValueChangeEvent
2009-11-28 13:01 1092public void genreOthersChang ... -
"node to traverse cannot be null"
2009-11-28 13:00 3413java hibernate 中"node to t ... -
what is “Microsoft-WebDAV-MiniRedir/5.1.2600″ ?
2009-11-28 12:58 244110 1月 2009 So, what is “Microso ... -
漏洞扫描工具nikto使用心得
2009-11-28 12:57 23992009-03-18 12:33:14 www.hackba ... -
Windows添加移动到 右键菜单
2009-11-28 12:56 968Windows Registry Editor Version ... -
Windows隐藏登录界面用户名
2009-11-28 12:55 980Windows Registry Editor Version ... -
Windows XP 注册表设置文件
2009-11-28 12:54 1751Windows XP 注册表设置文件 作者:admin 日期: ... -
Distributed Transaction Coordinator 服务因 3221229584 (0xC0001010) 服务性错误而停止
2009-11-28 12:53 2173Distributed Transaction Coordin ... -
安装GNOME中文桌面环境
2009-11-28 12:52 14258.3. 安装GNOME中文桌面环境 Prev Chapter ... -
Oracle命令行修改表空间大小
2009-11-28 12:50 2503alter tablespace system resize ... -
Oracle批量删除对象
2009-11-28 12:50 1546DECLARE TYPE name_list IS TABLE ... -
免安装Oracle运行pl/sql developer
2009-11-28 12:47 929Keiboc发布于 2008-5-08 | 1062次阅读 ... -
undefined reference to `_strcasestr'
2009-11-28 12:42 1561undefined reference to `_strcas ... -
使用automake的顺序
2009-11-28 12:41 964acloacl, autohead, automake --a ... -
ORA-01658: 无法为表空间XXX中的段创建 INITIAL 区
2009-11-28 12:40 2375表空间耗尽
相关推荐
《使用Rational Purify与GDB进行Power C/C++调试》一文,深入探讨了在UNIX平台上开发的C/C++应用程序中的调试技巧,特别聚焦于动态内存管理问题及其解决方案。文章由Rational Software B.V.的技术营销工程师Goran ...
**DWARF调试信息详解** DWARF是一种广泛使用的源代码级别的调试信息格式,它...通过阅读《Debugging using DWARF.pdf》这样的文档,开发者可以深入理解这一强大的调试格式,从而更好地利用它来优化和调试自己的代码。
Debugging Tools for Windows 是一套强大的开发和调试工具,主要用于对Windows操作系统进行深入的故障排查和性能分析。这个工具集包含了多种实用程序,如WinDbg、KD、CDB、NTSD等,它们都是针对不同场景的专业调试器...
Debugging and Troubleshooting-diagnosing problems with Tomcat or a web application * * Compiling your own Tomcat, rather than using the pre-built release * * Running two or more Tomcat ...
- 输入配置名称,例如`Remote Debugging Tomcat`。 - 在`Connect`选项卡中,设置`Host`为你运行Tomcat服务器的主机地址,`Port`设置为之前配置的8000。 2. **设置断点**: - 在Eclipse中打开你想调试的Java类,...
Advanced Apple Debugging & Reverse Engineering, Second Edition ISBN: Learn the powerful secrets of Apple’s software debugger, LLDB, that can get more information out of any program than you ever ...
【标题】:Debugging Tools for Windows.zip 【描述】:这个压缩包文件“Debugging Tools for Windows.zip”包含了用于Windows环境下的调试工具,特别针对Qt Creator的调试器配置问题。通常,当Qt Creator的调试器...
### H3C交换机Debugging命令入门使用介绍 #### 一、概述 H3C交换机作为网络设备的重要组成部分,在日常运维与故障排查过程中扮演着关键角色。通过使用H3C交换机的`debugging`命令,网络管理员可以获取详细的设备...
"A Debugging Tool for Application using Multiple DLLs"就是这样一款专门解决此类问题的工具。 首先,让我们深入了解一下DLL。DLL文件包含了可执行代码和数据,它们可以在运行时被多个程序加载,而不是每个程序都...
Advanced Apple Debugging & Reverse Engineering, Second Edition ISBN: Learn the powerful secrets of Apple’s software debugger, LLDB, that can get more information out of any program than you ever ...
Inside Windows Debugging - Practical Debugging and Tracing Strategies 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 ...
Debugging Tools for Windows (x64)和Debugging Tools for Windows (x86) 微软Debugging Tools for Windows工具,简称windbg,查看dmp文件,调试驱动程序、应用程序等。
Debugging Tools for Windows,是为WINDOWS设计的调试程序工具,能够查看软件指令栈等功能。
### 开发与调试CICS程序使用Rational Developer for System z (RDz) #### 概述 随着IBM Rational Developer for System z (简称RDz) V7.1版本的发布,集成开发CICS应用变得前所未所未有的简单。...
根据提供的信息,我们可以总结并详细解释与“debugging_with_gdb(中文版pdf)”相关的知识点。这份文档似乎是一份关于使用 GDB(GNU Debugger)进行调试的手册或指南的中文版 PDF 文件。GDB 是一个非常强大的开源调试...
标题中的“Debugging tools for windows(x86 6.10.3.233)”指的是特定版本的Windows调试工具,适用于x86架构,并且版本号为6.10.3.233。这个工具集包含了多种调试器,如WinDbg、KD、CDB和NTSD,它们都是系统级调试的...
《Windows分析工具——Debugging Tools for Windows (x86)深度解析》 Windows操作系统在运行过程中,有时会遇到各种异常情况,导致系统错误或应用程序崩溃。为了有效地诊断和解决这些问题,微软提供了一套强大的...
Debugging With GDB 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
You’ve learned the essentials of working with LLDB’s Python module, as well as how to correct any errors using Python’s PDB debugging module. Now you’ll explore the main players within the lldb ...