Skip to content

Commit 68fba8f

Browse files
Mikejo5000denrea
andauthored
Refactor breakpoints article and incorporate review feedback (#13377)
* Refactor breakpoints article * edits * fix table * edit * edits * Art update * edits * tweaks * Acrolinx fix, alt text --------- Co-authored-by: Dennis Rea <[email protected]>
1 parent 56f086e commit 68fba8f

File tree

7 files changed

+218
-188
lines changed

7 files changed

+218
-188
lines changed

docs/debugger/find-your-debugging-task.yml

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
metadata:
33
title: "FAQ - Debugger feature finder"
44
description: Review frequently asked questions to help you identify the Visual Studio debugger feature to help you debug your application.
5-
ms.date: "06/07/2023"
5+
ms.date: "11/22/2024"
66
ms.topic: faq
77
helpviewer_keywords:
88
- "debugging [Visual Studio], find your feature"
@@ -24,62 +24,31 @@ sections:
2424
answer: |
2525
- **How do I pause running code to inspect a line of code that may contain a bug?**
2626
27-
Set a breakpoint. For more information, see [Using breakpoints](using-breakpoints.md).
27+
Set a breakpoint. For more information, see [Use the right type of breakpoint](using-breakpoints.md) and [Get started with breakpoints](get-started-with-breakpoints.md).
2828
29-
- **Does my variable have an unexpected value. Or, do I want to inspect my app when it reaches a specific state?**
30-
31-
Try a conditional breakpoint to control where and when a breakpoint gets activated by using conditional logic. Right-click on a breakpoint to add conditions. Set the condition to be true when the variable equals the unexpected value.
29+
- **How do I pause running code based on specific criteria?**
3230
33-
For more information, see [Breakpoint conditions](using-breakpoints.md#breakpoint-conditions).
31+
Set the correct type of breakpoint. For more information, see [Use the right type of breakpoint](using-breakpoints.md).
3432
3533
- **How do I log information to the Output window under configurable conditions without modifying or stopping my code?**
3634
37-
Tracepoints allow you to log information to the Output window under configurable conditions without modifying or stopping your code.
35+
Tracepoints allow you to log information to the Output window under configurable conditions without modifying or stopping your code. For more information, see [Use tracepoints in the Visual Studio debugger](../debugger/using-tracepoints.md)
3836
39-
- **How do I know when the value of my variable changes?**
40-
41-
For C++, set a [data breakpoint](using-breakpoints.md#BKMK_set_a_data_breakpoint_native_cplusplus).
42-
::: moniker range=">= vs-2019"
43-
For apps using .NET Core 3, you can also set a [data breakpoint](using-breakpoints.md#BKMK_set_a_data_breakpoint_managed).
44-
::: moniker-end
45-
46-
Otherwise, for C# and F# only, you can [track an object ID with a conditional breakpoint](using-breakpoints.md#using-object-ids-in-breakpoint-conditions-c-and-f).
47-
48-
- **How do I break execution only if another breakpoint is hit?**
49-
50-
Set a Dependent Breakpoint that breaks execution only if another breakpoint is first hit. For more information, see [Dependent Breakpoint](using-breakpoints.md#BKMK_set_a_dependent_breakpoint).
51-
52-
- **Can I hit a breakpoint only once?**
53-
54-
Set a temporary breakpoint which lets you break the code only once. For more information, see [Temporary Breakpoint](using-breakpoints.md#BKMK_set_a_temporary_breakpoint).
55-
56-
- **Can I pause code inside a loop at a certain iteration?**
57-
58-
Set a Dependent breakpoint that breaks execution only if another breakpoint is first hit. For more information, see [Hit count](using-breakpoints.md#set-a-hit-count-condition).
59-
60-
- **How can I pause code at the start of a function when I know the function name but not its location?**
61-
62-
You can do this with a function breakpoint. For more information, see [Set function breakpoints](using-breakpoints.md#BKMK_Set_a_breakpoint_in_a_source_file).
63-
64-
- **How can I pause code at the start of multiple functions with the same name?**
65-
66-
When you have multiple functions with the same name (overloaded functions or functions in different projects), you can use a [function breakpoint](using-breakpoints.md#BKMK_Set_a_breakpoint_in_a_source_file).
67-
6837
- **Manage and keep track of my breakpoints**
6938
70-
Use the **Breakpoints** window. For more information, see [Manage breakpoints](using-breakpoints.md#BKMK_Specify_advanced_properties_of_a_breakpoint_).
39+
Use the **Breakpoints** window. For more information, see [Manage breakpoints](get-started-with-breakpoints.md#BKMK_Specify_advanced_properties_of_a_breakpoint_).
7140
7241
- **Pause code and debug when a specific handled or unhandled exception is thrown**
7342
7443
Although the Exception Helper shows you where an error occurred, if you want to pause and debug the specific error, you can [tell the debugger to break when an exception is thrown](managing-exceptions-with-the-debugger.md#tell-the-debugger-to-break-when-an-exception-is-thrown).
7544
7645
- **Set a breakpoint from the call stack**
7746
78-
If you want to pause and debug code while examining execution flow or viewing functions in the **Call Stack** windows, see [Set a breakpoint in the Call Stack window](using-breakpoints.md#BKMK_Set_a_breakpoint_from_debugger_windows).
47+
If you want to pause and debug code while examining execution flow or viewing functions in the **Call Stack** windows, see [Set a breakpoint in the Call Stack window](get-started-with-breakpoints.md#BKMK_Set_a_breakpoint_from_debugger_windows).
7948
8049
- **Pause code at a specific assembly instruction**
8150
82-
You can do this by [setting a breakpoint from the Disassembly window](using-breakpoints.md#BKMK_Set_a_breakpoint_from_debugger_windows).
51+
You can do this by [setting a breakpoint from the Disassembly window](get-started-with-breakpoints.md#BKMK_Set_a_breakpoint_from_debugger_windows).
8352
8453
- question: |
8554
Navigate code
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
---
2+
title: Get started with breakpoints
3+
description: Learn about breakpoints, one of the most important debugging techniques.
4+
ms.date: 11/22/2024
5+
ms.topic: how-to
6+
f1_keywords:
7+
- vs.debug.breakpointswin
8+
- vc.breakpoints
9+
- vs.debug.breakpoints
10+
- vs.debug.disassembly.insert
11+
- vs.debug.sourcewin.edit
12+
- vs.debug.file
13+
- vs.debug.breakpoints.delete
14+
- vs.debug.menu.insert
15+
- vs.debug.filenames
16+
- vs.debug.sourcewin.insert
17+
- vs.debug.address
18+
helpviewer_keywords:
19+
- breakpoints, about breakpoints
20+
author: mikejo5000
21+
ms.author: mikejo
22+
manager: mijacobs
23+
ms.subservice: debug-diagnostics
24+
---
25+
# Get started with breakpoints in the Visual Studio debugger
26+
27+
Breakpoints are one of the most important debugging techniques in your developer's 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.
28+
29+
## <a name="BKMK_Overview"></a> Set breakpoints in source code
30+
31+
You can set a breakpoint on any line of executable code. For example, take a look at this simple C# code that creates a simple loop.
32+
33+
```csharp
34+
int testInt = 3;
35+
36+
for (int i = 0; i < 10; i++)
37+
{
38+
testInt += i;
39+
}
40+
```
41+
42+
You could set a breakpoint on the line of code with the variable assignment (`int testInt = 3`), the `for` loop, or any code inside the `for` loop. You can't set a breakpoint on method signatures, declarations for a namespace or class, or variable declarations if there's no assignment and no getter/setter.
43+
44+
To set a breakpoint in source code:
45+
46+
- 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+
48+
For most languages (including C#), Visual Studio automatically highlights breakpoint and current execution lines. For some languages, such as C++, which isn't highlighted by default, you can turn on highlighting of breakpoint and current lines by selecting **Tools** (or **Debug**) > **Options** > **Debugging** > **Highlight entire source line for breakpoints and current statement (C++ only)**.
49+
50+
::: moniker range=">= vs-2022"
51+
![Set a breakpoint](../debugger/media/vs-2022/basic-breakpoint.png "Basic breakpoint")
52+
::: moniker-end
53+
::: moniker range="<= vs-2019"
54+
![Set a breakpoint](../debugger/media/basicbreakpoint.png "Basic breakpoint")
55+
::: moniker-end
56+
57+
To debug, press **F5** or select **Debug** > **Start Debugging**.
58+
59+
When you debug, execution pauses at the breakpoint, before the code on that line is executed. The breakpoint symbol shows a yellow arrow.
60+
61+
::: moniker range=">= vs-2022"
62+
At the breakpoint in the following example, the value of `testInt` is still 3. So, the value hasn't changed since the variable was initialized (set to a value of 3) because the statement in yellow hasn't yet executed.
63+
64+
![Breakpoint execution stopped](../debugger/media/vs-2022/breakpoint-execution.png "Breakpoint execution")
65+
::: moniker-end
66+
67+
::: moniker range="<= vs-2019"
68+
At the breakpoint in the following example, the value of `testInt` is still 1. So, the value hasn't changed since the variable was initialized (set to a value of 1) because the statement in yellow hasn't yet executed.
69+
70+
![Breakpoint execution stopped](../debugger/media/breakpointexecution.png "Breakpoint execution")
71+
::: moniker-end
72+
73+
When the debugger stops at the breakpoint, you can look at the current state of the app, including [variable values](../debugger/debugger-feature-tour.md#inspect-variables-with-data-tips) and the [call stack](../debugger/how-to-use-the-call-stack-window.md).
74+
75+
::: moniker range=">= vs-2022"
76+
For example, in the following illustration, you can see the value of `testInt` in a datatip and in the **Locals** window.
77+
78+
![Screenshot of viewing app state.](../debugger/media/vs-2022/basic-breakpoint-viewing-app-state.png)
79+
::: moniker-end
80+
81+
Here are a few general instructions for working with breakpoints.
82+
83+
- The breakpoint is a toggle. You can click it, press **F9**, or use **Debug** > **Toggle Breakpoint** to delete or reinsert it.
84+
85+
- 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 or the **Breakpoints** window. To re-enable a breakpoint, hover over or right-click it, and select **Enable breakpoint**.
86+
87+
- 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.
88+
89+
## Types of breakpoints
90+
91+
Visual Studio supports different types of breakpoints to support different debugging scenarios, such as conditional breakpoints that only activate based on specified criteria. For more information, see [Use the right type of breakpoint](../debugger/using-breakpoints.md).
92+
93+
## <a name="BKMK_Specify_advanced_properties_of_a_breakpoint_"></a> Manage breakpoints in the Breakpoints window
94+
95+
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.
96+
97+
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.
98+
99+
To open the **Breakpoints** window, select **Debug** > **Windows** > **Breakpoints**, or press **Ctrl**+**Alt**+**B**.
100+
101+
::: moniker range=">= vs-2022"
102+
![Breakpoints window](../debugger/media/vs-2022/breakpoints-window.png "Breakpoints window")
103+
::: moniker-end
104+
::: moniker range="<= vs-2019"
105+
![Breakpoints window](../debugger/media/breakpointswindow.png "Breakpoints window")
106+
::: moniker-end
107+
108+
To select the columns to display in the **Breakpoints** window, select **Show Columns**. Select a column header to sort the breakpoints list by that column.
109+
110+
### <a name="BKMK_Set_a_breakpoint_at_a_function_return_in_the_Call_Stack_window"></a> Breakpoint labels
111+
112+
You can use labels to sort and filter the list of breakpoints in the **Breakpoints** window.
113+
114+
1. To add a label to a breakpoint, right-click the breakpoint in the source code or the **Breakpoints** window, and then select **Edit labels**. Add a new label or choose an existing one, and then select **OK**.
115+
2. Sort the breakpoint list in the **Breakpoints** window by selecting the **Labels**, **Conditions**, or other column headers. You can select the columns to display by selecting **Show Columns** in the toolbar.
116+
117+
::: moniker range=">= vs-2022"
118+
### Breakpoint groups
119+
120+
For complex debugging scenarios, you may want to create breakpoint groups to organize your breakpoints. This allows you to quickly enable and disable logical groupings of breakpoints, based upon the current scenario that you're trying to debug.
121+
122+
You can create breakpoints in the **Breakpoints** window by selecting **New > Breakpoint Group**, and providing a name for the group. To add a breakpoint to a group, right-click the breakpoint and choose **Add to Breakpoint Group** > **\<group name\>**. Or, drag-and-drop your breakpoints into the desired group.
123+
124+
![Screenshot of breakpoint groups.](../debugger/media/vs-2022/breakpoints-window-breakpoint-groups.png)
125+
126+
To set a default breakpoint group, right-click a group and select **Set as default Breakpoint Group**. When you set a default breakpoint group, newly created breakpoints are automatically added to the group.
127+
128+
::: moniker-end
129+
130+
### Export and import breakpoints
131+
132+
To save or share the state and location of your breakpoints, you can export or import them.
133+
134+
::: moniker range=">= vs-2022"
135+
Starting in Visual Studio 2022 version 17.12 Preview 3, breakpoint groups are also included with the exported and imported breakpoints.
136+
::: moniker-end
137+
138+
- 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.
139+
- 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.
140+
- 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.
141+
- To import breakpoints, in the **Breakpoints** window, select the **Import breakpoints from a file** icon, navigate to the XML file location, and select **Open**.
142+
143+
## <a name="BKMK_Set_a_breakpoint_from_debugger_windows"></a> Set breakpoints from debugger windows
144+
145+
You can also set breakpoints from the **Call Stack** and **Disassembly** debugger windows.
146+
147+
### Set a breakpoint in the Call Stack window
148+
149+
To break at the instruction or line that a calling function returns to, you can set a breakpoint in the **Call Stack** window.
150+
151+
**To set a breakpoint in the Call Stack window:**
152+
153+
1. To open the **Call Stack** window, you must be paused during debugging. Select **Debug** > **Windows** > **Call Stack**, or press **Ctrl**+**Alt**+**C**.
154+
155+
2. In the **Call Stack** window, right-click the calling function and select **Breakpoint** > **Insert Breakpoint**, or press **F9**.
156+
157+
A breakpoint symbol appears next to the function call name in the left margin of the call stack.
158+
159+
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.
160+
161+
The debugger breaks at the instruction.
162+
163+
For more information about the call stack, see [How to: Use the Call Stack window](../debugger/how-to-use-the-call-stack-window.md).
164+
165+
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).
166+
167+
### Set a breakpoint in the Disassembly window
168+
169+
1. To open the **Disassembly** window, you must be paused during debugging. Select **Debug** > **Windows** > **Disassembly**, or press **Ctrl**+**Alt**+**D**.
170+
171+
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**.
172+
173+
## Related content
174+
175+
- [What is debugging?](../debugger/what-is-debugging.md)
176+
- [Write better C# code using Visual Studio](../debugger/write-better-code-with-visual-studio.md)
177+
- [First look at debugging](../debugger/debugger-feature-tour.md)
178+
- [Troubleshoot breakpoints in the Visual Studio debugger](../debugger/troubleshooting-breakpoints.md)

docs/debugger/how-to-use-the-call-stack-window.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ In the **Call Stack** window, select the function, right-click, and then choose
107107

108108
## Set a breakpoint on the exit point of a function call
109109

110-
See [Set a breakpoint at a call stack function](../debugger/using-breakpoints.md#BKMK_Set_a_breakpoint_from_debugger_windows).
110+
See [Set a breakpoint at a call stack function](../debugger/get-started-with-breakpoints.md#BKMK_Set_a_breakpoint_from_debugger_windows).
111111

112112
## Display calls to or from another thread
113113

26.9 KB
Loading

docs/debugger/toc.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
items:
4141
- name: Navigation
4242
href: navigating-through-code-with-the-debugger.md
43-
- name: Breakpoints
43+
- name: Get started with breakpoints
44+
href: get-started-with-breakpoints.md
45+
- name: Use the right type of breakpoint
4446
href: using-breakpoints.md
4547
- name: Move the execution pointer
4648
href: move-the-execution-pointer-with-the-debugger.md
@@ -56,6 +58,8 @@
5658
href: autos-and-locals-windows.md
5759
- name: Set a watch on variables
5860
href: watch-and-quickwatch-windows.md
61+
- name: View data values in data tips
62+
href: view-data-values-in-data-tips-in-the-code-editor.md
5963
- name: Expressions in the debugger
6064
items:
6165
- name: Use debugger expressions
@@ -68,8 +72,6 @@
6872
href: format-specifiers-in-csharp.md
6973
- name: Pseudovariables
7074
href: pseudovariables.md
71-
- name: View data values in DataTips
72-
href: view-data-values-in-data-tips-in-the-code-editor.md
7375
- name: View string values in a visualizer
7476
href: view-strings-visualizer.md
7577
- name: View .NET collections in a tabular visualizer

0 commit comments

Comments
 (0)