JDB debug configuration and skill set

The best way for using JDB is create a configuration file named jdb.ini in a specified folder.

---------------------------------------------------------------------------------------------------------------------------------------------------------------

Local debug support:

  Create a command line(ex. jdb_load.bat) and input the following commands set:

------------------------

   SET CLASSPATH=D:/work/ReverseTest/TestClass/bin

    jdb -J-Duser.home=.

------------------------

At the same folder of this command line, please create a jdb.ini and fill the following settings:

    stop in TestClass.main

    use D:/work/ReverseTest/TestClass/bin;D:/work/ReverseTest/TestClass/src

    run TestClass

    list

Finally by clicking "jdb_load.bat" and then you can debug the application -- TestClass.

 

---------------------------------------------------------------------------------------------------------------------------------------------------------------

Remote debug support:

--------------------

First create a command line set for loading the application like the following(Let's call this file load_app.bat)

    SET CP=D:/work/ReverseTest/TestClass/bin

    java  -cp %CP% -agentlib:jdwp=transport=dt_socket,address=localhost:8888,server=y,suspend=y TestClass

 

For a tomcat or Jboss, weblogic server, please set the following options in its loading shell script.

JBOSS:

Change run.bat/run.sh under JBOSS_HOME/bin(add the red line as following):

JBOSS_HOME: /var/jboss4

JAVA: /usr/java/j2sdk1.4.2_06/bin/java

JAVA_OPTS: -server -Xms128m -Xmx128m -Dprogram.name=run.sh

DEBUG_OPTS = -Xdebug -Xrunjdwp:transport= dt_socket,address=localhost:8888,server=y,suspend=n

CLASSPATH: /var/jboss4/bin/run.jar:/usr/java/j2sdk1.4.2_06/lib/tools.jar

 

TOMCAT:

Change catalina.bat/catalina.sh under TOMCAT_HOME/bin.(add the red line as following)

DEBUG_OPTS = -Xdebug -Xrunjdwp:transport= dt_socket,address=localhost:8888,server=y,suspend=n

 

--------------------

Second create a command line named jdb_load.bat.

   jdb -J-Duser.home=. -connect com.sun.jdi.SocketAttach:hostname=localhost,port=8888

Thirdly create a jdb.ini under the same folder of jdb_load.bat.

    stop in TestClass.main

    use D:/work/ReverseTest/TestClass/bin;D:/work/ReverseTest/TestClass/src

    run TestClass

    list

 

Finally by first clicking "load_app.bat", then clicking "jdb_load.bat" and then we can debug this application remotely.

---------------------------------------------------------------------------------------------------------------------------------------------------------------

 

Sample for debugging:

Jdb set breakpoint skill:

The best way for using JDB debug is by using the ini configuration file, this is the highly-efficient way for setting debug environment:

   stop in org.apache.commons.dbcp.PoolingConnection.<init>(java.sql.Connection)

   stop in org.apache.commons.dbcp.PoolingConnection.<init>(java.sql.Connection, org.apache.commons.pool.KeyedObjectPool)

   use D:/swap/commons-dbcp.jar;D:/swap/jar-src list

Attention: when we set the break point for a specified class, we should set their whole name (including its class path, package name etc.)

otherwise it won't make any effect on the specified execution routine, if there are multiple entries for a specified name, we should take the whole funciton's prototype into this call.
Using the remote debug configuration for a specified class will be the best choice.

 


Debug experience for using JDB: (Without source code to debug) 
 Firstly using the decompile tool to get the basic source code for a specified source package.
 Secondly we'll start the program and then the jdb debugger by using command line(see configdebugsupport).
 Thirdly when we get the break from the command line debug tool, we'll use the following commands:

     Where  -- Shows current break position and source code list.

 

------------------------

  http-01%2F192.168.1.133-8080-1[1] where

  [1] org.apache.commons.dbcp.DriverConnectionFactory.createConnection (DriverConnectionFactory.java:38)

  [2] org.apache.commons.dbcp.PoolableConnectionFactory.makeObject (PoolableConnectionFactory.java:294)

  [3] org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory (BasicDataSource.java:1,247)

  [4] org.apache.commons.dbcp.BasicDataSource.createDataSource (BasicDataSource.java:1,221)

  [5] org.apache.commons.dbcp.BasicDataSource.getConnection (BasicDataSource.java:880)

  [6] org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection (DataSourceUtils.java:113)

  [7] org.springframework.jdbc.datasource.DataSourceUtils.getConnection (DataSourceUtils.java:79)

    

       Then find your fields list (private fields) in the specified class.

        fields classid --- Shows all fields of the specified class.

------------------------ 

    http-01%2F192.168.1.133-8080-1[1] fields org.apache.commons.dbcp.DriverConnectionFactory

     ** fields list **

      java.sql.Driver _driver

      java.lang.String _connectUri

      java.util.Properties _props

 

   print/dump variables in current context

http-01%2F192.168.1.133-8080-1[1] print _driver

                 _driver = "jTDS 1.2"

http-01%2F192.168.1.133-8080-1[1] print _connectUri

                _connectUri = "jdbc:jtds:sqlserver://sql01:1433/Router_PROD;user=sa;password=SQL01;"

http-01%2F192.168.1.133-8080-1[1] print _props

               _props = "{user=sa, password=SQL01}"

 

    step up -- run until the return of current frame or function call

    We can read the decompiled source code and then use this step up to trace its logic and get the specified breakpoint for us, watch the specified/key variables in this process, then debug or remove the bug at last.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值