SlideShare a Scribd company logo
EFFECTIVE DEBUGGING
SPEND TIME FIXING PROBLEMS, NOT FINDING THEM
/AndyDawson @AD7six
THE WEB IS JUST PLUMBING WITH BYTES
Image:Wikipedia
OF COURSE IT'S NOT REALLY THAT SIMPLE
Image:Flickr.com
โ†– The hardestproblems to fix existhere.
In the developer's head.
FIND IT WITH A HAMMER
Image:Codinghorror.com
//pickone
thrownewException('Madeithere!');
print_r(debug_backtrace());
die(__FILE__.':'.__LINE__);
MOST APPS AREN'T THAT SIMPLE
Ahammer willwork, butitmighttake awhile.
Image:energysystemsgroup.com
HELLO WORLD EXAMPLE
"Where's mywebpage"
CHECK THE HTTP RESPONSE CODE
Is itactually an error?
READ THE WEBSERVER ERROR LOG
Location depends on configuration
Typically/var/log/*/
PHPParseerror: [...]in/var/www/example.dev/public/index.phponline4"
IDENTIFY THE PROBLEM
$cat/var/www/example.dev/public/index.php
<?php
echo"helloworld';
Parseerrorsareoftenthelinebefore(orearlier)inafile
NOT AN ERROR EXAMPLE
Notan error response code so no (direct) logmessages:"
GREP FOR IT
$grep-rl"NotFound"*
...
src/Really/Not/Obvious/File.php
$grep-r"NotFound"*
...
src/Really/Not/Obvious/File.php 404=>'NotFound',
$catsrc/Really/Not/Obvious/File.php
...
functionerror(){
die($this->_statusCodes['404']);
}
CAKEPHP HELLO WORLD EXAMPLE
"Whythe Four Oh Four?"
CHECK THE ERROR LOG
app/tmp/error.log
IDENTIFY THE PROBLEM
$catapp/View/Pages/home.ctp
<?php
...
if(!Configure::read('debug')):
thrownewNotFoundException();
endif;
DEBUG BASICS
Configand functions everydeveloper should know about
PHP CONFIG
Inifile settings are the defaults if notchanged (duh)
display_errors(On/Off)
log_errors(On)
display_startup_errors(Off)
error_reporting(On/Off)
Runtime settings override the inifile -no effectif the file theyare
in has aparse error (duh)
ini_set('display_errors', 0/1)
PHP FUNCTIONS
print_r();
debug_backtrace();
get_included_files();
phpinfo();
PHP VARIABLES/CONSTANTS
__FILE__
__LINE__
$_SERVER
et.al.
A WAY TO REPRODUCE
Have awayto consistentlyreproduce the error
$curl-Ihttp://example.dev/
HTTP/1.1500InternalServerError
Server:nginx
Date:Sat,23Aug201410:33:46GMT
Content-Type:text/html
gitbisect-find regression errors quickly
XDEBUG
peclinstallxdebug
WEBGRIND
Turn on xdebugprofiling, and look atwhatarequestis doing
CLI DEBUGGING
Pause execution with read:
print_r($somethingInteresting);
`readfoo`;
Usefulwhen debuggingaloop.
NOT CAKEPHP CODE?
Aghetto debugfunction:
functiondebug($var,$showHtml=null){
if(!defined('DEBUG')||!DEBUG){return;}
if($showHtml===null){
$showHtml=php_sapi_name()==='cli'?false:true;
}
$var=var_export($var,true);
if(!$showHtml){
echo$var;
return;
}
echo'<pre>'.htmlspecialchars($var).'</pre>';
}
createatracefunction(Debugger::trace)tooifneeded
LOGIC AIDES
Justvoicingaproblem can find the solution/error
Image:Wikipedia
ERROR MESSAGES DON'T LIE
PHP Parse error: syntax error, unexpected '$bar'(T_VARIABLE)
in parse.php on line 3
$catfoo.php
<?php
...
if($foo||bar){
There's an accidentalnone-breakingspace on thatline
NETWORKING PROBLEMS
If the problem is noton the webserver -where is it?
NAMESERVER PROBLEMS
No response from nameservers is the same as adomain not
existsing
$digcakefest.org
;<<>>DiG9.8.3-P1<<>>cakefest.org
;;globaloptions:+cmd
;;Gotanswer:
;;->>HEADER<<-opcode:QUERY,status:SERVFAIL,id:15266
;;flags:qrrdra;QUERY:1,ANSWER:0,AUTHORITY:0,ADDITIONAL:0
;;QUESTIONSECTION:
;cakefest.org. IN A
;;Querytime:4142msec
;;SERVER:8.8.8.8#53(8.8.8.8)
;;WHEN:TueAug1916:26:592014
;;MSGSIZE rcvd:30
...
;;ANSWERSECTION:
cakefest.org. 1568 IN A 50.56.232.22
...
DNS PROBLEMS
"No route to host"means the ip requested isn'taccessible
$traceroutecakefest.org
traceroutetocakefest.org(50.56.232.22),64hopsmax,52bytepackets
1 172.26.81.1(172.26.81.1) 1.032ms 0.912ms 0.912ms
2 192.168.0.1(192.168.0.1) 2.777ms 1.267ms 2.338ms
...
12 rackspace-ic-302090-dls-bb1.c.telia.net(62.115.33.78) 152.340ms 15
9.367ms 146.339ms
13 ***
14 ***
15 ***
If there are stars -there be problems
BACKEND SERVER IS
DOWN
502 Bad Gateway
E.g. php-fpm or hhvm is notrunning
Willbe in the webserver error log
There willnotbe anyapplication logentries
PITFALLS TO AVOID
Whatnotto do when debuggingcode
FIX PROBLEMS, NOT SYMPTOMS
Don'tignore errors/warnings/notices
Fix them in order, some errors willbe the concequence of earlier
problems.
COMMON MISTAKES
Notlookingfor error logs
Readingor focussingon the wrongerror message
Notreadingthe error message
Notreadingthe error message aloud
Misinterprettingthe error message
Stoppingdebuggingtoo early.
If "the problem"is aclass/function with source code -debug the
source code of thatfunction
New user: Ifound the problem, it's
app/webroot/index.php!
IMPLICIT ASSUMPTIONS
Be waryof implictassumptions
You're debuggingthe same file the browser is loading
You're debuggingthe same application the browser is loading
You're debuggingthe same server the browser is loading
You're debuggingthe same requestthe browser is loading
Conclusions so far are accurate
WTF?Backup, and re-verifyeverything.
COMMON PROBLEMS
And how to debug/identifythem
NO MODREWRITE
Don'tlook atphp files -the error is atthe webserver.
Enable mod rewrite
Restartthe webserver
CAKEPHP AUTOMODELS
$model=ClassRegistry::init('MyModel');
$model->methodName();
SQLError:1064:YouhaveanerrorinyourSQLsyntax;[...]
check[...]fortherightsyntaxtousenear'methodName'
MyModeldoes nothave the function methodName
MyModelhas no behaviour bound implementing
methodName
$modelis an instance of AppModel
CAKEPHP AUTOMODELS - IDENTIFICATION
$model=ClassRegistry::init('MyModel');
debug(get_class($model));
##########DEBUG##########
'MyModel'
###########################
$model=ClassRegistry::init('MyModel');
debug(get_included_files());
##########DEBUG##########
array(
...
...app/Model/MyModel.php
...
)
###########################
CAN'T FIX IT
(โ•ฏยฐโ–กยฐ๏ผ‰โ•ฏ๏ธต โ”ปโ”โ”ป
Can'tfind the problem/solution?-gethelp. Butfirst:
Collectthe information you've got
Write astandalone, reproducible example if possible
Reduce the question to it's simplest, form
Don'tover simplifyor make acontrived example
Ask colleagues/the internet
Brace for impact
Stack overflow, the google group and irc as greatplaces to get
help
SUMMARY
Identifythe rightpartof arequestto debug
Fix errors in order
Check your assumptions/conclusions ateveryWTF
Formulate aquestion, and Ask for help
Profit!

More Related Content

ODP
The Art Of Debugging
PPTX
Principles in software debugging
PPTX
Software Debugging for High-altitude Balloons
PPTX
Notes on Debugging
PPSX
Debugging by induction
PPT
Are Agile Projects Doomed to Half-Baked Design?
PPT
.Net Debugging Techniques
PPTX
Testing & should i do it
The Art Of Debugging
Principles in software debugging
Software Debugging for High-altitude Balloons
Notes on Debugging
Debugging by induction
Are Agile Projects Doomed to Half-Baked Design?
.Net Debugging Techniques
Testing & should i do it

What's hot (20)

PPTX
Entaggle: an Agile Software Development Case Study
PDF
FAQ - why does my code throw a null pointer exception - common reason #1 Rede...
PDF
React performance
PDF
Exploratory Testing in an Agile Context
PPT
Maintaining a Malware Collection
PDF
Php tests tips
PDF
Unit testing (workshop)
PPT
Testing Heuristic Detections
PPTX
Concurrency Errors in Java
PPTX
How to report bugs
KEY
Test Driven Development
PPTX
TDD Best Practices
PPTX
Software Quality via Unit Testing
PPT
About Malware Testing
PPT
Unit Testing
PPTX
Unit test
PPTX
Mock driven development using .NET
PDF
Meetup 06/2015 - @testsetup
PDF
javabasics_ programming development chapter01
PPT
The science of debugging
Entaggle: an Agile Software Development Case Study
FAQ - why does my code throw a null pointer exception - common reason #1 Rede...
React performance
Exploratory Testing in an Agile Context
Maintaining a Malware Collection
Php tests tips
Unit testing (workshop)
Testing Heuristic Detections
Concurrency Errors in Java
How to report bugs
Test Driven Development
TDD Best Practices
Software Quality via Unit Testing
About Malware Testing
Unit Testing
Unit test
Mock driven development using .NET
Meetup 06/2015 - @testsetup
javabasics_ programming development chapter01
The science of debugging
Ad

Viewers also liked (18)

PPT
Debugging
ZIP
Learning from 6,000 projects mining specifications in the large
PDF
Do Bugs Reside in Complex Code?
PPS
Vb net xp_11
PPS
Vb.net session 12
PPT
Debugging
PPTX
Debugging
PPTX
Parsing
PPTX
Parsing
ย 
PPTX
Error handling and debugging in vb
ย 
PPTX
Image Encryption in java ppt.
PDF
Advanced Production Debugging
ย 
PPTX
Image encryption and decryption
PPTX
Exception handling
PDF
Ubuntu 16.04 LTS Security Features
PPTX
All about Programmatic buying(RTB), DSP,SSP, DMP & DCT - A complete digital ...
PPTX
Basic controls of Visual Basic 6.0
ย 
Debugging
Learning from 6,000 projects mining specifications in the large
Do Bugs Reside in Complex Code?
Vb net xp_11
Vb.net session 12
Debugging
Debugging
Parsing
Parsing
ย 
Error handling and debugging in vb
ย 
Image Encryption in java ppt.
Advanced Production Debugging
ย 
Image encryption and decryption
Exception handling
Ubuntu 16.04 LTS Security Features
All about Programmatic buying(RTB), DSP,SSP, DMP & DCT - A complete digital ...
Basic controls of Visual Basic 6.0
ย 
Ad

Similar to Effective debugging (20)

PDF
Php Debugging from the Trenches
PDF
Automated code audits
PPTX
The Last Man Debugger | #wcnp2024
PDF
Throwing Laravel into your Legacy Appโ„ข
PDF
Php 7 errors messages
PDF
Static analysis saved my code tonight
PDF
PHP Static Code Review
PDF
errors in php 7
PDF
PHP Without PHPโ€”Confoo
PDF
Become a Better Developer with Debugging Techniques for Drupal (and more!)
ย 
PDF
So You Just Inherited a $Legacy Application...
PDF
Preparing for the next php version
PPTX
Resolving problems & high availability
PDF
Debugging LAMP Apps on Linux/UNIX Using Open Source Tools - Jess Portnot - OS...
PPTX
Debugging Effectively - ConFoo Montreal 2019
PPT
How to improve problem solving skills
PPTX
It Works On Dev
PPTX
Debugging Effectively - SymfonyLive San Francisco 2015
PDF
Php exceptions
PDF
So You Just Inherited a $Legacy Applicationโ€ฆ NomadPHP July 2016
Php Debugging from the Trenches
Automated code audits
The Last Man Debugger | #wcnp2024
Throwing Laravel into your Legacy Appโ„ข
Php 7 errors messages
Static analysis saved my code tonight
PHP Static Code Review
errors in php 7
PHP Without PHPโ€”Confoo
Become a Better Developer with Debugging Techniques for Drupal (and more!)
ย 
So You Just Inherited a $Legacy Application...
Preparing for the next php version
Resolving problems & high availability
Debugging LAMP Apps on Linux/UNIX Using Open Source Tools - Jess Portnot - OS...
Debugging Effectively - ConFoo Montreal 2019
How to improve problem solving skills
It Works On Dev
Debugging Effectively - SymfonyLive San Francisco 2015
Php exceptions
So You Just Inherited a $Legacy Applicationโ€ฆ NomadPHP July 2016

Recently uploaded (20)

PDF
๐Ÿ’ฐ ๐”๐Š๐“๐ˆ ๐Š๐„๐Œ๐„๐๐€๐๐†๐€๐ ๐Š๐ˆ๐๐„๐‘๐Ÿ’๐ƒ ๐‡๐€๐‘๐ˆ ๐ˆ๐๐ˆ ๐Ÿ๐ŸŽ๐Ÿ๐Ÿ“ ๐Ÿ’ฐ
ย 
PPT
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
DOCX
Unit-3 cyber security network security of internet system
PPTX
Digital Literacy And Online Safety on internet
PPTX
international classification of diseases ICD-10 review PPT.pptx
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PDF
Vigrab.top โ€“ Online Tool for Downloading and Converting Social Media Videos a...
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PPTX
E -tech empowerment technologies PowerPoint
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PDF
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PDF
Sims 4 Historia para lo sims 4 para jugar
PPTX
Introuction about WHO-FIC in ICD-10.pptx
PPTX
PptxGenJS_Demo_Chart_20250317130215833.pptx
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PDF
Paper PDF World Game (s) Great Redesign.pdf
PPTX
introduction about ICD -10 & ICD-11 ppt.pptx
๐Ÿ’ฐ ๐”๐Š๐“๐ˆ ๐Š๐„๐Œ๐„๐๐€๐๐†๐€๐ ๐Š๐ˆ๐๐„๐‘๐Ÿ’๐ƒ ๐‡๐€๐‘๐ˆ ๐ˆ๐๐ˆ ๐Ÿ๐ŸŽ๐Ÿ๐Ÿ“ ๐Ÿ’ฐ
ย 
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
Unit-3 cyber security network security of internet system
Digital Literacy And Online Safety on internet
international classification of diseases ICD-10 review PPT.pptx
WebRTC in SignalWire - troubleshooting media negotiation
Vigrab.top โ€“ Online Tool for Downloading and Converting Social Media Videos a...
Slides PDF The World Game (s) Eco Economic Epochs.pdf
E -tech empowerment technologies PowerPoint
522797556-Unit-2-Temperature-measurement-1-1.pptx
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
Unit-1 introduction to cyber security discuss about how to secure a system
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
Module 1 - Cyber Law and Ethics 101.pptx
Sims 4 Historia para lo sims 4 para jugar
Introuction about WHO-FIC in ICD-10.pptx
PptxGenJS_Demo_Chart_20250317130215833.pptx
Cloud-Scale Log Monitoring _ Datadog.pdf
Paper PDF World Game (s) Great Redesign.pdf
introduction about ICD -10 & ICD-11 ppt.pptx

Effective debugging