Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "Mark instance" in Eclipse Debug

I'm looking for the equivalent functionality of IntelliJ IDEA "Mark instance" in Eclipse Debug.

I've searched extensively also in documentation, but I think this feature is not existing in Eclipse Debugger. I can count instances, I can find references, but appears there is no way in the "Variables" window to mark a specific instance with ID with a visual label for convenience while debugging. Before giving up, I preferred to ask also this audience.

Practical example

Assuming the following (minimal, easy, synthetic) example code:

    Object obj1 = "Hello World";
    Object obj2 = 12345L;

    Object result;
    if (Math.random() > 0.5) {
        result = obj1;
    } else {
        result = obj2;
    }

    System.out.println(result);

if I put a breakpoint on the System.out line, I'd like to know if the instance of variable result is the same instance of variable obj1.

Using IntelliJ IDEA

This can be done by "Mark instance" on obj1 :

by "Mark instance" on <code>obj1</code>

As you can notice a visual label is applied to all the variable sharing the same instance reference, in this case also result:

a visual label is applied to all the variable sharing the same instance reference

Using Eclipse Debug

Appears there is now way to have the Eclipse Debugger visual mark instance ID=16 in order to recognize which other variables are sharing the same instance as of obj1.

Eclipse Debugger example

(Of course this is a simplified example and it's visually easy to detect it even without this feature, but in a real case it would be a very helpful way to understand where an instance is shared across "Variables" and a great additional tool for debugging)

Thanks!

like image 697
tarilabs Avatar asked Mar 31 '26 00:03

tarilabs


1 Answers

Eclipse 4.22 now has a feature for "marking a specific instance with ID with a visual label for convenience while debugging"!
(End of 2021, almost 5 years after the OP)

Label Objects during debugging

During debugging a Java application, often we have to deal with lot's of object instances, and it's not always easy to distinguish between them.

That's why the experience is improved, with the ability to set a label on individual objects.

Menu item -- https://www.eclipse.org/eclipse/news/4.22/images/label-object-menu.png

After setting a label, everywhere the object appears it is displayed with a distinctive color and with the label:

Objects with Label -- https://www.eclipse.org/eclipse/news/4.22/images/label-object-result.png

like image 164
VonC Avatar answered Apr 02 '26 11:04

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!