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

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 &#39;EastRiver&#39; 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...