17

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.

1
  • po in Xcode console ~= Expression in most of the java IDE's Commented Jun 27, 2018 at 7:51

5 Answers 5

24

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.

Sign up to request clarification or add additional context in comments.

5 Comments

+1 . Also the "Expression" view (in the Debug perspective). You can put Java code in this view that is evaluated when you reach a breakpoint, and at every step in debug.
@Baldrick - totally forgot about the Expression view, which is another excellent tool.
I want command-line console because I don't want to use mouse when evaluating an expression because usually the expression for debugging goes complex. And also, aiming small icon with mouse is a lot harder than using keyboard.
@Eonil - ah! A keyboard guy. No I don't think you will find something exactly like that in Eclipse. Though I think once you try the other methods available you will find them very powerful. Best of luck!
Thanks for suggestion. Actually I have been IDEs like VS or Eclipse for years, and finally I switched to keyboard based. Anyway it looks time to go back the old time haha :)
5
System.out.println(nameOfValue);

3 Comments

I can't find the window that I can input this :(
You can put it in the expressions window
The above code would go in the "Display" view since it is a command not an expression.
2

I'm not aware of any printing option of the whole object state in console while debugging.

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.

Comments

1

Click Window menu select show view type display and show that view. In this view you can type java such as System.out.println(objectName); when the application has paused during debugging.

2 Comments

It should print it in the console or give you an error in the display window if the code could not be run
Is the object your trying to print a string, if so could the string be blank try another line after to print some text and see if there is a space between the last console output and the text you printed
0

Override toString for that object/class. Then System.out.println(objectVariable).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.