Debugging is part of any development process, but unfortunately it’s never planned or expected. On top of that, it’s rarely approached in a structured way, and while many modern IDEs have powerful debugging tools – most developers are not aware of how they can be used to reduce the time and pain of debugging. The whole act of debugging is done as an ad-hoc, time consuming activity, which is considered less interesting then developing new features or investigating the latest and greatest technology. But while there are many articles and productivity tools aimed at writing better code – faster, it seems as though it’s impossible to find resources that teach you how to effectively debug your code. In this lecture, we will discuss how to approach a debugging session, and show the latest power debugging capabilities Visual Studio has to offer. These will help you save time and pain by first understanding the problem and then fixing the bug that caused it.
6. 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
7. Reasons to use the debugger
Gather
information
Prove
hypothesis
Check solution
8. 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!
9. 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
12. 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
23. Parallel Task & Parallel Stacks
View the logical call, the logical call stack and the task/thread state
24. 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
25. 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
26. 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
27. What we’ve learnt
Reproduce Analyze Hypothesis Fix Verify
Better debugging
Using Visual Studio capabilities
A structured process of finding and eliminating bugs
Need to find better way to show the steps and where the debugger comes in
Never ever start your debugger without a clear idea of where to go and what to check
What happens if I can’t?
- Help from you team
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
What cause it?
When did it start?
Inputs/env
Get to the issue
Gather information
Why it happen?
Prove!