- Eclipse Plug-in Development:Beginner's Guide(Second Edition)
- Dr Alex Blewitt
- 416字
- 2021-07-14 10:36:24
Time for action – setting a conditional breakpoint
Normally breakpoints fire on each invocation. It is possible to configure breakpoints such that they fire when certain conditions are met; these are known as conditional breakpoints.
- Go to the
execute
method of theSampleHandler
class. - Clear any existing breakpoints, by double-clicking on them or using Remove All Breakpoints from the Breakpoints view.
- Add a breakpoint to the first line of the
execute
method body. - Right-click on the breakpoint, and select the Breakpoint Properties menu (it can also be shown by Ctrl + double-clicking—or Cmd + double-clicking on macOS—on the breakpoint icon itself):
- Set Hit Count to
3
, and click on OK. - Click on the hello world icon button three times. On the third click, the debugger will open up at that line of code.
- Open the breakpoint properties, deselect Hit Count, and select the Enabled and Conditional options. Put the following line into the conditional trigger field:
((org.eclipse.swt.widgets.Event)event.trigger).stateMask==65536
- Click on the hello world icon, and the breakpoint will not fire.
- Hold down Alt + click on the hello world icon, and the debugger will open (
65536
is the value ofSWT.MOD3
, which is the Alt key).
What just happened?
When a breakpoint is created, it is enabled by default. A breakpoint can be temporarily disabled, which has the effect of removing it from the flow of execution. Disabled breakpoints can be easily re-enabled on a per breakpoint basis, or from the Breakpoints view. Quite often it's useful to have a set of breakpoints defined in the code base, but not necessarily have them all enabled at once.
It is also possible to temporarily disable all breakpoints using the Skip All Breakpoints setting, which can be changed from the corresponding item in the Run menu (when the Debug perspective is shown) or the corresponding icon in the Breakpoints view. When this is enabled, no breakpoints will be fired.
Conditional breakpoints must return a value. If the breakpoint is set to break whether or not the condition is true, it must be a Boolean expression. If the breakpoint is set to stop whenever the value changes, then it can be any Java expression. Multiple statements can be used provided that there is a return
keyword with a value expression.
Using exceptional breakpoints
Sometimes when debugging a program, an exception occurs. Typically this isn't known about until it happens, when an exception message is printed or displayed to the user via some kind of dialog box.
- Cocos2d Cross-Platform Game Development Cookbook(Second Edition)
- Spring Cloud Alibaba核心技術(shù)與實(shí)戰(zhàn)案例
- Docker and Kubernetes for Java Developers
- Bulma必知必會(huì)
- Swift 3 New Features
- HTML5 and CSS3 Transition,Transformation,and Animation
- SSM輕量級(jí)框架應(yīng)用實(shí)戰(zhàn)
- Ext JS 4 Web Application Development Cookbook
- Mastering Xamarin.Forms(Second Edition)
- 響應(yīng)式Web設(shè)計(jì):HTML5和CSS3實(shí)戰(zhàn)(第2版)
- Learning Grunt
- Python預(yù)測(cè)之美:數(shù)據(jù)分析與算法實(shí)戰(zhàn)(雙色)
- Java高級(jí)程序設(shè)計(jì)
- MySQL數(shù)據(jù)庫(kù)應(yīng)用實(shí)戰(zhàn)教程(慕課版)
- 3ds Max 2018從入門(mén)到精通