Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Debug JDK source code(java source code debug)
Debug JDK source code [message #642292] Tue, 30 November 2010 17:25 Go to next message
Al Mising name is currently offline Al Mising nameFriend
Messages: 123
Registered: July 2009
Senior Member
I want to debug the java source code in eclipse.

I am able to attach and see the JDK class files but I want to be able to stick a statement into the JDK source code.
e.g. in Container.addImpl():
System.out.println ("Container.addImpl(): " + component + "\tindex: " + index);

I went to the rt.jar in the package explorer. I right-clicked to get Properties, then select Java Source Attachment and then specify a path:
C:/Program Files/Java/jdk1.6.0_18/src.zip
but still I get Container.class not Container.java

So then unzipped the src.zip and using that directory as the source attachment. I can edit Container.java now in Eclipse at this point. When it runs it still uses the class file and the new line appears in the Container.class, but I don't see the output on the console.

Something is still not right. How do I do this?

(Note that I'm not looking for a bug in the JDK, just want to see what its doing)
Re: Debug JDK source code [message #642295 is a reply to message #642292] Tue, 30 November 2010 17:37 Go to previous messageGo to next message
Prakash G.R. is currently offline Prakash G.R.Friend
Messages: 621
Registered: July 2009
Senior Member
On 30/11/10 10:55 PM, Al wrote:
> I want to debug the java source code in eclipse.
>
> I am able to attach and see the JDK class files but I want to be able to
> stick a statement into the JDK source code.
> e.g. in Container.addImpl():
> System.out.println ("Container.addImpl(): " + component + "\tindex: " +
> index);
>
> I went to the rt.jar in the package explorer. I right-clicked to get
> Properties, then select Java Source Attachment and then specify a path:
> C:/Program Files/Java/jdk1.6.0_18/src.zip
> but still I get Container.class not Container.java
>
> So then unzipped the src.zip and using that directory as the source
> attachment. I can edit Container.java now in Eclipse at this point. When
> it runs it still uses the class file and the new line appears in the
> Container.class, but I don't see the output on the console.
>
> Something is still not right. How do I do this?
>
> (Note that I'm not looking for a bug in the JDK, just want to see what
> its doing)
>


Question should go to JDT forum. cc-ing.

If I'm not wrong, by attaching the source to a jar, you are merely
saying that is the source of the classes in the jar. It doesn't instruct
Eclipse to compile the source and create class files. That is done only
by having source files under the source folder.


In your case, I would put a breakpoint or a printpoint
( http://thecoderlounge.blogspot.com/2010/06/print-points-debu gging-by-writing-to.html)
That should help.

If you want a really complicated solution, I would suggest AspectJ
weaving ;-)


--
- Prakash
Platform UI Team, IBM

www.eclipse-tips.com
Re: Debug JDK source code [message #642301 is a reply to message #642292] Tue, 30 November 2010 17:56 Go to previous messageGo to next message
Al Mising name is currently offline Al Mising nameFriend
Messages: 123
Registered: July 2009
Senior Member
>>It doesn't instruct Eclipse to compile the source and create class >>files. That is done only by having source files under the source >>folder.
Yes, and this is why I extracted the src.zip file.
So I edit Container.java by adding this:
System.out.println ("Container.addImpl(): " + component + "\tindex: " + index);
and when compiled this line shows up in the Container.class, but for an unknown reason, nothing is output to the console.

Thanks for pointing out the printpoint trick, that's neat, though I can't use it here because I want variable information.
Re: Debug JDK source code [message #642401 is a reply to message #642295] Wed, 01 December 2010 08:13 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Prakash G.R. wrote:
> On 30/11/10 10:55 PM, Al wrote:
>> I want to debug the java source code in eclipse.
>>
>> I am able to attach and see the JDK class files but I want to be able to
>> stick a statement into the JDK source code.
>> e.g. in Container.addImpl():
>> System.out.println ("Container.addImpl(): " + component + "\tindex: " +
>> index);
>>
>> I went to the rt.jar in the package explorer. I right-clicked to get
>> Properties, then select Java Source Attachment and then specify a path:
>> C:/Program Files/Java/jdk1.6.0_18/src.zip
>> but still I get Container.class not Container.java
The source attachment is only used to show the original source for the
JAR. It cannot be edited.
>>
>> So then unzipped the src.zip and using that directory as the source
>> attachment. I can edit Container.java now in Eclipse at this point. When
>> it runs it still uses the class file and the new line appears in the
>> Container.class, but I don't see the output on the console.
Probably because the launch configuration has the original rt.jar on the
class path before your source folder.
>>
>> Something is still not right. How do I do this?
Actually, you shouldn't start to mess around with the rt.jar source and
use conditional breakpoints to print out debug info.

Dani
>>
>> (Note that I'm not looking for a bug in the JDK, just want to see what
>> its doing)
>>
>
>
> Question should go to JDT forum. cc-ing.
>
> If I'm not wrong, by attaching the source to a jar, you are merely
> saying that is the source of the classes in the jar. It doesn't
> instruct Eclipse to compile the source and create class files. That is
> done only by having source files under the source folder.
>
>
> In your case, I would put a breakpoint or a printpoint
> ( http://thecoderlounge.blogspot.com/2010/06/print-points-debu gging-by-writing-to.html)
> That should help.
>
> If you want a really complicated solution, I would suggest AspectJ
> weaving ;-)
>
>
Re: Debug JDK source code [message #642469 is a reply to message #642301] Wed, 01 December 2010 12:41 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Al wrote:
> Thanks for pointing out the printpoint trick, that's neat, though I
> can't use it here because I want variable information.

?

The conditional breakpoint is evaluated at that point in the method.
You have access to "this", to fields, and (with some minor exceptions)
to the local variables that have been resolved so far. What exactly is
it you don't have access to?

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Debug JDK source code [message #642520 is a reply to message #642469] Wed, 01 December 2010 16:22 Go to previous messageGo to next message
Al Mising name is currently offline Al Mising nameFriend
Messages: 123
Registered: July 2009
Senior Member
Paul,
Thanks for pointing out about using "this", though I don't think that is my problem here. So I am interested in Container.addImpl(Component comp, Object constraints, int index)
I use this statement in the breakpoint:
System.out.println ("Container.addImpl(): " + comp + "\tindex: " + index);
which gives me an error saying that comp and index cannot be resolved. Of course, this.comp will not help here.

Fwiw, it doesn't appear that "this" is necessary e.g. I can do this with no problems:
System.out.println ("Container.addImpl(): " + component);
(component is a class member of Container)

So it can resolve class member, but not the parameters passed in to the method.

Any suggestions?
Thanks for your help!


Re: Debug JDK source code [message #642533 is a reply to message #642520] Wed, 01 December 2010 16:58 Go to previous messageGo to next message
Prakash G.R. is currently offline Prakash G.R.Friend
Messages: 621
Registered: July 2009
Senior Member
On 01/12/10 9:52 PM, Al wrote:
> So it can resolve class member, but not the parameters passed in to the
> method.

When you compile with the debug flag off, the compiler removes all the
local variable names (including the method parameters) & other stuff
like line numbers. Only the names might have been removed from the
attribute tables, but their types has to be preserved. They might be
available in the breakpoint something like arg0, arg1, or similar.

--
- Prakash
Platform UI Team, IBM

www.eclipse-tips.com
Re: Debug JDK source code [message #642547 is a reply to message #642292] Wed, 01 December 2010 18:11 Go to previous messageGo to next message
Al Mising name is currently offline Al Mising nameFriend
Messages: 123
Registered: July 2009
Senior Member
Prakash,
Thanks for your response.
If I compile with the debug flag on, will I be able to see the variable names? If so, how to I turn the debug flag on?
Thanks
Re: Debug JDK source code [message #642581 is a reply to message #642547] Wed, 01 December 2010 20:15 Go to previous messageGo to next message
Catalin Gerea is currently offline Catalin GereaFriend
Messages: 89
Registered: July 2009
Location: Bucharest, Romania
Member

From the command line you use:
Quote:
javac -g
.

But in Eclipse to my shame I do not know where to set this. In the Java->Compiler properties page I cannot see this 'full debug' parameter that can be set or not. I can only see the equivalent of
Quote:
-g:{keyword list}
.

See http://download.oracle.com/javase/6/docs/technotes/guides/ja vac/index.html for more details about javac.


Time is what you make of it.
Re: Debug JDK source code [message #642603 is a reply to message #642292] Wed, 01 December 2010 22:52 Go to previous message
Al Mising name is currently offline Al Mising nameFriend
Messages: 123
Registered: July 2009
Senior Member
In Project -> properties -> Java Compiler, there is:
x Add variable attributes to generated class files (used by the debugger)
x Add line number attributes to generated class files (used by the debugger)
x Add source file name to generated class file (used by the debugger)
x Preserve unused (never read) local variables

These are the equivalent of -g[:none|:lines,vars,source]?
Previous Topic:project dependency on antbuilder product
Next Topic:Looking for a way to reference the product and plugin information from a common callback method
Goto Forum:
  


Current Time: Thu Apr 25 10:22:42 GMT 2024

Powered by FUDForum. Page generated in 0.04354 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top