visual studio 2015 debuggingsddconf.com/brands/sdd/library/vsdebugginng.pdf · 2016. 5. 18. · •...

30
Visual Studio 2015 Debugging Beyond F9

Upload: others

Post on 31-Dec-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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