首页 > 编程语言 >how to debug in java

how to debug in java

时间:2022-10-30 02:55:30浏览次数:44  
标签:java print DemToBin3 jdb how breakpoint debug main

jdb normal usages

1.compile period

javac -g, add complie information

mikeli@dell-pc:~/code/algo_java$ javac -g DemToBin3.java 

 

2.debug class in one window

jdb <className>

set breakpoint:

1:to method : stop in <class name>:<method name>

2:to line : stop at <calss name>.<line number>

run className

 

example 1:

mikeli@dell-pc:~/code/algo_java$ jdb DemToBin3
Initializing jdb ...
> stop in DemToBin3.main
Deferring breakpoint DemToBin3.main.
It will be set after the class is loaded.
> run DemToBin3
run  DemToBin3
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable

VM Started: Set deferred breakpoint DemToBin3.main

 

example 2:

mikeli@dell-pc:~/code/algo_java$ jdb DemToBin3
Initializing jdb ...
> stop at DemToBin3:5
Deferring breakpoint DemToBin3:5.
It will be set after the class is loaded.
> run DemToBin3
run  DemToBin3
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable

VM Started: Set deferred breakpoint DemToBin3:5

 

3.debug another class in other window

for example , A class is running in another window,or remote environment

we compile A class like below:

java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y Acalss

jvm will show the running port(such as :8008)

then we use this port to debug:

jdb -attach 8008

 

 

4.debug common usage

execute usage: step  and cont

show parameter information: locals,print

show executing code:list

main[1] step

Step completed: "thread=main", DemToBin3.main(), line=6 bci=3
6            String rs="";

main[1] step

Step completed: "thread=main", DemToBin3.main(), line=13 bci=6
13                if(x!=0)

 

cont   Continues execution of the debugged application after a breakpoint, exception, or step.

VM Started: Set deferred breakpoint DemToBin3.main

Breakpoint hit: "thread=main", DemToBin3.main(), line=5 bci=0
5            int x=10;

main[1] cont     
> 1010

 

 

              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()

 

 

main[1] list
1    public class DemToBin3
2    {
3        public static void main(String[] args)
4        {
5 =>         int x=10;
6            String rs="";
7    
8            //loop,until x=0
9            //if x!=0, x%2 as mod,link to result.
10            //then x/2,into next loop

 

 

attach source code:

like java option

jdb -sourcepath dir1:dir2:dir3 ...

such as      jdb -sourcepath  .:/bin:/

标签:java,print,DemToBin3,jdb,how,breakpoint,debug,main
From: https://www.cnblogs.com/lsjava/p/16840403.html

相关文章

  • Java Web
    javaweb是指,所有通过java语言编写可以通过浏览器访问的程序的总称,叫javaweb。javaweb是基于请求和影响来开发的。请求是指客户端给服务器发送的数,请求叫Request。......
  • Java安全之Tomcat6 Filter内存马
    Java安全之Tomcat6Filter内存马回顾Tomcat8打法先回顾下之前Tomcat789的打法这里先抛开78之间的区别,在8中,最后add到filterchain的都是一个filterconfig对象Applica......
  • JavaScript – event loop 事件循环, 单线程, Web Worker
    前言因为要写RxJS系列,有一篇要介绍scheduler.它需要基础的JS执行机制,于是就有了这里篇. 顺带也介绍以下WebWorker呗. 参考知乎–详解JavaScript中的......
  • netty高性能编程-第2章Java BIO编程
    2.1IO模型I/O模型简单的理解:就是用什么样的通道进行数据的发送和接收,很大程度上决定了程序通信的性能Java共支持3种网络编程模型/IO模式:BIO、NIO、AIOJavaBIO:同步......
  • java 二维数组
    publicclassArrayTwo{publicstaticvoidmain(String[]args){int[][]arr={{1,2,3},{11,223,44}};......
  • Java如何获取当前的jar包路径以及如何读取jar包中的资源
    如何加载jar包中的资源。1.比如说我要得到背景图片,源代码中它是/src/UI/image/background.jpg那么在jar包中它的路径应该是/UI/image/background.jpg路径最前面的/......
  • JAVA-事件监听机制
    packagecom.itheima;importjavax.swing.*;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;publicclassJFrame11{publicstati......
  • JavaScript
    JavaScriptJavaScript(JS)是一种脚本语言,可以用来更改页面内容,控制多媒体,制作图像动画等.在body标签里面写一个script标签,在script标签里面编写JavaScript代码......
  • JavaWeb-MySQL基础
    JavaWeb-MySQL基础1,数据库相关概念1.1数据库存储和管理数据的仓库,数据是有组织的进行存储。数据库英文名是DataBase,简称DB。数据库就是将数据存储在硬盘上,可......
  • Java顺序结构和分支结构
    Java顺序结构和分支结构1.*顺序结构任何编程语言中最常见的程序结构就是顺序结构。顺序结构就是程序从上到下逐行地执行,中间没有任何判断和跳转。如果main方法的多行代......