Jump to: navigation, search

Difference between revisions of "FAQ How do I set a conditional breakpoint?"

(added explanation regarding Conditional Breakpoint Error "<variable> cannot be resolved")
 
Line 8: Line 8:
 
context of the breakpoint execution, and the breakpoint is either
 
context of the breakpoint execution, and the breakpoint is either
 
ignored or honored, depending on the outcome of the expression.
 
ignored or honored, depending on the outcome of the expression.
 
 
  
 
Conditions can also be expressed in terms of other breakpoint attributes,
 
Conditions can also be expressed in terms of other breakpoint attributes,
 
such as hit count.
 
such as hit count.
 +
 +
===Why do I get the message "Conditional breakpoint has compilation error(s) - &lt;variable&gt; cannot be resolved" when my breakpoint gets hit?===
 +
 +
It can occur that an error message is issued when a conditional breakpoint gets hit, even though the breakpoint condition appears to be syntactically correct:
 +
 +
<br><center>[[Image:Conditional_Breakpoint_Error.PNG]]</center><br>
 +
 +
This can happen if you are setting a breakpoint in a class whose class file does not contain a local variable table. For example, let's say you want to set a conditional breakpoint on <code>Class.forName(String)</code>. If you have a source attachment for <code>rt.jar</code> the content assist will allow you to refer to the argument by its variable name, <code>className</code>. However, at debug runtime, the variable name will only be known if the class file contains a local variable table. Depending on the options used at compilation time, this information may have been stripped from the class file.
 +
 +
In the '''Variables''' view of the debugger, the argument will appear as <code>arg</code>''n'', and that placeholder name can actually also be used in the conditional expression for the breakpoint. So, instead of using the variable name <code>className</code> in your conditional expression, you simply use the placeholder <code>arg0</code>:
 +
 +
<br><center>[[Image:Conditional_breakpoint_in_java.lang.Class.PNG]]</center><br>
 +
 +
The content assist does currently not work for completing <code>arg</code>''n'' expressions.
 +
  
 
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>
 
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>

Latest revision as of 21:41, 23 June 2008

First, set a breakpoint at a given location. Then, use the context menu on the breakpoint in the left editor margin or in the Breakpoints view in the Debug perspective, and select the breakpoint’s properties. In the dialog box, check Enable Condition, and enter an arbitrary Java condition, such as list.size()==0. Now, each time the breakpoint is reached, the expression is evaluated in the context of the breakpoint execution, and the breakpoint is either ignored or honored, depending on the outcome of the expression.

Conditions can also be expressed in terms of other breakpoint attributes, such as hit count.

Why do I get the message "Conditional breakpoint has compilation error(s) - <variable> cannot be resolved" when my breakpoint gets hit?

It can occur that an error message is issued when a conditional breakpoint gets hit, even though the breakpoint condition appears to be syntactically correct:


Conditional Breakpoint Error.PNG

This can happen if you are setting a breakpoint in a class whose class file does not contain a local variable table. For example, let's say you want to set a conditional breakpoint on Class.forName(String). If you have a source attachment for rt.jar the content assist will allow you to refer to the argument by its variable name, className. However, at debug runtime, the variable name will only be known if the class file contains a local variable table. Depending on the options used at compilation time, this information may have been stripped from the class file.

In the Variables view of the debugger, the argument will appear as argn, and that placeholder name can actually also be used in the conditional expression for the breakpoint. So, instead of using the variable name className in your conditional expression, you simply use the placeholder arg0:


Conditional breakpoint in java.lang.Class.PNG

The content assist does currently not work for completing argn expressions.



This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.