in my project i want to debug the C/C++ source code of the OpenJDK version 8 using eclipse. For this purpose I have done following:
Compiled the OpenJDK8 with --with-debug-level=slowdebug using this readme.
Imported the sources makefile project into eclipse
Created an eclipse run configuration, executing gdb against the compiled OpenJDK's java.exe and targeting a sample java program. Into this configuration I have attached the JDK source code directory path, so that eclipse is able to translate debug symbols to source-code lines and view them to me (obviously)
With this approach, I am able to debug through the code of files like java.c.
My problem is that somehow I still cannot debug through native code. Like for example java.lang.System.currentTimeMillis().
To me it looked like the libraries were not included into the eclipse gdb-run. I tried to run gdb manually, and it still didn't work to debug through that code section.
Has anybody expirienced same behavior, or did ever try to debug the JDK source code? I guess I am missing something here... Maybe my approach is just not correct for the task? Would be glad to hear any proposal about how to debug the JDK source code propperly.
Thank you in advance.
You may need to force eclipse into debug mode via the top right corner beetle icon.
Another possible option is to use an assert(false) line instead of a break point.
finally, it's possible that you need to specify a compiler in your eclipse project settings.
Keep in mind that the Eclipse debugger does not work for all compilers, usually because of an incompatible linker. I would recommend looking online for a compatibility list.
Related
Just starting working on an existing project at work and wanted to use Visual Studio Code as my IDE (I have used it for a recent Rails project and loved it, so wanted to try with Java).
However, whenever I try to open one of the projects I receive a ton of different errors including:
When importing java.io, java.util, or anything similar, the error:
"The import of java.io (or java.util) cannot be resolved"
Existing classes have an error:
"The implicit super constructor is undefined for default constructor. Must define explicit constructor"
Other random "cannot resolve to a type" errors.
All of these seem to stem from some sort of setting error I have with VS Code but can seem to find what it is. I have already uninstalled and reinstalled the RedHat plug-in that enables the Java language for VS Code.
I have tried setting the java_home setting in the extension to the direct location of the install but that didn't work. Tried uninstalling and reinstalling java and that also didn't work.
My operating specs are as follows:
OS: macOS Sierra
VS Code version 1.15.1
JDK version 1.8.0.144
Any idea on what may be causing this? Do you think it may be an error in how I have VS Code set up or if it's an error (or rather incompatibility) with how the existing project is set up?
I ran into a similar issue. The solution was to remove everything from VS Code's workspace storage directory, which was located at $HOME/Library/Application Support/Code/User/workspaceStorage/.
I found this solution here: https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting#clean-the-workspace-directory
Update: This can now be done from within VS Code as of Language Support for Java(TM) by Red Hat Version 0.33.0. Open the command palette and type "java clean" (see official description in link).
As already mentioned previously, you require to clean the project, but that is a bit difficult thing because every folder is a Guid, and you do not know which one to clear, thus requiring you to delete everything. Starting with 0.33.0 version of the plugin you can automatically do that from within the IDE as well, use CTRL + Shift + P and type, java clean, and IDE will show you the suggestion tip for, Java: Clean the Java language server workspace. Upon selection, agree and restart the IDE. It will clean the language server workspace for you.
Another approach can be, the Maven tools within the IDE. If you have this plugin installed, you can use the side bar and utilize the Maven project helper options to perform actions like, clean, install, and package etc. For example, here is the project I am having and the options this shows,
That can be used, graphically, to manage your Maven-based projects. Also, this would work with the Java Extension Pack, not sure yet as to how it would behave with other extensions.
For me: CMD + Shift + P
Then type "Java: Clean Java language Server Workspace"
Note: This will reload/restart vscode as well.
Update:
This appears to not fix it anymore for me. In my case I am using a gradle project, and needed to set the rootProject.name in the settings.gradle to be the same as the folder name that the project is in.
I faced this issue after creating a whole Java project in one computer and then trying to run it on another computer.
After doing everything said in the other answers, what really made VS Code compile was to open each single project java file in VS Code and save it (a simple Ctrl + S). Maybe there is a simpler way of doing it, but that is what worked for me and I hope this helps anyone stuck in this issue.
Press ctrl+shift+p
then search 'java clean' and click 'java: clean java language server workspace' then click restart IDE.
I found another simple trick at least to get rid of "cannot be resolved to a type" errors which were coming from older workspaces and wrong project files I guess?. I just ran an empty main(), with the body commented out, while still keeping my local package / import commands at the start - no errors. After commenting in again, the project compiled without errors. Perhaps this refreshing effect might also help in this context?
I had to clean this folder to get it working on Windows
%APPDATA%\code\Local Storage
Just starting working on an existing project at work and wanted to use Visual Studio Code as my IDE (I have used it for a recent Rails project and loved it, so wanted to try with Java).
However, whenever I try to open one of the projects I receive a ton of different errors including:
When importing java.io, java.util, or anything similar, the error:
"The import of java.io (or java.util) cannot be resolved"
Existing classes have an error:
"The implicit super constructor is undefined for default constructor. Must define explicit constructor"
Other random "cannot resolve to a type" errors.
All of these seem to stem from some sort of setting error I have with VS Code but can seem to find what it is. I have already uninstalled and reinstalled the RedHat plug-in that enables the Java language for VS Code.
I have tried setting the java_home setting in the extension to the direct location of the install but that didn't work. Tried uninstalling and reinstalling java and that also didn't work.
My operating specs are as follows:
OS: macOS Sierra
VS Code version 1.15.1
JDK version 1.8.0.144
Any idea on what may be causing this? Do you think it may be an error in how I have VS Code set up or if it's an error (or rather incompatibility) with how the existing project is set up?
I ran into a similar issue. The solution was to remove everything from VS Code's workspace storage directory, which was located at $HOME/Library/Application Support/Code/User/workspaceStorage/.
I found this solution here: https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting#clean-the-workspace-directory
Update: This can now be done from within VS Code as of Language Support for Java(TM) by Red Hat Version 0.33.0. Open the command palette and type "java clean" (see official description in link).
As already mentioned previously, you require to clean the project, but that is a bit difficult thing because every folder is a Guid, and you do not know which one to clear, thus requiring you to delete everything. Starting with 0.33.0 version of the plugin you can automatically do that from within the IDE as well, use CTRL + Shift + P and type, java clean, and IDE will show you the suggestion tip for, Java: Clean the Java language server workspace. Upon selection, agree and restart the IDE. It will clean the language server workspace for you.
Another approach can be, the Maven tools within the IDE. If you have this plugin installed, you can use the side bar and utilize the Maven project helper options to perform actions like, clean, install, and package etc. For example, here is the project I am having and the options this shows,
That can be used, graphically, to manage your Maven-based projects. Also, this would work with the Java Extension Pack, not sure yet as to how it would behave with other extensions.
For me: CMD + Shift + P
Then type "Java: Clean Java language Server Workspace"
Note: This will reload/restart vscode as well.
Update:
This appears to not fix it anymore for me. In my case I am using a gradle project, and needed to set the rootProject.name in the settings.gradle to be the same as the folder name that the project is in.
I faced this issue after creating a whole Java project in one computer and then trying to run it on another computer.
After doing everything said in the other answers, what really made VS Code compile was to open each single project java file in VS Code and save it (a simple Ctrl + S). Maybe there is a simpler way of doing it, but that is what worked for me and I hope this helps anyone stuck in this issue.
Press ctrl+shift+p
then search 'java clean' and click 'java: clean java language server workspace' then click restart IDE.
I found another simple trick at least to get rid of "cannot be resolved to a type" errors which were coming from older workspaces and wrong project files I guess?. I just ran an empty main(), with the body commented out, while still keeping my local package / import commands at the start - no errors. After commenting in again, the project compiled without errors. Perhaps this refreshing effect might also help in this context?
I had to clean this folder to get it working on Windows
%APPDATA%\code\Local Storage
I'm trying to debug code that I've built from source. It is started with the wrapper from Tanuki.
I'm debugging inside IntelliJ idea but I'm not sure that is the problem.
The debugger correctly stops at all lines where I've put a break point but never else so F8, "step over" doesn't work. Very tiresome as I have to put break points every where :)
Am I doing something wrong?
How do you build the project? If you build it with Ant or some other tool, make sure that compilation is performed with debug info enabled (debug=true for Ant javac task). Obfuscation and bytecode instrumentation during the build can also affect the possibility to debug. If you run under some non-standard JVM, it may also cause such problem.
When performing remote debug, ensure the target process is started with the correct JVM options suggested in the IntelliJ IDEA Remote debug configuration. Your wrapper configuration may pass them incorrectly.
Make sure you don't have a different jar on the classpath (other than the project) with the same classes. You could be stepping through the compiled classes and "breakpointing" in the sources.
This worked for me: http://devnet.jetbrains.com/thread/267022. Basically there's another lib in the classpath confusing the debugger. Simply find out which library it is by stepping into during the debug. Then find it on the project and delete it.
In my case, it was an auto generated file that was causing the confusion.
happened to me as well, on Eclipse (Mars).
Restart of eclipse solved it... as simple as that...
I also faced the same problem.Below trick worked for me:
Delete the settings for Intellij
Windows User :C:\Users{username}.IntelliJIdea14
This will restart the Intellij for you from the beginning.
Hi I also had the same behavior and I got it fixed by installing the latest IntelliJ after removing/rename the folders found in these locations https://intellij-support.jetbrains.com/hc/articles/206544519
I had to delet all the versions I previously installed. Just give it a try.
Hi i've been trying to install the library on Thinking in Java book 4th edition and i hit a very thick brick wall. I've done everything that the guide from the website told me to do and i still can't get the library to work. From what i've read it seems that the problem is from the build.xml files. having no xml knowledge I am clueless about how I have to modify it in order for it to work. In both cmd and eclipse I am getting these error
c:\TIJ4\code\build.xml
Build Failed
c:\TIJ4\code\build.xml:59:J2SE5 required
Can anyone tell me what I should do ?
I am using eclipse if there is a simpler solution by using eclipse rather than ant please help me out. It's been a week now and I still can't make it work.
The important thing to do is to realize that your ant file has a specific java requirement.
Something to try that might fix this very easily : I believe you can remove any references to a specific JDK, and if you have a reasonably up to date JDK, the build will succeed.
The definete fix : Look into the exact (line 59) of your build file, and try to satisfy the java version that line requires. Java is generally backwords compatible -- something designed to run in J2SE5 should run in the latest JDK. Its not terribly difficult to update your JDK (just google for instructions on your OS).
The most common mistake I see is that people who have the java run time installed believe they also have the Java SDK as well.
Does this "install the library" means you want to look at the code and run them in your eclipse? If so I can share my experience with you.
First run the Eclipse.py script; this will add package info to the source code
Create a new Java project in Eclipse, and then just copy all the source code folders to the src source folder in eclipse, these folders will then be recognized as Java packages.
You should be able to run the classes with a main function.
You can also configure which java version to use for this project in Eclipse build path. 1.5 or higher will work.
I am using Eclipse 3.5 and I attached the src.zip to my global settings in Eclipse.
Windows--> Preferences -->Java -->Installed JREs -->rt.jar - Source attachment - ...../jdk/src.zip
I am successfully able to step in the java core library .class files and view the source code. I building a Class which uses the LinkedList and I have set a breakpoint inside the LinkedList class.
When I debug the breakpoints in my source code (my projects) are working good but when I need to step into the java core lib .classes I get the following error in my Eclipse
Unable to install breakpoint in java.util.LinkedList due to missing line Number attributes. Modify complier options to generate line number attributes.
I checked my complier settings in Preferences and found all options checked true.
It would to great if someone can help me resolve this issue.
Thanks in advance.
You may have the compiler set to include debugging information in YOUR class files, but the class files in rt.jar weren't compiled that way. You need to either recompile all the source for the classes in rt.jar (not for the faint of heart), or download a debug build of the jdk.
This blog posts give a comprehensive list of points to check
Follow the steps if you are compiling using Eclipse IDE
Go to windows > preferences > Java > compiler screen.
Make sure that add line number attributes to generated files (used by debugger) check box is checked.
Build again and try adding a breakpoint ahd hope it should work for you.
Note for ant builds
Follow the steps if you are compiling using ANT utility:
Check the build.xml file and make sure that debug attribute is set to true in javac task
Also, if you are using JBoss as an app server, then make sure that you have already opened a port for socket binding of remote
machine connection. If not then just ensure that C:/jboss/bin/run.bat has an entry with:
"set JAVA_OPTS=%JAVA_OPTS%
-Xdebug –Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=n" for opening port 5000 to listen all socket connections for debug/remote java application.
Build again and try adding a breakpoint ahd hope it should work for you.
You should not use a JRE with a JDR src attached as the JRE classes are not well suited for debugging.
Let Eclipse search for Java environments and then select the JDK from the resulting list. This Java environment will have the src.zip attached correctly and you should be able to investigate.
Note that even JDK classes do not have full debugging information available, so you cannot see local variables etc.
(Also, the Compiler settings panel only applies to your code. The JRE classes are pregenerated and the panel does not influence them).