Upload
others
View
7
Download
0
Embed Size (px)
Citation preview
Visual Studio 2015 Debugging
Beyond F9
2
Agenda
• Symbols
• Breakpoints
• Debugging threads
• Visualizing data
• Immediate window
• Debugging exceptions
• Diagnostics tools
– Memory
– CPU
– Program events
• Debugging Production issues with Visual Studio
3
Breakpoints – Beyond F9
• Breakpoints force debugger to break during execution
– Insert INT3 interrupt
• Options beyond simple break
– Condition
– Hit Count
– Filter
– Trace Points
4
Conditional Breakpoints
• Two kinds
– Is True
– When changed
• Is true
– Evaluates expression and breaks if true
• When Changed
– Evaluates expression and breaks if value different from last
time
5
Hit Count
• Can break based on current time through breakpoint
– Exact value
– Greater than value
– Multiple of value
6
Filters
• Can include only certain machines, processes or
threads
– Useful if library used in a number of contexts but only one has
issues
7
When Hit
• Can get trace statement rather than break
– Known as Actions
– Can see trends rather than execution being interrupted
8
Breakpoints
• Debug -> Windows -> Breakpoints
• Allow visualisation of all break points
• Assign label to break point
9
Tools
• Visual Studio gives you many views of the execution
– Call stack
– Immediate
– Threads
• Shows executing threads
• Allows Freezing and Thawing of threads during execution
– Parallel
• Stacks,Tasks
• Watch
– Diagnostic tools
• Memory
• Network
10
Parallel Tasks
• Used with new Task API
• Shows rich information
– Running
– Waiting
– Not Scheduled
– Deadlocked
11
Parallel Stacks
• Shows common call stacks of threads or tasks
12
Data Visualization
• Visual Studio has a number of ways to view data during
debugging
– Locals
– Watch Windows
– Parallel Watch
– Debug Visualizers
– Data Tips
• Locals and Watch windows show local or interesting
variables
– Can view and change values
13
Parallel Watch
• Watch local variables across multiple threads
• Useful for debugging data based parallelism
14
Debug Visualizers
• Two kinds of visualization of types
– Simple control of what is displayed in debugger
– Full blown data visualization
• Simple display
– Debugger calls ToString() by default
– Can override with [DebuggerDisplay] attribute
• Data Visualization
– Built in Visualizers for a number of types, e.g.
• DataSet
• XElement
• Window (WPF)
– Extensible
15
Creating a DebuggerVisualizer
• Derive from DialogDebuggerVisualizer
• Annotate visualizer to bind to type
• Drop DLL in Visualizer directory
[assembly:DebuggerVisualizer(typeof(AssemblyVisualizer),
typeof(VisualizerObjectSource),
Target = typeof(Assembly),
Description = "Assembly Visualizer")]
public class AssemblyVisualizer : DialogDebuggerVisualizer
{
protected override void Show(IDialogVisualizerService winService,
IVisualizerObjectProvider objProvider)
{
Assembly asm = (Assembly)objProvider.GetObject();
winService.ShowDialog(new AssemblyViewer(asm));
}
}
16
Data Tips
• Add watch to editor surface
– Add Expressions
– Collate many
– Can add notes
• Export and Import DataTips
17
Immediate Window
• Supports lambdas
18
Exceptions
• Exception handling performed in two passes
– First chance exceptions
– Second chance exceptions
• First chance
– Looks for matching handling block
– Detects unhandled exceptions
• Second Chance
– Unwinds finally blocks back to exception handling block
• Unhandled exceptions always force debugger to break
19
Visual Studio and Exceptions
• Can manage different kinds of exceptions
– Managed exceptions
– Native exceptions
– C++ Exceptions
• Debug -> Windows -> Exception Settings
20
CLR Exceptions
• Control how handling of exceptions is managed
– Always when thrown
– Only when unhandled
• Can specify behavior by exception type
21
WPF Debugging
• View the visual tree
• Locate code for a given element in the UI
• Manipulate properties on the visual tree
– Try ui tweaks with out re-compile
• Modify DataContext to try different values
• Reduces UI Design/Compile/Test round trips
22
Diagnostic Tools
• Memory
– Identifying memory leaks
• CPU
– Identity areas of intense CPU
– Identify areas of no CPU activity, blocking op
• Intellitrace events
– Records sequence of high level events through out the application
• Exceptions
• Database access
23
Memory
• See memory profile as application runs
• Denote GC events
– How long GC takes
• Very useful for UI apps to see memory being released
24
Memory usage
• Manually take snap shots
– Forces a full GC
• Compare snap shots to identify potential memory leaks
– Understand why an object is still live
25
CPU
• Shows CPU usage while in debug session
• With debug build can use break points to analyse blocks of
code
private static double CalculatePi(int iterations){double pi = 1;
Parallel.For(0, (iterations-3)/2, …);
return pi*4.0;}
26
Intellitrace
• Two modes
– Collect events
– Collect call information
• Collects richer information that allows stepping through the
code historically but is more invasive
• Only available in Enterprise SKU
27
Interactive Mode
• The intellitrace events and information can be viewed
during interactive debugging session
28
Interactive Mode (Contd)
• If call tracing is enabled can replay debugging session
– F10 /F11 walk forward Ctrl-Shift-F11 walks backwards
– Edit and Continue is disabled when using call tracing
29
Production issues and Visual Studio
• Take a dump of live process
– DebugDiag
– Task Manager
– Adplus
• Load dump into Visual Studio to analyse
30
Summary
• Visual Studio is a powerful debugging tool
• Much more functionality beyond F9 / F5
• Lots of functionality in 2015
– Breakpoint labels
– Parallel Tasks and Stacks
– Data Tips
– Diagnostic tools
– Support for production debugginng