Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print Java object's current value in debug console in Eclipse?

I'm newbie on Eclipse.

In Objective-C, I could print value of an object in console window with this command.

po nameOfValue

Maybe gdb command. I'm using Eclipse now, what's the equivalent of this in Eclipse?

P.S. I'm debugging a Java app.

like image 476
eonil Avatar asked Jan 20 '12 15:01

eonil


People also ask

How do I print an object in Eclipse?

But you can override the toString() method of your object and there concatenate the string with the values of each field or whatever you want to print for that object. Then when calling somewhere in the code System. out. print(myObject); it will print the result of the toString() method which you've overridden.

How do I show variables in debugging in Eclipse?

Variables/Expression view – Shows the declared variables and their values. Press Ctrl+Shift+d or Ctrl+Shift+i on a selected variable or expression to show its value. You can also add a permanent watch on an expression/variable that will then be shown in the Expressions view when debugging is on.

How do you show expressions in Eclipse?

To manually open the Expressions view, go to Window | Show View | Debug | Expressions. The Expressions view allows you to monitor certain variables which you have decided to 'watch' during the debugging process. Selecting a variable will display details in the detail pane below the view.


2 Answers

Eclipse has very robust debugging capabilities - much more so than Objective C.

First off, while debugging you can view the values of all variables in the Variables window. Additionally, in the lower part of the Variables window you can type arbitrary Java, select it, right click, then choose to Inspect or Execute. You can actually change the value of variables in your program this way, while its running.

You can do pretty much the same thing in your source pane. Highlight a variable, right click and choose to Inspect it. You can also type in a random expression and execute it. You can also places watches on variables (which I believe you can do in Objective-C), or on expressions.

There is an Expression view which is not displayed by default (on your menu select Window->Views->Expressions, while in Debug perspective). It allows you to add arbitrary (valid) Java expressions and the values of those expressions will then be watched over the lifetime of your debug session, very nifty. Thanks to @Baldrick for the reminder of this great tool.

like image 166
Perception Avatar answered Sep 27 '22 21:09

Perception


System.out.println(nameOfValue);
like image 24
Popescu Razvan Avatar answered Sep 27 '22 21:09

Popescu Razvan