java调试工具jdb
Finds and fixes bugs in Java platform programs.
Synopsis
jdb [options] [classname] [arguments]
options
-
Command-line options. See Options.
- classname
-
Name of the main class to debug.
- arguments
-
Arguments passed to the
main()
method of the class.
Description
The Java Debugger (JDB) is a simple command-line debugger for Java classes. The jdb
command and its options call the JDB. The jdb
command demonstrates the Java Platform Debugger Architecture (JDBA) and provides inspection and debugging of a local or remote Java Virtual Machine (JVM). See Java Platform Debugger Architecture (JDBA) athttp://docs.oracle.com/javase/8/docs/technotes/guides/jpda/index.html
Start a JDB Session
There are many ways to start a JDB session. The most frequently used way is to have JDB launch a new JVM with the main class of the application to be debugged. Do this by substituting the jdb
command for the java
command in the command line. For example, if your application's main class is MyClass
, then use the following command to debug it under JDB:
jdb MyClass
When started this way, the jdb
command calls a second JVM with the specified parameters, loads the specified class, and stops the JVM before executing that class's first instruction.
Another way to use the jdb
command is by attaching it to a JVM that is already running. Syntax for starting a JVM to which the jdb
command attaches when the JVM is running is as follows. This loads in-process debugging libraries and specifies the kind of connection to be made.
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n MyClass
You can then attach the jdb
command to the JVM with the following command:
jdb -attach 8000
The MyClass
argument is not specified in the jdb
command line in this case because the jdb
command is connecting to an existing JVM instead of launching a new JVM.
There are many other ways to connect the debugger to a JVM, and all of them are supported by the jdb
command. The Java Platform Debugger Architecture has additional documentation on these connection options.
Basic jdb Commands
The following is a list of the basic jdb
commands. The JDB supports other commands that you can list with the -help
option.
help or ?
The help
or ?
commands display the list of recognized commands with a brief description.
run
After you start JDB and set breakpoints, you can use the run
command to execute the debugged application. The run
command is available only when the jdb
command starts the debugged application as opposed to attaching to an existing JVM.
cont
Continues execution of the debugged application after a breakpoint, exception, or step.
-
Displays Java objects and primitive values. For variables or fields of primitive types, the actual value is printed. For objects, a short description is printed. See the dump command to find out how to get more information about an object.
Note: To display local variables, the containing class must have been compiled with the
javac -g
option.The
print
command supports many simple Java expressions including those with method invocations, for example:print MyClass.myStaticField
print myObj.myInstanceField
print i + j + k (i, j, k are primities and either fields or local variables)
print myObj.myMethod() (if myMethod returns a non-null)
print new java.lang.String("Hello").length()
dump
For primitive values, the dump
command is identical to the print
command. For objects, the dump
command prints the current value of each field defined in the object. Static and instance fields are included. The dump
command supports the same set of expressions as the print
command.
threads
List the threads that are currently running. For each thread, its name and current status are printed and an index that can be used in other commands. In this example, the thread index is 4, the thread is an instance of java.lang.Thread
, the thread name is main
, and it is currently running.
4. (java.lang.Thread)0x1 main running
thread
Select a thread to be the current thread. Many jdb
commands are based on the setting of the current thread. The thread is specified with the thread index described in the threads command.
where
The where
command with no arguments dumps the stack of the current thread. The where
all
command dumps the stack of all threads in the current thread group. The where
threadindex
command dumps the stack of the specified thread.
If the current thread is suspended either through an event such as a breakpoint or through the suspend
command, then local variables and fields can be displayed with the print
and dump
commands. The up
and down
commands select which stack frame is the current stack frame.
Breakpoints
Breakpoints can be set in JDB at line numbers or at the first instruction of a method, for example:
The command
stop at MyClass:22
sets a breakpoint at the first instruction for line 22 of the source file containingMyClass
.The command
stop in java.lang.String.length
sets a breakpoint at the beginning of the methodjava.lang.String.length
.The command
stop in MyClass.<clinit>
uses<clinit>
to identify the static initialization code forMyClass
.
When a method is overloaded, you must also specify its argument types so that the proper method can be selected for a breakpoint. For example, MyClass.myMethod(int,java.lang.String)
or MyClass.myMethod()
.
The clear
command removes breakpoints using the following syntax: clear MyClass:45
. Using the clear
or stop
command with no argument displays a list of all breakpoints currently set. The cont
command continues execution.
Stepping
The step
command advances execution to the next line whether it is in the current stack frame or a called method. The next
command advances execution to the next line in the current stack frame.
Exceptions
When an exception occurs for which there is not a catch
statement anywhere in the throwing thread's call stack, the JVM typically prints an exception trace and exits. When running under JDB, however, control returns to JDB at the offending throw. You can then use the jdb
command to diagnose the cause of the exception.
Use the catch
command to cause the debugged application to stop at other thrown exceptions, for example: catch java.io.FileNotFoundException
or catch
mypackage.BigTroubleException
. Any exception that is an instance of the specified class or subclass stops the application at the point where it is thrown.
The ignore
command negates the effect of an earlier catch
command. The ignore
command does not cause the debugged JVM to ignore specific exceptions, but only to ignore the debugger.
Options
When you use the jdb
command instead of the java
command on the command line, the jdb
command accepts many of the same options as the java
command, including -D
, -classpath
, and -X
options. The following list contains additional options that are accepted by the jdb
command.
Other options are supported to provide alternate mechanisms for connecting the debugger to the JVM it is to debug. For additional documentation about these connection alternatives, see Java Platform Debugger Architecture (JPDA) athttp://docs.oracle.com/javase/8/docs/technotes/guides/jpda/index.html
- -help
-
Displays a help message.
- -sourcepath dir1:dir2: . . .
-
Uses the specified path to search for source files in the specified path. If this option is not specified, then use the default path of dot (.).
- -attach address
-
Attaches the debugger to a running JVM with the default connection mechanism.
- -listen address
-
Waits for a running JVM to connect to the specified address with a standard connector.
- -launch
-
Starts the debugged application immediately upon startup of JDB. The
-launch
option removes the need for therun
command. The debugged application is launched and then stopped just before the initial application class is loaded. At that point, you can set any necessary breakpoints and use thecont
command to continue execution. - -listconnectors
-
List the connectors available in this JVM.
- -connect connector-name:name1=value1
-
Connects to the target JVM with the named connector and listed argument values.
- -dbgtrace [flags]
-
Prints information for debugging the
jdb
command. - -tclient
-
Runs the application in the Java HotSpot VM client.
- -tserver
-
Runs the application in the Java HotSpot VM server.
- -Joption
-
Passes
option
to the JVM, where option is one of the options described on the reference page for the Java application launcher. For example,-J-Xms48m
sets the startup memory to 48 MB. Seejava
(1).
Options Forwarded to the Debugger Process
- -v -verbose[:class|gc|jni]
-
Turns on verbose mode.
- -Dname=value
-
Sets a system property.
- -classpath dir
-
Lists directories separated by colons in which to look for classes.
- -Xoption
-
Nonstandard target JVM option.
java调试工具jdb的更多相关文章
- 2020年最佳Java调试工具(翻译)
调试是应用程序开发周期不可或缺的一部分.用Java或任何其他语言编写程序时,每个开发人员应解决的首要问题之一是可靠的调试工具的可用性. 所使用的工具类型可能影响或破坏应用程序的调试过程,因此至关重要的 ...
- java调试工具
jps当前用户已启动的java进程信息,信息包括进程号和简短的进程command. jstat输出指定 jvm 实例的特定统计量:统计量:-class-compiler-gc-gccapacity-g ...
- 远程debug调试java代码
远程debug调试java代码 日常环境和预发环境遇到问题时,可以用远程调试的方法本地打断点,在本地调试.生产环境由于网络隔离和系统稳定性考虑,不能进行远程代码调试. 整体过程是通过修改远程服务JAV ...
- JAVA初学者的JDB 尝试
使用JDB调试简单递归程序 跟着娄老师的博客学习, 首先在终端使用Ctrl+Shift+T打开三个标签,方便操作. 使用Vim编辑自己的程序,练习程序如下 1 public class Factori ...
- JAVA命令大全
1.java.exe:======================运行java程序,这个相信每一位用Java的人知道了. 2.javac.exe:======================编译的Ja ...
- Android 调试工具集【转】
1.TraceView1)功能:用于热点分析和性能优化,分析每个函数占用的CPU时间,调用次数,函数调用关系等 2)方法: a)在程序代码中加入追踪开关 import android.os.Debug ...
- 使用jdb调试apk
jdb是一个支持java代码级调试的工具,它是由java jdk提供的,存在于xxx\Java\jdk1.6.0_21\bin之下 使用ddms调试时,主机会打开另外一个网络端口,在DDMS里查看,一 ...
- JDK(Java Development Kit)内置常用自带工具一览(转)
注意:可能随着JDK的版本升级,工具也会随着增多. JDK(Java Development Kit)是Java程序员最核心的开发工具,没有之一. JDK是一个功能强大的Java开发套装,它不仅仅为我 ...
- 深入 Java 调试体系: 第 1 部分,JPDA 体系概览
JPDA 概述 所有的程序员都会遇到 bug,对于运行态的错误,我们往往需要一些方法来观察和测试运行态中的环境.在 Java 程序中,最简单的,您是否尝试过使用 System.out.println( ...
随机推荐
- centos6.5 mysql忘记登入密码
1.修改文件目录为/etc/my.cnf的文件; 在[mysqld]的段中加上一句:skip-grant-tables,保存文件重启数据库: 例如: [mysqld] skip-grant-table ...
- Linux系统——常见的系统调用
本文列出了大部分常见的Linux系统调用,并附有简要中文说明. 以下是Linux系统调用的一个列表,包含了大部分常用系统调用和由系统调用派生出的的函数.这可能是你在互联网上所能看到的唯一一篇中文注释的 ...
- 游戏(game)
游戏(game) 题目描述 这个游戏是这样的,你有一个初始序列S ,你每次可以选择一段任意长度的连续区间,把他们+1 再膜k,给定目标序列,你需要尝试用尽量少的操作次数将初始序列变为目标序列.作为一名 ...
- 洛谷 [P3620] 数据备份
贪心神题 首先我们发现一个显然的贪心策略,连接相邻两个写字楼总是更优. 所以本题就变成了数轴上一堆点,要选 k 个彼此不相邻的区间,使得区间长度最小 对于 10000 的数据来说,我们可以用 DP 解 ...
- Springboot - 在启动完成后执行特定方法
1.实现方式 实现ApplicationRunner接口 实现CommandLineRunner接口 @Component @Slf4j public class AfterServiceStarte ...
- 洛谷P2168 荷马史诗
哈夫曼树原理. k=2时,和合并果子一样一样的. 由此思考,k>2时,应该也有相似的原理.确实如此,k进制哈夫曼树,每个结点最多会有k-1个子结点,对应k-1个元素(“元素”可以是更深层的子树) ...
- linux下的用户管理(一)
linux下有三类用户: 1.超级用户:root具有操作系统的一切权限,UID值为0的是超级用户 2.普通用户:只具有操作系统有限的权限,UID是从500到6000范围 3.伪用户:是为了方便系统管理 ...
- 只用一次循环开销 将类似 1 A 、1 B 的数据返回成为 1 A,B 的拼接形式
/// <summary> ///将类似 1 A .1 B 的数据返回成为 1 A,B 的拼接形式 /// </summary> /// <param name=&quo ...
- C# .NET4.0 改为 到.NET2.0 时 TypedTableBase 报错解决方法
.NET 4.0 降版本 到.NET 2.0.不出意外,问题必然来了. 编译错误一: 错误 1 命名空间“System”中不存在类型或命名空间名称“Linq”(是缺少程序集引用吗?)解决: 删掉该引用 ...
- 爬虫学习笔记(六)PyQuery模块
PyQuery模块也是一个解析html的一个模块,它和Beautiful Soup用起来差不多,它是jquery实现的,和jquery语法差不多,会用jquery的人用起来就比较方便了. Pyquer ...