Michael
Michael

Reputation: 2250

Debug Watch Expression: How to customize the display of an object in Eclipse

In Eclipse's watch window ("Expressions"), is there a way to have eclipse interpret the contents of a class/structure, rather than having to open the tree? Currently the "value" for any class/structure is {...}, and opening it consumes multiple lines in the Expressions window.

i.e, suppose I have a class complex with real and imag.

class complex_t {
    double real, imag;
}

Is there an XML file somewhere in eclipse to indicate that complex_t should display the values for .real and .imag instead of {...}? I've been searching on Visualizers, but I think that is something else.

Visual Studio, had this functionality say 10 years ago or so and I found it very handy (autoexp.dat). I don't use VS anymore but I think it might now be called Native Visualizer (NatVis). I even found that that Boost provides these XML files to visualizing objects in their library. (https://svn.boost.org/trac/boost/wiki/DebuggerVisualizers). No mention of Eclipse, which is an indication that the answer is no.


Edit: I'm looking for a solution for C/C++ (specifically for Code Composer Studio actually).

Below josivan does have a solution for Java though.

Upvotes: 0

Views: 1120

Answers (1)

josivan
josivan

Reputation: 2073

If you want to show details during debug you can do something like

Window > Preferences > Java > Debug > Detail Formatters

Click in Add, Choose your class. In area "Detail formatter code snippet" you define what you want. For example:

enter image description here

return "[r: " + real + ", i: " + imag + "]";

On debug Perpective you can see details of your class.

Take a look in the imagem bellow.

enter image description here

In eclipse help you can get more details. And here are a good article about it.

Upvotes: 3

Related Questions