`
deadcode
  • 浏览: 43125 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Debugging Tomcat Using JDB

阅读更多
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.
分享到:
评论

相关推荐

    Power C-C++ Debugging-Using Rational Purify with GDB.pdf

    《使用Rational Purify与GDB进行Power C/C++调试》一文,深入探讨了在UNIX平台上开发的C/C++应用程序中的调试技巧,特别聚焦于动态内存管理问题及其解决方案。文章由Rational Software B.V.的技术营销工程师Goran ...

    Debugging using DWARF V1-4

    **DWARF调试信息详解** DWARF是一种广泛使用的源代码级别的调试信息格式,它...通过阅读《Debugging using DWARF.pdf》这样的文档,开发者可以深入理解这一强大的调试格式,从而更好地利用它来优化和调试自己的代码。

    DebuggingTools

    Debugging Tools for Windows 是一套强大的开发和调试工具,主要用于对Windows操作系统进行深入的故障排查和性能分析。这个工具集包含了多种实用程序,如WinDbg、KD、CDB、NTSD等,它们都是针对不同场景的专业调试器...

    Tomcat The Definitive Guide, 2nd Edition(PDF)

    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 ...

    eclipse远程调试tomcat

    - 输入配置名称,例如`Remote Debugging Tomcat`。 - 在`Connect`选项卡中,设置`Host`为你运行Tomcat服务器的主机地址,`Port`设置为之前配置的8000。 2. **设置断点**: - 在Eclipse中打开你想调试的Java类,...

    Advanced.Apple.Debugging.&.Reverse.Engineering.v2.0 Code Part2

    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 【描述】:这个压缩包文件“Debugging Tools for Windows.zip”包含了用于Windows环境下的调试工具,特别针对Qt Creator的调试器配置问题。通常,当Qt Creator的调试器...

    H3C交换机debugging命令入门使用介绍

    ### H3C交换机Debugging命令入门使用介绍 #### 一、概述 H3C交换机作为网络设备的重要组成部分,在日常运维与故障排查过程中扮演着关键角色。通过使用H3C交换机的`debugging`命令,网络管理员可以获取详细的设备...

    A Debugging Tool for Application using Multiple DLLs使用多个

    "A Debugging Tool for Application using Multiple DLLs"就是这样一款专门解决此类问题的工具。 首先,让我们深入了解一下DLL。DLL文件包含了可执行代码和数据,它们可以在运行时被多个程序加载,而不是每个程序都...

    Advanced Apple Debugging & Reverse Engineering Code part1

    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

    Inside Windows Debugging - Practical Debugging and Tracing Strategies 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 ...

    Debugging Tools for Windows(X86+X64)

    Debugging Tools for Windows (x64)和Debugging Tools for Windows (x86) 微软Debugging Tools for Windows工具,简称windbg,查看dmp文件,调试驱动程序、应用程序等。

    Debugging Tools for Windows

    Debugging Tools for Windows,是为WINDOWS设计的调试程序工具,能够查看软件指令栈等功能。

    Developing and Debugging CICS Programs Using Rational Developer for System z(RDz).pdf

    ### 开发与调试CICS程序使用Rational Developer for System z (RDz) #### 概述 随着IBM Rational Developer for System z (简称RDz) V7.1版本的发布,集成开发CICS应用变得前所未所未有的简单。...

    debugging_with_gdb(中文版pdf)

    根据提供的信息,我们可以总结并详细解释与“debugging_with_gdb(中文版pdf)”相关的知识点。这份文档似乎是一份关于使用 GDB(GNU Debugger)进行调试的手册或指南的中文版 PDF 文件。GDB 是一个非常强大的开源调试...

    Debugging tools for windows

    标题中的“Debugging tools for windows(x86 6.10.3.233)”指的是特定版本的Windows调试工具,适用于x86架构,并且版本号为6.10.3.233。这个工具集包含了多种调试器,如WinDbg、KD、CDB和NTSD,它们都是系统级调试的...

    Debugging Tools for Windows (x86)windows分析工具

    《Windows分析工具——Debugging Tools for Windows (x86)深度解析》 Windows操作系统在运行过程中,有时会遇到各种异常情况,导致系统错误或应用程序崩溃。为了有效地诊断和解决这些问题,微软提供了一套强大的...

    Debugging With GDB 无水印pdf

    Debugging With GDB 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    Advanced Apple Debugging & Reverse Engineering v0.9.5

    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 ...

Global site tag (gtag.js) - Google Analytics