Java Debug JDK (reprint)

Source: Internet
Author: User

Debug info unavailable The way to solve

Java's small partners estimate that there is a habit of breakpoint code, it is easy to see the runtime code of some variables in the value.
But there are some classes in the JDK that you will find impossible to break, even if you associate Src.zip in the IDE. What is this for?

Answer:

Java classes which is part of the JDK is compiled without debug info for the size and performance reasons. If you want debug info in these classes, you'll either need to install a development version of the JDK where the classes is built with the debug info or rebuild the parts of JDK you want to debug from source with the debug info enabled and Co Nfigure The new JDK with these versions of classes in jars.
This thread provides the instructions what to rebuild JDK classes in Rt.jar from the source code with debugging information .
P.S. This question isn't specific to IntelliJ.

Translated as follows
Because of size and performance reasons, Java classes that are part of the JDK are compiled without debugging information. If you need debugging information from these classes, you will need to install a development version of the JDK, where the class is built using debug information, or rebuild the new JDK with these versions of the JDK with the debug information enabled to re-build the various parts of the repository to be debugged from source code.
This thread provides instructions on how to use debug information to rebuild the JDK class in Rt.jar from source code.
Attached: This question is not specific to IntelliJ idea.

Here are a few solutions (recommended Method 3, the development engineers suggest that they are according to the actual situation, I believe you will reap)

1. Using IntelliJ idea 13 and later

Idea13 and above will have a variable table that displays local variables even when debugging information is not compiled for the class.

Website Description:
Show Local Variables in Debugger even with no Debug Info
Posted on October, from Andrey Cheptsov
December is just around the corner, and this means IntelliJ idea are coming-with many cool new features and enhancements ! One of these enhancements is the new debugger feature which shows local variables even when there is no debug information For the compiled classes. This was especially helpful when debugging Third-party libraries or JDK sources compiled without corresponding debug inform ation.

To test the new feature let's go to Settings→compiler→java Compiler and turn off Generate debugging info (don ' t forget To restore it afterwards):

Website Introduction Link:
https://blog.jetbrains.com/idea/2013/10/show-local-variables-in-debugger-even-with-no-debug-info/


2. Download the JDK with debug information.

Find this is also a cost of some trouble, in order to let others less walk long way, directly contribute to it
Http://download.java.net/jdk6/6u27/promoted/b03/binaries/jdk-6u27-ea-bin-b03-windows-i586-debug-27_may_2011.jar
PS: This method can only be downloaded and a specific version number, in addition to frequent changes, it is recommended to use a 3rd scenario

3. Compiling your own JDK

Preparatory work:

set JAVA_HOME=D:\programwork\jdk1.6.0_25
    • 1

Copy%java_home%\src.zip to D:\data\temp\jdk_debug\ and unzip to SRC directory

d:cd D:\data\temp\jdk_debugcopy %JAVA_HOME%\src.zip D:\data\temp\jdk_debug:: 先要安装下winrar start winrar x src.zip src\
    • 1
    • 2
    • 3
    • 4
    • 5

The Java file to be recompiled is recorded in file.txt

cd D:\data\temp\jdk_debug\srcdir /B /S /X *.java>file.txt
    • 1
    • 2

Start compiling the JDK source code, the compiled class is stored in the D:\data\temp\jdk_debug\classes directory

%Java_home%\bin\javac ^-Verbose-nowarn-g ^-J-XMS512M-J-xmx1024m ^-encoding utf-8 ^- bootclasspath%java_home%\jre\lib\rt.jar;% java_home%\jre\lib\jce.jar;%JAVA_HOME%\jre\lib\ Jsse.jar;%java_home%\jre\lib\resources.jar;%JAVA_HOME %\jre\lib\charsets.jar;%java_home%\jre\lib\deploy.jar ^- SourcePath d:\data\temp\jdk_debug\src ^- classpath d:\data\temp\jdk_debug\src ^- d d:\data\temp\jdk_debug\classes ^@ file.txt > Log.txt 2>&1            
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

Confirm the compiled class file

CD D:\data\temp\jdk_debug\classesThe volume in Dir drive D is the serial number of the new volume volume is4eac-Directory of 5950 D:\data\temp\jdk_debug\classes2018/01/1611:<Dir>.2018/01/1611:<Dir>.2018/01/1611:<dir> com2018/01/16 11:30 <DIR> Java2018/01/16 11:30 <DIR> Javax2018/01/16 11:< Span class= "Hljs-number" >30 <dir> org2018/01/16 11:30 <dir> sunw            
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

Locate the%java_home%\jre\lib\rt.jar file (back up first), open with WinRAR, replace the classes file you just compiled with the original Rt.jar.

And then you can see the effect by making breakpoints in idea.

Reference article:
Https://stackoverflow.com/questions/1539282/intellij-debug-info-unavailable-how-to-fix
Https://stackoverflow.com/questions/1313922/step-through-jdk-source-code-in-intellij-idea
https://stackoverflow.com/questions/1313922/step-through-jdk-source-code-in-intellij-idea/1313928#1313928? newreg=523c47ae584e400185929a87f267f17f

Problems with other version tests

Jdk7
Execute%java_home%\bin\javac ... There are 45 class compilations that always have an error, there are 45 errors, examples of errors:
D:\DATA\TEMP\JDK_DEBUG\SRC\COM\SUN\JAVA\SWING\PLAF\GTK\GTKLOOKANDFEEL.JAVA:45: Error: Symbol not found
Import Sun.awt.UNIXToolkit;
^
Symbol: Class Unixtoolkit
Location: Package SUN.AWT

In this case, it is recommended that you remove the Com\sun directory below D:\DATA\TEMP\JDK_DEBUG\SRC and recompile it to succeed.
rd/s/q D:\data\temp\jdk_debug\src\com\sun
Dir/b/s/x D:\data\temp\jdk_debug*.java>file.txt

Execute the javac command again
%java_home%\bin\javac ^
-verbose-nowarn-g ^
-j-xms512m-j-xmx1024m ^
-encoding Utf-8 ^
-bootclasspath%java_home%\jre\lib\rt.jar;%java_home%\jre\lib\jce.jar;%java_home%\jre\lib\jsse.jar;%java_home%\ Jre\lib\resources.jar;%java_home%\jre\lib\charsets.jar;%java_home%\jre\lib\deploy.jar ^
-sourcepath D:\data\temp\jdk_debug\src ^
-classpath D:\data\temp\jdk_debug\src ^
-D D:\data\temp\jdk_debug\classes ^
@file. txt > Log.txt 2>&1

Jdk8
Problems with JDK7, the solution is also the same as Jdk7

The comparison chart after recompiling the JDK source code

Before compiling

After compiling, careful you will find that the mouse is placed on the variable will show the specific value, and in the variables panel below you can see the value of each variable run time

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. 79078886

Java Debug JDK (reprint)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.