JetBrains Rider 2021.3 Help

Breakpoints

Breakpoints let you suspend the program execution at specific statement and then analyze variables values, call stack, and other program parameters, evaluate expressions, as well as step through the program. In JetBrains Rider, you can work with the following types of breakpoints:

  • Line breakpoints, which you can set at a particular statement in your code. The debugger suspends program execution once the execution reaches this line. Line breakpoints can be set only on executable lines — comments, declarations, and empty lines are not valid locations for line breakpoints.

  • Exception breakpoints suspend the program when the specified exception is thrown. Unlike a line breakpoint, which requires specific source reference, an exception breakpoint applies globally.

  • Method breakpoints suspend the program each time it calls the specified method. Similarly to exception breakpoints, method breakpoints are not displayed in the editor, but only visible and configurable in the Breakpoints dialog (Ctrl+Shift+F8 or Run | View Breakpoints…) .

You can set breakpoints before you start debugging your program and also when the program is already running under the debugger control (when it is in the debug mode). All breakpoints are saved and will not get lost after you restart JetBrains Rider.

To view all breakpoints in the current solution, use the Breakpoints dialog (Ctrl+Shift+F8 or Run | View Breakpoints…) . For each individual breakpoint in the list, you can view and change its properties as required.

Line breakpoint states

In the editor, you can see line breakpoints as red circles on the left gutter. Breakpoint icons denote breakpoint states and other properties.

State

Icon

Description

Enabled

Breakpoint enabled

Line breakpoint. Shown at design-time

Breakpoint enabled conditional

Conditional line breakpoint. The breakpoint is hit only when a particular condition is satisfied. Shown at design-time

Disabled

Breakpoint disabled Breakpoint disabled conditional

A disabled breakpoint will not break the program execution. You may want to disable a breakpoint instead of removing it if you want to enable and use it in the future.

Disabled by dependency

Breakpoint dependent Breakpoint dependent conditional

Dependent line breakpoint. A dependant breakpoint becomes enabled only after the breakpoint it depends on is hit.

Tracepoint

Tracepoint Tracepoint conditional

If a breakpoint does not suspend the program execution (the Suspend flag is disabled in the breakpoint properties), it effectively becomes a tracepoint, which you can use to log the program state when the program reaches the code line marked by it.

Valid

Breakpoint valid Breakpoint valid conditional

Shown at runtime when the breakpoint is recognized by the debugger as set on an executable code line.

Invalid

Breakpoint invalid Breakpoint invalid conditional

Shown when the breakpoint is set on a non-executable line indicating that such breakpoint would not be hit. A breakpoint can become invalid, for example, if you do not have correct PDB files for the debugged program.

Muted

Breakpoint muted

Shown when all breakpoints are temporarily disabled (muted). You can mute/unmute breakpoints by clicking Mute Breakpoints Icons debugger mute breakpoints in the Debug window.

Line breakpoints

Set a line breakpoint

  • Set the cursor at the statement where you want to suspend the program execution and do one of the following:

    • Press Ctrl+F8.

    • In the main menu, choose Run | Toggle Line Breakpoint.

  • Click the left gutter area at a line where you want to toggle a breakpoint. By default, the Show breakpoint preview on mouse hover option is enabled on the Build, Execution, Deployment | Debugger page of JetBrains Rider settings Ctrl+Alt+S, so you will see a preview icon when you hover your mouse over a line where it is possible to set a breakpoint:

    JetBrains Rider: Breakpoint suggestion on mouse hover

Initially, a breakpoint is represented with a filled red circle on the left gutter Breakpoint enabled. The line of code where the breakpoint is set is highlighted. After you start debugging, a valid breakpoint is marked with the green check mark Breakpoint valid and program execution will stop before this line of code is executed.

JetBrains Rider: A breakpoint is hit

You have an option to temporarily disable a breakpoint without actually deleting it. Disabled breakpoints are shown as empty red circles Breakpoint disabled.

Disable/enable a line breakpoint

  • While holding Alt, click the corresponding breakpoint icon the left gutter.

  • Click the breakpoint with the middle mouse button.

  • In the Breakpoints dialog, use the checkbox next to the breakpoint or the Enabled flag in the breakpoint properties.

Disable/enable all line breakpoints

  • In the Debug window, click Mute Breakpoints Icons debugger mute breakpoints. In the muted state, all breakpoints in the editor are shown in solid grey Breakpoint muted.

Delete a line breakpoint

  • In the editor, locate the line with the line breakpoint to be deleted, and click its icon in the left gutter.

  • Place the caret at the desired line and press Ctrl+F8.

  • In the Breakpoints dialog, select the desired breakpoint, and click Remove Icons general remove.

If you need a breakpoint that works just once, you can either set a temporary breakpoint with the dedicated command or make any line, method, or exception breakpoint temporary. When hit, such breakpoints are immediately removed.

Set a temporary line breakpoint

  1. Set the cursor at the statement where you want to suspend execution.

  2. Do one of the following:

    • Press Ctrl+Alt+Shift+F8.

    • In the main menu, choose Run | Toggle Temporary Line Breakpoint.

  3. Alternatively, select the desired breakpoint in the Breakpoints dialog, select the desired line breakpoint, and use the Remove once hit flag in the breakpoint properties.

Conditional line breakpoints

The debugger allows you to set a condition, under which a particular breakpoint will be hit. This may be helpful, for example, if you want to see how your program behaves when a variable takes a certain value.

Set a condition for a line breakpoint

  1. Do one of the following:

    • Right-click the corresponding breakpoint icon in the left gutter.

    • In the Breakpoints dialog, select the desired line breakpoint.

  2. Select the Condition flag and enter an expression that uses variables available in the context and evaluates to true or false. Press Shift+Enter to open the multiline editor.

If the expression evaluates to true, the breakpoint is hit. For instance, in the example below, the breakpoint will be hit only if result > 100.

JetBrains Rider: conditional breakpoints

For simple conditions, when all you need is to trigger the breakpoint after a certain number of hits (for example, if a breakpoint is inside a loop), you can use its Hit count property. In the example below, the program will be suspended on each breakpoint hit which is a multiple of two, that is 2, 4, 6, 8, and so on.

JetBrains Rider: breakpoints. hit count

Dependent breakpoints

In some complex debugging cases (for example, debugging a multi-thread application), suspending on a breakpoint may not make a lot of sense until some other breakpoint is hit. For this purpose, the debugger allows you to create dependent breakpoints.

Set a breakpoint the current one must depend on

  1. Do one of the following:

    • Right-click the corresponding breakpoint icon in the left gutter and click More in the opened breakpoint properties.

    • In the Breakpoints dialog (Ctrl+Shift+F8 or Run | View Breakpoints…) , select the desired breakpoint.

  2. In Disabled until selected breakpoint is hit, select a breakpoint the current one must depend on.

  3. In After breakpoint was hit, select

    • Disable again to disable the current breakpoint after the selected breakpoint is hit.

    • Leave enabled to keep the current breakpoint enabled after the selected breakpoint is hit.

Tracepoints for logging program state

Sometimes, you may need to evaluate an expression at a specific execution point and log the result or log the fact that the breakpoint was reached. Typically, you do not need to suspend the program execution for each log entry.

For these purposes, JetBrains Rider allows you to turn any line, method, or exception breakpoint into a tracepoint. Tracepoint messages will be logged to the debug output (the Debug Output tab of the Debug window).

Log the program state at a tracepoint

  1. Set a breakpoint Ctrl+F8 at the desired statement or choose one of the existing breakpoints.

  2. Do one of the following:

    • Right-click the breakpoint and then click More in the breakpoint properties.

    • In the Breakpoints dialog (Ctrl+Shift+F8 or Run | View Breakpoints…) , select the desired breakpoint.

  3. Clear the Suspend checkbox to make it a tracepoint. This is optional, of course. If you want both to stop at the breakpoint and to log its hit, leave the checkbox selected.

  4. Choose how you want to log the breakpoint hit — a 'Breakpoint hit' message, the program's stack trace at this point, or both.

  5. For line breakpoints you can also evaluate any expression and log its result — select Evaluate and log and enter the desired expression(s).

    You can use any variables, classes, and their methods available in the scope. To add clarifying text to the output, use String.Format() or string concatenation.

    If necessary, press Shift+Enter to open the multiline editor.

For example, an expression like this:

JetBrains Rider: evaluating expressions on tracepoint
will print the following result to the Debug Output tab:
JetBrains Rider: evaluating expressions on tracepoint

Labels for breakpoints

In the the Breakpoints dialog (Ctrl+Shift+F8 or Run | View Breakpoints…) , you can add names or short descriptions to breakpoints: right-click a breakpoint, choose Edit description from the context menu and then type the desired name/description.

You can use these labels to see the purpose of specific breakpoints and you can also start typing in the dialog to search labeled breakpoints:

JetBrains Rider: searching breakpoints

Groups of breakpoints

In the Breakpoints dialog, you can organize breakpoints in a group, for example, to mark out breakpoints for a specific problem. When a group is created, you can move breakpoints into and out of the group and enable/disable all breakpoints in a group at once.

JetBrains Rider: grouping breakpoints

Create a group of breakpoints

  1. Open the Breakpoints dialog (Ctrl+Shift+F8 or Run | View Breakpoints…) .

  2. Select a breakpoint you are interested in. To select multiple breakpoints, hold the Ctrl key while selecting the breakpoints.

  3. Right-click the selection and choose Move to group | Create new... from the context menu.

  4. In the New Group dialog, type the name of the new group. The selected breakpoint moves to the newly created group.

  5. Optionally, you can right-click a group of breakpoints and choose Set as default. After that, all newly created breakpoints will be automatically added to this group.

  6. Optionally, you can select or clear the group checkbox to enable/disable all breakpoints within a group.

After a group is created you can move other breakpoints to that group by right-clicking and choosing Move to group in the context menu.

To move a breakpoint out of a group, right-click it and choose Move to group | [group name] or Move to group | <no group>. As soon as the last breakpoint is moved out of the group, the group is removed.

To remove a group together with all breakpoints in it, click Remove Remove when that group is selected.

Thread-specific breakpoints

Debugging multi-threaded applications can be challenging: whenever you continue execution, you may be on another thread the next time a breakpoint is hit. To focus on debugging a specific thread, you can make any breakpoint thread-specific.

By default, any breakpoint will suspend program execution independently of the thread that hits it.

Make a breakpoint thread-specific

  1. Start a debugging session so that the debugger can collect the program threads.

  2. Right-click the breakpoint or find it in the Breakpoints dialog Ctrl+Shift+F8.

  3. Select Suspend only on specific thread and then choose one of the program threads:

    JetBrains Rider: Making a breakpoint thread-specific

Method breakpoints

A method breakpoint will suspend the program each time it calls the specified method. Similarly to exception breakpoints, method breakpoints are not displayed in the editor, but only visible and configurable in the Breakpoints dialog (Ctrl+Shift+F8 or Run | View Breakpoints…) .

Add a method breakpoint

  1. Open the Breakpoints dialog (Ctrl+Shift+F8 or Run | View Breakpoints…) .

  2. Click Icons general add and select Method Breakpoints.

  3. In the dialog that opens, specify a fully-qualified name of the type (Namespace.TypeName) and the name of the method, and then click OK

Data breakpoints

A data breakpoint lets you break the program execution when a marked property of a specific object changes. Data breakpoints are helpful when you observe a change of value and want to figure out which code actually does the change.

Unlike other kinds of breakpoints, data breakpoints apply to objects in a specific debug session, so they are only available during the session in the Debug window Alt+5.

Use a data breakpoint

  1. Start a debugging session and then break the program execution to examine the program state. If necessary, do some stepping until the desired object gets into the local scope.

  2. Open the Debug window, switch to the Threads & Variables tab, find the desired object, and expand it to locate the field or the property whose value you want to watch.

  3. Right-click the property and choose Set Data Breakpoint.

  4. Resume the program execution F9.

  5. As soon as the property marked with the breakpoint changes its value, debugger will break the program at the line that caused the change.

The following short video shows how to set and use a data breakpoint:

Last modified: 07 April 2022