官术网_书友最值得收藏!

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.

  1. Go to the execute method of the SampleHandler class.
  2. Clear any existing breakpoints, by double-clicking on them or using Remove All Breakpoints from the Breakpoints view.
  3. Add a breakpoint to the first line of the execute method body.
  4. 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):
  5. Set Hit Count to 3, and click on OK.
  6. Click on the hello world icon button three times. On the third click, the debugger will open up at that line of code.
  7. 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
    
  8. Click on the hello world icon, and the breakpoint will not fire.
  9. Hold down Alt + click on the hello world icon, and the debugger will open (65536 is the value of SWT.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.

主站蜘蛛池模板: 那曲县| 临泉县| 松桃| 故城县| 南华县| 沐川县| 黔江区| 浠水县| 绥中县| 莱阳市| 成安县| 榕江县| 淮南市| 且末县| 兴文县| 台东市| 泗洪县| 宝兴县| 二手房| 隆安县| 门头沟区| 衡阳市| 石景山区| 深州市| 花垣县| 成都市| 西城区| 富民县| 侯马市| 郴州市| 三原县| 宜兰市| 井陉县| 静乐县| 扎兰屯市| 广宁县| 南陵县| 阳曲县| 铁岭市| 东台市| 汶上县|