![Page 1: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/1.jpg)
Visual Studio 2015 Debugging
Beyond F9
![Page 2: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/2.jpg)
2
Agenda
• Symbols
• Breakpoints
• Debugging threads
• Visualizing data
• Immediate window
• Debugging exceptions
• Diagnostics tools
– Memory
– CPU
– Program events
• Debugging Production issues with Visual Studio
![Page 3: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/3.jpg)
3
Breakpoints – Beyond F9
• Breakpoints force debugger to break during execution
– Insert INT3 interrupt
• Options beyond simple break
– Condition
– Hit Count
– Filter
– Trace Points
![Page 4: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/4.jpg)
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
![Page 5: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/5.jpg)
5
Hit Count
• Can break based on current time through breakpoint
– Exact value
– Greater than value
– Multiple of value
![Page 6: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/6.jpg)
6
Filters
• Can include only certain machines, processes or
threads
– Useful if library used in a number of contexts but only one has
issues
![Page 7: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/7.jpg)
7
When Hit
• Can get trace statement rather than break
– Known as Actions
– Can see trends rather than execution being interrupted
![Page 8: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/8.jpg)
8
Breakpoints
• Debug -> Windows -> Breakpoints
• Allow visualisation of all break points
• Assign label to break point
![Page 9: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/9.jpg)
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
![Page 10: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/10.jpg)
10
Parallel Tasks
• Used with new Task API
• Shows rich information
– Running
– Waiting
– Not Scheduled
– Deadlocked
![Page 11: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/11.jpg)
11
Parallel Stacks
• Shows common call stacks of threads or tasks
![Page 12: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/12.jpg)
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
![Page 13: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/13.jpg)
13
Parallel Watch
• Watch local variables across multiple threads
• Useful for debugging data based parallelism
![Page 14: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/14.jpg)
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
![Page 15: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/15.jpg)
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));
}
}
![Page 16: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/16.jpg)
16
Data Tips
• Add watch to editor surface
– Add Expressions
– Collate many
– Can add notes
• Export and Import DataTips
![Page 17: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/17.jpg)
17
Immediate Window
• Supports lambdas
![Page 18: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/18.jpg)
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
![Page 19: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/19.jpg)
19
Visual Studio and Exceptions
• Can manage different kinds of exceptions
– Managed exceptions
– Native exceptions
– C++ Exceptions
• Debug -> Windows -> Exception Settings
![Page 20: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/20.jpg)
20
CLR Exceptions
• Control how handling of exceptions is managed
– Always when thrown
– Only when unhandled
• Can specify behavior by exception type
![Page 21: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/21.jpg)
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
![Page 22: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/22.jpg)
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
![Page 23: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/23.jpg)
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
![Page 24: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/24.jpg)
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
![Page 25: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/25.jpg)
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;}
![Page 26: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/26.jpg)
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
![Page 27: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/27.jpg)
27
Interactive Mode
• The intellitrace events and information can be viewed
during interactive debugging session
![Page 28: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/28.jpg)
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
![Page 29: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/29.jpg)
29
Production issues and Visual Studio
• Take a dump of live process
– DebugDiag
– Task Manager
– Adplus
• Load dump into Visual Studio to analyse
![Page 30: Visual Studio 2015 Debuggingsddconf.com/brands/sdd/library/VSDebugginng.pdf · 2016. 5. 18. · • Visual Studio is a powerful debugging tool • Much more functionality beyond F9](https://reader036.vdocuments.net/reader036/viewer/2022062415/609f0a4315de1f786f20129d/html5/thumbnails/30.jpg)
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