You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/debugger/using-breakpoints.md
+45-41
Original file line number
Diff line number
Diff line change
@@ -38,36 +38,36 @@ ms.workload:
38
38
- "multiple"
39
39
---
40
40
# Use breakpoints in the Visual Studio debugger
41
-
Breakpoints are one of the most important debugging techniques in your toolbox. You set breakpoints where you want to pause debugger execution. For example, you may want to see the state of code variables or look at the call stack at the breakpoint.
41
+
Breakpoints are one of the most important debugging techniques in your toolbox. You set breakpoints wherever you want to pause debugger execution. For example, you may want to see the state of code variables or look at the call stack at a certain breakpoint.
42
42
43
43
## <aname="BKMK_Overview"></a> Set line breakpoints in source code
44
-
You can set a breakpoint on any line of executable code. For example, in the following C# code, you could set a breakpoint on the variable declaration, the `for` loop, or any code inside the `for` loop. You can't set a breakpoint on the namespace or class declarations, or the method signature.
44
+
You can set a breakpoint on any line of executable code. For example, in the following C# code, you could set a breakpoint on the variable declaration, the `for` loop, or any code inside the `for` loop. You can't set a breakpoint on the namespace or class declarations, or on the method signature.
45
45
46
-
To set a line breakpoint in source code, select a line and then click in the left margin. You can also press **F9**, select **Debug** > **Toggle Breakpoint**, or right-click and select **Breakpoint** > **Insert breakpoint**. The breakpoint appears as a red dot in the left margin.
46
+
To set a line breakpoint in source code, click in the far left margin next to a line of code. You can also select the line and press **F9**, select **Debug** > **Toggle Breakpoint**, or right-click and select **Breakpoint** > **Insert breakpoint**. The breakpoint appears as a red dot in the left margin.
47
47
48
48

49
49
50
-
When you debug the code, execution pauses at the breakpoint, before the code on that line is executed. The breakpoint symbol shows a yellow arrow.
50
+
When you debug, execution pauses at the breakpoint, before the code on that line is executed. The breakpoint symbol shows a yellow arrow.
51
51
52
52
At the breakpoint in the following example, the value of `testInt` is still 1.
When the debugger stops at the breakpoint, you can look at the current state of the app, including variable values and the call stack. For more information about the call stack, see [How to: Use the Call Stack window](../debugger/how-to-use-the-call-stack-window.md).
57
57
58
-
- The breakpoint is a toggle. You can click it to delete it, then click again in the same spot to reinsert it, press **F9** to delete or reinsert it, or use **Debug** > **Toggle Breakpoint**.
58
+
- The breakpoint is a toggle. You can click it, press **F9**, or use **Debug** > **Toggle Breakpoint** to delete or reinsert it.
59
59
60
-
- To disable a breakpoint without deleting it, hover over it, or right-click, and select **Disable breakpoint**. Disabled breakpoints appear as empty circles in the left margin. To re-enable a breakpoint, hover over it, or right-click, and select **Enable breakpoint**.
60
+
- To disable a breakpoint without deleting it, hover over or right-click it, and select **Disable breakpoint**. Disabled breakpoints appear as empty dots in the left margin. To re-enable a breakpoint, hover over or right-click it, and select **Enable breakpoint**.
61
61
62
-
-You can set conditions and actions, add and edit labels, or export a breakpoint by right-clicking it and selecting the appropriate command, or hovering over it and selecting the **Settings** icon.
62
+
-Set conditions and actions, add and edit labels, or export a breakpoint by right-clicking it and selecting the appropriate command, or hovering over it and selecting the **Settings** icon.
63
63
64
-
## <aname="BKMK_Set_a_breakpoint_in_a_function"></a> Set breakpoints in debugger windows
64
+
## <aname="BKMK_Set_a_breakpoint_in_a_function"></a> Set breakpoints from debugger windows
65
65
66
66
You can also set breakpoints from the **Call Stack** and **Disassembly** debugger windows.
67
67
68
68
### <aname="BKMK_Set_a_breakpoint_in_the_call_stack_window"></a> Set a breakpoint in the Call Stack window
69
69
70
-
Set a breakpoint in the **Call Stack** window to break at the instruction or line that a calling function returns to. For more information about the call stack, see [How to: Use the Call Stack window](../debugger/how-to-use-the-call-stack-window.md).
70
+
To break at the instruction or line that a calling function returns to, you can set a breakpoint in the **Call Stack** window.
71
71
72
72
**To set a breakpoint in the Call Stack window:**
73
73
@@ -77,17 +77,19 @@ You can also set breakpoints from the **Call Stack** and **Disassembly** debugge
77
77
78
78
A breakpoint symbol appears next to the function call name in the left margin of the call stack.
79
79
80
-
The call stack breakpoint appears in the **Breakpoints** window as an address with a memory location that corresponds to the next executable instruction in the function.
80
+
The call stack breakpoint appears in the **Breakpoints** window as an address, with a memory location that corresponds to the next executable instruction in the function.
81
81
82
82
The debugger breaks at the instruction.
83
83
84
-
To visually trace breakpoints during code execution, see [Map methods on the call stack while debugging](../debugger/map-methods-on-the-call-stack-while-debugging-in-visual-studio.md).
84
+
For more information about the call stack, see [How to: Use the Call Stack window](../debugger/how-to-use-the-call-stack-window.md).
85
+
86
+
To visually trace breakpoints during code execution, see [Map methods on the call stack while debugging](../debugger/map-methods-on-the-call-stack-while-debugging-in-visual-studio.md).
85
87
86
88
### Set a breakpoint in the Disassembly window
87
89
88
90
1. To open the **Disassembly** window, you must be paused during debugging. Select **Debug** > **Windows** > **Disassembly**, or press **Ctrl**+**Alt**+**D**.
89
91
90
-
2. In the **Disassembly** window, click in the left margin of the instruction you want to break at, select it and press **F9**, or right-click and select **Breakpoint** > **Insert Breakpoint**.
92
+
2. In the **Disassembly** window, click in the left margin of the instruction you want to break at. You can also select it and press **F9**, or right-click and select **Breakpoint** > **Insert Breakpoint**.
91
93
92
94
## <aname="BKMK_Set_a_breakpoint_in_a_source_file"></a> Set function breakpoints
93
95
@@ -105,10 +107,10 @@ To visually trace breakpoints during code execution, see [Map methods on the cal
105
107
106
108
- Use the fully qualified function name.
107
109
Example: `Namespace1.ClassX.MethodA()`
108
-
110
+
109
111
- Add the parameter types of an overloaded function.
110
112
Example: `MethodA(int, string)`
111
-
113
+
112
114
- Use the '!' symbol to specify the module.
113
115
Example: `App1.dll!MethodA`
114
116
@@ -120,13 +122,16 @@ To visually trace breakpoints during code execution, see [Map methods on the cal
120
122
121
123
1. Select **OK**.
122
124
123
-
### Set a breakpoint with a memory address (native C++ only)
125
+
### Set a function breakpoint using a memory address (native C++ only)
124
126
You can use the address of an object to set a function breakpoint on a method called by a specific instance of a class. For example, given an addressable object of type `my_class`, you can set a function breakpoint on the `my_method` method that instance calls.
125
127
126
128
1. Set a breakpoint somewhere after the instance of the class is instantiated.
129
+
127
130
2. Find the address of the instance (for example, `0xcccccccc`).
4. Add the following text to the **Function Name** box:
133
+
134
+
4. Add the following to the **Function Name** box, and select **C++** language.
130
135
131
136
```C++
132
137
((my_class *) 0xcccccccc)->my_method
@@ -138,33 +143,33 @@ To visually trace breakpoints during code execution, see [Map methods on the cal
138
143
139
144
**To set a data breakpoint:**
140
145
141
-
1.Start debugging, and wait until a breakpoint is reached. On the **Debug** menu, choose **New Breakpoint** > **Data Breakpoint**
146
+
1.In a C++ project, start debugging, and wait until a breakpoint is reached. On the **Debug** menu, choose **New Breakpoint** > **Data Breakpoint**
142
147
143
148
You can also select **New** > **Data Breakpoint** in the **Breakpoints** window.
144
149
145
150
2. In the **Address** box, type a memory address, or an expression that evaluates to a memory address. For example, type `&avar` to break when the contents of the variable `avar` changes.
146
151
147
152
3. In the **Byte Count** dropdown, select the number of bytes you want the debugger to watch. For example, if you select **4**, the debugger will watch the four bytes starting at `&avar` and break if any of those bytes change value.
148
153
149
-
>[!NOTE]
150
-
>Data breakpoints depend on specific memory addresses. The address of a variable changes from one debugging session to the next, so data breakpoints are automatically disabled at the end of each debugging session.
151
-
>
152
-
>If you set a data breakpoint on a local variable, the breakpoint remains enabled when the function ends, but the memory address is no longer applicable, so the behavior of the breakpoint is unpredictable. If you set a data breakpoint on a local variable, you should delete or disable the breakpoint before the function ends.
153
-
154
-
Data breakpoints don't work under these conditions:
154
+
Data breakpoints don't work under the following conditions:
155
155
- A process that is not being debugged writes to the memory location.
156
156
- The memory location is shared between two or more processes.
157
157
- The memory location is updated within the kernel. For example, if memory is passed to the 32-bit Windows `ReadFile` function, the memory will be updated from kernel mode, so the debugger won't break on the update.
158
158
159
+
>[!NOTE]
160
+
>- Data breakpoints depend on specific memory addresses. The address of a variable changes from one debugging session to the next, so data breakpoints are automatically disabled at the end of each debugging session.
161
+
>
162
+
>- If you set a data breakpoint on a local variable, the breakpoint remains enabled when the function ends, but the memory address is no longer applicable, so the behavior of the breakpoint is unpredictable. If you set a data breakpoint on a local variable, you should delete or disable the breakpoint before the function ends.
163
+
159
164
## <aname="BKMK_Specify_advanced_properties_of_a_breakpoint_"></a> Manage breakpoints in the Breakpoints window
160
165
161
-
You can use the **Breakpoints** window (**Debug** > **Windows** > **Breakpoints**, or **Ctrl**+**Alt**+**B**) to see and manage all the breakpoints in your solution. This centralized location is especially helpful in a large solution or for complex debugging scenarios where breakpoints are critical.
166
+
You can use the **Breakpoints** window to see and manage all the breakpoints in your solution. This centralized location is especially helpful in a large solution, or for complex debugging scenarios where breakpoints are critical.
162
167
163
168
In the **Breakpoints** window, you can search, sort, filter, enable/disable, or delete breakpoints. You can also set conditions and actions, or add a new function or data breakpoint.
164
169
165
-
To open the **Breakpoints** window, select **Debug > **Windows** > **Breakpoints** or press **Alt**+**F9**.
170
+
To open the **Breakpoints** window, select **Debug** > **Windows** > **Breakpoints**, or press **Alt**+**F9** or **Ctrl**+**Alt**+**B**.
You can use labels to sort and filter the list of breakpoints in the **Breakpoints** window.
@@ -175,11 +180,10 @@ You can use labels to sort and filter the list of breakpoints in the **Breakpoin
175
180
### Export and import breakpoints
176
181
To save or share the state and location of your breakpoints, you can export or import them.
177
182
178
-
- To export a single breakpoint to an XML file, right-click the breakpoint in the source code or **Breakpoints** window, and select **Export** or **Export selected**. Select an export location, and then select **Save**.
179
-
- To export several breakpoints, select the boxes next to the breakpoints in the **Breakpoints** window, or enter search criteria in the **Search** field. Select the **Export all breakpoints matching the current search criteria** icon, and save the file.
180
-
- To export all breakpoints, deselect all boxes and leave the **Search** field blank, select the **Export all breakpoints matching the current search criteria** icon, and save the file.
181
-
- To import breakpoints, in the **Breakpoints** window toolbar, select the **Import breakpoints from a file** icon, navigate to the XML file location, and select **Open**.
182
-
183
+
- To export a single breakpoint to an XML file, right-click the breakpoint in the source code or **Breakpoints** window, and select **Export** or **Export selected**. Select an export location, and then select **Save**. The default location is the solution folder.
184
+
- To export several breakpoints, in the **Breakpoints** window, select the boxes next to the breakpoints, or enter search criteria in the **Search** field. Select the **Export all breakpoints matching the current search criteria** icon, and save the file.
185
+
- To export all breakpoints, deselect all boxes and leave the **Search** field blank. Select the **Export all breakpoints matching the current search criteria** icon, and save the file.
186
+
- To import breakpoints, in the **Breakpoints** window, select the **Import breakpoints from a file** icon, navigate to the XML file location, and select **Open**.
183
187
184
188
## Breakpoint conditions
185
189
You can control when and where a breakpoint executes by setting conditions. The condition can be any valid expression that the debugger recognizes. For more information about valid expressions, see [Expressions in the debugger](../debugger/expressions-in-the-debugger.md).
@@ -190,11 +194,11 @@ You can use labels to sort and filter the list of breakpoints in the **Breakpoin
When you select **Conditional Expression**, you can choose between two conditions: **Is true** or **When changed**. Choose **Is true** to break when the expression is satisfied, or **When changed** to break when the value of the expression has changed.
200
204
@@ -213,8 +217,8 @@ When you select **Conditional Expression**, you can choose between two condition
213
217
>- For native code, the debugger doesn't consider the first evaluation of the condition to be a change, so doesn't hit the breakpoint on the first evaluation.
214
218
>- For managed code, the debugger hits the breakpoint on the first evaluation after **When changed** is selected.
215
219
216
-
####Using Object IDs in conditional expressions (C# and F# only)
217
-
There are times when you want to observe the behavior of a specific object. For example, you might want to find out why an object was inserted more than once into a collection. In C# and F#, you can create object IDs for specific instances of [reference types](/dotnet/csharp/language-reference/keywords/reference-types), and use them in breakpoint conditions. The object ID is generated by the common language runtime (CLR) debugging services and associated with the object.
220
+
### Using Object IDs in conditional expressions (C# and F# only)
221
+
There are times when you want to observe the behavior of a specific object. For example, you might want to find out why an object was inserted into a collection more than once. In C# and F#, you can create object IDs for specific instances of [reference types](/dotnet/csharp/language-reference/keywords/reference-types), and use them in breakpoint conditions. The object ID is generated by the common language runtime (CLR) debugging services and associated with the object.
218
222
219
223
**To create an Object ID:**
220
224
@@ -226,13 +230,13 @@ When you select **Conditional Expression**, you can choose between two condition
226
230
227
231
You should see a **$** plus a number in the **Locals** window. This is the object ID.
228
232
229
-
3. Add a new breakpoint at the point you want to investigate; for example, when the object is to be added to the collection, and open the **Conditions** dialog.
233
+
3. Add a new breakpoint at the point you want to investigate; for example, when the object is to be added to the collection. Right-click the breakpoint and select **Conditions**.
230
234
231
-
4. Use the Object ID in the **Conditional Expression** field. For example, if the variable `item` is the object to be added to the collection, put**item == $\<n>**, where \<n> is the object ID number.
235
+
4. Use the Object ID in the **Conditional Expression** field. For example, if the variable `item` is the object to be added to the collection, select **Is true** and type**item == $\<n>**, where \<n> is the object ID number.
232
236
233
237
Execution will break at the point when that object is to be added to the collection.
234
238
235
-
To later delete the Object ID, right-click the variable in the **Locals** window and select **Delete Object ID**.
239
+
To delete the Object ID, right-click the variable in the **Locals** window and select **Delete Object ID**.
236
240
237
241
>[!NOTE]
238
242
>Object IDs create weak references, and do not prevent the object from being garbage collected. They are valid only for the current debugging session.
@@ -278,9 +282,9 @@ Enclose string values in double quotes. You can combine clauses using `&` (AND),
278
282
-**$TNAME** - Thread name
279
283
-**$TICK** - Tick count (from Windows `GetTickCount`)
280
284
281
-
1. To break execution when the tracepoint is hit, clear the **Continue Execution**check box, or select the **Continue Execution** box to print the message to the **Output** window without breaking.
285
+
1. To print the message to the **Output**window without breaking, select the **Continue Execution**check box. To print the message and break execution at the tracepoint, clear the check box.
282
286
283
-
Tracepoints appear as red diamonds in the left margin of in the source code and **Breakpoints** windows.
287
+
Tracepoints appear as red diamonds in the left margin of the source code and **Breakpoints** windows.
284
288
285
289
## See also
286
290
[Troubleshoot breakpoints in the Visual Studio debugger](../debugger/troubleshooting-breakpoints.md)
0 commit comments