SlideShare una empresa de Scribd logo
1 de 24
Notes on Debugging
–Edsger Dijkstra
“ If debugging is the process of removing software bugs, then
programming must be the process of putting them in. ”
The Natural Progression of Debugging
• Logging: Logger.log(“This f&*%@ing thing again: #{bad_value}”)
• Asserting: assertTrue(something, “This should never happen”)
• Quitting: exit(55) // 55 - ABEND: Widget does not fit doodad. Call Bob for help
• Interactive Debuggers: I will kill this bug, line by line! Or: “Wait, I can just inspect
my program when it’s broken!”
• All of them have uses, often together!
• Logging: Track complex control flow, monitor background activity
• Should be able to toggle on/off as needed
• Asserting: Preventing known issues at design time, enforcing your constraints
and assumptions
• Exiting: Preventing a problem for getting worse, and terminating at the problem
Interactive Debugging
Tools
Breakpoints:
The first tool everyone finds in their
debugger. Suddenly, I can stop the
world, right where I want to!
But wait! There’s so much more…
That we can get to after we cover the
thinking part.
–John Johnson
“First, solve the problem. Then, write the code.”
Information Gathering
• Get all the information you can about what happened, and what was expected to
happen
• Validate the error
• Gather any additional information – recent commits, new features, refactoring
• Figure out how to reproduce the problem
Make it repeatable
• Write a script, a test, whatever you need.
But make it repeatable.
• Often, this may guide you to a starting
point
Start Stupid
• Most bugs are silly, small errors. Think about the impact a typo or switched
variable might cause!
• Don’t start big, start small, start stupid.
• Question all of your assumptions, especially if you wrote the code.
Binary Search
• Look, I stole this from The Pragmatic Programmer, but it’s probably as close a
silver bullet as you can get.
• Start at opposite ends of the problem, and keep cutting the problem in to smaller
halves. Narrow down the areas of impact until you find yourself looking at one
file, one method.
• git bisect works similarly
Corollary: Turn things off
• When lots of things happen in the background, turning them off can work
similarly.
Best Practices
• Isolate changes, and measure carefully. One change at a time!
• Take copious notes of what you try, and what happened.
• Read the docs as you go, and question everything.
• Never say “Can’t happen” — it probably already did!
• Trust me: It’s not the compiler.**
** Except when it is… but really, it like never happens. It’s probably your code.
Other Techniques
• Rubber Duck Debugging – Talk it out
• Make yourself wrong – Tell yourself, or your
coworker all the reasons this should never
happen
• Stay Shallow – Don’t deep dive until you’re
sure you’re close to the issue
More Techniques and Tips
• Don’t look for the Zebra – When you hear
hoofbeats, remind yourself it’s probably a
horse.
• Know when to ask for help
Collaborating on a bug
• Take copious notes where you can, and be ready to deliver context
• Use the 20 minute rule
• Always bring context and notes – Don’t make anyone start from zero
(Pause for effect) Now let’s talk tools
Interactive Command Line Debuggers
• gdb, lldb, jdp, pry
• Pause the program, step through. Super cool.
• So much more you can do!
• Watchpoints: Watch a global variable, or a region of memory
• Registers: Read the contents of registers
• Symbolic Breakpointing: Break on a method call, not a specific line number
• Examine the current frame
• Execute code
• Show a backtrace
Scripting the Debugger
• LLDB: Use python to execute common
commands
For iOS:
• Print all visible views or view controllers
• Render a view into an image
• Set a watchpoint on an instance variable
• And more: https://github.com/facebook/chisel
Visual Debugging
• Inspect the visual hierarchy of your
application
• We use Spark Inspector, Xcode 6
Even More Debugging Tools
• Network Debuggers: wireshark, Charles Proxy
• Instrumenting Debuggers: Instruments, dtrace
• Memory Debuggers: valgrind
Don’t get tunnel vision
There are so many great tools for debugging at various parts of the stack. Don’t get stuck in just one!
Enjoy that moment when you find the bug

Más contenido relacionado

La actualidad más candente

Software reliability growth model
Software reliability growth modelSoftware reliability growth model
Software reliability growth modelHimanshu
 
The Art Of Debugging
The Art Of DebuggingThe Art Of Debugging
The Art Of Debuggingsvilen.ivanov
 
Software Testing Techniques: An Overview
Software Testing Techniques: An Overview Software Testing Techniques: An Overview
Software Testing Techniques: An Overview QA InfoTech
 
Chapter #1 overview of programming and problem solving
Chapter #1 overview of programming and problem solvingChapter #1 overview of programming and problem solving
Chapter #1 overview of programming and problem solvingAbdul Shah
 
Software Testing - Part 1 (Techniques, Types, Levels, Methods, STLC, Bug Life...
Software Testing - Part 1 (Techniques, Types, Levels, Methods, STLC, Bug Life...Software Testing - Part 1 (Techniques, Types, Levels, Methods, STLC, Bug Life...
Software Testing - Part 1 (Techniques, Types, Levels, Methods, STLC, Bug Life...Ankit Prajapati
 
Software Testing Fundamentals
Software Testing FundamentalsSoftware Testing Fundamentals
Software Testing FundamentalsChankey Pathak
 
Bug life cycle
Bug life cycleBug life cycle
Bug life cycleBugRaptors
 
Software testing principles
Software testing principlesSoftware testing principles
Software testing principlesDonato Di Pierro
 
V model in software testing
V model in software testingV model in software testing
V model in software testingAbdullah Al Rumy
 
Introduction to iOS Development
Introduction to iOS DevelopmentIntroduction to iOS Development
Introduction to iOS DevelopmentAsim Rais Siddiqui
 
Security Testing: Fuzzing
Security Testing: FuzzingSecurity Testing: Fuzzing
Security Testing: FuzzingAndrei Rubaniuk
 

La actualidad más candente (20)

Software reliability growth model
Software reliability growth modelSoftware reliability growth model
Software reliability growth model
 
The Art Of Debugging
The Art Of DebuggingThe Art Of Debugging
The Art Of Debugging
 
Software Testing Techniques: An Overview
Software Testing Techniques: An Overview Software Testing Techniques: An Overview
Software Testing Techniques: An Overview
 
Static analysis
Static analysisStatic analysis
Static analysis
 
Coding with kids
Coding with kidsCoding with kids
Coding with kids
 
Software testing ppt
Software testing pptSoftware testing ppt
Software testing ppt
 
Chapter #1 overview of programming and problem solving
Chapter #1 overview of programming and problem solvingChapter #1 overview of programming and problem solving
Chapter #1 overview of programming and problem solving
 
An introduction to Xamarin
An introduction to XamarinAn introduction to Xamarin
An introduction to Xamarin
 
Software Testing - Part 1 (Techniques, Types, Levels, Methods, STLC, Bug Life...
Software Testing - Part 1 (Techniques, Types, Levels, Methods, STLC, Bug Life...Software Testing - Part 1 (Techniques, Types, Levels, Methods, STLC, Bug Life...
Software Testing - Part 1 (Techniques, Types, Levels, Methods, STLC, Bug Life...
 
Keyloggers.ppt
Keyloggers.pptKeyloggers.ppt
Keyloggers.ppt
 
Software Testing Fundamentals
Software Testing FundamentalsSoftware Testing Fundamentals
Software Testing Fundamentals
 
White Box Testing
White Box Testing White Box Testing
White Box Testing
 
Manual testing ppt
Manual testing pptManual testing ppt
Manual testing ppt
 
Types of testing
Types of testingTypes of testing
Types of testing
 
Bug life cycle
Bug life cycleBug life cycle
Bug life cycle
 
Software testing principles
Software testing principlesSoftware testing principles
Software testing principles
 
Exploratory test
Exploratory testExploratory test
Exploratory test
 
V model in software testing
V model in software testingV model in software testing
V model in software testing
 
Introduction to iOS Development
Introduction to iOS DevelopmentIntroduction to iOS Development
Introduction to iOS Development
 
Security Testing: Fuzzing
Security Testing: FuzzingSecurity Testing: Fuzzing
Security Testing: Fuzzing
 

Similar a Notes on Debugging

We Make Debugging Sucks Less
We Make Debugging Sucks LessWe Make Debugging Sucks Less
We Make Debugging Sucks LessAlon Fliess
 
Back to basics simple, elegant, beautiful code
Back to basics   simple, elegant, beautiful codeBack to basics   simple, elegant, beautiful code
Back to basics simple, elegant, beautiful codeAndrew Harcourt
 
Community and Github: 7/27/2011
Community and Github: 7/27/2011Community and Github: 7/27/2011
Community and Github: 7/27/2011Andy Lester
 
Software Development Whats & Whys
Software Development Whats & Whys Software Development Whats & Whys
Software Development Whats & Whys Harun Yardımcı
 
Git for Writers: Dumping the Bucket Metaphor
Git for Writers: Dumping the Bucket MetaphorGit for Writers: Dumping the Bucket Metaphor
Git for Writers: Dumping the Bucket MetaphorMysti Berry
 
Become a Better Developer with Debugging Techniques for Drupal (and more!)
Become a Better Developer with Debugging Techniques for Drupal (and more!)Become a Better Developer with Debugging Techniques for Drupal (and more!)
Become a Better Developer with Debugging Techniques for Drupal (and more!)Acquia
 
The Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with androidThe Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with androidStanojko Markovik
 
Unbreaking Your Django Application
Unbreaking Your Django ApplicationUnbreaking Your Django Application
Unbreaking Your Django ApplicationOSCON Byrum
 
Game Programming 13 - Debugging & Performance Optimization
Game Programming 13 - Debugging & Performance OptimizationGame Programming 13 - Debugging & Performance Optimization
Game Programming 13 - Debugging & Performance OptimizationNick Pruehs
 
How I Learned to Stop Worrying and Love Legacy Code.....
How I Learned to Stop Worrying and Love Legacy Code.....How I Learned to Stop Worrying and Love Legacy Code.....
How I Learned to Stop Worrying and Love Legacy Code.....Mike Harris
 
How to write good quality code
How to write good quality codeHow to write good quality code
How to write good quality codeHayden Bleasel
 
CNIT 126 Ch 9: OllyDbg
CNIT 126 Ch 9: OllyDbgCNIT 126 Ch 9: OllyDbg
CNIT 126 Ch 9: OllyDbgSam Bowne
 

Similar a Notes on Debugging (20)

Bug Hunting Safari
Bug Hunting SafariBug Hunting Safari
Bug Hunting Safari
 
Git Makes Me Angry Inside
Git Makes Me Angry InsideGit Makes Me Angry Inside
Git Makes Me Angry Inside
 
PHP - Introduction to PHP Bugs - Debugging
PHP -  Introduction to  PHP Bugs - DebuggingPHP -  Introduction to  PHP Bugs - Debugging
PHP - Introduction to PHP Bugs - Debugging
 
Code Forensics
Code ForensicsCode Forensics
Code Forensics
 
We Make Debugging Sucks Less
We Make Debugging Sucks LessWe Make Debugging Sucks Less
We Make Debugging Sucks Less
 
Back to basics simple, elegant, beautiful code
Back to basics   simple, elegant, beautiful codeBack to basics   simple, elegant, beautiful code
Back to basics simple, elegant, beautiful code
 
Tweakers Anonymous
Tweakers AnonymousTweakers Anonymous
Tweakers Anonymous
 
Community and Github: 7/27/2011
Community and Github: 7/27/2011Community and Github: 7/27/2011
Community and Github: 7/27/2011
 
Software Development Whats & Whys
Software Development Whats & Whys Software Development Whats & Whys
Software Development Whats & Whys
 
Git for Writers: Dumping the Bucket Metaphor
Git for Writers: Dumping the Bucket MetaphorGit for Writers: Dumping the Bucket Metaphor
Git for Writers: Dumping the Bucket Metaphor
 
Become a Better Developer with Debugging Techniques for Drupal (and more!)
Become a Better Developer with Debugging Techniques for Drupal (and more!)Become a Better Developer with Debugging Techniques for Drupal (and more!)
Become a Better Developer with Debugging Techniques for Drupal (and more!)
 
The Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with androidThe Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with android
 
Unbreaking Your Django Application
Unbreaking Your Django ApplicationUnbreaking Your Django Application
Unbreaking Your Django Application
 
Game Programming 13 - Debugging & Performance Optimization
Game Programming 13 - Debugging & Performance OptimizationGame Programming 13 - Debugging & Performance Optimization
Game Programming 13 - Debugging & Performance Optimization
 
Preocupações Desenvolvedor Ágil
Preocupações Desenvolvedor ÁgilPreocupações Desenvolvedor Ágil
Preocupações Desenvolvedor Ágil
 
How I Learned to Stop Worrying and Love Legacy Code.....
How I Learned to Stop Worrying and Love Legacy Code.....How I Learned to Stop Worrying and Love Legacy Code.....
How I Learned to Stop Worrying and Love Legacy Code.....
 
How to write good quality code
How to write good quality codeHow to write good quality code
How to write good quality code
 
Fuzzing - Part 2
Fuzzing - Part 2Fuzzing - Part 2
Fuzzing - Part 2
 
Spaghetti gate
Spaghetti gateSpaghetti gate
Spaghetti gate
 
CNIT 126 Ch 9: OllyDbg
CNIT 126 Ch 9: OllyDbgCNIT 126 Ch 9: OllyDbg
CNIT 126 Ch 9: OllyDbg
 

Más de Cotap Engineering

Natural language processing in iOS / OSX
Natural language processing in iOS / OSXNatural language processing in iOS / OSX
Natural language processing in iOS / OSXCotap Engineering
 
Efficient data transfer in Android
Efficient data transfer in AndroidEfficient data transfer in Android
Efficient data transfer in AndroidCotap Engineering
 
Architecting for the Cloud: Hoping for the best, prepared for the worst
Architecting for the Cloud: Hoping for the best, prepared for the worstArchitecting for the Cloud: Hoping for the best, prepared for the worst
Architecting for the Cloud: Hoping for the best, prepared for the worstCotap Engineering
 

Más de Cotap Engineering (7)

How to video.
How to video.How to video.
How to video.
 
MQTT
MQTTMQTT
MQTT
 
Security best practices.
Security best practices.Security best practices.
Security best practices.
 
Natural language processing in iOS / OSX
Natural language processing in iOS / OSXNatural language processing in iOS / OSX
Natural language processing in iOS / OSX
 
Startup survival lessons
Startup survival lessonsStartup survival lessons
Startup survival lessons
 
Efficient data transfer in Android
Efficient data transfer in AndroidEfficient data transfer in Android
Efficient data transfer in Android
 
Architecting for the Cloud: Hoping for the best, prepared for the worst
Architecting for the Cloud: Hoping for the best, prepared for the worstArchitecting for the Cloud: Hoping for the best, prepared for the worst
Architecting for the Cloud: Hoping for the best, prepared for the worst
 

Último

OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 

Último (20)

OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 

Notes on Debugging

  • 2. –Edsger Dijkstra “ If debugging is the process of removing software bugs, then programming must be the process of putting them in. ”
  • 3. The Natural Progression of Debugging
  • 4. • Logging: Logger.log(“This f&*%@ing thing again: #{bad_value}”) • Asserting: assertTrue(something, “This should never happen”) • Quitting: exit(55) // 55 - ABEND: Widget does not fit doodad. Call Bob for help • Interactive Debuggers: I will kill this bug, line by line! Or: “Wait, I can just inspect my program when it’s broken!” • All of them have uses, often together!
  • 5. • Logging: Track complex control flow, monitor background activity • Should be able to toggle on/off as needed • Asserting: Preventing known issues at design time, enforcing your constraints and assumptions • Exiting: Preventing a problem for getting worse, and terminating at the problem
  • 6. Interactive Debugging Tools Breakpoints: The first tool everyone finds in their debugger. Suddenly, I can stop the world, right where I want to! But wait! There’s so much more… That we can get to after we cover the thinking part.
  • 7. –John Johnson “First, solve the problem. Then, write the code.”
  • 8. Information Gathering • Get all the information you can about what happened, and what was expected to happen • Validate the error • Gather any additional information – recent commits, new features, refactoring • Figure out how to reproduce the problem
  • 9. Make it repeatable • Write a script, a test, whatever you need. But make it repeatable. • Often, this may guide you to a starting point
  • 10. Start Stupid • Most bugs are silly, small errors. Think about the impact a typo or switched variable might cause! • Don’t start big, start small, start stupid. • Question all of your assumptions, especially if you wrote the code.
  • 11. Binary Search • Look, I stole this from The Pragmatic Programmer, but it’s probably as close a silver bullet as you can get. • Start at opposite ends of the problem, and keep cutting the problem in to smaller halves. Narrow down the areas of impact until you find yourself looking at one file, one method. • git bisect works similarly
  • 12. Corollary: Turn things off • When lots of things happen in the background, turning them off can work similarly.
  • 13. Best Practices • Isolate changes, and measure carefully. One change at a time! • Take copious notes of what you try, and what happened. • Read the docs as you go, and question everything. • Never say “Can’t happen” — it probably already did! • Trust me: It’s not the compiler.** ** Except when it is… but really, it like never happens. It’s probably your code.
  • 14. Other Techniques • Rubber Duck Debugging – Talk it out • Make yourself wrong – Tell yourself, or your coworker all the reasons this should never happen • Stay Shallow – Don’t deep dive until you’re sure you’re close to the issue
  • 15. More Techniques and Tips • Don’t look for the Zebra – When you hear hoofbeats, remind yourself it’s probably a horse. • Know when to ask for help
  • 16. Collaborating on a bug • Take copious notes where you can, and be ready to deliver context • Use the 20 minute rule • Always bring context and notes – Don’t make anyone start from zero
  • 17. (Pause for effect) Now let’s talk tools
  • 18. Interactive Command Line Debuggers • gdb, lldb, jdp, pry • Pause the program, step through. Super cool. • So much more you can do!
  • 19. • Watchpoints: Watch a global variable, or a region of memory • Registers: Read the contents of registers • Symbolic Breakpointing: Break on a method call, not a specific line number • Examine the current frame • Execute code • Show a backtrace
  • 20. Scripting the Debugger • LLDB: Use python to execute common commands For iOS: • Print all visible views or view controllers • Render a view into an image • Set a watchpoint on an instance variable • And more: https://github.com/facebook/chisel
  • 21. Visual Debugging • Inspect the visual hierarchy of your application • We use Spark Inspector, Xcode 6
  • 22. Even More Debugging Tools • Network Debuggers: wireshark, Charles Proxy • Instrumenting Debuggers: Instruments, dtrace • Memory Debuggers: valgrind
  • 23. Don’t get tunnel vision There are so many great tools for debugging at various parts of the stack. Don’t get stuck in just one!
  • 24. Enjoy that moment when you find the bug

Notas del editor

  1. Just one viewpoint Lots has been written Idea is to create discussion, cause us to think about how we solve problems
  2. Also not a big fan of “goto”
  3. How do we learn to debug? Most people follow a pretty common path
  4. You print out at various points You realize you can assert, or quit to make it obvious when things go wrong Eventually you realize your language probably ships with an interactive debugger, and that it might be good to learn to use it But the things you learned previously don’t become obsolete! Each item has uses in preventing and diagnosing errors
  5. If you need to log to understand something when you’re writing, leave the logs in, but make them toggle-able. Future you says: “THANK YOU!” Great example: Apple Collection View Demo - Rendering is crazy to follow. Assert: I have an expectation, and i’m going to prevent you from doing something wrong when you write the code. Exiting is a last resort method of ensuring that, if you have to stop execution, at least you stop when the problem occurs — You get a stack trace that ends with the program, and presumably the issue.
  6. This is the major leagues of debugging. These tools don’t mess around, and often feel like the giant swiss army knife where you really only use the nail clippers, but I guess it’s nice to know it’s there if I need it.
  7. The most important step in debugging is understanding the problem You may fix a bug without understanding the problem, but this is unlikely to work well long term The best fixes come from a strong understanding of the situation
  8. Users experience your software “not working” — often the most important details are in the user’s story, so get as much of it as you can. Ask lots of questions, and gather as much context as possible. Validate that the error is actually an ‘error’: Maybe it’s just poor or undefined behavior. Still worth fixing, but changes the context. Look at the tools you have that provide context – crash reports, git history, recent new features and refactors, system updates
  9. If you can’t verify it happens, and make it happen on command it can be very difficult to feel confident in a solution Creating a repeatable test case may even lead you to a foothold in the code for finding the problem
  10. Much like proofreading your own paper, debugging your own code is often very challenging. You know what you meant when you wrote it! Small changes can have a huge impact, and can tell you a great deal about what’s really going on. You have assumptions, but you need to be a scientist: Make a hypothesis, verify it, and throw it away if it doesn’t prove to be true
  11. This is your debugging bread and butter. When you don’t know where to start, cut the whole program in half over and over until you’ve narrowed down there the problem is. Use tools like Git Bisect to identify when a change introduced the bug
  12. Background updating, syncing, data migrations, etc… Can be tricky, but sometimes useful. Does the bug still come up when things are turned off?
  13. Be a scientist: Only one variable at a time Take notes: Breadcrumbs to find your way back out, and keep from taking the same path Question Everything/Read the docs: In very established ecosystems, the documentation will often have notes that may point you right at the answer! Really though, it’s not the compiler. Unless you are debugging a compiler, in which case good luck.
  14. Talking out a problem makes you explain it with more context, and can often drag out details and assumptions you weren’t fully considering Telling someone why it can’t possibly happen is a great way to motivate yourself to figure it out It can’t happen because this can’t happen - triggers you to realize “That actually could be what happened!” Avoid the rabbit holes!
  15. It’s always tempting (and fun!) to conjure up a complicated picture of what’s gone wrong, but bugs are rarely exotic or interesting. Often just typos. Don’t bury yourself, and don’t go it alone! Know when to ask for help, and don’t forget to do it.
  16. 20 Minute Rule: Try for 20 minutes, and take notes. Then ask for help.
  17. The swiss army knives, and often the least well understood. More than just a way to stop and start your program! Learn about the power these tools provide, and how to leverage it
  18. Don’t get trapped just in your ecosystem. There are lots of ways to attack a problem!
  19. On the opposite side: Use the right tool for the job! Valgrind won’t help you find out why your view is misplaced. This all leads to one final lesson for debugging
  20. What tools do you use? What techniques? Where am I wrong?