Debugging with Visual Studio Beyond ‘F5’
Dror Helper (@dhelper)
About.ME
Consultant & software architect @ Practical Software
Developing software since 2002
Clean Coder & Test-Driven Developer
Pluralsight author
Blogger: http://helpercode.com
Twitter: @dhelper
Why I hate debugging:
It’s never
planned
Usually
complicated
Extremely
frustrating
Tend to be
stressful
Always time consuming
Why debugging consumes so much
time?
There are 0b10 types of developers
A practical approach to debugging
1. Reproduce the problem
2. Get to where the issue happens
3. Analyze the system state
4. Create hypothesis
5. Fix the bug
6. Verify your solution
7. Celebrate
Reasons to use the debugger
Gather
information
Prove
hypothesis
Check solution
Reproduce the issue
Is it reproducible?
Is it reproducible on my machine?
What input caused the problem?
When was the last time it worked?
Answer those questions before continuing to the next step!
Get to where the issue is
How to waste time:
- Not knowing where we’re going
- Running through all the code
- Multiple reruns + long startup time
Immediate
window
Exception
thrown
Breakpoints
Who can help us get to the bug
Immediate window
debug and evaluate expressions
execute statements
print variable values
Stop on exceptions
We can tell Visual Studio to break whe
- An exception is thrown and not handled
- An exception is thrown
* Reduce noise using exception type
Breakpoints
Pause execution
So I can inspect my code
• Always
• Conditional
• Trace*
• Data (VS2019)
Data breakpoints
New in VS2019
.NET Core 3.0 only!
Value must be on the managed heap
Gathering information
Understand all the information
Don’t waste time traveling your code
Quickly find relevant information
Learn to use your keyboard
Reduce mental overhead
Debug naturally
Tracepoints
Special kind of breakpoint
Log information instead of stopping
Use text and existing variables
When to use Tracepoints
Huge data + iterations (LINQ)
Multi-Threading
Sync issues (up to a point)
Visual Studio’s tool windows
Simple – Stack, Watches, Exceptions, Breakpoints
Advanced – Tasks, Threads, Modules
Make Object Id
Distinguish between different instances
Track an object even if it’s out of scope
Debugging parallel code
Tracepoints for ad-hoc logging
Tasks/Threads to find Blocked/Deadlocks
Parallel Stacks to understand flow
Parallel Watch
22
Parallel Task & Parallel Stacks
View the logical call, the logical call stack and the task/thread state
Understanding your data
Use Make Object Id to follow specific instances
Search for objects and properties in Watch windows (VS019)
Format how your data is displayed
- ToString
- DebbugerDisplayAttribute
Edit & Continue during Fix – Build – Run cycles
Immediate window to avoid crash on exception
Edit values to for and prove hypothesis
Avoid restarting your debugger
Edit & Continue
Make sure Edit and Continue is enabled!
Check list of supported/unsupported changes
https://github.com/dotnet/roslyn/wiki/EnC-Supported-Edits
... Or just try and find out
What we’ve learnt
Reproduce Analyze Hypothesis Fix Verify
Better debugging
Using Visual Studio capabilities
A structured process of finding and eliminating bugs
Dror Helper | @ dhelper | http://helpercode.com
Thank you!
Debugging with visual studio beyond 'F5'

Debugging with visual studio beyond 'F5'

  • 1.
    Debugging with VisualStudio Beyond ‘F5’ Dror Helper (@dhelper)
  • 2.
    About.ME Consultant & softwarearchitect @ Practical Software Developing software since 2002 Clean Coder & Test-Driven Developer Pluralsight author Blogger: http://helpercode.com Twitter: @dhelper
  • 3.
    Why I hatedebugging: It’s never planned Usually complicated Extremely frustrating Tend to be stressful Always time consuming
  • 4.
  • 5.
    There are 0b10types of developers
  • 6.
    A practical approachto debugging 1. Reproduce the problem 2. Get to where the issue happens 3. Analyze the system state 4. Create hypothesis 5. Fix the bug 6. Verify your solution 7. Celebrate
  • 7.
    Reasons to usethe debugger Gather information Prove hypothesis Check solution
  • 8.
    Reproduce the issue Isit reproducible? Is it reproducible on my machine? What input caused the problem? When was the last time it worked? Answer those questions before continuing to the next step!
  • 9.
    Get to wherethe issue is How to waste time: - Not knowing where we’re going - Running through all the code - Multiple reruns + long startup time
  • 10.
  • 11.
    Immediate window debug andevaluate expressions execute statements print variable values
  • 12.
    Stop on exceptions Wecan tell Visual Studio to break whe - An exception is thrown and not handled - An exception is thrown * Reduce noise using exception type
  • 13.
    Breakpoints Pause execution So Ican inspect my code • Always • Conditional • Trace* • Data (VS2019)
  • 14.
    Data breakpoints New inVS2019 .NET Core 3.0 only! Value must be on the managed heap
  • 15.
    Gathering information Understand allthe information Don’t waste time traveling your code Quickly find relevant information
  • 16.
    Learn to useyour keyboard Reduce mental overhead Debug naturally
  • 17.
    Tracepoints Special kind ofbreakpoint Log information instead of stopping Use text and existing variables
  • 18.
    When to useTracepoints Huge data + iterations (LINQ) Multi-Threading Sync issues (up to a point)
  • 19.
    Visual Studio’s toolwindows Simple – Stack, Watches, Exceptions, Breakpoints Advanced – Tasks, Threads, Modules
  • 20.
    Make Object Id Distinguishbetween different instances Track an object even if it’s out of scope
  • 21.
    Debugging parallel code Tracepointsfor ad-hoc logging Tasks/Threads to find Blocked/Deadlocks Parallel Stacks to understand flow
  • 22.
  • 23.
    Parallel Task &Parallel Stacks View the logical call, the logical call stack and the task/thread state
  • 24.
    Understanding your data UseMake Object Id to follow specific instances Search for objects and properties in Watch windows (VS019) Format how your data is displayed - ToString - DebbugerDisplayAttribute
  • 25.
    Edit & Continueduring Fix – Build – Run cycles Immediate window to avoid crash on exception Edit values to for and prove hypothesis Avoid restarting your debugger
  • 26.
    Edit & Continue Makesure Edit and Continue is enabled! Check list of supported/unsupported changes https://github.com/dotnet/roslyn/wiki/EnC-Supported-Edits ... Or just try and find out
  • 27.
    What we’ve learnt ReproduceAnalyze Hypothesis Fix Verify Better debugging Using Visual Studio capabilities A structured process of finding and eliminating bugs
  • 28.
    Dror Helper |@ dhelper | http://helpercode.com Thank you!

Editor's Notes

  • #7 Need to find better way to show the steps and where the debugger comes in
  • #8 Never ever start your debugger without a clear idea of where to go and what to check
  • #9 What happens if I can’t? - Help from you team
  • #17 When you use the debugger you want it to be a simple intuitive experience which means you do not want o use the mouse, you need the keyboard, and without thinking which requires some practice, especially since duerring debnugging we too frustrated to learn new stuff
  • #28 What cause it? When did it start? Inputs/env Get to the issue Gather information Why it happen? Prove!