Advanced Debugging With Visual Studio & OzCode Omer Raviv Co-founder & CTO omerr@codevalue.net http://www.magicaldebugging.com http://codevalue.net
Every minute spent in the debugger is a minute squandered. Period. Why are we here today? Every minute spent in the debugger is a minute squandered. Period. 4/27/2019 OzCode
About Me Omer Raviv: Co-founder and CTO of OzCode Senior Consultant @ CodeValue .NET Open-source enthusiast Passionate about developer productivity
A leading software company About CodeValue A leading software company ~100 employees: more than 90 technology experts Provides high quality software development solutions Turn-Key projects Software development and consultation Tailor-made courses and training Fields of expertise include: Desktop & LOB applications Cloud Computing Advanced Mobile & Web Technologies User Experience (UX) & User Interface (UI) Application Lifecycle Management (ALM) and DevOps Embedded & IoT
Agenda Introduction The psychology of debugging The debugging process Debugging in VS2015 OzCode
About OzCode An innovative debugging extension for Visual-Studio Simplify & visualize complex statements Compare objects and collections Search and filter collections Focus on relevant data http://oz-code.com
My Journey as a developer
The Psychology of Debugging
Debug like a Boss Tennis Pro! 12/1/2014
The Psychology of Debugging Elizabeth Spiegel 12/1/2014
The Debugging Process Overview The two most common ways of using a debugger: 1. Wasting time 2. Quality time
The Debugging Process Overview Wasting time: Not knowing what your hypothesis is at any given time Getting into a rot mindlessly hitting F10 Staring blankly at the screen Praying for a miracle
The Debugging Process Overview Quality time: Know exactly WHY you started the debugger Run it in your head first (rubber-ducking) Apply the Scientific Method, religiously Simplify the scenario, then write a test!
The Debugging Process Overview Separate facts from interpretation Wrong interpretation leads to a dead-end Divide and conquer Trap the bug in the corner Use the right tool for the bug & the context Isolate changes - do one change at a time See its effect (fact), draw a conclusion (interpretation)
Sherlock Holmes’ Advice on Debugging It is a capital mistake to theorise before one has data. Insensibly one begins to twist facts to suit theories, instead of theories to suit facts. A Scandal in Bohemia, 1892 —
Use the right tools to decrease your Time-to-Aha factor The bottom line Debugging is HARD. Use the right tools to decrease your Time-to-Aha factor
.NET Debugger Options Visual Studio MDbg.exe - .Net Command line Debugger WinDbg + SOS.DLL|SOSEX.DLL|PSSCOR4.DLL
There are some moments in life… After which, life is no longer the same! The first kiss Your wedding The first child The first time you saw OzCode
Visual Studio 2015 – Lambda Evaluation in Immediate Window, Watch & OzCode Custom Expression
Controlling the Execution Context Using the debugger UI, you can switch between processes, threads, and stack locations Within the current context of the process and thread: Moving the instruction pointer to Skip code Re-run code Setting variable values that control the execution path Expressions in if, switch, loop conditions Using Edit & Continue – SO MUCH BETTER IN VS2015!
Setting New Breakpoints Setting Breakpoints with Visual Studio 2015
.NET Performance & Debugging Method Breakpoints If you type a method name (without class name) VS select all that matches .NET Performance & Debugging
Visual Studio 2015 – Profiling While Debugging In VS 2015 – Performance Data “in your face” Performance tips Performance graphs
Let the Magic Begin
Tracing with Tracepoints Can print out any expression by surrounding with {} property/field/method call Special code can be used: Tracepoint variable name Meaning $ADDRESS Current instruction address $CALLER Caller name of current method $CALLSTACK The call stack at the current location $FUNCTION Current function name $PID Current process ID $PNAME Current process name $TID Current thread ID $TNAME Current thread name
Visual Studio Parallel Task & Parallel Stacks View the logical call, the logical call stack and the task/thread state
Parallel Watch - View local variable in each thread’s context
Summary The debugging process .NET debuggers Controlling the debugger The debugging loop Make it fail Make a hypothesis Collect evidence Prove or refine the hypothesis Advanced techniques and tools What’s new in Visual Studio 2015 C# debugger
Thanks!