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. ?
???? 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. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |