Getting an Object Identifier String given a line of source code? HELP!

(forgot to close the code tag on that last one!)

Hi there,

I am in desparate need of getting the object identifier given a particular line of source code. I need this for the debugger I'm writing, and since the jdb forum never gets reponses; just more unanswered questions.

Right so, here's my problem in more detail. I can find out when a method is called in the Java virtual machine, and what its name is, and arguments and values and such like - using the Java Debugging Interface. BUT: unfortunately I cannot get the object identifier used in the source code that generated this call. I can however get a unique long id that identifies this object .. if that helps?(thinking hashtables here maybe?!)

So, I may know that the constructor of EddClass has been called, and this the following line generated this call:

EddClass edd =new EddClass();

.. so what I need is a fail safe way of finding out "edd" from this - given all types of method calls.

This is quite tricky because there are loads of ways methods can be called e.g.

tty.getClassExclusions();// Here I would know getClassExclusions had been called, and I would need to find out the object identifier "tty" called it

Temp a, b, c;

a = b = c =new Temp();// Here I would know the constructor for Temp had been called, but now I would just want to know "c"

AnotherEg ae = (new Egg()).getAnotherEg();// and in this last case if I had found out that the Egg constructor had been called, I don't want to find out any object identifier from this line of code - since the object is anonymous; however if I had found out that getAnotherEg() had been called I would want "ae"

Ok, well - please help: I'm making a Java Animator that will be freely available - that serves to graphically animate the execution of another java program. It'd be cool if one of you guys could help make it really cool. Plus there are Dukes available!!

- Edd.

[2177 byte] By [mightymightyeddturnipa] at [2007-9-28 14:02:43]
# 1
quote>>a = b = c = new Temp(); // Here I would know the constructor for Temp had been called, but now I would just want to know "c"<<I don't think so. Not even the VM knows of 'c' while it's constructing an object...
trejkaza at 2007-7-12 10:20:59 > top of Java-index,Other Topics,Algorithms...
# 2

I work a lot with the java debugging interface and I know what is going on in it. I understand that I cannot get the actual "c" identifier directly from it, BUT I CAN get the line of code which resulted in this call. That is what my question is - how can I get the identifier from the line of code? What I am after clearly exists since a form of it appears during the parsing and sematic checking of the compilation phase. Is there any well clever person out there who knows how this works, and could they please assist me?

Hope that cleared up what I was really asking, sorry for any confusion,

.. please help!

- Edd.

mightymightyeddturnipa at 2007-7-12 10:20:59 > top of Java-index,Other Topics,Algorithms...
# 3

this is quite a complicated question I think!

I'm not sure but you maybe need to know just about the whole java lang. spec to do this.

I'm sure there are plenty of free java parsers around, so unless you have a lot of time available its probably best to download one, figure some way to feed it a single line from within a code block, and extract its symbol table.

Once you have the symbol table, there will probably be some other data available from the parser to say which are identifiers.

Its then up to your debugger to figure out which one is the interesting one!

sorry this is so vague but I think you've asked for something that is quite involved!

asjf

asjfa at 2007-7-12 10:21:00 > top of Java-index,Other Topics,Algorithms...
# 4

I would suggest that the best source of help is more like found in http://forum.java.sun.com/forum.jsp?forum=37 the JVM forum.

http://forte.sun.com/s1scc/articles/Java_debug/Java_debug_print.html

The fact that Suns own java debugger requires access to the source suggests that the symbol naming information is not preseved class files and this would therefore only be possible by parsing the source files.

MartinS.a at 2007-7-12 10:21:00 > top of Java-index,Other Topics,Algorithms...