how to become a .net debugging jedi
TRANSCRIPT
![Page 1: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/1.jpg)
1
Moaid HathotSoftware Consultanthttp://moaid.codes
How to become a debugging Jedi
![Page 2: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/2.jpg)
222
• Software engineer, consultant and code Jedi• Developing Software professionally since 2013• Software Craftsmanship advocate• Clean Coder
@[email protected]://www.moaid.codes
About Me
![Page 3: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/3.jpg)
333
About CodeValue
A leading software company• ~180 employees: more than 120 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
![Page 4: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/4.jpg)
Agenda
IntroductionBreakpointsDebugging attributesDebugging multithreaded codeToolsPost-mortem debugging
4
![Page 5: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/5.jpg)
555
The Original Bug Report
• “Debugging is the process of finding and resolving bugs or defects that prevent correct operation of computer software or a system”
• The terms "bug" and "debugging" are popularly attributed to Admiral Grace Hopper in the 1940s
• However the term is much older• Thomas Edison wrote the following words in a letter to an associate in 1878:
• “It has been just so in all of my inventions. The first step is an intuition, and comes with a burst, then difficulties arise — this thing gives out and [it is] then that "Bugs" — as such little faults and difficulties are called — show themselves and months of intense watching, study and labor are requisite before commercial success or failure is certainly reached”
![Page 6: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/6.jpg)
666
The Original Bug Report
![Page 7: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/7.jpg)
777
Squandered time
Every minute spent in the debugger is a minute squandered.
Period.
![Page 8: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/8.jpg)
888
Debugging is a time-travel
![Page 9: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/9.jpg)
999
The Aha Moment• The two endpoints of debugging
1. What the heck.
2. Aha!
![Page 10: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/10.jpg)
101010
Know your tools
Know your tools
![Page 11: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/11.jpg)
111111
Know your tools
Know your tools
![Page 12: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/12.jpg)
121212
Controlling The Debugger• There are 10 types of (human) debuggers:
• The “I am too tired to think, let the debugger lead and control” type
• The “everything is under control” type
![Page 13: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/13.jpg)
131313
Rubber ducking
rubber duck debugging or rubber ducking is a method of debugging code
The name is a reference to a story in the book The Pragmatic Programmer in which a programmer would carry around a rubber duck and debug their code by forcing themselves to explain it, line-by-line, to the duck
![Page 14: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/14.jpg)
141414
Rubber ducking
rubber duck debugging or rubber ducking is a method of debugging code
The name is a reference to a story in the book The Pragmatic Programmer in which a programmer would carry around a rubber duck and debug their code by forcing themselves to explain it, line-by-line, to the duck
![Page 15: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/15.jpg)
15
Breakpoints
15
![Page 16: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/16.jpg)
Conditional Breakpoints
16
![Page 17: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/17.jpg)
171717
Filters
![Page 18: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/18.jpg)
Tracepoints (VS)
18
![Page 19: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/19.jpg)
Tracepoints (VS)
19
![Page 20: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/20.jpg)
Method Breakpoints
Ctrl + BIf you type a method name (without class name)
VS select all that matches
20
![Page 21: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/21.jpg)
212121
Conditional Breakpoint’s drawbacks
What are the drawbacks of Conditional Breakpoints?
![Page 22: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/22.jpg)
222222
Debugger Anatomy
Wait for debug event
Handle debug event
Continue debug event
Start the debugger or attach to it
Enter main debugger loop
![Page 23: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/23.jpg)
232323
Debugger Main Loop
1. …2. for(;;) 3. { 4. WaitForDebugEvent(DebugEv, INFINITE); 5. switch (DebugEv->dwDebugEventCode) 6. { 7. case EXCEPTION_DEBUG_EVENT: 8. switch(DebugEv->u.Exception.ExceptionRecord.9. ExceptionCode)10. { 11. case EXCEPTION_ACCESS_VIOLATION: 12. case …13. }
Source: https://msdn.microsoft.com/en-us/library/windows/desktop/ms681675(v=vs.85).aspx
![Page 24: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/24.jpg)
242424
Debugger Main Loop
Source: https://msdn.microsoft.com/en-us/library/windows/desktop/ms681675(v=vs.85).aspx
1. break;2. case CREATE_THREAD_DEBUG_EVENT: 3. dwContinueStatus = 4. OnCreateThreadDebugEvent(DebugEv);5. break;6. …7. } 8. // Resume executing the thread that reported the9. debugging event. 10. ContinueDebugEvent(DebugEv->dwProcessId, 11. DebugEv->dwThreadId, 12. dwContinueStatus);13. }}
![Page 25: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/25.jpg)
252525
Debugger break
![Page 26: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/26.jpg)
262626
Debugger break
![Page 27: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/27.jpg)
272727
Conditional Attribute
![Page 28: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/28.jpg)
282828
Object ID’s
![Page 29: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/29.jpg)
292929
Lambda Evaluation in Immediate & Watch Windows
![Page 30: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/30.jpg)
30
Debugging Attributes
30
![Page 31: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/31.jpg)
313131
Debugger Display Attribute
![Page 32: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/32.jpg)
323232
Debugger Display Attribute
![Page 33: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/33.jpg)
333333
Debugger Display Attribute
![Page 34: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/34.jpg)
343434
Debugger Type Proxy Attribute
![Page 35: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/35.jpg)
353535
Debugger Browsable Attribute
![Page 36: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/36.jpg)
363636
Debugger Visualizer
![Page 37: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/37.jpg)
373737
Debugger Visualizer
![Page 38: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/38.jpg)
38
Multithreading
38
![Page 39: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/39.jpg)
Staying on the same thread (freezing other threads)
39
![Page 40: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/40.jpg)
Finding Tasks Deadlocks
Debug –> windows –> Tasks
40
![Page 41: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/41.jpg)
414141
Parallel Task & Parallel Stacks
View the logical call, the logical call stack and the task/thread state
![Page 42: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/42.jpg)
424242
Parallel Watch - View local variable in each thread’s context
![Page 43: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/43.jpg)
434343
Concurrent Visualizer
https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.ConcurrencyVisualizerforVisualStudio2015
![Page 44: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/44.jpg)
444444
Concurrent Visualizer
https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.ConcurrencyVisualizerforVisualStudio2015
![Page 45: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/45.jpg)
45
OzCode
45
![Page 46: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/46.jpg)
LINQ Debugging
46
![Page 47: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/47.jpg)
Predicting the future
Predict
47
![Page 48: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/48.jpg)
Custom Expressions
48
![Page 49: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/49.jpg)
Show All Instances
49
![Page 50: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/50.jpg)
Tracepoints (OzCode)
50
![Page 51: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/51.jpg)
Conditional Breakpoints (OzCode)
51
invoice.Id 915486 intinvoice.Id 915486 int
![Page 52: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/52.jpg)
OzCode Comapre
52
![Page 53: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/53.jpg)
Export
53
![Page 55: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/55.jpg)
55
System Internals
55
![Page 56: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/56.jpg)
Where to download
Browser: http://Live.sysinternals.comShared folder: \\live.sysinternals.com\tools
56
![Page 57: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/57.jpg)
Process Explorer
57
![Page 58: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/58.jpg)
Process Monitor
58
![Page 59: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/59.jpg)
59
Post-Mortem Debugging
59
![Page 60: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/60.jpg)
606060
Dump Files
• A minidump is a snapshot of a process– May be created at any time, not just when a process crashes
• Minidump types– Kernel minidumps (not relevant for this course)– Basic (usually enough for native processes)– Full (required to get useful info for managed processes)
![Page 61: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/61.jpg)
616161
Dump Creation
• Minidump creation– WinDbg– On Vista, 2008 and up can use Task Manager– ADPlus– ProcDump
• Opening Dump files– WinDbg– Visual Studio 2012/2013
![Page 62: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/62.jpg)
62
Automatic Dump Creation
To enable it, set the reg key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps\<appName>
DumpFolder – Location for the output dumpsDumpCount – Maximum amount of dumps in the folderDumpType
1 – Mini Dump2 – Full Dump0 – Custom Dump
CustomDumpFlags – if DumpType is 0, set the dump options
![Page 63: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/63.jpg)
Debugging using the Dump (1)
63
![Page 64: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/64.jpg)
Debugging using the Dump (2)
64
![Page 65: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/65.jpg)
666666
Generating Symbol Tables
1. Open DotPeek2. Add the required assembly 3. Press start Symbol server4. In VS add new symbol source
![Page 66: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/66.jpg)
676767
Debugging is Hard
Debugging is HARD.Even the Pros get befuddled
sometimesUse the right tools to decrease your Time-to-Aha factor
![Page 68: How to become a .net debugging jedi](https://reader036.vdocuments.us/reader036/viewer/2022062400/5899a8ae1a28ab30688b6f79/html5/thumbnails/68.jpg)
69 69
Presenter contact detailst: @MoaidHathote: [email protected]: http://www.moaid.codesw: www.codevalue.net
Free 3 months of OzCodehttp://tinyurl.com/jpn4y96