37

At the link below it explains that the "display view allows you to manipulate live code in a scrapbook type fashion (see Figure 8). To manipulate a variable, simply type the name of the variable in the Display view, and you'll be greeted with a familiar content assist."

http://www.ibm.com/developerworks/library/os-ecbug/

However, I am having trouble getting it to work. I have the view open but all the buttons are disabled. I have tried putting code in the view, selecting code in the view, selecting code in other views, while running and while not running debug, but the only button that is ever enabled on the view is "clear console".

Suggestions on what I am doing wrong?

jzd
  • 23,473
  • 9
  • 54
  • 76

5 Answers5

38

You can view the Display view as a place where you can inspect all sorts of variables and boolean expressions during runtime. While your debugger is frozen on a breakpoint start typing the name of an object variable for instance and you'll get autocomplete functionality as you start calling methods or fields to reach deeper class datastructures. Then when you select/mark the portion you need to inspect or everything, the buttons on the Display view will be clickable. You can always perform the Ctrl+Shift+I shortcut on the selection to view what's the current runtime state of your selection i.e. variable, object, boolean exrepssion etc

dimitrisli
  • 20,895
  • 12
  • 59
  • 63
  • 1
    I find it especially useful to sys out some values inferred via getters which are not accessible in the Variables view. Saves precious time... Not sure why it is not there by default in Eclipse, it should be ! – Christophe Roussy Apr 24 '15 at 08:55
  • 1
    Is there any keyboard shortcut for the Display Result/Evaluate button? I find it inconvinient to select, then move the mouse all the way to the right everytime. Note that I don't mean SHIFT+CTRL+I, I mean clicking "J" icon in the view itself. I haven't found a shortcut for that yet. – Jose Cifuentes Sep 09 '16 at 13:46
  • 3
    Never mind, I found the answer: SHIFT+CTRL+D evaluates the selected text. – Jose Cifuentes Sep 09 '16 at 14:44
  • How can you execute few Java statements with a small for-loop for example in the Display Window, and then show the result? I tried everything, nothing is working. I am able to display the variables that are defined in the program during the break-point only. Can you help, please? – tarekahf Mar 24 '20 at 17:04
12

I think this powerful feature should be used way more often.

  1. In the debug perspective: Window -> Show View -> (search for) Display
  2. Put a break point in your code
  3. Trigger the breakpoint by executing this code
  4. Once on the breakpoint go to the Display view
  5. Write some code like myObject.getSomeData();, you can autocomplete (Ctrl+Space)
  6. Select the expression (code) you want to evaluate
  7. Use one of the many display view buttons which should now be enabled
  8. Save some precious time...

Not sure why this view is not there by default, it should be !

Christophe Roussy
  • 16,299
  • 4
  • 85
  • 85
10

As of Eclipse Photon Release (4.8.0)

This same functionality can be performed inside the the Debug Shell. I do this by:

  1. Make sure I'm at a breakpoint in a Debug execution of some script
  2. Open the Debug Shell
  3. Type in the code that I want to run
  4. Highlight the specific line of code
  5. Use either of the buttons for: Execute Selected Text, or Display Result of Evaluating Selected Text

I'm including this answer because as of 2018, with the Photon Release, I was unable to get the Display view to work in any capacity or to even show up. But I was able to perform the same work through this method.

Andrew
  • 1,423
  • 1
  • 17
  • 26
6

When you've stopped at a breakpoint, you can write or paste code into the Display view, select it, and press Ctrl+Shift+I to inspect (i.e. evaluate) the selection.

Eli Acherkan
  • 6,401
  • 2
  • 27
  • 34
4

It will only work while running in debug, and you can only manipulate variables that are live in the context of the currrent thread, which means that you need to place a breakpoint at (or just after) the point where the variables you want to inspect become active. Whilst you hold on the breakpoint you can use the Display tab to interact (execute code snippets, evaluate etc..) with all the variables that you can see in the Variables tab

Joel
  • 29,538
  • 35
  • 110
  • 138