SlideShare a Scribd company logo
Debugging with
Drupal
The art of
Debugging
Anoop John, CTO
Vimal Joseph, Technical Architect
The Art of Debugging
Bugs everywhere...
SA-CORE-2014-005
The Art of Debugging
Bug-free Software?
The Art of Debugging
Debugging
It's hard enough to find an error in your code when
you're looking for it; it's even harder when you've
assumed your code is error-free.
Steve McConnel
The Art of Debugging
Story Time
Tell us a story on your debugging experience
The Art of Debugging
Set up Debugging Environment
PHP configuration (php.ini)
display_errors = On
log_errors = On
error_reporting = E_ALL | E_STRICT
Drupal modules
Devel
A good editor
Geany
Emacs is better – but learning curve is bit steep.
Learn to setup a development environment for a
given project quickly. Drush will help.
The Art of Debugging
Debugging Tools - PHP
Basic PHP
print/echo
print_r()
exit()/die()
debug_backtrace()/debug_print_backtrace()
The Art of Debugging
Debugging Tools - Drupal
drupal_set_message()
watchdog()
Views
views_trace()
Devel
dpm()
dargs()
dd()
ddebug_backtrace()
db_queryd()
The Art of Debugging
Debugging Tools - HTML, JS,
CSS
Firebug
Web Developer Toolbar
Javascript debugger
The Art of Debugging
Debugging Tools - CLI
Drush – a life saver.
archive-dump, archive-restore, vget, vset, php-
eval, sql-cli, sql-query, user-login etc..
Xdebug
cat, grep, awk, cut
The Art of Debugging
General Approach for
Debugging
Understand the symptom
Understand the context
Define problem statement
Replicate bug
Read through code
Isolate location in code causing bug
Understand code
Understand data / context
Understand cause
Identify solution
Fix bug
The Art of Debugging
Tips for Debugging Code
Trial and error may work – but do not rely on that
Binary search is the best method to isolate a bug
Learn to navigate through code
Learn to read logs
Webserver Access/Error logs
Database Error logs
Drupal error logs
Be familiar with the shell commands
cat, zcat, grep, less etc..
The Art of Debugging
Errors, Notices, Warnings
Warning: htmlspecialchars() expects
parameter 1 to be string, array given in
check_plain() (line 1566 of
/var/www/d7/includes/bootstrap.inc).
Invalid argument supplied for foreach()
in /var/www/d7/includes/common.inc on
line 1919.
Illegal offset type in isset or empty in
/home/pgil1/public_html/modules/taxon
omy/taxonomy.module on line 1090.
The Art of Debugging
Backtrace – your guide
views_trace
debug_backtrace
debug_print_backtrace
ddebug_backtrace
The Art of Debugging
Tips for Debugging Code
// function drupal_set_message() bootstrap.inc
if ($type == 'error') {
// here are some alternatives – views_trace()
// is part of views module
// $message .= '<pre>' . print_r(debug_backtrace(),
TRUE) . '</pre>';
// $message .= '<pre>' . views_trace() . '</pre>';
}
// Or in function watchdog() bootstrap.inc
if ($type == 'php') {
$message .= '<pre>'. print_r(debug_backtrace(),
1) .'</pre>';
//$message .= '<pre>'. views_trace() .'</pre>';
}
// Or in the function which error occurred
ddebug_backtrace(); or dpm() or print_r() //make sure
to add the necessary conditions so that the debug
The Art of Debugging
Tips for Debugging Code
// Debuging cron
// module_invoke() module.inc
if ($hook == 'cron') {
watchdog('debugging', "CRON: Calling
$module");
}
// Errors like “Cannot use object of type
stdClass as array”
// Insert right before the moment of disaster
if (!is_array($x)) {
dpm(ddebug_backtrace(TRUE));
}
The Art of Debugging
Tips for Debugging HTML, CSS,
JS
Inspect using Firebug
Create test HTML
Set custom properties
Walk through JS code execution
Inspect variables
Zyxware Technologies and Drupal
Zyxware is a leading contributor to Drupal from India and is one of only
six Featured Service Providers from India listed on drupal.org
● Over 40,000 websites use our modules and themes
● More than 30 contributed modules and themes
● Maintainer of Search404, a top 100 Drupal module
● Over 1000 commits at drupal.org
● Contributes all patches back to Drupal
● Our profile on drupal.org - http://drupal.org/user/222163
● Knowledge partnerships with Acquia, New Relic and Volacci
● Freedom Walk, a 44 day walk by a team of
Free Software Evangelists across the length of
Kerala to promote Free Software
● Building RithuOS, an Operating System for Engineering
students with Free Software Engineering applications
● GNU/Linux Install Fests in Schools, Colleges and at Technopark.
● Local language (Malayalam) computing camps in colleges
● Building and Maintenance of Freedom Toaster, a Free Software
kiosk
● Conducting Free Software workshops and
lectures in colleges in Kerala
Free Software and Zyxware Technologies
• Check us out at http://www.zyxware.com
• Mail us at drupal@zyxware.com
• Like us at http://www.facebook.com/zyxware
• Follow us at http://www.twitter.com/zyxware
• Connect with us at
http://www.linkedin.com/companies/zyxware-technologies
• Talk to us at +91-9495969446 between 9AM - 9PM IST
• Skype me at aj_zyxware
Contact Us
The Art of Debugging
Thank you …
The Art of Debugging
Credits
http://randyfay.com/content/debugging-techniques
http://www.lullabot.com/articles/quick_and_dirty_de
bugging

More Related Content

PDF
Drupal debugging tips
PDF
Introduction to Drupal, Training conducted at MES-AIMAT, Aluva on 2013-09-26
PPT
How to? Drupal developer toolkit. Dennis Povshedny.
ODP
Drupal development
PPT
Build your own PHP extension
PDF
DrupalCampLA 2011: Drupal backend-performance
PPTX
Drupal Backend Performance and Scalability
PPT
Heavy Web Optimization: Backend
Drupal debugging tips
Introduction to Drupal, Training conducted at MES-AIMAT, Aluva on 2013-09-26
How to? Drupal developer toolkit. Dennis Povshedny.
Drupal development
Build your own PHP extension
DrupalCampLA 2011: Drupal backend-performance
Drupal Backend Performance and Scalability
Heavy Web Optimization: Backend

What's hot (20)

ODP
Drupal 7x Installation - Introduction to Drupal Concepts
PPSX
Cms drupal installation & configuration anil mishra
PDF
DrupalCampLA 2011 - Drupal frontend-optimizing
PPTX
Drupal development environment
PPTX
Drupal performance optimization Best Practices
ODP
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
PPT
Drupal Installation &amp; Configuration
PDF
04 web optimization
PPT
Drupal 6 Performance Tips
PPT
Speeding Up The Snail
PPTX
How to reduce database load using Memcache
PDF
Django Documentation
PPTX
Web profiler in drupal 8
PPTX
PHP Summer Training Presentation
PPT
Implementing High Performance Drupal Sites
PPTX
WordPress Structure and Best Practices
PPTX
Learn How To Develop With CakePHP
ODP
Practical catalyst
PPTX
Performance Optimization in Drupal 8
PDF
Drupal feature proposal: two new stream-wrappers
Drupal 7x Installation - Introduction to Drupal Concepts
Cms drupal installation & configuration anil mishra
DrupalCampLA 2011 - Drupal frontend-optimizing
Drupal development environment
Drupal performance optimization Best Practices
Best Practices For Drupal Developers By Mir Nazim @ Drupal Camp India 2008
Drupal Installation &amp; Configuration
04 web optimization
Drupal 6 Performance Tips
Speeding Up The Snail
How to reduce database load using Memcache
Django Documentation
Web profiler in drupal 8
PHP Summer Training Presentation
Implementing High Performance Drupal Sites
WordPress Structure and Best Practices
Learn How To Develop With CakePHP
Practical catalyst
Performance Optimization in Drupal 8
Drupal feature proposal: two new stream-wrappers
Ad

Viewers also liked (6)

PDF
Phalcon - самый быстрый PHP Framework
PPTX
Drupal 8 и хостинг
PDF
Debugging in PHP
PDF
Если не Drupal 8, то что? Обзор Laravel 5
PDF
Headless Drupal на примере Drupal 8 и React
PDF
Why I Hate Drupal
Phalcon - самый быстрый PHP Framework
Drupal 8 и хостинг
Debugging in PHP
Если не Drupal 8, то что? Обзор Laravel 5
Headless Drupal на примере Drupal 8 и React
Why I Hate Drupal
Ad

Similar to Debugging Drupal - How to Debug your Drupal Application (20)

PDF
Modernize Your Drupal Development
PDF
Become a Better Developer with Debugging Techniques for Drupal (and more!)
PDF
Debugging Drupal with Xdebug
ODP
Debugging With Php
PDF
Open Source CMS Certification
PPTX
Debugging Effectively - SymfonyLive San Francisco 2015
PPTX
Xdebug
PDF
Сontinuous Integration - step to continuous deployment
PPTX
Debugging Effectively
PPT
Contributing to Drupal
PPTX
DDD (Debugger Driven Development)
PDF
Why Drupal is Rockstar?
PDF
Debugging PHP with xDebug inside of Eclipse PDT 2.1
PPTX
Debugging Effectively - php[world] 2015
PDF
Debugging PHP with Xdebug - PHPUK 2018
PDF
Drupal Auckland Meetup; Debug like a pro
PDF
Debugging PHP With Xdebug
PPTX
Debugging Effectively - Frederick Web Tech 9/6/16
ZIP
Voiture tech talk
PPTX
Debugging Effectively - ConFoo Montreal 2019
Modernize Your Drupal Development
Become a Better Developer with Debugging Techniques for Drupal (and more!)
Debugging Drupal with Xdebug
Debugging With Php
Open Source CMS Certification
Debugging Effectively - SymfonyLive San Francisco 2015
Xdebug
Сontinuous Integration - step to continuous deployment
Debugging Effectively
Contributing to Drupal
DDD (Debugger Driven Development)
Why Drupal is Rockstar?
Debugging PHP with xDebug inside of Eclipse PDT 2.1
Debugging Effectively - php[world] 2015
Debugging PHP with Xdebug - PHPUK 2018
Drupal Auckland Meetup; Debug like a pro
Debugging PHP With Xdebug
Debugging Effectively - Frederick Web Tech 9/6/16
Voiture tech talk
Debugging Effectively - ConFoo Montreal 2019

More from Zyxware Technologies (19)

PDF
Google Docs - Leverage the power of collaboration with shared documents
PDF
CETAA Vision 2025 - Making CETAA the best alumni association in India
PDF
Learn Drupal 8 Render Pipeline
PDF
Come, build your career at Zyxware Technologies
PDF
Personalized customer experience using ecommerce portal
PDF
Web Application Performance Audit and Optimization
PDF
Drupal is taking over Australia
PDF
Setting in place a product development strategy
PDF
Drupal Performance Audit and Optimization
PDF
Drupal as a Rapid Application Development Framework for Non Profits / NGOs
PDF
An introduction to cyber forensics and open source tools in cyber forensics
PDF
Exploring Wider Collaboration Mechanisms in the Drupal Space
PDF
The art of communication - managing digital communication
PDF
Code quality - aesthetics & functionality of writing beautiful code
PDF
Drupal ecosystem in India and Drupal's market potential in India
PDF
Drupal as a Rapid Application Development (RAD) Framework for Startups
ODP
Collaborative development using git, Session conducted at Model Engineering C...
PDF
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
PDF
ICFOSS Interaction with Small and Medium Enterprises on IT Enabling SMEs with...
Google Docs - Leverage the power of collaboration with shared documents
CETAA Vision 2025 - Making CETAA the best alumni association in India
Learn Drupal 8 Render Pipeline
Come, build your career at Zyxware Technologies
Personalized customer experience using ecommerce portal
Web Application Performance Audit and Optimization
Drupal is taking over Australia
Setting in place a product development strategy
Drupal Performance Audit and Optimization
Drupal as a Rapid Application Development Framework for Non Profits / NGOs
An introduction to cyber forensics and open source tools in cyber forensics
Exploring Wider Collaboration Mechanisms in the Drupal Space
The art of communication - managing digital communication
Code quality - aesthetics & functionality of writing beautiful code
Drupal ecosystem in India and Drupal's market potential in India
Drupal as a Rapid Application Development (RAD) Framework for Startups
Collaborative development using git, Session conducted at Model Engineering C...
Introduction to Bash Scripting, Zyxware Technologies, CSI Students Convention...
ICFOSS Interaction with Small and Medium Enterprises on IT Enabling SMEs with...

Recently uploaded (20)

PPTX
Cloud computing and distributed systems.
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Approach and Philosophy of On baking technology
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
KodekX | Application Modernization Development
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Electronic commerce courselecture one. Pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Big Data Technologies - Introduction.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Cloud computing and distributed systems.
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Spectral efficient network and resource selection model in 5G networks
Network Security Unit 5.pdf for BCA BBA.
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Approach and Philosophy of On baking technology
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Per capita expenditure prediction using model stacking based on satellite ima...
KodekX | Application Modernization Development
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Electronic commerce courselecture one. Pdf
Understanding_Digital_Forensics_Presentation.pptx
Big Data Technologies - Introduction.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
NewMind AI Weekly Chronicles - August'25 Week I
The AUB Centre for AI in Media Proposal.docx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf

Debugging Drupal - How to Debug your Drupal Application

  • 1. Debugging with Drupal The art of Debugging Anoop John, CTO Vimal Joseph, Technical Architect
  • 2. The Art of Debugging Bugs everywhere... SA-CORE-2014-005
  • 3. The Art of Debugging Bug-free Software?
  • 4. The Art of Debugging Debugging It's hard enough to find an error in your code when you're looking for it; it's even harder when you've assumed your code is error-free. Steve McConnel
  • 5. The Art of Debugging Story Time Tell us a story on your debugging experience
  • 6. The Art of Debugging Set up Debugging Environment PHP configuration (php.ini) display_errors = On log_errors = On error_reporting = E_ALL | E_STRICT Drupal modules Devel A good editor Geany Emacs is better – but learning curve is bit steep. Learn to setup a development environment for a given project quickly. Drush will help.
  • 7. The Art of Debugging Debugging Tools - PHP Basic PHP print/echo print_r() exit()/die() debug_backtrace()/debug_print_backtrace()
  • 8. The Art of Debugging Debugging Tools - Drupal drupal_set_message() watchdog() Views views_trace() Devel dpm() dargs() dd() ddebug_backtrace() db_queryd()
  • 9. The Art of Debugging Debugging Tools - HTML, JS, CSS Firebug Web Developer Toolbar Javascript debugger
  • 10. The Art of Debugging Debugging Tools - CLI Drush – a life saver. archive-dump, archive-restore, vget, vset, php- eval, sql-cli, sql-query, user-login etc.. Xdebug cat, grep, awk, cut
  • 11. The Art of Debugging General Approach for Debugging Understand the symptom Understand the context Define problem statement Replicate bug Read through code Isolate location in code causing bug Understand code Understand data / context Understand cause Identify solution Fix bug
  • 12. The Art of Debugging Tips for Debugging Code Trial and error may work – but do not rely on that Binary search is the best method to isolate a bug Learn to navigate through code Learn to read logs Webserver Access/Error logs Database Error logs Drupal error logs Be familiar with the shell commands cat, zcat, grep, less etc..
  • 13. The Art of Debugging Errors, Notices, Warnings Warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() (line 1566 of /var/www/d7/includes/bootstrap.inc). Invalid argument supplied for foreach() in /var/www/d7/includes/common.inc on line 1919. Illegal offset type in isset or empty in /home/pgil1/public_html/modules/taxon omy/taxonomy.module on line 1090.
  • 14. The Art of Debugging Backtrace – your guide views_trace debug_backtrace debug_print_backtrace ddebug_backtrace
  • 15. The Art of Debugging Tips for Debugging Code // function drupal_set_message() bootstrap.inc if ($type == 'error') { // here are some alternatives – views_trace() // is part of views module // $message .= '<pre>' . print_r(debug_backtrace(), TRUE) . '</pre>'; // $message .= '<pre>' . views_trace() . '</pre>'; } // Or in function watchdog() bootstrap.inc if ($type == 'php') { $message .= '<pre>'. print_r(debug_backtrace(), 1) .'</pre>'; //$message .= '<pre>'. views_trace() .'</pre>'; } // Or in the function which error occurred ddebug_backtrace(); or dpm() or print_r() //make sure to add the necessary conditions so that the debug
  • 16. The Art of Debugging Tips for Debugging Code // Debuging cron // module_invoke() module.inc if ($hook == 'cron') { watchdog('debugging', "CRON: Calling $module"); } // Errors like “Cannot use object of type stdClass as array” // Insert right before the moment of disaster if (!is_array($x)) { dpm(ddebug_backtrace(TRUE)); }
  • 17. The Art of Debugging Tips for Debugging HTML, CSS, JS Inspect using Firebug Create test HTML Set custom properties Walk through JS code execution Inspect variables
  • 18. Zyxware Technologies and Drupal Zyxware is a leading contributor to Drupal from India and is one of only six Featured Service Providers from India listed on drupal.org ● Over 40,000 websites use our modules and themes ● More than 30 contributed modules and themes ● Maintainer of Search404, a top 100 Drupal module ● Over 1000 commits at drupal.org ● Contributes all patches back to Drupal ● Our profile on drupal.org - http://drupal.org/user/222163 ● Knowledge partnerships with Acquia, New Relic and Volacci
  • 19. ● Freedom Walk, a 44 day walk by a team of Free Software Evangelists across the length of Kerala to promote Free Software ● Building RithuOS, an Operating System for Engineering students with Free Software Engineering applications ● GNU/Linux Install Fests in Schools, Colleges and at Technopark. ● Local language (Malayalam) computing camps in colleges ● Building and Maintenance of Freedom Toaster, a Free Software kiosk ● Conducting Free Software workshops and lectures in colleges in Kerala Free Software and Zyxware Technologies
  • 20. • Check us out at http://www.zyxware.com • Mail us at drupal@zyxware.com • Like us at http://www.facebook.com/zyxware • Follow us at http://www.twitter.com/zyxware • Connect with us at http://www.linkedin.com/companies/zyxware-technologies • Talk to us at +91-9495969446 between 9AM - 9PM IST • Skype me at aj_zyxware Contact Us
  • 21. The Art of Debugging Thank you …
  • 22. The Art of Debugging Credits http://randyfay.com/content/debugging-techniques http://www.lullabot.com/articles/quick_and_dirty_de bugging