This recipe shows how to set regular and conditional breakpoints.
1. To begin debugging your project, put Xamarin Studio or Visual Studio in its Debug view. This opens up a set of helpful tools that let you set breakpoints, watch variables, view the call stack, and more.
Hint: you can configure which tools you see in the Debug view by selecting View -> Debug Windows.
2. To set a breakpoint, simply click to the left of the line number at the place in your code that you need to troubleshoot. In the example below, taken from the Button Event Demo sample, the breakpoint will be hit when a button is pressed.
You will see the breakpoint appear in the Breakpoints window on the bottom left.
3. To debug the application, first choose the mode and target location from the menu at the top of the IDE. Then, hit the Debug icon to start the process.
Hint: You can also hit Command + return to launch the debugger.
4. When a breakpoint is hit, it will light up in yellow. You can use the other debugging tools to get more information about what is happening in your code at that moment.
Set a Conditional Breakpoint
You can also use breakpoints to tell you valueable information about
variables in your code. Adding rules for when a breakpoint is hit is known as
setting a conditional breakpoint.
1. To set a conditional breakpoint, you need to accesss the breakpoint properties window. There are several ways to toggle this.
Right click on the space to the left of the line number where you want to set the breakpoint, and select "New Breakpoint".
For an existing breakpoint, right click on the breakpoint and select "Breakpoint Properties".
Select a breakpoint in the Breakpoints window, and hit the wrench icon.
This will bring up the breakpoint properties window:
2. Add conditions to your breakpoint. In our case, our log window will print a message telling us the value of count when a button is hit ten times.