Upload
moaid-hathot
View
31
Download
4
Embed Size (px)
Citation preview
1
Moaid HathotSoftware Consultanthttp://moaid.codes
How to become a debugging Jedi
222
• Software engineer, consultant and code Jedi• Developing Software professionally since 2013• Software Craftsmanship advocate• Clean Coder
@[email protected]://www.moaid.codes
About Me
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
Agenda
IntroductionBreakpointsDebugging attributesDebugging multithreaded codeToolsPost-mortem debugging
4
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”
666
The Original Bug Report
777
Squandered time
Every minute spent in the debugger is a minute squandered.
Period.
888
Debugging is a time-travel
999
The Aha Moment• The two endpoints of debugging
1. What the heck.
2. Aha!
101010
Know your tools
Know your tools
111111
Know your tools
Know your tools
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
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
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
15
Breakpoints
15
Conditional Breakpoints
16
171717
Filters
Tracepoints (VS)
18
Tracepoints (VS)
19
Method Breakpoints
Ctrl + BIf you type a method name (without class name)
VS select all that matches
20
212121
Conditional Breakpoint’s drawbacks
What are the drawbacks of Conditional Breakpoints?
222222
Debugger Anatomy
Wait for debug event
Handle debug event
Continue debug event
Start the debugger or attach to it
Enter main debugger loop
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
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. }}
252525
Debugger break
262626
Debugger break
272727
Conditional Attribute
282828
Object ID’s
292929
Lambda Evaluation in Immediate & Watch Windows
30
Debugging Attributes
30
313131
Debugger Display Attribute
323232
Debugger Display Attribute
333333
Debugger Display Attribute
343434
Debugger Type Proxy Attribute
353535
Debugger Browsable Attribute
363636
Debugger Visualizer
373737
Debugger Visualizer
38
Multithreading
38
Staying on the same thread (freezing other threads)
39
Finding Tasks Deadlocks
Debug –> windows –> Tasks
40
414141
Parallel Task & Parallel Stacks
View the logical call, the logical call stack and the task/thread state
424242
Parallel Watch - View local variable in each thread’s context
434343
Concurrent Visualizer
https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.ConcurrencyVisualizerforVisualStudio2015
444444
Concurrent Visualizer
https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.ConcurrencyVisualizerforVisualStudio2015
45
OzCode
45
LINQ Debugging
46
Predicting the future
Predict
47
Custom Expressions
48
Show All Instances
49
Tracepoints (OzCode)
50
Conditional Breakpoints (OzCode)
51
invoice.Id 915486 intinvoice.Id 915486 int
OzCode Comapre
52
Export
53
55
System Internals
55
Where to download
Browser: http://Live.sysinternals.comShared folder: \\live.sysinternals.com\tools
56
Process Explorer
57
Process Monitor
58
59
Post-Mortem Debugging
59
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)
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
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
Debugging using the Dump (1)
63
Debugging using the Dump (2)
64
666666
Generating Symbol Tables
1. Open DotPeek2. Add the required assembly 3. Press start Symbol server4. In VS add new symbol source
676767
Debugging is Hard
Debugging is HARD.Even the Pros get befuddled
sometimesUse the right tools to decrease your Time-to-Aha factor
69 69
Presenter contact detailst: @MoaidHathote: [email protected]: http://www.moaid.codesw: www.codevalue.net
Free 3 months of OzCodehttp://tinyurl.com/jpn4y96