1

Is there a way to program (Java), I mean, write some piece of code anywhere in IDE, to evaluate something in the current debug context when the program execution is waiting on some debug point in an Eclipse IDE?

The feature I require is very much similar to what Google Chrome offers for a Javascript developer.

In below image $(this).text() returns the button's text in current debug context.

Chrome js debugging

Community
  • 1
  • 1
Niranjan
  • 1,776
  • 1
  • 13
  • 21

2 Answers2

6

You can use the Expressions view where you can write an expression and view its result.

The material below is what I wrote in SO Documentation.

Evaluating expressions within a debugging session

There are several to evaluate a certain expression when debugging a Java application.

1. Manually inspecting an expression

When the program execution is suspended at a certain line (either due to a breakpoint or manually stepping through the debugger), you can manually evaluate an expression by selecting the expression in the code, then right-clicking and selecting Inspect as shown in the below screenshot. Alternatively, do Ctrl+Shift+I after selecting the expression.

enter image description here

2. Watching an expression in the Expressions view

If you want to continuously evaluate an expression, say because it is within in a loop, you can watch it in the Expressions view. This way its value will be displayed whenever the program is suspended at each iteration of the loop. To do this, select the desired expression, then right-click and select Watch. This will open the Expressions view and show the value of the expression (see below image). You can also manually write the expression in the view.

enter image description here

3. Using the Display view to evaluate and execute statements

The Display view allows you to write your own expressions, statements or any code in general that would be evaluated or executed in context with the suspended program code. This can be useful if you want to evaluate complex expressions without changing your original and restart the debugging.

To open the Display view, select Window > Show View > Display. Then write your expression or statements in the view, and select one of the options in the toolbar of the view, for example to execute the written statements, or display the result of evaluating them in the view as shown in the below image. The code written in the Display view can also be inspected or executed by selecting it, then right-clicking and selecting the desired action.

enter image description here

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
M A
  • 71,713
  • 13
  • 134
  • 174
2

Use Display window. You can write piece of code in display window and see the result immidiately.

Morteza Adi
  • 2,413
  • 2
  • 22
  • 37
  • Display Window is a perfect solution for my problem. Meanwhile what I did is, written the piece of code in the program editor beneath the breakpoint, selected the code and did Execute (CTRL + U) or Inspect (CTRL + SHIFT + I) which worked like a charm. – Niranjan Oct 25 '14 at 11:18