Solution to the problem that Debug JDK source cannot view local variables

1. Explanation of the problem
  First of all, we need to understand why the JDK source cannot observe local variables when debugging, because in jdk, when sun compiles the classes in rt.jar, the debugging information is removed, so that the local variables cannot be seen in eclipse. the value of the variable.
In this case, if you view local variables during debugging, you must compile the corresponding source code yourself to have debugging information.
To achieve this goal, one is to find a version that has been compiled by others on the Internet, and the rest can only be compiled by yourself.
Below we provide a method for our own compilation, I hope it will be helpful to you, if you have any questions, please leave a message.

2. Solution
1. Select or create your working directory, for example, I choose: E:\
2. In the E drive, create a folder jdk_src to store the source code; create a folder jdk_debug in the E drive to output the compilation results .
3. Find src.zip from the place where jdk is installed on your machine, and it can be found in your JDK installation directory, for example, mine is in the F:\SoftWare\Java\jdk1.7.0_80 directory. Then extract the src to the jdk_src directory.
4. After decompression, select the content you need to compile and delete the rest. Here you can select the following folders: java javax org These three directories are enough
5. Copy rt.jar from your JDK dark directory such as: F:\SoftWare\Java\jre7\lib to your working directory (ie E:\), the purpose of this is to allow you to reduce the number of filenames you type on the command line.
6. Enter cmd, enter the E drive, and execute the following command:

dir /B /S /X jdk_src\*.java > filelist.txt

Create a file called filelist.txt that holds the names of all the classes you will compile.

 

7. Next, execute the following command:

javac -J-Xms16m -J-Xmx1024m -sourcepath e:\jdk_src -cp e:\rt.jar -d e:\jdk_debug -g @filelist.txt >> log.txt 2>&1

This command will compile all the files you specify, output the compilation results to the jdk_debug directory, and generate the log.txt journal file. This log file records compilation warnings, but no errors.

 

8. Enter the jdk_debug directory and enter the following command:

jar cf0 rt_debug.jar *

 

 This command can generate the jar package of rt.jar with compilation information that we need.
9. Copy the generated rt_debug.jar package to JDK_HOME\jre\lib\endorsed. If there is no endorsed directory, create it yourself.
10. If you debug in eclipse. Click Window->Installed JRES, select the corresponding JDK, click Edit, r and then click Add External jars, select rt_debug.jar in our step 9, and that's it.

Note: If the rt.jar package already exists in the original JRE directory, the location of the newly compiled rt_debug.jar must be before the original jar package, as shown in the following figure.


 

Now that all the steps are completed, try to debug it quickly. If you can view the local variables, then congratulations on your success.

 

Source: http://www.cnblogs.com/zjrodger/p/5110538.html

 


 Note: After using this method, when I use the smtp server and TLS protocol to send emails, it fails all the time and reports

javax.mail.MessagingException: Could not convert socket to TLS error, just remove rt_debug.jar and re-join the jdk environment. The reason is currently unknown.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326403780&siteId=291194637