简体   繁体   中英

Programming in Debug context in Eclipse IDE

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调试

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.

在此处输入图片说明

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.

在此处输入图片说明

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.

在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM