Bewerken

Delen via


FAQ - Debugger feature finder

This documentation addresses frequent questions about debugging features in Visual Studio. It also maps debugging tasks or issues to the relevant feature in the Visual Studio debugger. These links cover tasks or issues such as debugging multi-threaded application, code navigation, memory leak, inspecting variables, using breakpoints, external code debugging and many more. If you need an overview of debugger features, see First look at the debugger instead.

Breakpoints

  • How do I pause running code to inspect a line of code that may contain a bug?

    Set a breakpoint. For more information, see Using breakpoints.

  • Does my variable have an unexpected value. Or, do I want to inspect my app when it reaches a specific state?

    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.

    For more information, see Breakpoint conditions.

  • How do I log information to the Output window under configurable conditions without modifying or stopping my code?

    Tracepoints allow you to log information to the Output window under configurable conditions without modifying or stopping your code.

  • How do I know when the value of my variable changes?

    For C++, set a data breakpoint.

    For apps using .NET Core 3, you can also set a data breakpoint.

    Otherwise, for C# and F# only, you can track an object ID with a conditional breakpoint.

  • How do I break execution only if another breakpoint is hit?

    Set a Dependent Breakpoint that breaks execution only if another breakpoint is first hit. For more information, see Dependent Breakpoint.

  • Can I hit a breakpoint only once?

    Set a temporary breakpoint which lets you break the code only once. For more information, see Temporary Breakpoint.

  • Can I pause code inside a loop at a certain iteration?

    Set a Dependent breakpoint that breaks execution only if another breakpoint is first hit. For more information, see Hit count.

  • How can I pause code at the start of a function when I know the function name but not its location?

    You can do this with a function breakpoint. For more information, see Set function breakpoints.

  • How can I pause code at the start of multiple functions with the same name?

    When you have multiple functions with the same name (overloaded functions or functions in different projects), you can use a function breakpoint.

  • Manage and keep track of my breakpoints

    Use the Breakpoints window. For more information, see Manage breakpoints.

  • Pause code and debug when a specific handled or unhandled exception is thrown

    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.

  • Set a breakpoint from the call stack

    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.

  • Pause code at a specific assembly instruction

    You can do this by setting a breakpoint from the Disassembly window.

  • How can I learn the commands to step through my code while debugging?

    For more information, see Navigate code with the debugger.

  • Can I run the code to a particular line while skipping breakpoints without removing or disabling them?

    You can use “Force Run To Cursor” for these scenarios. You can keep your breakpoints and the debugger will skip over them until it reaches the line of code with the cursor. It will also skip any of the first-chance exceptions break conditions that may occur. For more information, see Navigate code with the debugger.

  • If my line of code has calls to different methods, can I step into a specific method?

    Right-click on the line of code to bring up a context menu that allows you to select ‘Step Into Specific’. This will show a list of all the methods that you could step into. You can now select the method of interest.

Inspect and Visualize data

  • How can I check the value of variables while running my app?

    Hover over variables using data tips or inspect variables in the Autos and Locals window.

  • Can I observe the changing value of a specific variable?

    Set a watch on the variable. For more information, see Set a watch on variables.

  • How can I view strings that are too long for the debugger window?

    String Visualizer shows strings that are too long for a data tip or debugger window. It can also help you identify malformed strings.
    Built-in string visualizer in Visual Studio include Text, XML, HTML, and JSON options.

  • How can I view large collection objects?

    The DataSet Visualizer allows you to view the contents of a DataSet, DataTable, DataView, or DataViewManager. The IEnumerable Visualizer allows you to view objects such as Arrays, List, etc. For more information, see Tabular visualizers.

Debug an app that is already running

  • How can I debug running apps on local or remote computers, debug multiple processes simultaneously, debug apps that weren't created in Visual Studio, or debug any app I didn't start from Visual Studio?

    See Attach to a running processes.

  • How can I to attach to the same application repeatedly?

    You can use Reattach to Process (Shift+Alt+P) to easily allow you to start debugging your application in one click without needing to go through the Attach to Process dialog every time. See Reattach to a process

Debug multithreaded applications

Analyze memory

  • Does my application have a memory leak?

    Take a snapshot and open it with memory tool to troubleshoot further. See Measure memory usage.

  • How can I analyze memory usage for native or managed applications?

    Use the Visual Studio memory tool via live debugging, heap dumps, or the performance profiler.
    See Choose a memory analysis tool.

  • How can I analyze memory usage for native or managed applications without attaching a debugger? Use the Visual Studio performance profiler with the memory usage tool enabled.
    See Analyze memory usage.

  • Can I compare memory usage between two points in time?

    Compare snapshots in the memory tool or compare two heap dumps using the diff functionality. See Analyze memory usage.

External Code Debugging

  • Can I see only user code while debugging?

    Just My Code is a Visual Studio debugging feature that automatically steps over calls to system, framework, and other non-user code. In the Call Stack window, Just My Code collapses these calls into [External Code] frames. See Debug only user code with Just My Code

  • How can I view or debug the raw assembly instructions that my program is executing?

    Use the Disassembly Window from Debug > Windows > Disassembly. You can step over one instruction at a time and even set breakpoints on individual assembly instructions.

  • Can I see source code for .NET Libraries?

    Enable Microsoft Symbol Servers from Debug > Options > Symbols in order to download symbols and source for .NET Libraries. See Specify symbol

  • How can I load PDBs from a specific or shared location or server?

    Configure your Symbol Servers from Debug > Options > Symbols. See Specify symbol

  • How can I never load a specific PDB? Or, how can I always load one?

    Configure your Include and Exclude Lists in Debug > Options > Symbols.
    See Specify symbol

Configure debugging

  • How do I configure debugger settings?

    To configure debugger options and debugger project settings, see Debugger settings and preparation.

  • How can I customize information shown in the debugger?

    You may want to show information other than the object type as the value in different debugger windows. For C#, Visual Basic, F#, and C++/CLI code, use the DebuggerDisplay attribute. For more advanced options, you can also customize the UI by creating a custom visualizer. For native C++, use the NatVis framework.

Additional tasks

  • Do I need to save a dump?

    While stopped at an error or breakpoint during debugging, select Debug > Save Dump As. See Dump files

  • How do I analyze a dump file?

    Open the dump by choosing File > Open in Visual Studio. To start debugging, select Debug with Managed Only, Debug with Native Only, Debug with Mixed, or Debug with Managed Memory. See Dump files

  • Can I edit code during a debugging session?

    Use Edit and continue. For XAML, use XAML Hot Reload.

  • How can I debug on remote machines?

    See Remote debugging.

  • How can I fix performance issues?

    See First look at the profiling tools

  • How do I fix an exception?

    See Fix an exception.